From 08c3c84a405168aec2b4d687b82c8659e9e2a36d Mon Sep 17 00:00:00 2001 From: mathiasg Date: Thu, 19 Dec 2024 23:16:08 -0500 Subject: [PATCH] ENH: Allow ingestion of alternatively grouped CompositeH5s --- nitransforms/io/itk.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nitransforms/io/itk.py b/nitransforms/io/itk.py index afabfd98..c4789ea4 100644 --- a/nitransforms/io/itk.py +++ b/nitransforms/io/itk.py @@ -383,12 +383,20 @@ def from_h5obj(cls, fileobj, check=True, only_linear=False): xfm_list = [] h5group = fileobj["TransformGroup"] typo_fallback = "Transform" + + start_idx = 1 + for i, group in enumerate(h5group): + found = h5group[group].get(f'{typo_fallback}Parameters', None) + if found is not None: + start_idx = i + break + try: - h5group["1"][f"{typo_fallback}Parameters"] + h5group[f'{start_idx}'][f"{typo_fallback}Parameters"] except KeyError: typo_fallback = "Tranform" - for xfm in list(h5group.values())[1:]: + for xfm in list(h5group.values())[start_idx:]: if xfm["TransformType"][0].startswith(b"AffineTransform"): _params = np.asanyarray(xfm[f"{typo_fallback}Parameters"]) xfm_list.append(