impy.arrays.bases package

Submodules

impy.arrays.bases.historyarray module

class impy.arrays.bases.historyarray.HistoryArray(obj, name=None, axes=None, dirpath=None, history=None, metadata=None, dtype=None)[source]

Bases: impy.arrays.bases.metaarray.MetaArray

dirpath: str
name: str
split(axis=None) impy.collections.DataList[impy.arrays.bases.historyarray.HistoryArray][source]

Split n-dimensional image into (n-1)-dimensional images.

Parameters

axis (str or int, optional) – Along which axis the original image will be split, by default “c”

Returns

Separate images

Return type

list of arrays

tile(shape: tuple[int, int] | None = None, along: str | None = None, order: str | None = None) HistoryArray[source]

Tile images in a certain order.

Parameters
  • shape (tuple[int, int], optional) – Grid shape. This parameter must be specified unless the length of along is 2.

  • along (str, optional) – Axis (Axes) over which will be iterated.

  • order (str, {"r", "c"}, optional) –

    Order of iteration. “r” means row-wise and “c” means column-wise.

    row-wise

    —–> —–> —–>

    column-wise
    | |
    | |

    v v v

Returns

Tiled array

Return type

HistoryArray

impy.arrays.bases.metaarray module

class impy.arrays.bases.metaarray.MetaArray(obj, name=None, axes=None, dirpath=None, metadata=None, dtype=None)[source]

Bases: impy.arrays.axesmixin.AxesMixin, numpy.ndarray

NP_DISPATCH = {<function squeeze>: <function _>, <function take>: <function _>, <function stack>: <function _>, <function concatenate>: <function _>, <function block>: <function _>, <function zeros_like>: <function _>, <function empty_like>: <function _>, <function expand_dims>: <function _>, <function transpose>: <function _>, <function split>: <function _>}
additional_props = ['dirpath', 'metadata', 'name']
apply_dask(func: Callable, c_axes: str | None = None, drop_axis: Iterable[int] = [], new_axis: Iterable[int] = None, dtype=<class 'numpy.float32'>, out_chunks: tuple[int, ...] = None, args: tuple[Any] = None, kwargs: dict[str, Any] = None) MetaArray[source]

Convert array into dask array and run a batch process in parallel. In many cases batch process in this way is faster than multiprocess module.

Parameters
  • func (callable) – Function to apply.

  • c_axes (str, optional) – Axes to iterate.

  • drop_axis (Iterable[int], optional) – Passed to map_blocks.

  • new_axis (Iterable[int], optional) – Passed to map_blocks.

  • dtype (any that can be converted to np.dtype object, default is np.float32) – Output data type.

  • out_chunks (tuple of int, optional) – Output chunks. This argument is important when the output shape will change.

  • args (tuple, optional) – Arguments that will passed to func.

  • kwargs (dict) – Keyword arguments that will passed to func.

Returns

Processed array.

Return type

MetaArray

dirpath: str
classmethod implements(numpy_function)[source]

Add functions to NP_DISPATCH so that numpy functions can be overloaded.

iter(axes: str, israw: bool = False, exclude: str = '') tuple[Slices, np.ndarray | MetaArray][source]

Iteration along axes. If axes=”tzc”, then equivalent to following pseudo code:

for t in all_t:
    for z in all_z:
        for c in all_c:
            yield self[t, z, c, ...]
Parameters
  • axes (str or int) – On which axes iteration is performed. Or the number of spatial dimension.

  • israw (bool, default is False) – If True, MetaArray will be returned. If False, np.ndarray will be returned.

  • exclude (str, optional) – Which axes will be excluded in output. For example, self.axes=”tcyx” and exclude=”c” then the axes of output will be “tyx” and slice is also correctly arranged.

Yields

slice and (np.ndarray or MetaArray) – slice and a subimage=self[sl]

name: str
property shape

Tuple of array dimensions.

The shape property is usually used to get the current shape of an array, but may also be used to reshape the array in-place by assigning a tuple of array dimensions to it. As with numpy.reshape, one of the new shape dimensions can be -1, in which case its value is inferred from the size of the array and the remaining dimensions. Reshaping an array in-place will fail if a copy is required.

Examples

>>> x = np.array([1, 2, 3, 4])
>>> x.shape
(4,)
>>> y = np.zeros((2, 3, 4))
>>> y.shape
(2, 3, 4)
>>> y.shape = (3, 8)
>>> y
array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]])
>>> y.shape = (3, 6)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: total size of new array must be unchanged
>>> np.zeros((4,2))[::2].shape = (-1,)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: Incompatible shape for in-place modification. Use
`.reshape()` to make a copy with the desired shape.

See also

numpy.reshape

similar function

ndarray.reshape

similar method

showinfo()[source]
sort_axes() impy.arrays.bases.metaarray.MetaArray[source]

Sort image dimensions to ptzcyx-order

Returns

Sorted image

Return type

MetaArray

transpose(axes)[source]

change the order of image dimensions. ‘axes’ will also be arranged.

property value: numpy.ndarray

impy.arrays.bases.overload module

impy.arrays.bases.overload.safe_set_info(out, img, history, new_axes)[source]

Module contents