Skip to content

Commit

Permalink
Merge 655eaf4 into 6170cf3
Browse files Browse the repository at this point in the history
  • Loading branch information
po09i committed Jan 25, 2024
2 parents 6170cf3 + 655eaf4 commit d01b24a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion shimmingtoolbox/cli/b0shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ def _initial_in_bounds(coefs: dict, bounds: dict):
# If the scanner coefficients are valid, update the initial coefficients
if scanner_shim_settings['has_valid_settings']:
if scanner_shim_settings['0'] is not None and 0 in orders:
initial_coefs['0'] = np.array([scanner_shim_settings['0']])
initial_coefs['0'] = np.array(scanner_shim_settings['0'])
if scanner_shim_settings['1'] is not None and 1 in orders:
initial_coefs['1'] = scanner_shim_settings['1']
if scanner_shim_settings['2'] is not None and 2 in orders:
Expand Down
23 changes: 9 additions & 14 deletions shimmingtoolbox/shim/shim_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def get_scanner_shim_settings(bids_json_dict):

# get_imaging_frequency
if bids_json_dict.get('ImagingFrequency'):
scanner_shim['0'] = int(bids_json_dict.get('ImagingFrequency') * 1e6)
scanner_shim['0'] = [int(bids_json_dict.get('ImagingFrequency') * 1e6)]

# get_shim_orders
if bids_json_dict.get('ShimSetting'):
Expand Down Expand Up @@ -311,18 +311,13 @@ def concatenate_shim_settings(self, orders=[2]):
logger.warning("Invalid Shim Settings")
return coefs

if self.shim_settings.get('0') is not None and any(order>=0 for order in orders):
# Concatenate 2 lists
coefs = [self.shim_settings.get('0')]
else:
coefs = [0]

for order in orders:
if self.shim_settings.get(order) is not None:
# Concatenate 2 lists
coefs.extend(self.shim_settings.get(order))
else:
n_coefs = (order + 1) * 2
coefs.extend([0] * n_coefs)
if any(order >= 0 for order in orders):
for order in sorted(orders):
if self.shim_settings.get(str(order)) is not None:
# Concatenate 2 lists
coefs.extend(self.shim_settings.get(str(order)))
else:
n_coefs = (order + 1) * 2
coefs.extend([0] * n_coefs)

return coefs
8 changes: 7 additions & 1 deletion test/cli/test_cli_b0shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,19 @@ def test_cli_dynamic_absolute(self, nii_fmap, nii_anat, nii_mask, fm_data, anat_
'--fmap', fname_fmap,
'--anat', fname_anat,
'--mask', fname_mask,
'--scanner-coil-order', '2',
'--scanner-coil-order', '0, 2',
'--output-value-format', 'absolute',
'--output', tmp],
catch_exceptions=False)

assert res.exit_code == 0
assert os.path.isfile(os.path.join(tmp, "coefs_coil0_Prisma_fit.txt"))
with open(os.path.join(tmp, "coefs_coil0_Prisma_fit.txt"), 'r') as file:
lines = file.readlines()
line = lines[8].strip().split(',')
values = [float(val) for val in line if val.strip()]

assert values == [123259067.330864, -718.069583, 138.656751, -110.517759, 24.97596, -4.888655]

def test_cli_2d_fmap(self, nii_fmap, nii_anat, nii_mask, fm_data, anat_data):

Expand Down

0 comments on commit d01b24a

Please sign in to comment.