|
7 | 7 | #
|
8 | 8 | ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
|
9 | 9 | """Common interface for transforms."""
|
| 10 | + |
10 | 11 | from pathlib import Path
|
11 | 12 | import numpy as np
|
12 | 13 | import h5py
|
@@ -146,13 +147,13 @@ def from_arrays(cls, coordinates, triangles):
|
146 | 147 | darrays = [
|
147 | 148 | nb.gifti.GiftiDataArray(
|
148 | 149 | 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"], |
151 | 152 | ),
|
152 | 153 | nb.gifti.GiftiDataArray(
|
153 | 154 | 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"], |
156 | 157 | ),
|
157 | 158 | ]
|
158 | 159 | gii = nb.gifti.GiftiImage(darrays=darrays)
|
@@ -279,6 +280,22 @@ def __add__(self, b):
|
279 | 280 |
|
280 | 281 | return TransformChain(transforms=[self, b])
|
281 | 282 |
|
| 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 | + |
282 | 299 | @property
|
283 | 300 | def reference(self):
|
284 | 301 | """Access a reference space where data will be resampled onto."""
|
@@ -335,10 +352,8 @@ def apply(self, *args, **kwargs):
|
335 | 352 |
|
336 | 353 | Deprecated. Please use ``nitransforms.resampling.apply`` instead.
|
337 | 354 | """
|
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) |
342 | 357 | from .resampling import apply
|
343 | 358 |
|
344 | 359 | return apply(self, *args, **kwargs)
|
|
0 commit comments