Scripting Resources for DigitalMicrograph™


Dave Mitchell's DigitalMicrograph™ Scripting Website

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


SEM Stage Scanning
Drives an SEM stage in an X-Y raster while capturing scanning images using DigiScan to build up a large area montage.
version:20170803, v1.0
D. R. G. Mitchell
Thanks to Mitchell Nancarrow for assistance with testing and suggestions for improvements.

This script is designed to be used on an SEM which has DigiScan attached. Typically, this will be a CL system. It creates a large area montage by moving the stage in an X-Y raster while capturing snapsphots from a continuously running DigiScan image. There is no post-capture alignment, such as cross-correlation. It simply relies on the stage positioning. This script was designed to capture large area survey images at very low magnification (eg 250x), and under these conditions, the stage should be reasonably accurate. No automatic focusing is applied either. Provided the specimen is flat and the magnification is low, this should not be an issue. Images are copied into a montage to create a large map. Images can be either pasted or merged. The former produces an montage which contains lots of floating sub-images. This doubles the size of the final image, but does allow individual frames to be selected and manually repositioned. This would allow manual correction of any minor stage errors, provided the montages contain only a small number of images. Merging images result in a montage which is a single image, and which does not allow for post-acquisition repositioning. The merged image is around half the size of the pasted counterpart as it is only a single image.The absence of alignment/focusing and the fast image capture from a continuous acquisition makes mapping very fast. A montage of some hundred or so images (1.2mm x 2mm area!) took around 20mins to capture. In contrast, using a proprietary routine on commercial EDS software with position realignment would have taken over 2hrs.

This script was written to provide a way of mapping large areas in CL mode, to look for zircons - which can be present at very low density. The aim was to write a companion script to then interrogate the map via thresholding or other image processing, to move the stage to regions containing potentially interesting particles. It turns out that in the Oxford EDS system we have we can import this large map, and then link the current stage position with the image. Thereafter, clicking anywhere on the large map will move the stage to the selected position automatically. Mission accomplished.

I have not tested this script on a TEM, but since the stage control commands are generic and common to both SEM and TEM, it should work. However, in the absence of any image realignment, this would only be feasible at the bottom end of the magnification range, at perhaps 2,000x or less. Biology folk might find it useful. I would recommend using the paste rather than merge option, so that you have the option to manually adjust any individual frame positions. Detailed instructions on choosing the paste or merg options are provided at the start of the script.


System Requirements
This script has been tested using GMS 2.3 and Gatan's DigiScan II. Compatibility with older DigiScans and GMS 1.x is unknown. Tested on a JEOL 6490L SEM, but should be compatible with most SEMs which have a DigiScan attached. It may be compatible with most modern TEMs too.
Known Issues

WARNING: This script moves the microscope stage. There is the potential to drive inclined or incorrectly set specimens into a detector or the polepiece. A CL mirror may be particularly vulnerable to damage if the specimen colides with it. This script does not monitor stage to detector/polepice distances, and does not protect against collisions. Users must ensure that the specimen height is appropriate over the scanned areas.

This script is provided in good faith, but with no warranty as to its fitness for purpose. Anyone using this script does so entirely at their own risk. The author accepts no responsibility for any damages or losses which may occur from its use.

I have not implemented this script as a background thread, so you will not be able to do other things in DM while it is running. To halt the script simply hold down the SPACE BAR. This script can create seriously large images, especially if you are using high resolution DigiScan resolutions such as 1k x 1k. 32bit versions of DM will be limited to images no larger than 2GB, which will take some doing. Be aware that if you paste images (into a larger montage image), you have to deal with the size of the large image as well as all the small component images. If you merge, then you only have to deal with the size of the large image. If you need to make really big images, use the merge option. This is set through the Global Info Tags - see the start of the script for more details.

You can set an overlap between adjacent images. A small value like 5% is good. If you set it to zero, you will end up with some narrow black lines between images due to minor stage errors. If you set the value to be large (eg 30%), then the total acquisition time will increase significantly. I have not implemented image aligned by cross-correlation, so large overlaps offer no benefit. It would be fairly easy to implement alignment, but my aim here was speed, and this is quick. Also, the stage seems pretty good on the microscope I tested it on. I have included a backlash correction option. There are two settings which you will need to set if you want to use this option (in the Global Info Tags). These are the backlash correction percentages. They have a sign and a magnitude. The percentage is a displacement as a fraction of the individual frame size. The sign dictates which direction the offset is applied. The correction is applied at the start of each row of images. Scanning is left to right and top to bottom the stage backlash correction should be down and right at the start of the row, before moving back to the starting row position. This ensures the stage is being driven in the direction it will move, before the row scan starts. A backlash value of 5-10% seems reasonable and the sign will depend on your system - some stages may have flipped axes. Chose positive values and run the script to see what the stage does. Then reverse the of any correction which is not correct.

MAKE SURE that scan rotation is turned off in the SEM and in DigiScan before running this script. My SEM had an option to link rotation correction to magnification. This deals with the fact that the image rotates slightly as the magnification is changed. In order to get reliable mapping, this had to be set to on.

To keep things fast, DigiScan runs continously and the script takes snapshots of the resulting image. For this reason it is essential that the Settling Time (time the script waits after a stage movement) is sufficient for at least one complete frame to be captured by DigiScan and where stage movement or drift is not present. Typically, the Settling Time should be twice the DigiScan exposure time. I may develop this script further if users show any interest or have specific requests.

Included Files
Main script.
Source Code

see attached script