ptypy.core.ptycho.Ptycho#

class ptypy.core.ptycho.Ptycho(pars=None, level=2, **kwargs)#

Bases: Base

Ptycho : 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

Type:

ptypy.io.interaction.Server

runtime#

Runtime information, e.g. errors, iteration etc.

Type:

Param

~Ptycho.model

THE managing instance for POD, View and Geo instances

Type:

ModelManager

~Ptycho.probe, ~Ptycho.obj,~Ptycho.exit,~Ptycho.diff,~Ptycho.mask

Container instances for illuminations, samples, exit waves, diffraction data and detector masks / weights

Type:

Container

__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,

      see init_structures()

    • 2also configures Containers, initializes ModelManager

      see init_data()

    • 3also initializes ZeroMQ-communication

      see init_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

init_communication()

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.

init_structures()

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

ID

numID

owner

DEFAULT

containers

Dict of all Container instances in the pool of self

pods

Dict of all POD instances in the pool of self

property containers#

Dict of all Container instances 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 if print_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.engines which 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 model and the containers probe for illumination, obj for the samples, exit for the exit waves, diff for diffraction data and Ptycho.mask for 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:

Ptycho

plot_overview(fignum=100)#

plots whole the first four layers of every storage in probe, object % diff

property pods#

Dict of all POD instances in the pool of self

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.runtime will be filled with content.

Parameters:
  • label (str, optional) – Engine label of engine to run. If None all available engines are run in the order they were stored in self.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 see engine

  • engine (BaseEngine, optional) – An engine instance that should be a subclass of BaseEngine or 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