Functions and classes for array-like objects, implementing common numpy array features for datasets or nested sequences, while trying to avoid copying data.
Classes:
- DatasetView: Similar to a numpy view, to access a h5py dataset as if it was transposed, without casting it into a numpy array (this lets h5py handle reading the data from the file into memory, as needed).
- ListOfImages: Similar to a numpy view, to access a list of 2D numpy arrays as if it was a 3D array (possibly transposed), without casting it into a numpy array.
Functions:
Return True if object implements necessary attributes to be considered similar to a numpy array.
Attributes needed are “shape”, “dtype”, “__getitem__” and “__array__”.
Parameters: | obj – Array-like object (numpy array, h5py dataset...) |
---|---|
Returns: | boolean |
Return True if object is a sequence of numpy arrays, e.g. a list of images as 2D arrays.
Parameters: | obj – list of arrays |
---|---|
Returns: | boolean |
Return True if object is a nested sequence.
A simple 1D sequence is considered to be a nested sequence.
Numpy arrays and h5py datasets are not considered to be nested sequences.
To test if an object is a nested sequence in a more general sense, including arrays and datasets, use:
is_nested_sequence(obj) or is_array(obj)
Parameters: | obj – nested sequence (numpy array, h5py dataset...) |
---|---|
Returns: | boolean |
Return shape of an array like object.
In case the object is a nested sequence but not an array or dataset (list of lists, tuples...), the size of each dimension is assumed to be uniform, and is deduced from the length of the first sequence.
Parameters: | array_like – Array like object: numpy array, hdf5 dataset, multi-dimensional sequence |
---|---|
Returns: | Shape of array, as a tuple of integers |
Return dtype of an array like object.
In the case of a nested sequence, the type of the first value is inspected.
Parameters: | array_like – Array like object: numpy array, hdf5 dataset, multi-dimensional nested sequence |
---|---|
Returns: | numpy dtype of object |
Return dtype of array resulting of concatenation of a list of arrays (without actually concatenating them).
Parameters: | arrays – list of numpy arrays |
---|---|
Returns: | resulting dtype after concatenating arrays |
This class provides a way to access values and slices in a stack of images stored as a list of 2D numpy arrays, without creating a 3D numpy array first.
A transposition can be specified, as a 3-tuple of dimensions in the wanted order. For example, to transpose from xyz (0, 1, 2) into yzx, the transposition tuple is (1, 2, 0)
All the 2D arrays in the list must have the same shape.
The global dtype of the stack of images is the one that would be obtained by casting the list of 2D arrays into a 3D numpy array.
Parameters: |
|
---|
List of images
Tuple of array dimensions
Data-type of the global array
Number of array dimensions
Number of elements in the array.
List of dimension indices, in an order depending on the specified transposition. By default this is simply [0, ..., self.ndim], but it can be changed by specifying a different transposition parameter at initialization.
Use transpose(), to create a new ListOfImages with a different transposition.
Return a re-ordered (dimensions permutated) ListOfImages.
The returned object refers to the same images but with a different transposition.
Parameters: | transposition (list[int]) – List/tuple of dimension numbers in the wanted order. If None (default), reverse the dimensions. |
---|---|
Returns: | new ListOfImages object |
This class provides a way to transpose a dataset without casting it into a numpy array. This way, the dataset in a file need not necessarily be integrally read into memory to view it in a different transposition.
Note
The performances depend a lot on the way the dataset was written to file. Depending on the chunking strategy, reading a complete 2D slice in an unfavorable direction may still require the entire dataset to be read from disk.
Parameters: |
|
---|
original dataset
Tuple of array dimensions
Data-type of the array’s element
Number of array dimensions
Number of elements in the array.
List of dimension indices, in an order depending on the specified transposition. By default this is simply [0, ..., self.ndim], but it can be changed by specifying a different transposition parameter at initialization.
Use transpose(), to create a new DatasetView with a different transposition.
Return a re-ordered (dimensions permutated) DatasetView.
The returned object refers to the same dataset but with a different transposition.
Parameters: | transposition (list[int]) – List of dimension numbers in the wanted order. If None (default), reverse the dimensions. |
---|---|
Returns: | Transposed DatasetView |