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


EELS Display Component Spectra
Extracts and displays each slice in a composite EELS spectrum as stand-alone spectra.
version:150912, v1.1
D. R. G. Mitchell
Although this script is billed as a EELS script - it should work on any intensity profile, EDS spectrum etc. These frequently consist of overlaid spectra and in the case of EELS, background fits and extracted edges. This script will extract all such slices present in the front-most spectrum and display them as stand-alone spectra.


System Requirements
This script should be compatible with all recent versions of DigitalMicrograph.
Known Issues
Included Files
Main script.
Source Code

// Script to extract and display overlaid spectra. For example an EELS spectrum with a

// background fitted contains the spectrum, the background and the extracted edge.

// Running this script with such a spectrum front-most would display the three component

// spectra as individual spectra.


// D. R. G. Mitchell, (remove the nospam to make this work)

// version:20150912, v1.1, September 2015,


// Source the front-most image and check that it is a 1D spectrum


number nodocs=countdocumentwindowsoftype(5)



showalert("Ensure an EELS Spectrum is shown front-most.",2)





image front:=getfrontimage()

number xsize, ysize

getsize(front, xsize, ysize)



showalert("Ensure an EELS spectrum is shown front-most.",2)





// Count the number of slices in the image and get some info


number i, noslices, found

imagedisplay imgdisp=front.imagegetimagedisplay(0)


string imgname=getname(front)

taggroup sourcetags=front.imagegettaggroup()



// Loop through the slices in the spectrum, displaying each slice as a stand-alone spectrum



for(i=0; i<noslices; i++)


// Get the slice

object sliceid=imgdisp.imagedisplaygetsliceidbyindex(i)

string slicename=imgdisp.imagedisplaygetslicelabelbyid(sliceid)



// Extract it as an image and display it

image slice:=imageclone(front{i})// clone the actual slice to pick up all the image calibrations, tags etc



// label and display the component spectrum

setname(slice, imgname+" ("+slicename+")")

documentwindow docwin=getdocumentwindow(0)

docwin.windowsetframeposition(found*30, found*30)

imagecopycalibrationfrom(slice, front)