Skip to content

Commit 92780b9

Browse files
committed
DBG: Better reporting for ANTs h5 parsing failures
1 parent 691f1a1 commit 92780b9

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

fmriprep/utils/transforms.py

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,41 +43,34 @@ def load_ants_h5(filename: Path) -> nt.TransformChain:
4343
return nt.TransformChain([warp_transform, nt.Affine(affine)])
4444

4545

46+
FIXED_PARAMS = np.array([
47+
193.0, 229.0, 193.0,
48+
96.0, 132.0, -78.0,
49+
1.0, 1.0, 1.0,
50+
-1.0, 0.0, 0.0,
51+
0.0, -1.0, 0.0,
52+
0.0, 0.0, 1.0,
53+
]) # fmt:skip
54+
55+
4656
def parse_combined_hdf5(h5_fn, to_ras=True):
4757
# Borrowed from https://github.com/feilong/process
4858
# process.resample.parse_combined_hdf5()
4959
h = h5py.File(h5_fn)
5060
xform = ITKCompositeH5.from_h5obj(h)
5161
affine = xform[0].to_ras()
62+
transform2 = h['TransformGroup']['2']
5263
# Confirm these transformations are applicable
53-
assert (
54-
h['TransformGroup']['2']['TransformType'][:][0] == b'DisplacementFieldTransform_float_3_3'
55-
)
56-
assert np.array_equal(
57-
h['TransformGroup']['2']['TransformFixedParameters'][:],
58-
np.array(
59-
[
60-
193.0,
61-
229.0,
62-
193.0,
63-
96.0,
64-
132.0,
65-
-78.0,
66-
1.0,
67-
1.0,
68-
1.0,
69-
-1.0,
70-
0.0,
71-
0.0,
72-
0.0,
73-
-1.0,
74-
0.0,
75-
0.0,
76-
0.0,
77-
1.0,
78-
]
79-
),
80-
)
64+
if transform2['TransformType'][:][0] != b'DisplacementFieldTransform_float_3_3':
65+
msg = 'Unknown transform type [2]\n'
66+
for i in h['TransformGroup'].keys():
67+
msg += f'[{i}]: {h["TransformGroup"][i]["TransformType"][:][0]}\n'
68+
raise ValueError(msg)
69+
if not np.array_equal(transform2['TransformFixedParameters'], FIXED_PARAMS):
70+
msg = 'Unexpected fixed parameters\n'
71+
msg += f'Expected: {FIXED_PARAMS}\n'
72+
msg += f'Found: {transform2["TransformFixedParameters"][:]}'
73+
raise ValueError(msg)
8174
warp = h['TransformGroup']['2']['TransformParameters'][:]
8275
warp = warp.reshape((193, 229, 193, 3)).transpose(2, 1, 0, 3)
8376
warp *= np.array([-1, -1, 1])

0 commit comments

Comments
 (0)