ptypy.core.classes.Storage#

class ptypy.core.classes.Storage(container, ID=None, data=None, shape=(1, 1, 1), fill=0.0, psize=1.0, origin=None, layermap=None, padonly=False, padding=0, **kwargs)#

Bases: Base

Inner container handling access to data arrays.

This class essentially manages access to an internal numpy array buffer called data

  • It returns a view to coordinates given (slicing)

  • It contains a physical coordinate grid

__init__(container, ID=None, data=None, shape=(1, 1, 1), fill=0.0, psize=1.0, origin=None, layermap=None, padonly=False, padding=0, **kwargs)#
Parameters:
  • container (Container) – The container instance

  • ID (None, str or int) – A unique ID, managed by the parent, if None ID is generated by parent.

  • data (ndarray or None) – A numpy array to use as initial buffer. Deprecated in v0.3, use fill method instead.

  • shape (tuple, int, or None) – The shape of the buffer. If None or int, the dimensionality is found from the owning Container instance. Otherwise the dimensionality is len(shape)-1.

  • fill (float or complex) – The default value to fill storage with, will be converted to data type of owner.

  • psize (float or (ndim)-tuple of float) – The physical pixel size.

  • origin ((ndim)-tuple of int) – The physical coordinates of the [0,..,0] pixel (upper-left corner of the storage buffer).

  • layermap (list or None) – A list (or 1D numpy array) mapping input layer indices to the internal buffer. This may be useful if the buffer contains only a portion of a larger data set (as when using distributed data with MPI). If None, provide direct access. to the 3d internal data.

  • padonly (bool) – If True, reformat() will enlarge the internal buffer if needed, but will not shrink it.

  • padding (int) – Number of pixels (voxels) to add as padding around the area defined by the views.

Methods

__init__(container[, ID, data, shape, fill, ...])

allreduce([op])

Performs MPI parallel allreduce with a default sum as reduction operation for internal data buffer self.data.

calc_mem_usage()

copy([owner, ID, fill])

Return a copy of this storage object.

fill([fill])

Fill managed buffer.

formatted_report([table_format, offset, ...])

Returns formatted string and a dict with the respective information

get_view_coverage()

Creates an array in the shape of internal buffer where the value of each pixel represents the number of views that cover that pixel

grids()

reformat([newID, update])

Crop or pad if required.

report()

update()

Update internal state, including all views on this storage to ensure consistency with the physical coordinate system.

update_views([v])

Update the access information for a given view.

zoom_to_psize(new_psize, **kwargs)

Changes pixel size and zooms the data buffer along last two axis accordingly, updates all attached views and reformats if necessary.

Attributes

ID

numID

owner

center

Return the position of the origin relative to the upper-left corner of the storage, in pixel coordinates

dtype

ndim

Number of dimensions for View access

origin

Return the physical position of the upper-left corner of the storage.

psize

The pixel size.

views

Return all the views that refer to this storage.

fill_value

Default fill value

data

Three/four or potentially N-dimensional array as data buffer

allreduce(op=None)#

Performs MPI parallel allreduce with a default sum as reduction operation for internal data buffer self.data. This method does nothing if the storage is distributed across nodes.

Parameters:

op – Reduction operation. If None uses sum.

property center#

Return the position of the origin relative to the upper-left corner of the storage, in pixel coordinates

copy(owner=None, ID=None, fill=None)#

Return a copy of this storage object.

Note: the returned copy has the same container as self.

Parameters:
  • ID (str or int) – A unique ID, managed by the parent

  • fill (scalar or None) – If float, set the content to this value. If None, copy the current content.

data#

Three/four or potentially N-dimensional array as data buffer

fill(fill=None)#

Fill managed buffer.

Parameters:

fill (scalar, numpy array or None.) – Fill value to use. If fill is a numpy array, it is cast as self.dtype and self.shape is updated to reflect the new buffer shape. If fill is None, use default value (self.fill_value).

fill_value#

Default fill value

formatted_report(table_format=None, offset=8, align='right', separator=' : ', include_header=True)#

Returns formatted string and a dict with the respective information

Parameters:
  • table_format (list, optional) –

    List of (item,*length*) pairs where item is name of the info to be listed in the report and length is the column width. The following items are allowed:

    • memory, for memory usage of the storages and total use

    • shape, for shape of internal storages

    • dimensions, is shape \* psize

    • psize, for pixel size of storages

    • views, for number of views in each storage

  • offset (int, optional) – First column width

  • separator (str, optional) – Column separator.

  • align (str, optional) – Column alignment, either 'right' or 'left'.

  • include_header (bool, optional) – Include a header if True.

Returns:

  • fstring (str) – Formatted string

  • dct (dict) – Dictionary containing with the respective info to the keys in table_format

get_view_coverage()#

Creates an array in the shape of internal buffer where the value of each pixel represents the number of views that cover that pixel

Returns:

view coverage in the shape of internal buffer

Return type:

ndarray

grids()#
Returns:

x, y – grids in the shape of internal buffer

Return type:

ndarray

property ndim#

Number of dimensions for View access

property origin#

Return the physical position of the upper-left corner of the storage.

property psize#

The pixel size.

reformat(newID=None, update=True)#

Crop or pad if required.

Parameters:
  • newID (str or int) – If None (default) act on self. Otherwise create a copy of self before doing the cropping and padding.

  • update (bool) – If True, updates all Views before reformatting. Not necessarily needed, if Views have been recently instantiated. Roughly doubles execution time.

Returns:

s – returns new Storage instance in same Container if newId is not None.

Return type:

Storage

report()#
Returns:

a formatted string giving a report on this storage.

Return type:

str

update()#

Update internal state, including all views on this storage to ensure consistency with the physical coordinate system.

update_views(v=None)#

Update the access information for a given view.

Parameters:

v (View or None) – The view object to update. If None, loop through all views. Apart from that, no check is done, not even whether the view is actually on self. Use cautiously.

property views#

Return all the views that refer to this storage.

zoom_to_psize(new_psize, **kwargs)#

Changes pixel size and zooms the data buffer along last two axis accordingly, updates all attached views and reformats if necessary. untested!!

Parameters:

new_psize (scalar or array_like) – new pixel size