Skip to content

Commit 7650dbe

Browse files
committed
maint: restructure submodule io to contain submodules
1 parent 9763e62 commit 7650dbe

File tree

4 files changed

+48
-22
lines changed

4 files changed

+48
-22
lines changed

nitransforms/io/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
2+
# vi: set ft=python sts=4 ts=4 sw=4 et:
3+
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
4+
#
5+
# See COPYING file distributed along with the NiBabel package for the
6+
# copyright and license terms.
7+
#
8+
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
9+
"""
10+
Read and write transforms.
11+
12+
.. currentmodule:: nitransforms
13+
14+
.. autosummary::
15+
:toctree: ../generated
16+
17+
transform
18+
"""
19+
from .lta import LinearTransform, LinearTransformArray, VolumeGeometry
20+
21+
22+
__all__ = ['LinearTransform', 'LinearTransformArray', 'VolumeGeometry']

nitransforms/io/base.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Read/write linear transforms."""
2+
import numpy as np
3+
from nibabel.wrapstruct import LabeledWrapStruct as LWS
4+
5+
6+
class LabeledWrapStruct(LWS):
7+
def __setitem__(self, item, value):
8+
self._structarr[item] = np.asanyarray(value)
9+
10+
11+
class StringBasedStruct(LabeledWrapStruct):
12+
def __init__(self,
13+
binaryblock=None,
14+
endianness=None,
15+
check=True):
16+
if binaryblock is not None and getattr(binaryblock, 'dtype',
17+
None) == self.dtype:
18+
self._structarr = binaryblock.copy()
19+
return
20+
super(StringBasedStruct, self).__init__(binaryblock, endianness, check)
21+
22+
def __array__(self):
23+
return self._structarr

nitransforms/io.py renamed to nitransforms/io/lta.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
"""Read/write linear transforms."""
12
import numpy as np
23
from nibabel.volumeutils import Recoder
34
from nibabel.affines import voxel_sizes
45

5-
from .patched import LabeledWrapStruct
6+
from .base import StringBasedStruct
7+
68

79
transform_codes = Recoder((
810
(0, 'LINEAR_VOX_TO_VOX'),
@@ -13,21 +15,6 @@
1315
fields=('code', 'label'))
1416

1517

16-
class StringBasedStruct(LabeledWrapStruct):
17-
def __init__(self,
18-
binaryblock=None,
19-
endianness=None,
20-
check=True):
21-
if binaryblock is not None and getattr(binaryblock, 'dtype',
22-
None) == self.dtype:
23-
self._structarr = binaryblock.copy()
24-
return
25-
super(StringBasedStruct, self).__init__(binaryblock, endianness, check)
26-
27-
def __array__(self):
28-
return self._structarr
29-
30-
3118
class VolumeGeometry(StringBasedStruct):
3219
template_dtype = np.dtype([
3320
('valid', 'i4'), # Valid values: 0, 1

nitransforms/patched.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import numpy as np
2-
from nibabel.wrapstruct import LabeledWrapStruct as LWS
32

43

54
def shape_zoom_affine(shape, zooms, x_flip=True, y_flip=False):
@@ -64,8 +63,3 @@ def shape_zoom_affine(shape, zooms, x_flip=True, y_flip=False):
6463
aff[:3, :3] = np.diag(zooms)
6564
aff[:3, -1] = -origin * zooms
6665
return aff
67-
68-
69-
class LabeledWrapStruct(LWS):
70-
def __setitem__(self, item, value):
71-
self._structarr[item] = np.asanyarray(value)

0 commit comments

Comments
 (0)