Skip to content

Commit 8be3a0e

Browse files
committed
DOC: Update docstrings, comments, for clarity
1 parent 3b6d7fe commit 8be3a0e

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

nibabel/ecat.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,25 @@ def __array__(self):
705705
return data
706706

707707
def get_scaled(self, dtype=None):
708+
""" Read data from file and apply scaling
709+
710+
The dtype of the returned array is the narrowest dtype that can
711+
represent the data without overflow, and is at least as wide as
712+
the dtype parameter.
713+
714+
If dtype is unspecified, it is automatically determined.
715+
716+
Parameters
717+
----------
718+
dtype : numpy dtype specifier
719+
A numpy dtype specifier specifying the narrowest acceptable
720+
dtype.
721+
722+
Returns
723+
-------
724+
array
725+
Scaled of image data of data type `dtype`.
726+
"""
708727
data = self.__array__()
709728
if dtype is None:
710729
return data

nibabel/minc1.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,25 @@ def _get_scaled(self, dtype, slicer):
269269
return data.astype(final_type, copy=False)
270270

271271
def get_scaled(self, dtype=None):
272+
""" Read data from file and apply scaling
273+
274+
The dtype of the returned array is the narrowest dtype that can
275+
represent the data without overflow, and is at least as wide as
276+
the dtype parameter.
277+
278+
If dtype is unspecified, it is automatically determined.
279+
280+
Parameters
281+
----------
282+
dtype : numpy dtype specifier
283+
A numpy dtype specifier specifying the narrowest acceptable
284+
dtype.
285+
286+
Returns
287+
-------
288+
array
289+
Scaled of image data of data type `dtype`.
290+
"""
272291
return self._get_scaled(dtype=dtype, slicer=())
273292

274293
def __array__(self):

nibabel/parrec.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,33 @@ def _get_scaled(self, dtype, slicer):
670670

671671

672672
def get_unscaled(self):
673+
""" Read data from file
674+
675+
This is an optional part of the proxy API
676+
"""
673677
return self._get_unscaled(slicer=())
674678

675679
def get_scaled(self, dtype=None):
680+
""" Read data from file and apply scaling
681+
682+
The dtype of the returned array is the narrowest dtype that can
683+
represent the data without overflow, and is at least as wide as
684+
the dtype parameter.
685+
686+
If dtype is unspecified, it is the wider of the dtypes of the slopes
687+
or intercepts
688+
689+
Parameters
690+
----------
691+
dtype : numpy dtype specifier
692+
A numpy dtype specifier specifying the narrowest acceptable
693+
dtype.
694+
695+
Returns
696+
-------
697+
array
698+
Scaled of image data of data type `dtype`.
699+
"""
676700
return self._get_scaled(dtype=dtype, slicer=())
677701

678702
def __array__(self):

nibabel/tests/test_image_api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ def _check_proxy_interface(self, imaker, meth_name):
314314
# New data dtype, no caching, doesn't use or alter cache
315315
fdata_new_dt = img.get_fdata(caching='unchanged', dtype='f4')
316316
# We get back the original read, not the modified cache
317+
# Allow for small rounding error when the data is scaled with 32-bit
318+
# factors, rather than 64-bit factors and then cast to float-32
319+
# Use rtol/atol from numpy.allclose
317320
assert_allclose(fdata_new_dt, proxy_data.astype('f4'), rtol=1e-05, atol=1e-08)
318321
assert_equal(fdata_new_dt.dtype, np.float32)
319322
# The original cache stays in place, for default float64

0 commit comments

Comments
 (0)