Scripting Resources for DigitalMicrograph™ |
PyJEM Example: Sourcing STEM Detector Info as a JSON dict | |
Function |
An example Python script which shows how to source detector info as a JSON dict file. |
Version |
version:20220907, v1.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
- |
Comments |
Run this script at the microscope, and it will source a JSON dictionary file (dict) containing a wealth of information on the settings for a particular detector. There are many commands which will set various microscope parameters. However, often the corresponding get command, to source a setting is not provided. Such information can be sourced from the dictionary file for the detector, which is a JSON type file. This file can be interrogated to extract various bits of information. Here the the HAADF detector is selected. The microscope (in STEM mode) has its scan mode set to subarea (green rectangle on the scan image frame). This sets the parameter. However, there is no equivalent get command to see what scan mode the microscope is in. Therefore, the JSON dict file for the detector is sourced and the scanMode parameter is read, which returns this value. Note, there seems to be inconsistency around the numerical values of Full Scan, Point Mode and Subarea scan - see the script for details. The script also shows how to extract parameters which are nested. Note, that the numbering of detectors in this context depends on which detectors are installed in your microscope. On my F200 there are as follows: 0=camera, 1=HAADF, 2=BF, 3=Ext1, 4=Ext2. My F200, has two STEM detectors and two EDS detectors. Your setup will likely be different. There is also a distinction here between the above description which relates to using the detector.function module to source this type of information, and the approach using the Detector3 module described in this script. The two numbering systems are different and should not be confused - even though it is confusing. |
System Requirements |
Written in Spyder in Anaconda3. Requires a PyJEM-equipped microscope. The script can be opened in Spyder and run from there. Alternatively, double clicking on the script will run it in Python. If the downloaded script as a generic grey file icon it does not have Python set as the default application to open it. Right click on it and set Python to open it. Python lives in the Anaconda3 folder. |
Known Issues |
You have to be careful when reading information from a dict file. For example, if you read it from a STEM detector, it will have a parameter called scanMode (which describes full, spot or subarea mode). However, if you read a dict from another type of detector, eg the camera (JEOL camera not the Gatan camera), it will not have this information, because scanMode is only relevant to STEM detectors. If you try and read a parameter from a dict, which does not exist, it will throw an error, so you will need to be clever about it, for example by using a Try/Catch approach. |
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
zip archive containing the script. |