ptypy.core.classes.Container#

class ptypy.core.classes.Container(owner=None, ID=None, data_type='complex', data_dims=2, distribution='cloned')#

Bases: Base

High-level container class.

Container can be seen as a “super-numpy-array” which can contain multiple sub-containers of type Storage, potentially of different shape, along with all View instances that act on these Storages to extract data from the internal data buffer Storage.data.

Typically there will be five such base containers in a Ptycho reconstruction instance:

  • Cprobe, Storages for the illumination, i.e. probe,

  • Cobj, Storages for the sample transmission, i.e. object,

  • Cexit, Storages for the exit waves,

  • Cdiff, Storages for diffraction data, usually one per scan,

  • Cmask, Storages for masks (and weights), usually one per scan,

A container can conveniently duplicate all its internal Storage instances into a new Container using copy(). This feature is intensively used in the reconstruction engines where buffer copies are needed to temporarily store results. These copies are referred by the “original” container through the property copies() and a copy refers to its original through the attribute original In order to reduce the number of View instances, Container copies do not hold views and use instead the Views held by the original container

original#

If self is copy of a Container, this attribute refers to the original Container. Otherwise it is None.

Type:

Container

data_type#

Either “single” or “double”

Type:

str

__init__(owner=None, ID=None, data_type='complex', data_dims=2, distribution='cloned')#
Parameters:
  • ID (str or int) – A unique ID, managed by the parent.

  • owner (Base) – A possible subclass of Base that holds this Container.

  • data_type (str or numpy.dtype) – data type - either a numpy.dtype object or ‘complex’ or ‘real’ (precision is taken from ptycho.FType or ptycho.CType)

  • data_dims (int) – dimension of data, can be 2 or 3

  • distribution (str) – Indicates if the data is “cloned” in all MPI processes or “scattered”

Methods

__init__([owner, ID, data_type, data_dims, ...])

allreduce([op])

Performs MPI parallel allreduce with a sum as reduction for all Storage instances held by self

calc_mem_usage()

clear()

Reduce / delete all data in attached storages

copy([ID, fill, dtype])

Create a new Container matching self.

delete_copy([copy_IDs])

Delete a copy or all copies of this container from owner instance.

fill([fill])

Fill all storages with scalar value fill

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

Returns formatted string and a dict with the respective information

info()

Returns the container's total buffer space in bytes and storage info.

new_storage([ID])

Create and register a storage object.

reformat([also_in_copies])

Reformats all storages in this container.

report()

Returns a formatted report string on all storages in this container.

views_in_storage(s[, active_only])

Return a list of views on Storage s.

Attributes

ID

numID

owner

S

A property that returns the internal dictionary of all Storage instances in this Container

Sp

A property that returns the internal dictionary of all Storage instances in this Container as a Param

V

A property that returns the internal dictionary of all View instances in this Container

Vp

A property that returns the internal dictionary of all View instances in this Container as a Param

copies

Property that returns list of all copies of this Container

dtype

Property that returns numpy dtype of all internal data buffers

nbytes

Return total number of bytes used by numpy array buffers in this container.

size

Return total number of pixels in this container.

storages

A property that returns the internal dictionary of all Storage instances in this Container

views

A property that returns the internal dictionary of all View instances in this Container

ndim

Default data dimensionality for Views and Storages.

property S#

A property that returns the internal dictionary of all Storage instances in this Container

property Sp#

A property that returns the internal dictionary of all Storage instances in this Container as a Param

property V#

A property that returns the internal dictionary of all View instances in this Container

property Vp#

A property that returns the internal dictionary of all View instances in this Container as a Param

allreduce(op=None)#

Performs MPI parallel allreduce with a sum as reduction for all Storage instances held by self

Parameters:
  • c (Container) – Input

  • op – Reduction operation. If None uses sum.

clear()#

Reduce / delete all data in attached storages

property copies#

Property that returns list of all copies of this Container

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

Create a new Container matching self.

The copy does not manage views.

Parameters:
  • fill (scalar or None) – If None (default), copy content. If scalar, initializes to this value

  • dtype (valid data type or None) – If None, the copy will have the same data type as the original, is specified the returned instance will contain empty buffers.

delete_copy(copy_IDs=None)#

Delete a copy or all copies of this container from owner instance.

Parameters:

copy_IDs (str) – ID of copy to be deleted. If None, deletes all copies

property dtype#

Property that returns numpy dtype of all internal data buffers

fill(fill=0.0)#

Fill all storages with scalar value fill

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) –

    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) – Include a header if True

Returns:

  • fstring (str) – Formatted string

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

info()#

Returns the container’s total buffer space in bytes and storage info.

Returns:

  • space (int) – Accumulated memory usage of all data buffers in this Container

  • fstring (str) – Formatted string

Note

May get deprecated in future. Use formatted_report instead.

property nbytes#

Return total number of bytes used by numpy array buffers in this container. This is not the actual size in memory of the whole container, as it does not include the views or dictionary overhead.

ndim#

Default data dimensionality for Views and Storages.

new_storage(ID=None, **kwargs)#

Create and register a storage object.

Parameters:
  • ID (str) – An ID for the storage. If None, a new ID is created. An error will be raised if the ID already exists.

  • kwargs – Arguments for new storage creation. See doc for Storage.

reformat(also_in_copies=False)#

Reformats all storages in this container.

Parameters:

also_in_copies (bool) – If True, also reformat associated copies of this container

report()#

Returns a formatted report string on all storages in this container.

property size#

Return total number of pixels in this container.

property storages#

A property that returns the internal dictionary of all Storage instances in this Container

property views#

A property that returns the internal dictionary of all View instances in this Container

views_in_storage(s, active_only=True)#

Return a list of views on Storage s.

Parameters:
  • s (Storage) – The storage to look for.

  • active_only (True or False) – If True (default), return only active views.