From e81919e75d446cff9c3134b5e62390b4e63bd4ed Mon Sep 17 00:00:00 2001 From: Arnaud Breheret Date: Wed, 26 Jun 2024 17:18:43 -0400 Subject: [PATCH 1/3] Add grad optimizer and change sequential ordering --- .../tabs/b0shim_tab.py | 39 +++++++++++++++---- installer/install_shimming_toolbox.sh | 2 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/fsleyes_plugin_shimming_toolbox/tabs/b0shim_tab.py b/fsleyes_plugin_shimming_toolbox/tabs/b0shim_tab.py index 4e7d6b8..c99bdaa 100644 --- a/fsleyes_plugin_shimming_toolbox/tabs/b0shim_tab.py +++ b/fsleyes_plugin_shimming_toolbox/tabs/b0shim_tab.py @@ -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 = [ { @@ -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", @@ -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 = [ @@ -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", @@ -345,7 +367,7 @@ def create_sizer_dynamic_shim(self, metadata=None): { "label": "Volume", "option_value": "volume" - }, + } ] self.dropdown_slice_dyn = DropdownComponent( @@ -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()] ) diff --git a/installer/install_shimming_toolbox.sh b/installer/install_shimming_toolbox.sh index 10b39f2..ec9f12d 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="cf28d353240fd510de1e8aa492c6c23ae57e66bd" +ST_VERSION="e136db64e0cf9110adf321a1adc957453009f475" curl -L "https://github.com/shimming-toolbox/shimming-toolbox/archive/${ST_VERSION}.zip" > "shimming-toolbox-${ST_VERSION}.zip" From 3cc431e4dda003fae5b1bdad0c89b394e5c24c93 Mon Sep 17 00:00:00 2001 From: Arnaud Breheret Date: Thu, 27 Jun 2024 11:38:01 -0400 Subject: [PATCH 2/3] 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') From 7b42616140a377fc62e4a3cba1d46a2a10edb403 Mon Sep 17 00:00:00 2001 From: Arnaud Breheret Date: Thu, 27 Jun 2024 14:10:05 -0400 Subject: [PATCH 3/3] Change to updated commmit on ST --- installer/install_shimming_toolbox.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/install_shimming_toolbox.sh b/installer/install_shimming_toolbox.sh index 745099a..d612a9c 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="420905677bf624228e2e1088d842178de1f30196" +ST_VERSION="cb579afefb8ac742909e5d706a85c2c6dc091274" curl -L "https://github.com/shimming-toolbox/shimming-toolbox/archive/${ST_VERSION}.zip" > "shimming-toolbox-${ST_VERSION}.zip"