Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load_unit(self, unit_id):
"""Loads the image data for display."""
skip_subject = False
self.images = dict()
for img_name in self.image_names:
ipath = realpath(pjoin(self.in_dir, unit_id, img_name))
img_data = read_image(ipath, error_msg=img_name)
if np.count_nonzero(img_data) == 0:
skip_subject = True
print('image {} is empty!'.format(img_name, self.current_unit_id))
self.images[img_name] = scale_0to1(img_data)
if not skip_subject:
# TODO implement crop to extents for more than 2 images
# self.image_one, self.image_two = crop_to_seg_extents(self.image_one,
# self.image_two,
# self.padding)
self.slices = pick_slices(self.images[self.image_names[0]], # first img
self.views, self.num_slices_per_view)
# # where to save the visualization to
# out_vis_path = pjoin(self.out_dir, 'visual_qc_{}_{}'.format(
# self.vis_type, unit_id))
return skip_subject
parser.exit(1)
# parsing
try:
user_args = parser.parse_args()
except:
parser.exit(1)
vis_type = 'defacing'
user_dir, id_list, images_for_id, defaced_name, mri_name, render_name \
= check_inputs_defacing(user_args.user_dir, user_args.defaced_name,
user_args.mri_name, user_args.render_name,
user_args.id_list)
out_dir = check_out_dir(user_args.out_dir, user_dir)
wf = RatingWorkflowDefacing(id_list, images_for_id, user_dir, out_dir,
defaced_name, mri_name, render_name,
cfg.defacing_default_issue_list, vis_type)
return wf
# parsing
try:
user_args = parser.parse_args()
except:
parser.exit(1)
vis_type, label_set, label_map = check_labels(user_args.vis_type, user_args.label_set)
in_dir, source_of_features = check_input_dir(user_args.fs_dir, None, vis_type,
freesurfer_install_required=False)
mri_name = user_args.mri_name
seg_name = user_args.seg_name
id_list, images_for_id = check_id_list(user_args.id_list, in_dir, vis_type, mri_name,
seg_name)
out_dir = check_out_dir(user_args.out_dir, in_dir)
alpha_set = check_alpha_set(user_args.alpha_set)
views = check_views(user_args.views)
num_slices, num_rows = check_finite_int(user_args.num_slices, user_args.num_rows)
contour_color = user_args.contour_color
if not is_color_like(contour_color):
raise ValueError('Specified color is not valid. Choose a valid spec from\n'
' https://matplotlib.org/users/colors.html')
outlier_method, outlier_fraction, outlier_feat_types, disable_outlier_detection = \
check_outlier_params(user_args.outlier_method, user_args.outlier_fraction,
user_args.outlier_feat_types,
user_args.disable_outlier_detection,
id_list, vis_type, source_of_features)
parser.exit(1)
# parsing
try:
user_args = parser.parse_args()
except:
parser.exit(1)
vis_type = 'collage_t1_mri'
type_of_features = 't1_mri'
in_dir, in_dir_type = check_input_dir_T1w(user_args.fs_dir, user_args.user_dir, user_args.bids_dir)
mri_name = user_args.mri_name
id_list = check_id_list_T1w(in_dir, in_dir_type, user_args.id_list, mri_name, vis_type)
out_dir = check_out_dir(user_args.out_dir, in_dir)
views = check_views(user_args.views)
num_slices_per_view, num_rows_per_view = check_finite_int(user_args.num_slices,
user_args.num_rows)
outlier_method, outlier_fraction, \
outlier_feat_types, disable_outlier_detection = check_outlier_params(
user_args.outlier_method,
user_args.outlier_fraction,
user_args.outlier_feat_types,
user_args.disable_outlier_detection,
id_list, vis_type, type_of_features)
wf = RatingWorkflowT1(id_list, in_dir, out_dir,
cfg.t1_mri_default_issue_list,
mri_name, in_dir_type,
try:
user_args = parser.parse_args()
except:
parser.exit(1)
# TODO methods to restore from previous runs, without having re-enter all parameters
vis_type, label_set = check_labels(user_args.vis_type, user_args.labels)
in_dir = check_input_dir(user_args.fs_dir, user_args.user_dir, vis_type)
mri_name = user_args.mri_name
seg_name = user_args.seg_name
id_list, images_for_id = check_id_list(user_args.id_list, in_dir, vis_type, mri_name, seg_name)
out_dir = check_out_dir(user_args.out_dir, in_dir)
alpha_set = check_alpha_set(user_args.alpha_set)
views = check_views(user_args.views)
num_slices, num_rows = check_finite_int(user_args.num_slices, user_args.num_rows)
contour_color = user_args.contour_color
if not is_color_like(contour_color):
raise ValueError(
'Specified color is not valid. Choose a valid spec from\n https://matplotlib.org/users/colors.html')
outlier_method, outlier_fraction, outlier_feat_types, no_outlier_detection = check_outlier_params(user_args.outlier_method,
user_args.outlier_fraction,
user_args.outlier_feat_types,
user_args.disable_outlier_detection,
user_args = parser.parse_args()
except:
parser.exit(1)
vis_type = cfg.alignment_default_vis_type
type_of_features = 'alignment'
in_dir, in_dir_type = check_input_dir_quantitative_MR(user_args.in_dir)
image_names = user_args.image_names
id_list, images_for_id = check_id_list_quantitative(user_args.id_list, in_dir,
image_names,
in_dir_type=in_dir_type)
delay_in_animation = check_time(user_args.delay_in_animation, var_name='Delay')
out_dir = check_out_dir(user_args.out_dir, in_dir)
views = check_views(user_args.views)
num_slices_per_view, num_rows_per_view = check_finite_int(user_args.num_slices,
user_args.num_rows)
wf = QuantitativeMrRatingWorkflow(id_list,
in_dir,
image_names,
out_dir=out_dir,
in_dir_type=in_dir_type,
prepare_first=user_args.prepare_first,
delay_in_animation=delay_in_animation,
views=views,
num_slices_per_view=num_slices_per_view,
num_rows_per_view=num_rows_per_view)
return wf
user_args = parser.parse_args()
except:
parser.exit(1)
vis_type = cfg.alignment_default_vis_type
type_of_features = 'alignment'
in_dir, in_dir_type = check_input_dir_alignment(user_args.in_dir)
image1 = user_args.image1
image2 = user_args.image2
id_list, images_for_id = check_id_list(user_args.id_list, in_dir, vis_type,
image1, image2, in_dir_type=in_dir_type)
delay_in_animation = check_time(user_args.delay_in_animation, var_name='Delay')
out_dir = check_out_dir(user_args.out_dir, in_dir)
views = check_views(user_args.views)
num_slices_per_view, num_rows_per_view = check_finite_int(user_args.num_slices,
user_args.num_rows)
outlier_method, outlier_fraction, \
outlier_feat_types, disable_outlier_detection = check_outlier_params(
user_args.outlier_method,
user_args.outlier_fraction,
user_args.outlier_feat_types,
user_args.disable_outlier_detection,
id_list, vis_type, type_of_features)
wf = AlignmentRatingWorkflow(id_list,
in_dir,
image1,
image2,
try:
user_args = parser.parse_args()
except:
parser.exit(1)
vis_type = 'collage_t1_mri'
type_of_features = 't1_mri'
in_dir, in_dir_type = check_input_dir_T1w(user_args.fs_dir, user_args.user_dir, user_args.bids_dir)
mri_name = user_args.mri_name
id_list = check_id_list_T1w(in_dir, in_dir_type, user_args.id_list, mri_name, vis_type)
out_dir = check_out_dir(user_args.out_dir, in_dir)
views = check_views(user_args.views)
num_slices_per_view, num_rows_per_view = check_finite_int(user_args.num_slices,
user_args.num_rows)
outlier_method, outlier_fraction, \
outlier_feat_types, disable_outlier_detection = check_outlier_params(
user_args.outlier_method,
user_args.outlier_fraction,
user_args.outlier_feat_types,
user_args.disable_outlier_detection,
id_list, vis_type, type_of_features)
wf = RatingWorkflowT1(id_list, in_dir, out_dir,
cfg.t1_mri_default_issue_list,
mri_name, in_dir_type,
outlier_method, outlier_fraction,
outlier_feat_types, disable_outlier_detection,
user_args.prepare_first,
parser.exit(1)
vis_type, label_set, label_map = check_labels(user_args.vis_type, user_args.label_set)
in_dir, source_of_features = check_input_dir(user_args.fs_dir, None, vis_type,
freesurfer_install_required=False)
mri_name = user_args.mri_name
seg_name = user_args.seg_name
id_list, images_for_id = check_id_list(user_args.id_list, in_dir, vis_type, mri_name,
seg_name)
out_dir = check_out_dir(user_args.out_dir, in_dir)
alpha_set = check_alpha_set(user_args.alpha_set)
views = check_views(user_args.views)
num_slices, num_rows = check_finite_int(user_args.num_slices, user_args.num_rows)
contour_color = user_args.contour_color
if not is_color_like(contour_color):
raise ValueError('Specified color is not valid. Choose a valid spec from\n'
' https://matplotlib.org/users/colors.html')
outlier_method, outlier_fraction, outlier_feat_types, disable_outlier_detection = \
check_outlier_params(user_args.outlier_method, user_args.outlier_fraction,
user_args.outlier_feat_types,
user_args.disable_outlier_detection,
id_list, vis_type, source_of_features)
wf = FreesurferRatingWorkflow(id_list,
images_for_id,
in_dir,
out_dir,
parser.exit(1)
vis_type = cfg.alignment_default_vis_type
type_of_features = 'alignment'
in_dir, in_dir_type = check_input_dir_quantitative_MR(user_args.in_dir)
image_names = user_args.image_names
id_list, images_for_id = check_id_list_quantitative(user_args.id_list, in_dir,
image_names,
in_dir_type=in_dir_type)
delay_in_animation = check_time(user_args.delay_in_animation, var_name='Delay')
out_dir = check_out_dir(user_args.out_dir, in_dir)
views = check_views(user_args.views)
num_slices_per_view, num_rows_per_view = check_finite_int(user_args.num_slices,
user_args.num_rows)
wf = QuantitativeMrRatingWorkflow(id_list,
in_dir,
image_names,
out_dir=out_dir,
in_dir_type=in_dir_type,
prepare_first=user_args.prepare_first,
delay_in_animation=delay_in_animation,
views=views,
num_slices_per_view=num_slices_per_view,
num_rows_per_view=num_rows_per_view)
return wf