Skip to content

Commit b141a8e

Browse files
authored
Merge pull request #215 from nipy/enh/reenable-parallelization-apply-214
ENH: Serialize+parallelize 4D ``apply()`` into 3D+t and add 'low memory' loading
2 parents 7c9eaed + 063e1f0 commit b141a8e

File tree

7 files changed

+720
-413
lines changed

7 files changed

+720
-413
lines changed

nitransforms/base.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
99
"""Common interface for transforms."""
10+
1011
from pathlib import Path
1112
import numpy as np
1213
import h5py
@@ -146,13 +147,13 @@ def from_arrays(cls, coordinates, triangles):
146147
darrays = [
147148
nb.gifti.GiftiDataArray(
148149
coordinates.astype(np.float32),
149-
intent=nb.nifti1.intent_codes['NIFTI_INTENT_POINTSET'],
150-
datatype=nb.nifti1.data_type_codes['NIFTI_TYPE_FLOAT32'],
150+
intent=nb.nifti1.intent_codes["NIFTI_INTENT_POINTSET"],
151+
datatype=nb.nifti1.data_type_codes["NIFTI_TYPE_FLOAT32"],
151152
),
152153
nb.gifti.GiftiDataArray(
153154
triangles.astype(np.int32),
154-
intent=nb.nifti1.intent_codes['NIFTI_INTENT_TRIANGLE'],
155-
datatype=nb.nifti1.data_type_codes['NIFTI_TYPE_INT32'],
155+
intent=nb.nifti1.intent_codes["NIFTI_INTENT_TRIANGLE"],
156+
datatype=nb.nifti1.data_type_codes["NIFTI_TYPE_INT32"],
156157
),
157158
]
158159
gii = nb.gifti.GiftiImage(darrays=darrays)
@@ -279,6 +280,22 @@ def __add__(self, b):
279280

280281
return TransformChain(transforms=[self, b])
281282

283+
def __len__(self):
284+
"""
285+
Enable ``len()``.
286+
287+
By default, all transforms are of length one.
288+
This must be overriden by transforms arrays and chains.
289+
290+
Example
291+
-------
292+
>>> T1 = TransformBase()
293+
>>> len(T1)
294+
1
295+
296+
"""
297+
return 1
298+
282299
@property
283300
def reference(self):
284301
"""Access a reference space where data will be resampled onto."""
@@ -335,10 +352,8 @@ def apply(self, *args, **kwargs):
335352
336353
Deprecated. Please use ``nitransforms.resampling.apply`` instead.
337354
"""
338-
message = (
339-
"The `apply` method is deprecated. Please use `nitransforms.resampling.apply` instead."
340-
)
341-
warnings.warn(message, DeprecationWarning, stacklevel=2)
355+
_msg = "This method is deprecated. Please use `nitransforms.resampling.apply` instead."
356+
warnings.warn(_msg, DeprecationWarning, stacklevel=2)
342357
from .resampling import apply
343358

344359
return apply(self, *args, **kwargs)

0 commit comments

Comments
 (0)