From 3cc431e4dda003fae5b1bdad0c89b394e5c24c93 Mon Sep 17 00:00:00 2001 From: Arnaud Breheret Date: Thu, 27 Jun 2024 11:38:01 -0400 Subject: [PATCH] Add test for signal loss optimization --- .../tabs/b0shim_tab.py | 2 +- installer/install_shimming_toolbox.sh | 2 +- test/gui/test_b0shim_tab.py | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/fsleyes_plugin_shimming_toolbox/tabs/b0shim_tab.py b/fsleyes_plugin_shimming_toolbox/tabs/b0shim_tab.py index c99bdaa..619eb17 100644 --- a/fsleyes_plugin_shimming_toolbox/tabs/b0shim_tab.py +++ b/fsleyes_plugin_shimming_toolbox/tabs/b0shim_tab.py @@ -281,7 +281,7 @@ def create_sizer_dynamic_shim(self, metadata=None): weighting_signal_loss_metadata = [ { - "button_label": "weighting signal loss", + "button_label": "Weighting signal loss", "name": "weighting-signal-loss", "default_text": "0.01", }, diff --git a/installer/install_shimming_toolbox.sh b/installer/install_shimming_toolbox.sh index ec9f12d..745099a 100644 --- a/installer/install_shimming_toolbox.sh +++ b/installer/install_shimming_toolbox.sh @@ -14,7 +14,7 @@ rm -rf "${ST_DIR}/shimming-toolbox" print info "Downloading Shimming-Toolbox" -ST_VERSION="e136db64e0cf9110adf321a1adc957453009f475" +ST_VERSION="420905677bf624228e2e1088d842178de1f30196" curl -L "https://github.com/shimming-toolbox/shimming-toolbox/archive/${ST_VERSION}.zip" > "shimming-toolbox-${ST_VERSION}.zip" diff --git a/test/gui/test_b0shim_tab.py b/test/gui/test_b0shim_tab.py index 773d464..7c0f099 100644 --- a/test/gui/test_b0shim_tab.py +++ b/test/gui/test_b0shim_tab.py @@ -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', @@ -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')