Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Acquire STEM Rotation Series with temscript
from pprint import pprint
import temscript as ts
from math import pi
dwelltime = 1e-5 # seconds
tem = ts.Microscope()
illumination = tem._tem_illumination
instrument = ts.GetInstrument()
acq = instrument.Acquisition
stem_detectors = [det for det in acq.Detectors]
values = {'dwelltime(s)':dwelltime, 'image_size':'QUARTER'}
tem.set_detector_param(stem_detectors[0].Info.Name, values)
for detector in stem_detectors:
pprint(detector.Info.Name)
pprint(tem.get_detector_param(detector.Info.Name))
acq.AddAcqDevice(detector)
datas = []
for i in range(4):
illumination.StemRotation = i * pi/2
illumination.BeamBlanked = False
images = acq.AcquireImages()
illumination.BeamBlanked = True
data = {}
for img in images:
data[img.Name] = img.Array
datas.append(data)
pprint(datas)
### Show images with matplotlib
import matplotlib.pyplot as plt
fig, AX = plt.subplots(ncols=2, nrows=2)
(ax1, ax2, ax3, ax4) = AX.flatten()
d = datas[0]['HAADF']
ax1.imshow(d)
d = datas[1]['HAADF']
ax2.imshow(d)
d = datas[2]['HAADF']
ax3.imshow(d)
d = datas[3]['HAADF']
ax4.imshow(d)
plt.show()
### Save data with Hyperspy
import hyperspy.api as hs
signal_names = [detector.Info.Name for detector in stem_detectors]
signals = []
for name in signal_names:
signal_data = []
for rot_data in datas:
signal_data.append(rot_data[name])
s = hs.signals.Signal2D(signal_data)
s.save(name, overwrite=True)
signals.append(s)
hs.stack(signals).save('stack.hspy', overwrite=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment