Skip to content

Commit

Permalink
Merge pull request #215 from nipy/enh/reenable-parallelization-apply-214
Browse files Browse the repository at this point in the history
ENH: Serialize+parallelize 4D ``apply()`` into 3D+t and add 'low memory' loading
  • Loading branch information
oesteban authored Aug 10, 2024
2 parents 7c9eaed + 063e1f0 commit b141a8e
Show file tree
Hide file tree
Showing 7 changed files with 720 additions and 413 deletions.
31 changes: 23 additions & 8 deletions nitransforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Common interface for transforms."""

from pathlib import Path
import numpy as np
import h5py
Expand Down Expand Up @@ -146,13 +147,13 @@ def from_arrays(cls, coordinates, triangles):
darrays = [
nb.gifti.GiftiDataArray(
coordinates.astype(np.float32),
intent=nb.nifti1.intent_codes['NIFTI_INTENT_POINTSET'],
datatype=nb.nifti1.data_type_codes['NIFTI_TYPE_FLOAT32'],
intent=nb.nifti1.intent_codes["NIFTI_INTENT_POINTSET"],
datatype=nb.nifti1.data_type_codes["NIFTI_TYPE_FLOAT32"],
),
nb.gifti.GiftiDataArray(
triangles.astype(np.int32),
intent=nb.nifti1.intent_codes['NIFTI_INTENT_TRIANGLE'],
datatype=nb.nifti1.data_type_codes['NIFTI_TYPE_INT32'],
intent=nb.nifti1.intent_codes["NIFTI_INTENT_TRIANGLE"],
datatype=nb.nifti1.data_type_codes["NIFTI_TYPE_INT32"],
),
]
gii = nb.gifti.GiftiImage(darrays=darrays)
Expand Down Expand Up @@ -279,6 +280,22 @@ def __add__(self, b):

return TransformChain(transforms=[self, b])

def __len__(self):
"""
Enable ``len()``.
By default, all transforms are of length one.
This must be overriden by transforms arrays and chains.
Example
-------
>>> T1 = TransformBase()
>>> len(T1)
1
"""
return 1

@property
def reference(self):
"""Access a reference space where data will be resampled onto."""
Expand Down Expand Up @@ -335,10 +352,8 @@ def apply(self, *args, **kwargs):
Deprecated. Please use ``nitransforms.resampling.apply`` instead.
"""
message = (
"The `apply` method is deprecated. Please use `nitransforms.resampling.apply` instead."
)
warnings.warn(message, DeprecationWarning, stacklevel=2)
_msg = "This method is deprecated. Please use `nitransforms.resampling.apply` instead."
warnings.warn(_msg, DeprecationWarning, stacklevel=2)
from .resampling import apply

return apply(self, *args, **kwargs)
Expand Down
Loading

0 comments on commit b141a8e

Please sign in to comment.