Skip to content

ENH: Implement BIDS X5 io module #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nitransforms/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""Read and write transforms."""
from nitransforms.io import afni, fsl, itk, lta

from nitransforms.io import afni, fsl, itk, lta, x5
from nitransforms.io.base import TransformIOError, TransformFileError

__all__ = [
Expand All @@ -22,6 +23,7 @@
"fs": (lta, "FSLinearTransform"),
"fsl": (fsl, "FSLLinearTransform"),
"afni": (afni, "AFNILinearTransform"),
"x5": (x5, "X5LinearTransform"),
}


Expand Down
39 changes: 39 additions & 0 deletions nitransforms/io/x5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
# See COPYING file distributed along with the NiBabel package for the
# copyright and license terms.
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Read/write x5 transforms."""

import numpy as np
from h5py import File as H5File


def to_filename(fname, xfm, moving=None):
"""Store the transform in BIDS-Transforms HDF5 file format (.x5)."""
with H5File(fname, "w") as out_file:
out_file.attrs["Format"] = "X5"
out_file.attrs["Version"] = np.uint16(1)
x5_root = out_file.create_group("/0")

# Serialize this object into the x5 file format.
transform_group = x5_root.create_group("TransformGroup")

# Group '0' containing Affine transform
transform_0 = transform_group.create_group("0")

transform_0.attrs["Type"] = "Affine"
transform_0.create_dataset("Transform", data=xfm.matrix)
transform_0.create_dataset("Inverse", data=~xfm)

metadata = {"key": "value"}
transform_0.attrs["Metadata"] = str(metadata)

# sub-group 'Domain' contained within group '0'
transform_0.create_group("Domain")
# domain_group.attrs["Grid"] = self._grid
# domain_group.create_dataset("Size", data=_as_homogeneous(self._reference.shape))
# domain_group.create_dataset("Mapping", data=self.mapping)
Loading