Humboldt-Universität zu Berlin - Faculty of Mathematics and Natural Sciences - Strukturforschung / Elektronenmikroskopie

recordEFTEMStack.txt

// This script will record an EFTEM series with variable exposure time.
// The script may be used, for example for recording a low-loss-series
// that starts with the zeros loss (requires very short exposure times
// and covers part of the low-loss region with much longer exposure time.
//
// This script will implement a kind of auto-exposure feature by
// increasing/decreasing the exposure time, if the average image intensity
// is above/below a certain threshold.

number lowThresh = 500 // expTime will increase if mean below
number highThresh = 3000 // expTime will decrease if mean above
number expTime = 0.1 // exposure time to start with
number imgCount = 10 // number of images
number dE = 1 // energy step in eV
number E0 = 0 // starting energy in eV
number processing = 3 // 3 = gain normalized, 1 = unprocessed

number binX,binY,E
number meanInt,jImg
number expTime0 // exposure time of first image

///////////////////////////////////////////////////////////
// Obtain a few acquisition parameters:
object camera = CM_GetCurrentCamera()
object acq_params = CM_GetCameraAcquisitionParameterSet(camera,"Imaging","Acquire","Record",0)

CM_GetBinning(acq_params, binX, binY)
CM_CCD_GetSize(camera, width, height)

if (!getnumber("Please enter number of images: ",imgCount,imgCount))
throw("EFTEM acquisition cancelled!");
if (!getnumber("Please enter starting energy (eV): ",E0,E0))
throw("EFTEM acquisition cancelled!");
if (!getnumber("Please enter energy step (eV): ",dE,dE))
throw("EFTEM acquisition cancelled!");
if (!getnumber("Please enter Binning in X-direction: ",binX,binX))
throw("EFTEM acquisition cancelled!");
if (!getnumber("Please enter Binning: ",binY,binY))
throw("EFTEM acquisition cancelled!");

//Initialize energy filter communication:
if (!IFSetupCommunication())
throw("Energy filter communication failed!\n");

// create the image for holding the current recording
RealImage img = IntegerImage("current image",2,1,width/binX,height/binY)
RealImage stack = IntegerImage("current image",2,1,width/binX,height/binY,imgCount)

for (jImg=0;jImg<imgCount;jImg++) {
// set the energy offset:
E = E0+jImg*dE
SetDeltaE(E)
// acquire the image
CM_AcquireInplace(img,camera,processing,expTime,binX,binY,0,0,height,width)
meanInt = mean(img)

// check the average intensity and redo the recording, if necessary:
if ((meanInt < lowThresh) || (meanInt > highThresh)) {
// increase/decrease the exposure time by factors that are powers of 2
if (meanInt < lowThresh) expTime *= 2**ceil(log(lowThresh/meanInt)/log(2))
else expTime *= 2**ceil(log(meanInt/highThresh)/log(2))
// acquire the image again, this time with a more appropriate exposure time:
CM_AcquireInplace(img,camera,processing,expTime,binX,binY,0,0,height,width)
}
if (jImg==0) expTime0 = expTime;

// add the current image, normalized to the exposure time to the image stack:
stack[0,0,jImg,width,height,jImg+1] = img*expTime0/expTime;
result("Recorded image "+jImg+" at energy="+E"eV with exposure time="+expTime+"s.\n")
}

setname(stack,"EFTEM series")
showimage(stack)