Skip to content

Commit

Permalink
Ab/signal recovery (#70)
Browse files Browse the repository at this point in the history
* Add grad optimizer and change sequential ordering

* Add test for signal loss optimization

* Change to updated commmit on ST
  • Loading branch information
4rnaudB authored Jun 27, 2024
1 parent c580658 commit 6d1d777
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
39 changes: 31 additions & 8 deletions fsleyes_plugin_shimming_toolbox/tabs/b0shim_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def create_sizer_dynamic_shim(self, metadata=None):
},
]
component_slice_int = InputComponent(self, input_text_box_metadata_slice, cli=dynamic_cli)
component_slice_seq = InputComponent(self, input_text_box_metadata_slice, cli=dynamic_cli)
component_slice_asc = InputComponent(self, input_text_box_metadata_slice, cli=dynamic_cli)
component_slice_des = InputComponent(self, input_text_box_metadata_slice, cli=dynamic_cli)

output_metadata = [
{
Expand Down Expand Up @@ -277,7 +278,16 @@ def create_sizer_dynamic_shim(self, metadata=None):
]
component_reg_factor_lsq = InputComponent(self, reg_factor_metadata, cli=dynamic_cli)
component_reg_factor_qp = InputComponent(self, reg_factor_metadata, cli=dynamic_cli)


weighting_signal_loss_metadata = [
{
"button_label": "Weighting signal loss",
"name": "weighting-signal-loss",
"default_text": "0.01",
},
]
component_slice_w_sig_loss = InputComponent(self, weighting_signal_loss_metadata, cli=dynamic_cli)

criteria_dropdown_metadata = [
{
"label": "Mean Squared Error",
Expand All @@ -290,15 +300,23 @@ def create_sizer_dynamic_shim(self, metadata=None):
{
"label": "Root Mean Squared Error",
"option_value": "rmse",
},
{
"label": "Mean Squared Error + Z gradient",
"option_value": "grad",
}
]
]

dropdown_crit = DropdownComponent(
panel=self,
dropdown_metadata=criteria_dropdown_metadata,
label="Optimizer Criteria",
option_name='optimizer-criteria',
cli=dynamic_cli
cli=dynamic_cli,
list_components=[self.create_empty_component(),
self.create_empty_component(),
self.create_empty_component(),
component_slice_w_sig_loss]
)

dropdown_opt_metadata = [
Expand Down Expand Up @@ -335,8 +353,12 @@ def create_sizer_dynamic_shim(self, metadata=None):
"option_value": "auto"
},
{
"label": "Sequential",
"option_value": "sequential"
"label": "Ascending",
"option_value": "ascending"
},
{
"label": "Descending",
"option_value": "descending"
},
{
"label": "Interleaved",
Expand All @@ -345,7 +367,7 @@ def create_sizer_dynamic_shim(self, metadata=None):
{
"label": "Volume",
"option_value": "volume"
},
}
]

self.dropdown_slice_dyn = DropdownComponent(
Expand All @@ -355,7 +377,8 @@ def create_sizer_dynamic_shim(self, metadata=None):
cli=dynamic_cli,
option_name='slices',
list_components=[self.create_empty_component(),
component_slice_seq,
component_slice_asc,
component_slice_des,
component_slice_int,
self.create_empty_component()]
)
Expand Down
2 changes: 1 addition & 1 deletion installer/install_shimming_toolbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rm -rf "${ST_DIR}/shimming-toolbox"

print info "Downloading Shimming-Toolbox"

ST_VERSION="cf28d353240fd510de1e8aa492c6c23ae57e66bd"
ST_VERSION="cb579afefb8ac742909e5d706a85c2c6dc091274"

curl -L "https://github.com/shimming-toolbox/shimming-toolbox/archive/${ST_VERSION}.zip" > "shimming-toolbox-${ST_VERSION}.zip"

Expand Down
23 changes: 23 additions & 0 deletions test/gui/test_b0shim_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ def _test_st_plugin_b0shim_dyn(view, overlayList, displayCtx, options=options):


def test_st_plugin_b0shim_dyn_lsq_mae():
options = {'optimizer-method': 'Least Squares',
'optimizer-criteria': 'Mean Squared Error + Z gradient',
'weighting-signal-loss': '0.01',
'slices': 'Auto detect',
'scanner-coil-order': '1',
'output-file-format-scanner': 'Slicewise per Channel',
'output-file-format-coil': 'Slicewise per Channel',
'output-value-format': 'delta'
}

def _test_st_plugin_b0shim_dyn(view, overlayList, displayCtx, options=options):
__test_st_plugin_b0shim_dyn(view, overlayList, displayCtx, options=options)
run_with_orthopanel(_test_st_plugin_b0shim_dyn)


def test_st_plugin_b0shim_dyn_lsq_grad():
options = {'optimizer-method': 'Least Squares',
'optimizer-criteria': 'Mean Absolute Error',
'slices': 'Auto detect',
Expand Down Expand Up @@ -106,6 +122,13 @@ def __test_st_plugin_b0shim_dyn(view, overlayList, displayCtx, options):

with tempfile.TemporaryDirectory(prefix='st_' + pathlib.Path(__file__).stem) as tmp:
nii_fmap, nii_anat, nii_mask, nii_coil, fm_data, anat_data, coil_data, _ = _define_inputs(fmap_dim=3)

# Duplicate nii_fmap's last dimension
if 'weighting-signal-loss' in options.keys():
fmap = nii_fmap.get_fdata()
fmap = np.repeat(fmap, 5, axis=2)
nii_fmap = nib.Nifti1Image(fmap, nii_fmap.affine, header=nii_fmap.header)

fname_fmap = os.path.join(tmp, 'fmap.nii.gz')
fname_fm_json = os.path.join(tmp, 'fmap.json')
fname_mask = os.path.join(tmp, 'mask.nii.gz')
Expand Down

0 comments on commit 6d1d777

Please sign in to comment.