Skip to content

Commit

Permalink
Fixed the bug in plot_coefs + changes in calc_shimmed_anat_orient
Browse files Browse the repository at this point in the history
make sure that the program doesn't crash if the slices dimension is different than 1
  • Loading branch information
Aurelienpujolm committed Dec 14, 2022
1 parent 0993d52 commit ab5e5e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
5 changes: 2 additions & 3 deletions shimmingtoolbox/cli/b0shim.py
Expand Up @@ -1031,15 +1031,14 @@ def _plot_coefs(coil, slices, static_coefs, path_output, coil_number, rt_coefs=N
temp_max = np.array(static_coefs).max()
if max_y is None or max_y < temp_max:
max_y = np.array(static_coefs).max()
nb_slices = 0
for nb_slices, i_shim in enumerate(shimmed_slice):
i_slice = slices[i_shim]
_add_sub_figure(i_shim, fig, number_slices_shimmed, nb_slices, rt_coefs, pres_probe_min,
_add_sub_figure(i_shim, fig, number_slices_shimmed, nb_slices+1, rt_coefs, pres_probe_min,
pres_probe_max, bounds, min_y, max_y,
units, static_coefs, i_slice)
# Print a subplot for all the non shimmed slices
nb_slices = nb_slices + 1
_add_sub_figure(last_i, fig, number_slices_shimmed, nb_slices, rt_coefs, pres_probe_min,
_add_sub_figure(last_i, fig, number_slices_shimmed, nb_slices+1, rt_coefs, pres_probe_min,
pres_probe_max, bounds, min_y, max_y,
units, static_coefs, list_slice_wo_shimmed)
# Save the figure
Expand Down
11 changes: 4 additions & 7 deletions shimmingtoolbox/shim/sequencer.py
Expand Up @@ -281,14 +281,11 @@ def _cal_shimmed_anat_orient(coefs, coils, nii_mask_anat, nii_fieldmap, slices,
mode='grid-constant',
cval=0).get_fdata()
shimmed_anat_orient = fieldmap_anat
nb_channel = np.shape(coefs)[1]
dimx = np.shape(coils_anat)[0]
dimy = np.shape(coils_anat)[1]

for i_shim in list_shim_slice:
# We want to do the np.sum with a 2D matrix so that it is faster
coils_anat_reduced = np.reshape(coils_anat[:, :, slices[i_shim], :], (-1, nb_channel))
corr = np.sum(coefs[i_shim] * coils_anat_reduced, axis=1, keepdims=False)
shimmed_anat_orient[..., slices[i_shim]] += np.reshape(corr, (dimx, dimy, 1))
# We want to do the np.sum with a 3D matrix if possible
corr = np.sum(coefs[i_shim] * coils_anat[:,:, slices[i_shim], :], axis=3, keepdims=False)
shimmed_anat_orient[..., slices[i_shim]] += corr
fname_shimmed_anat_orient = os.path.join(path_output, 'fig_shimmed_anat_orient.nii.gz')
nii_shimmed_anat_orient = nib.Nifti1Image(shimmed_anat_orient * nii_mask_anat.get_fdata(), nii_mask_anat.affine,
header=nii_mask_anat.header)
Expand Down

0 comments on commit ab5e5e9

Please sign in to comment.