ptypy.core.ptycho.Ptycho#
- class ptypy.core.ptycho.Ptycho(pars=None, level=2, **kwargs)#
Bases:
BasePtycho : A ptychographic data holder and reconstruction manager.
This is the highest level class. It organizes and contains the data, manages the reconstruction engines, and interacts with the outside world.
If MPI is enabled, this class acts both as a manager (rank = 0) and a worker (any rank), and most information exists on all processes. In its original design, the only part that is divided between processes is the diffraction data.
By default Ptycho is instantiated once per process, but it can also be used as a managed container to load past runs.
- CType,FType
numpy dtype for arrays. FType is for data, i.e. real-valued arrays, CType is for complex-valued arrays
- Type:
numpy.dtype
- interactor#
ZeroMQ interaction server for communication with e.g. plotting clients
- ~Ptycho.probe, ~Ptycho.obj,~Ptycho.exit,~Ptycho.diff,~Ptycho.mask
Container instances for illuminations, samples, exit waves, diffraction data and detector masks / weights
- Type:
- __init__(pars=None, level=2, **kwargs)#
- Parameters:
pars (Param) – Input parameters, subset of the ptypy parameter tree
level (int) –
Determines how much is initialized.
<= 0 : empty ptypy structure
- 1reads parameters, configures interaction server,
- 2also configures Containers, initializes ModelManager
see
init_data()
- 3also initializes ZeroMQ-communication
- 4also initializes reconstruction engines,
see
init_engine()
- >= 4also and starts reconstruction
see
run()
Methods
__init__([pars, level])calc_mem_usage()copy_state([name, overwrite])Store a copy of the current state of object/probe and exit
finalize()Cleanup
Called on __init__ if
level >= 3.init_data([print_stats])Called on __init__ if
level >= 2.init_engine([label, epars])Called on __init__ if
level >= 4.Called on __init__ if
level >= 1.load_run(runfile[, load_data])Load a previous run.
plot_overview([fignum])plots whole the first four layers of every storage in probe, object % diff
print_stats([table_format, detail])Calculates the memory usage and other info of ptycho instance
restore_state([name, reformat_exit])Restore object/probe based on a previously saved copy The exit buffer can be reformatted or loaded from the state
run([label, epars, engine])Called on __init__ if
level >= 5.save_run([alt_file, kind, force_overwrite])Save run to file.
Attributes
IDnumIDownerDEFAULTDict of all
Containerinstances in the pool of selfDict of all
PODinstances in the pool of self- copy_state(name='baseline', overwrite=False)#
Store a copy of the current state of object/probe and exit
Warning: This feature is under development and syntax might change!
- finalize()#
Cleanup
- init_communication()#
Called on __init__ if
level >= 3.Initializes ZeroMQ communication on the master node and spawns an optional plotting client.
- init_data(print_stats=True)#
Called on __init__ if
level >= 2.Call
ModelManager.new_data()Prints statistics on the ptypy structure ifprint_stats=True
- init_engine(label=None, epars=None)#
Called on __init__ if
level >= 4.Initializes engine with label label from parameters and lists it internally in
self.engineswhich is an ordered dictionary.- Parameters:
label (str) – Label of engine which is to be created from parameter set of the same label in input parameter tree. If
None, an engine is created for each available parameter set in input parameter tree sorted by label.epars (Param or dict) – Set of engine parameters. The created engine is listed as auto00, auto01 , etc in
self.engines
- init_structures()#
Called on __init__ if
level >= 1.Prepare everything for reconstruction. Creates attributes
modeland the containersprobefor illumination,objfor the samples,exitfor the exit waves,difffor diffraction data andPtycho.maskfor detectors masks
- classmethod load_run(runfile, load_data=True)#
Load a previous run.
- Parameters:
runfile (str) – file dump of Ptycho class
load_data (bool) – If True also load data (thus regenerating pods & views for ‘minimal’ dump
- Returns:
P – Ptycho instance with
level == 2- Return type:
- plot_overview(fignum=100)#
plots whole the first four layers of every storage in probe, object % diff
- print_stats(table_format=None, detail='summary')#
Calculates the memory usage and other info of ptycho instance
- restore_state(name='baseline', reformat_exit=True)#
Restore object/probe based on a previously saved copy The exit buffer can be reformatted or loaded from the state
Warning: This feature is under development and syntax might change!
- run(label=None, epars=None, engine=None)#
Called on __init__ if
level >= 5.Start the reconstruction with at least one engine. As a consequence,
self.runtimewill be filled with content.- Parameters:
label (str, optional) – Engine label of engine to run. If
Noneall available engines are run in the order they were stored inself.engines. If the engine is not yet created,init_engine()is called for that label.epars (dict or Param, optional) – Engine parameter set. An engine is created from this set, using
init_engine()and run immediately afterwards. For parameters seeengineengine (BaseEngine, optional) – An engine instance that should be a subclass of
BaseEngineor have the same methods.
- save_run(alt_file=None, kind='minimal', force_overwrite=True)#
Save run to file.
As for now, diffraction / mask data is not stored
- Parameters:
alt_file (str) – Alternative filepath, will override io.save_file
kind (str) –
Type of saving, one of:
’minimal’, only initial parameters, probe and object storages, positions and runtime information is saved.
’full_flat’, (almost) complete environment