arrayproxy¶
Array proxy base class
The proxy API is - at minimum:
- The object has a read-only attribute
shape - read only
is_proxyattribute / property set to True - the object returns the data array from
np.asarray(prox) - returns array slice from
prox[<slice_spec>]where<slice_spec>is any ndarray slice specification that does not use numpy ‘advanced indexing’. - modifying no object outside
objwill affect the result ofnp.asarray(obj). Specifically:- Changes in position (
obj.tell()) of passed file-like objects will not affect the output of fromnp.asarray(proxy). - if you pass a header into the __init__, then modifying the original header will not affect the result of the array return.
- Changes in position (
See nibabel.tests.test_proxy_api for proxy API conformance checks.
ArrayProxy(*args, **kwargs) |
Class to act as proxy for the array that can be read from a file |
is_proxy(obj) |
Return True if obj is an array proxy |
ArrayProxy¶
-
class
nibabel.arrayproxy.ArrayProxy(*args, **kwargs)¶ Bases:
objectClass to act as proxy for the array that can be read from a file
The array proxy allows us to freeze the passed fileobj and header such that it returns the expected data array.
This implementation assumes a contiguous array in the file object, with one of the numpy dtypes, starting at a given file position
offsetwith singleslopeandinterceptscaling to produce output values.The class
__init__requires aheaderobject with methods:- get_data_shape
- get_data_dtype
- get_data_offset
- get_slope_inter
The header should also have a ‘copy’ method. This requirement will go away when the deprecated ‘header’ propoerty goes away.
This implementation allows us to deal with Analyze and its variants, including Nifti1, and with the MGH format.
Other image types might need more specific classes to implement the API. See
nibabel.minc1,nibabel.ecatandnibabel.parrecfor examples.Initialize array proxy instance
Parameters: file_like : object
File-like object or filename. If file-like object, should implement at least
readandseek.header : object
Header object implementing
get_data_shape,get_data_dtype,get_data_offset,get_slope_intermmap : {True, False, ‘c’, ‘r’}, optional, keyword only
mmap controls the use of numpy memory mapping for reading data. If False, do not try numpy
memmapfor data array. If one of {‘c’, ‘r’}, try numpy memmap withmode=mmap. A mmap value of True gives the same behavior asmmap='c'. If file_like cannot be memory-mapped, ignore mmap value and read array from file.scaling : {‘fp’, ‘dv’}, optional, keyword only
Type of scaling to use - see header
get_data_scalingmethod.-
__init__(*args, **kwargs)¶ Initialize array proxy instance
Parameters: file_like : object
File-like object or filename. If file-like object, should implement at least
readandseek.header : object
Header object implementing
get_data_shape,get_data_dtype,get_data_offset,get_slope_intermmap : {True, False, ‘c’, ‘r’}, optional, keyword only
mmap controls the use of numpy memory mapping for reading data. If False, do not try numpy
memmapfor data array. If one of {‘c’, ‘r’}, try numpy memmap withmode=mmap. A mmap value of True gives the same behavior asmmap='c'. If file_like cannot be memory-mapped, ignore mmap value and read array from file.scaling : {‘fp’, ‘dv’}, optional, keyword only
Type of scaling to use - see header
get_data_scalingmethod.
-
get_unscaled()¶ Read of data from file
This is an optional part of the proxy API
-
header¶
-
inter¶
-
is_proxy¶
-
offset¶
-
order= 'F'¶
-
shape¶
-
slope¶
