Scripting Resources for DigitalMicrograph™

banner

Dave Mitchell's DigitalMicrograph™ Scripting Website

Home | Scripts | Examples | Functions | Recent Updates | Tutorials | Resources | Publications | Consulting | Projects | Contact & Bio |PyJEM| Search

 

PyJEM Example: Getting and Setting Aperture Positions.
Function
Shows how to select a microscope aperture and change its size.
Version
version:20220824, v1.0
Author
D. R. G. Mitchell
Acknowledgements
-
Comments

This Python script sources the currently selected aperture identity from a PyJEM-equipped JEOL microscope. It then selects and inserts the largest SA aperture, and finally sets the aperture selection back to what it originally was. This can be tested in an offline system. However, if you test it at the microscope, ensure that the .offline is removed from line where the TEM3 module is imported from PyJEM. Instructions are provided at the start of the script.

If you run this script at the microscope interface you will see the SA aperture get seleted, the largest SA aperture inserted and the aperture selection get restored to what it was previously. Remember to remove the SA aperture after testing.

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
Aperture selection/movement takes time, as do many other microscope operations, such as moving the screen, inserting detectors etc. There does not appear to be any kind of 'microscope is busy, please wait' flag available within PyJEM with which to pause the script until the microscope is ready. If you send a command to the microscope when it is busy doing something else, it will beep and throw an error. This is not fatal, but it does mean the offending command did not get actioned. The solution, is to provide delays between calls to the microscope. This can be tricky, because some operations (eg retracting the Faraday Cup in the HXA aperture) can take five or more seconds to complete. In practice you will have to fine tune your script to ensure that the delays are long enough to avoid errors, but not so long that script execution is sluggish.
Supported
Yes
Included Files
Main script file.
Source Code

zip archive containing the script.