Gatan | AMETEKSkip to Main Content
No options found

Extracting a spectrum

Python Script

Access a single spectrum from a 3D STEM SI in DigitalMicrograph. This script assumes a 3D image is frontmost on the workspace.

Preview

'''
Access a single spectrum from a 3D STEM SI in DigitalMicrograph.
This script assume a 3D image is front most on the workspace.
'''
import DigitalMicrograph as DM
import numpy as np

dmImg = DM.GetFrontImage() # Get reference to front most image
dmImgData = dmImg.GetNumArray() # Get NumpyArray to image data
del dmImg	# Always explicitly delete Py_Image variables when no longer needed

# Prompt the user for positions
ok, xPos = DM.GetNumber( 'Enter X coordinate to extract spectrum from.', 0 ) 
ok, yPos = DM.GetNumber( 'Enter Y coordinate to extract spectrum from.', 0 )

# Address spectrum data.
# View indices have to be integers, so convert
# Also note, that the numpy array is of shape (Z,Y,X)
spectrum = dmImgData[:,int(yPos),int(xPos)]

# Show as separate DM image
# We can not create images from VIEWS so we need to copy first
DM.CreateImage(spectrum.copy()).ShowImage()