Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _animate_through_gradients(self):
"""Show image 1, wait, show image 2"""
# fixing the same slices for all gradients
slices = pick_slices(self.b0_volume, self.views, self.num_slices_per_view)
for grad_idx in range(self.num_gradients):
self.show_3dimage(self.dw_volumes[:, :, :, grad_idx].squeeze(),
slices=slices, annot='gradient {}'.format(grad_idx))
plt.pause(0.05)
time.sleep(self.delay_in_animation)
def attach_image_to_foreground_axes(self, image3d, cmap='gray'):
"""Attaches a given image to the foreground axes and bring it forth"""
image3d = crop_image(image3d, self.padding)
image3d = scale_0to1(image3d)
slices = pick_slices(image3d, self.views, self.num_slices_per_view)
for ax_index, (dim_index, slice_index) in enumerate(slices):
slice_data = get_axis(image3d, dim_index, slice_index)
self.images_fg[ax_index].set(data=slice_data, cmap=cmap)
for ax in self.fg_axes:
ax.set(visible=True, zorder=self.layer_order_zoomedin)
def overlay_dwi_edges(self):
# not cropping to help checking align in full FOV
overlaid = scale_0to1(self.b0_volume)
base_img = scale_0to1(self.dw_volumes[..., self.current_grad_index].squeeze())
slices = pick_slices(base_img, self.views, self.num_slices_per_view)
for ax_index, (dim_index, slice_index) in enumerate(slices):
mixed = dwi_overlay_edges(get_axis(base_img, dim_index, slice_index),
get_axis(overlaid, dim_index, slice_index))
self.images_fg[ax_index].set(data=mixed)
self.images_fg_label[ax_index].set_text(str(slice_index))
# the following needs to be done outside show_image3d, as we need custom mixing
self._set_backgrounds_visibility(False)
self._set_foregrounds_visibility(True)
self._identify_foreground('Alignment check to b=0, '
'grad index {}'.format(self.current_grad_index))
num_rows_per_view, num_slices_per_view, padding = check_params(qcw.num_rows, qcw.num_slices, padding)
mri, seg = crop_to_seg_extents(mri, seg, padding)
surf_vis = dict() # empty - no vis to include
# TODO broaden this to include subcortical structures as well
if 'cortical' in qcw.vis_type:
if qcw.in_dir is not None and subject_id is not None and qcw.out_dir is not None:
surf_vis = make_vis_pial_surface(qcw.in_dir, subject_id, qcw.out_dir)
num_surf_vis = len(surf_vis)
# TODO calculation below is redundant, if surf vis does not fail
# i.e. if num_surf_vis is fixed, no need to recompute for every subject
num_views = len(qcw.views)
num_rows = num_rows_per_view * num_views
slices = pick_slices(seg, qcw.views, num_slices_per_view)
num_volumetric_slices = len(slices)
total_num_panels = num_volumetric_slices + num_surf_vis
num_rows_for_surf_vis = 1 if num_surf_vis > 0 else 0
num_rows = num_rows + num_rows_for_surf_vis
num_cols = check_layout(total_num_panels, num_views, num_rows_per_view, num_rows_for_surf_vis)
plt.style.use('dark_background')
if figsize is None:
# figsize = [min(15,4*num_rows), min(12,4*num_cols)] # max (15,12)
figsize = [4 * num_rows, 2* num_cols]
fig, ax = plt.subplots(num_rows, num_cols, figsize=figsize)
display_params_mri = dict(interpolation='none', aspect='equal', origin='lower',
alpha=qcw.alpha_mri)
display_params_seg = dict(interpolation='none', aspect='equal', origin='lower',
if 'cortical' in self.vis_type:
if not self.no_surface_vis and self.current_unit_id in self.surface_vis_paths:
surf_paths = self.surface_vis_paths[self.current_unit_id] # is a dict of paths
for sf_ax_index, ((hemi, view), spath) in enumerate(surf_paths.items()):
plt.sca(self.axes[sf_ax_index])
img = mpimg.imread(spath)
# img = crop_image(img)
h_surf = plt.imshow(img)
self.axes[sf_ax_index].text(0, 0, '{} {}'.format(hemi, view))
self.UI.data_handles.append(h_surf)
else:
msg = 'no surface visualizations\navailable or disabled'
print('{} for {}'.format(msg, self.current_unit_id))
self.axes[1].text(0.5, 0.5, msg)
slices = pick_slices(self.current_seg, self.views, self.num_slices_per_view)
for vol_ax_index, (dim_index, slice_index) in enumerate(slices):
panel_index = self.volumetric_start_index + vol_ax_index
plt.sca(self.axes[panel_index])
slice_mri = get_axis(self.current_t1_mri, dim_index, slice_index)
slice_seg = get_axis(self.current_seg, dim_index, slice_index)
mri_rgba = self.mri_mapper.to_rgba(slice_mri, alpha=self.alpha_mri)
# self.h_images_mri[ax_index].set_data(mri_rgb)
h_m = plt.imshow(mri_rgba, interpolation='none',
aspect='equal', origin='lower')
self.UI.data_handles.append(h_m)
if 'volumetric' in self.vis_type:
seg_rgba = self.seg_mapper.to_rgba(slice_seg, alpha=self.alpha_seg)
# self.h_images_seg[ax_index].set_data(seg_rgb)
h_seg = plt.imshow(seg_rgba, interpolation='none',