Scan Models#
Learning about the different scan models and their parameters, and when to use which one of them.
The scan model is one of the core components that defines a ptychography experiment, it creates different data structures such as Views, Containers and Storages. It also creates the PODs which link the containers (and views) of probe, object, exit wave and diffraction data. PtyPy offers a range of different scan models
The most commonly used scan model is
Full
and should work in most cases, but might not be suitable for large datasets (>10k frames)GradFull
is a variation ofFull
that does not create separate exit containers for each POD - it therefore has a much lower memory footprint while remaining compatibility with theePIE
andML
engines (not compatible withDM
and other projectional engines).BlockFull
is another variation ofFull
designed for large data and accelerated engines.BlockFull
requiresp.frames_per_block
to be set to a reasonable value.Vanilla
is a lightweight scan model that can be useful for simple simulations.
All the Full
- flavoured models share the same set of parameters, while Vanilla
has a much smaller sub-set of parameters.
Let’s look at some of these parameters in a bit more detail. When we define a scan in the parameter tree, we can give it a name (e.g. MF
) and specify the scan model to be used (e.g. Full
)
p.scans = u.Param()
p.scans.MF = u.Param()
p.scans.MF.name = "Full"
Next, we can specify the initial illumination to be a circular aperture with a 3-micron diameter and a 2-pixel wide edge
p.scans.MF.illumination = u.Param()
p.scans.MF.illumination.aperture = u.Param()
p.scans.MF.illumination.aperture.form = "circ"
p.scans.MF.illumination.aperture.size = 3e-6
p.scans.MF.illumination.aperture.offset = 0
p.scans.MF.illumination.aperture.edge = 2
We should also define the number of photons of the incident illumination. Setting photons
to None
will estimate this value from the statistics of the data
p.scans.MF.illumination.photons = None
For the initial object we can just use an empty image filled with ones
p.scans.MF.sample = u.param()
p.scans.MF.sample.fill = 1
p.scans.MF.sample.process = None
PtyPy can reconstruct data from ptychography experiments that are collected in either farfield
or nearfield
geometry
p.scans.MF.propagation = "farfield"
And finally, we need to specify which data to load into the scan model. Here we can use the same MoonFlowerScan
simulation as in previous examples
p.scans.MF.data= u.Param()
p.scans.MF.data.name = "MoonFlowerScan"
p.scans.MF.data.shape = 128
p.scans.MF.data.num_frames = 200
p.scans.MF.data.save = None
p.scans.MF.data.density = 0.2
p.scans.MF.data.photons = 1e8
p.scans.MF.data.psf = 0.
Challenge
Modify the illumination
and sample
parameters in the example below and observe how it affects the initial state and final state of the reconstruction by using different levels in Ptycho(…)
and ptypy.utils.plot_client.figure_from_ptycho
for plotting. Note that a change in the initial state of illumination and/or object might affect the convergence and/or quality of the reconstruction.
import ptypy
import ptypy.utils as u
p = u.Param()
p.verbose_level = "interactive"
p.io = u.Param()
p.io.rfile = None
p.io.autosave = u.Param(active=False)
p.io.interaction = u.Param(active=False)
# Live-plotting
p.io.autoplot = u.Param()
p.io.autoplot.active=True
p.io.autoplot.threaded = False
p.io.autoplot.layout = "jupyter"
p.io.autoplot.interval = 10
# Define the scan model
p.scans = u.Param()
p.scans.MF = u.Param()
p.scans.MF.name = "Full"
# Define initial illumination
p.scans.MF.illumination = u.Param()
p.scans.MF.illumination.aperture = u.Param()
p.scans.MF.illumination.aperture.form = "circ"
p.scans.MF.illumination.aperture.size = 3e-6
p.scans.MF.illumination.aperture.offset = 0
p.scans.MF.illumination.aperture.edge = 2
# Define initial object
p.scans.MF.sample = u.Param()
p.scans.MF.sample.fill = 1
p.scans.MF.sample.process = None
# Set the nr. of photons in the initial illumination
# None will use data to estimate this value
p.scans.MF.illumination.photons = None
# Farfield or Nearfield geometry
p.scans.MF.propagation = "farfield"
# Data loader / simulator
p.scans.MF.data= u.Param()
p.scans.MF.data.name = "MoonFlowerScan"
p.scans.MF.data.shape = 128
p.scans.MF.data.num_frames = 200
p.scans.MF.data.save = None
p.scans.MF.data.density = 0.2
p.scans.MF.data.photons = 1e8
p.scans.MF.data.psf = 0.
p.engines = u.Param()
p.engines.engine00 = u.Param()
p.engines.engine00.name = "DM"
p.engines.engine00.numiter = 80
P = ptypy.core.Ptycho(p,level=4)
fig = ptypy.utils.plot_client.figure_from_ptycho(P)