Skip to content

Commit

Permalink
Address ruff's concerns.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed May 7, 2024
1 parent d267a86 commit 00d3440
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/fmripost_aroma/utils/resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,13 @@ def parse_combined_hdf5(h5_fn, to_ras=True):
xform = ITKCompositeH5.from_h5obj(h)
affine = xform[0].to_ras()
# Confirm these transformations are applicable
assert (
if (
h['TransformGroup']['2']['TransformType'][:][0]
== b'DisplacementFieldTransform_float_3_3'
)
assert np.array_equal(
!= b'DisplacementFieldTransform_float_3_3'
):
raise ValueError('Unsupported transform type')

if not np.array_equal(
h['TransformGroup']['2']['TransformFixedParameters'][:],
np.array(
[
Expand All @@ -340,7 +342,9 @@ def parse_combined_hdf5(h5_fn, to_ras=True):
1.0,
]
),
)
):
raise ValueError('Unsupported fixed parameters')

warp = h['TransformGroup']['2']['TransformParameters'][:]
warp = warp.reshape((193, 229, 193, 3)).transpose(2, 1, 0, 3)
warp *= np.array([-1, -1, 1])
Expand Down Expand Up @@ -533,7 +537,8 @@ def resample_bold(
The BOLD series resampled into the target space
"""
# HMC goes last
assert isinstance(transforms[-1], nt.linear.LinearTransformsMapping)
if not isinstance(transforms[-1], nt.linear.LinearTransformsMapping):
raise ValueError('Last transform must be a linear mapping')

# Retrieve the RAS coordinates of the target space
coordinates = (
Expand Down Expand Up @@ -645,8 +650,8 @@ def main(
hmc = derivs.get(
extension='.txt', **mkents('orig', 'boldref', **entities)
)[0]
except IndexError:
raise ValueError('Could not find HMC transforms')
except IndexError as err:
raise ValueError('Could not find HMC transforms') from err

bold_xfms.append(hmc)

Expand All @@ -659,8 +664,8 @@ def main(
coreg = derivs.get(
extension='.txt', **mkents('boldref', 'T1w', **entities)
)[0]
except IndexError:
raise ValueError('Could not find coregistration transform')
except IndexError as err:
raise ValueError('Could not find coregistration transform') from err

bold_xfms.append(coreg)
fmap_xfms.append(coreg)
Expand All @@ -682,10 +687,8 @@ def main(
subject=entities['subject'],
**mkents('T1w', space),
)[0]
except IndexError:
raise ValueError(
f'Could not find template registration for {space}'
)
except IndexError as err :
raise ValueError(f'Could not find template registration for {space}') from err

bold_xfms.append(template_reg)
fmap_xfms.append(template_reg)
Expand Down

0 comments on commit 00d3440

Please sign in to comment.