Save microscope and camera parameters in DataModules
I am currently implementing #4 (closed) including an example PyTorch-Lightning script that makes use of the resulting DataModule
s. I have noticed that for each experiment a number of parameters need to be set that should not typically be changed for an experiment. This means, for example, that it would be very easy to set energy=300 keV for the PTO simulation data, even though it was simulated using 200 keV electrons! Similar can be said of the microscope parameters, CCD characteristics, etc.
This is also important for us to create a nominal probe wavefunction, since the abberations defocus and aperture are specific to the experiment and need to be input properly.
Approach
There should be a standard way for us to set most of these parameters when importing a new dataset (in the .prepare_data()
method of its DataModule ideally). This standardization is useful since it will allow down-stream code like our ptychography scripts to infer reasonable defaults. In order to make this as simple as possible, I suggest we save microscope.json
file for each STEMDataModule. The contents of that file should be available in a .microscope
member variable of the data module. Scripts should handle missing keys gracefully, using the .get()
method and providing a default value, or raising a warning that the user must supply a missing value.
Note that the parameters saved in the /Microscope
group in Mark's h5 files are the following:
2-Fold astig.
3-Fold astig.
3-Lobe aberr.
3rd order spher.
4-Fold astig.
4th order coma
5-Fold astig
5th order rosette
5th order spher.
5th order star
6-Fold astig.
Aperture
Axial coma
Axial star aber.
Defocus
Energy
These could be grouped as follows:
energy
aperture
defocus
aberrations
axial_coma
....
We can then add some helper functions to create probes using such parameters.
Plan
I will implement this for the PTODataModule
and push to !5 (merged), reading the appropriate values from the .h5 files. I will update examples/lightning.py
to read these values and initialize the probe to a best-guess nominal wavefunction.
This is a bit tough to test, but if we add functionality to create new probes, we should definitely add tests for at least those portions.