Search code examples
dm-script

Reconstructing EELS Spectra from Individual Files for SI-picker


I have EELS spectra from a STEM experiment that were unfortunately output into individual files instead of a single stack. Given that the dimensions in the real and EELS space are known, would it be possible to allocate the spectra and reconstruct an image recognizable by SI-picker?

I regret to say that I did not get too far, but I have replicated my situation by generating a set of line spectra filled with random values and saving each into a file.

number numSpectra = 100
number spectrumLength = 512
string baseName = "spectrum_"
string saveDir
GetDirectoryDialog(saveDir)
Image spectrumImage := RealImage("spectrum", 4, spectrumLength)

for( number i = 0; i < numSpectra; i++)
{
    for( number j=1; j< spectrumLength; j++)
    {
        spectrumImage.SetPixel(j, 0, Random()*100)
    }

    string filename = saveDir + baseName + (i + 1)
    spectrumImage.SetName(filename)
    spectrumImage.Save()
    spectrumImage.ShowImage()
}   

Solution

  • This would for sure work, provided the EELS spectra are all the same number of channels (and hopefully calibrated the same.) But you should not iterate over intividual pixels, or you will wait for a very long time. Instead, you need:

    • Create an appropriately sized 3D image
    • Iterate over the x & y dimension of the 3D image, utilizing the slice1() command to address the spectral "slice" at (x,y) - examples can be found both in the F1 help section examples and here on StackOverflow
    • at each position open the correct image-file and copy the values into the slice, i.e.
      Stack3D.Slice1(x,y,0, 2,sizeZ,1 ) = LoadedImage
    • Tag the 3D image so that the software knows it is a Spectrum image: Tags
    • Important: The picker-tool will only work, when the two tags are found prior first data-display. Either tag, then display, or you will have to save and reopen the SI after the script.