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

 

Function: Gaussian Fit
Function
Fits a Gaussian function to a passed in 1D data set, such as an EELS zero loss peak.
Version
version:20230117, v1.0
Author
D. R. G. Mitchell and W. Bertram
Acknowledgements
-
Comments

This function will do a Gaussian fit to the passed in spectrum. The function returns 1 for a successful fit and 0 if it fails. The function returns by reference the fit parameters. The fit parameters returned by reference are the peak centroid, the amplitude, the full width at half maximum and the sigma value. Also returned by reference is the fitted peak.

The threshold fitting parameter is a weighting parameter which determines how much of the peak tails are fitted. The value (a fraction of the peak intensity value normalised to 1) specifies the range fitted. So a value of say 0.5, will fit all the peak regions from the left-most channel which exceeds this intensity (normalised to the peak intensity), through the peak centroid and across to the right-most channel which exceeds this intensity value.

The script will process the front-most image displayed, which should be a 1D intensity profile containing a Gaussian-shaped peak.

This is based on my earlier script, but here the code is wrapped up in a function, making it easier to implement, and much faster for recursive application using the fit parameters.

System Requirements
Should be compatible with all recent versions of DigitalMicrograph. Tested on GMS 2.32.
Known Issues
A true Gaussian peak will trail off to zero in the tails. Many experimental peaks, like EDS and EELS ZLPs do not do this. If fitting fails, try adjusting the threshold parameter to higher values such as 0.2 to 0.5. This will weight the fit on the centroid and ignore the tails. This is fine where, for example, it is the position of the peak centroid/peak intensity which is of interest, rather than the integrated peak intensity. Values of around 0.2 seem to provide both reliable and accurate fitting.
Supported
Yes
Included Files
Main script file.
Source Code

See attached script file.