Introduction#

The purpose of these tutorials is to provide a comprehensive collection of examples targeting a wide range of scientists and engineers interested in ptychography, from experimental users to algorithm and code developers.

Overview#

The table below gives an overview of all examples with associated data and a link for downloading the data.

Tutorial

Download Data

File Size

Reference

The Basics

The Parameter Tree

No Data Required

-

-

JSON/YAML Config Files

No Data Required

-

-

Input/Output Parameters

No Data Required

-

-

Scan Models

No Data Required

-

-

Reconstruction Engines

No Data Required

-

-

Projectional Engines

No Data Required

-

-

Stochastic Engines

No Data Required

-

-

Gradient-based Engines

No Data Required

-

-

Experimental X-ray Data

Loading HDF5 data

small_data.zip

126 MB

DOI

Working With Large Data

dls_i08_nanogold_spiral.zip

1.11 GB

DOI

Fixing Issues Related to Data (Loading)

small_data.zip

126 MB

DOI

Partial Coherence

dls_i08_nanogold_spiral.zip

1.11 GB

DOI

Position Refinement

dls_i14_test_structure.zip

3.68 GB

DOI

Missing Detector Frames

dls_i08_nanogold_raster.zip

993 MB

DOI

Testing different algorithms

dls_i13_butterfly.zip

286 MB

DOI

Using multiple GPUs

dls_i08_nanogold_spiral.zip

1.11 GB

DOI

Working with Data from SOLEIL - the SWING beamline

TBA

4.8 GB

TBA

Maximum Likelihood with the wavefield pre-conditioner

TBA

4.8 GB

TBA

Working with Data from NanoMAX

NanoMax example dataset 10_keV.zip

432 MB

DOI

Working with Data from SoftiMAX

ptycho_on_siemensstar_MAXIV_SoftiMAX.zip

565 MB

DOI

Working with Data from CoSAXS

ptycho_on_siemensstar_MAXIV_CoSAXS.zip

463 MB

DOI

Electron Ptychography Data

Working With Electron Data

dls_epsic_80kV_graphene.zip

270 MB

DOI

Chaining Multiple Engines

dls_epsic_80kV_graphene.zip

270 MB

DOI

Starting From a Previous Reconstruction

dls_epsic_80kV_graphene.zip

270 MB

DOI

Advanced Examples

Nearfield Ptychography

esrf_id16_AlNi_nearfield.zip

532 MB

TBA

Modifying an Engine

esrf_id16_AlNi_nearfield.zip

532 MB

TBA

Live visualisation

dls_i08_nanogold_spiral.zip

1.11 GB

DOI

Simulating Data

No Data Required

-

-

Modified Initial Probe

small_data.zip

126 MB

DOI

User Examples

Template

-

-

-

Super resolution

SiemensStar_ID16A_ESRF_farfieldptycho.zip

67 MB

DOI

Jupyter Lab/Notebooks#

Note

Most of the content of this tutorial has been created in the form of Jupyter Notebooks and the JupyterLab interface is the recommended way of working through these examples. JupyterLab is very easy to use, should you wish to learn more about the Jupyter project and the tools it provides, visit: https://jupyter.org.

As a minimal introduction, a few words about Jupyter Notebooks, which offer a convenient way to provide executable code (e.g. Python) alongside formatted text (using markdown). All notebooks used here are structured in the same way, with some informative content at the top and a full code example at the bottom, separated by a horizontal line:

_images/jupyter_notebook_1.PNG

In order to execute the code cell (or any other cell), simply select the cell and type SHIFT+ENTER or ALT+ENTER

_images/jupyter_notebook_2.PNG

Working with this tutorial within an HPC environment#

It might not always be possible to run Jupyter Notebooks with access to accelerated GPU hardware, for example in the case of only having terminal-based access to an HPC cluster. Below are a few pointers as to how best to run the PtyPy tutorials on an interactive HPC compute node, e.g. using Slurm.

  1. Start an interactive session in the terminal, e.g. single GPU on slurm: srun --ntasks 1 --cpus-per-task 1 --gpus 1 --time 02:00:00 --pty bash

  2. Create a new Python file and paste the full-length code block at the end of the Jupyter-based tutorial into it

  3. Some of the settings in the PtyPy parameter tree are optimised for running it as a Jupyter Notebook, in particular the following should be modified when running interactively with Python

# Give your reconstruction a name
p.run = "test"

# Set verbose level to info
p.verbose_level = "info"

# Set io settings (no files saved)
p.io = u.Param()
p.io.home = "./"
p.io.rfile = "recons/%(run)s/%(run)s_%(engine)s_%(iterations)04d.ptyr"
p.io.autosave = u.Param(active=False)
p.io.interaction = u.Param(active=False)
p.io.autoplot = u.Param(active=False)

this will turn off all interactive plotting that is configured in all Jupyter Notebook tutorials, and it will save the results in a folder called recons in the folder defined as p.io.home.

How to visualise PtyPy output from a .ptyr file#

From a terminal with Graphics#

The simplest way to inspect the reconstruction results saved in the .ptyr file is to use the following command from a terminal with access to Graphics

ptypy.plot <PATH-TO-PTYR-FILE>

From a Jupyter Notebook or a Python script#

An alternative approach is to visualise the results in a Jupyter Notebook or from a Python script using the following code

import os
import ptypy.utils.plot_client as pc
ptyr_filename = "<PATH-TO-PTYR-FILE>"
fig = pc.figure_from_ptyr(ptyr_filename)