ptypy.core.classes.Container#
- class ptypy.core.classes.Container(owner=None, ID=None, data_type='complex', data_dims=2, distribution='cloned')#
Bases:
BaseHigh-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 allViewinstances that act on these Storages to extract data from the internal data bufferStorage.data.Typically there will be five such base containers in a
Ptychoreconstruction 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
Storageinstances into a new Container usingcopy(). 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 propertycopies()and a copy refers to its original through the attributeoriginalIn order to reduce the number ofViewinstances, 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:
- 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
Basethat 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
allreducewith a sum as reduction for allStorageinstances held by selfcalc_mem_usage()clear()Reduce / delete all data in attached storages
copy([ID, fill, dtype])Create a new
Containermatching 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
Storages.Attributes
IDnumIDownerA property that returns the internal dictionary of all
Storageinstances in thisContainerA property that returns the internal dictionary of all
Storageinstances in thisContaineras aParamA property that returns the internal dictionary of all
Viewinstances in thisContainerA property that returns the internal dictionary of all
Viewinstances in thisContaineras aParamProperty that returns list of all copies of this
ContainerProperty that returns numpy dtype of all internal data buffers
Return total number of bytes used by numpy array buffers in this container.
Return total number of pixels in this container.
A property that returns the internal dictionary of all
Storageinstances in thisContainerA property that returns the internal dictionary of all
Viewinstances in thisContainerDefault data dimensionality for Views and Storages.
- property S#
A property that returns the internal dictionary of all
Storageinstances in thisContainer
- property Sp#
A property that returns the internal dictionary of all
Storageinstances in thisContaineras aParam
- property Vp#
A property that returns the internal dictionary of all
Viewinstances in thisContaineras aParam
- allreduce(op=None)#
Performs MPI parallel
allreducewith a sum as reduction for allStorageinstances held by self- Parameters:
c (Container) – Input
op – Reduction operation. If
Noneuses sum.
- clear()#
Reduce / delete all data in attached storages
- copy(ID=None, fill=None, dtype=None)#
Create a new
Containermatching 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 \* psizepsize, 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
See also
- 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.
See also
- 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
Storageinstances in thisContainer