Scripting Resources for DigitalMicrograph™ |
PyJEM: ApCon - Aperture Control | |
Function |
A Python script which provides control of microscope apertures via the keyboard. |
Version |
version:20220921, v1.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
- |
Comments |
The software control in TEM Centre for aperture positioning on current generation JEOL microscopes (which do not have the (optional) hardware control panel) is pretty ordinary to say the least. When looking through the binoculars hitting the requisite aperture movement button with the mouse is challenging, and of course the left direction button moves the aperture in any direction but leftwards. This Python script creates an aperture control panel which allows apertures to be inserted/retracted. It also allows an aperture to be selected and in this state the microscope keyboard arrow keys can be used to position the selected aperture. There are two control values per aperture, the step size and the angle. These change the magnitude of each movement step and the direction of movement respectively. The latter means that some vague correlation between the direction key being pressed and the direction of aperture movement is achievable. The complete set of step and angle settings for all aperture can be saved/loaded, making it possible to create mutliple configurations, since these values will change between STEM and TEM modes, and different step sizes may be needed for low, medium and high magnifications. Finally, the script can configure the microscope into Ronchigram mode. While the JEOL interface has this capability, the functionality in this script is fully customisable. For example, the BF STEM detector can be withdrawn during Ronchigram mode and reinserted afterwards, to avoid the common issue of the microscope forgetting it had a BF STEM detector inserted prior to the Ronchigram mode being setup. The script listener, which listens for keyboard presses is only active when the ApCon dialog is front-most (selected). When you are not using it, you can click anywhere in the TEM Centre interface and the dialog will sit in the background doing nothing. When you need to use it, select it from the Windows Task Bar, and provided you have an aperture selected in ApCon, keyboard control will work. Press Esc or deselect the aperture in ApCon to turn off keyboard listening. |
System Requirements |
Written in Spyder in Anaconda3. Requires a PyJEM-equipped JEOL 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 appears 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 C://Anaconda3 folder. When you launch ApCon by double clicking on it, a Console window will also appear. The script will report diagnostic information in that Console. However, you do need to refer to this window during use. You can minimise the Console, but you must not close it. If you encounter any problems, the Console will tell you which operations were the last to be successfully completed before the script stopped. You MUST configure this script to match your microscope hardware. This was set up on a JEOL F200. Even if you have this microscope, you may have different (optional) apertures installed. Detailed instructions on configuring the script are provided at the start of the script. |
Known Issues |
Many microscope operations, such as retracting a detector, lowering the screen, moving an aperture etc take a finite amount of time. If the script makes a call to the microscope while such an operation is still occurring, an error occurs - the microscope beeps and an error message appears in TEM Centre. Such errors are not fatal, but the offending microscope command will be skipped. To avoid this issue a delay parameter called sleeptime is used to pause the script after each microscope operation in order to give it time to complete. In the case of aperture movements, if the previous aperture movement has not completed before the next request is received, an error/beep will occur. However, the next, aperture movement request after that will be executed normally ie these errors are a minor irritation, not a problem. To avoid such errors you may need to increase the sleeptime parameter (at the start of the script) in small increments (eg 0.1s) until you no longer encounter frequent beeps while moving apertures. Large movement steps for slow apertures may require such large values of sleeptime, that the response becomes annoyingly sluggish. You can avoid having to use an excessively large sleeptime value by pulse pressing the aperture direction keys, while listening to the aperture motor - once it stops - press again. This is my first (recent) major Python scripting project. This code is not how you should write Python script. I have not used Classes/ Class Methods and as a result I have used a huge number of global variables. This is very poor coding practice. In my subsequent scripts I have corrected this deficiency. If you are looking to develop your own PyJEM scripts, follow my subsequent scripts, such as Beam Shower. I may rework this (ApCon) script into a better form, if I make future revisions to it. This script is provided in good faith. The author provides no warranty as to its fitness for purpose. Users of this script do so entirely at their own risk. The author accepts no responsibility for any losses or damages which may arise from its use. Users are advised to consult with their microscope manager before using PyJEM scripts.
Troubleshooting: Minor Errors: The errors mentioned above, caused by asking the microscope to do something while it is busy, are trivial. The microscope beeps, an error message appears in TEM Centre, the offending command is skipped and everything continues to work as normal - no further action is required.
Major Errors: Step 1: I have not encountered any with this script. However, I have seen them in other scripts and they likely arise from untrapped exceptions (the script encounters an error but the error is not caught and Python hangs). Symptoms will include a beep, but no error message popup. In the error log a cryptic error message may appear. Script interaction with TEM Centre stops - TEM Centre continues to work normally. This can be resolved by right clicking on the TEM icon (bottom right of TEM Centre window) to bring up the Emergency panel. This shows LEDs which indicate error states. None will be lit. Click on Stop Alarm in the bottom right of the Emergency window. Normal operation should resume. Step 2: If the above does not work, then in TEM Centre switch from Scanning to TEM mode and then back again. If scripting was blocked, you might find that the script dialog would not appear. Doing the above STEM to TEM to STEM shuffle causes it to reappear, and normal operation is resumed. Step 3: The above two steps have resolved all the major errors I have encountered. However, had they not, then restarting TEM Centre would have been the last thing to try. |
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
zip archive containing the script. |