Reading a DM3 File with ScopeReader#

Gerd Duscher

10/09/2020

This document is a simple example of how to read DM3 Files into the sidpy dataformat

UNDER CONSTRUCTION

Introduction#

Digital Micrograph from Gatan runs on many TEMs for data acquisition. We read and plot such files here.

Import all necessary packages#

There are a few setup procedures that need to be followed before any code is written. In this step, we simply load a few python packages that will be necessary in the later steps.

[2]:
%matplotlib widget
import matplotlib.pylab as plt
import numpy as np

import sys
from sidpy.io.interface_utils import open_file_dialog
sys.path.insert(0,'../../')
from SciFiReaders import DM3Reader
import SciFiReaders
print('SciFiReaders version: ', SciFiReaders.__version__)
import sidpy
print('sidpy version: ', sidpy.__version__)
You don't have igor2 installed.     If you wish to open igor files, you will need to install it     (pip install igor2) before attempting.
You don't have gwyfile installed.     If you wish to open .gwy files, you will need to      install it (pip install gwyfile) before attempting.
c:\Users\gduscher\Documents\Github\SciFiReaders\notebooks\01_using_readers\../..\SciFiReaders\readers\microscopy\spm\afm\AR_hdf5.py:250: SyntaxWarning: invalid escape sequence '\s'
  match = re.search(r"^" + name + ":\s+(.+$)", self.notes, re.M)
SciFiReaders version:  0.11.6
sidpy version:  0.12.3

Open a file dialog#

Here we select the name of the file to open. We will be using the sidpy interface to do that.

The openfile_dialog will open QT file dialog to select a file.

For examples go to the example_data directory in the original folder of this notebook.

Note.: in some operating systems the window will not show up on top, look in your task bar.

[2]:
%gui qt5
Cannot execute code, session has been disposed. Please try restarting the Kernel.
The Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details.
[3]:

file_list = open_file_dialog()
[13]:
FileList = open_file_dialog()
[4]:
file_list.file_name

[4]:
'c:\\Users\\gduscher\\Documents\\2022-Experiment\\2022-08-18\\eels2.dm3'

Catch a bad selection or cancelling of file selection#

[5]:


if len(file_list.file_name) < 3 or file_list.file_name[-4:] != '.dm3': print('File not supported')
[4]:
file_list.file_name
[4]:
'c:\\Users\\gduscher\\Documents\\2023-Experiments\\09222023eels\\gr_LL_0.dm4'

Read file#

We use the ScopeReader to read the file into a sidpy dataset. All metadata (absolutely everything) is saved in the original_metadata attribute of the sidpy Dataset. If the selected file is not a dm3 File you get an IOError.

[6]:
dm3_reader = DM3Reader(file_list.file_name)
datasets = dm3_reader.read()
datasets

[6]:
{'Channel_000': sidpy.Dataset of type SPECTRUM with:
  dask.array<array, shape=(2048,), dtype=float32, chunksize=(2048,), chunktype=numpy.ndarray>
  data contains: intensity (counts)
  and Dimensions:
 energy_loss:  energy-loss (eV) of size (2048,)
  with metadata: ['experiment']}
[7]:
dataset = datasets['Channel_000']
dataset
[7]:
Array Chunk
Bytes 8.00 kiB 8.00 kiB
Shape (2048,) (2048,)
Dask graph 1 chunks in 1 graph layer
Data type float32 numpy.ndarray
2048 1

Plot File#

Only one command is necessary to plot the file.

[8]:
FileWidget.file_name
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[8], line 1
----> 1 FileWidget.file_name

NameError: name 'FileWidget' is not defined
[11]:
view = dataset.plot()

DM3 Original Metadata#

Digital micrograph stores a lot of metadata in the file and we read all of them and store that information in the original_metadata.

[13]:
dataset.view_original_metadata()
ImageData :
        Calibrations :
                Brightness :
                        Origin : 0.0
                        Scale : 1.0
                        Units : Counts
                Dimension :
                        0 :
                                Origin : -1400.0
                                Scale : 0.25
                                Units : eV
                DisplayCalibratedUnits : 1
        Data : read
        DataType : 2
        Dimensions :
                0 : 2048
        PixelDepth : 4
ImageTags :
        Acquisition :
                Device :
                        Active Size (pixels) : [2048, 520]
                        Camera Number : 0
                        CCD :
                                Pixel Size (um) : [14.0, 14.0]
                        Configuration :
                                Transpose :
                                        Diagonal Flip : 0
                                        Horizontal Flip : 0
                                        Vertical Flip : 0
                        Name : QUEFINA 1
                        Source : QUEFINA 1
                Frame :
                        Area :
                                Transform :
                                        Class Name : cm_acquisitiontransform_list
                                        Transform List :
                                                0 :
                                                        Binning : [1, 130]
                                                        Class Name : cm_acquisitiontransform
                                                        Sub Area Adjust : [0, 0, 0, 0]
                                                        Transpose :
                                                                Diagonal Flip : 0
                                                                Horizontal Flip : 0
                                                                Vertical Flip : 0
                        CCD :
                                Pixel Size (um) : [1820.0, 14.0]
                        Intensity :
                                Transform :
                                        Class Name : cm_valuetransform_list
                                        Transform List :
                                                0 :
                                                        Class Name : cm_valuetransform_affine
                                                        Offset : 250.0
                                                        Scale : 1.0
                                                1 :
                                                        ADC Max : 65535.0
                                                        ADC Min : 0.0
                                                        Class Name : cm_valuetransform_adc
                Parameters :
                        Acquisition Write Flags : 4294967295
                        Base Detector :
                                Class Name : cm_namedcameradetectorparameterset
                                Name : default
                        Detector :
                                continuous : 1
                                exposure (s) : 2.0
                                hbin : 1
                                height : 260
                                left : 0
                                top : 130
                                vbin : 130
                                width : 2048
                        Environment :
                                Mode Name : Spectroscopy
                        High Level :
                                Acquisition Buffer Size : 0
                                Antiblooming : 0
                                Binning : [1, 130]
                                CCD Read Area : [130, 0, 390, 2048]
                                CCD Read Ports : 1
                                Choose Number Of Frame Shutters Automatically : 1
                                Class Name : cm_camera_highlevelparameters
                                Continuous Readout : 1
                                Corrections : 305
                                Corrections Mask : 817
                                Exposure (s) : 2.0
                                Number Of Frame Shutters : 1
                                Processing : Dark Subtracted
                                Quality Level : 1
                                Read Frame Style : 0
                                Read Mode : 13
                                Secondary Shutter Post Exposure Compensation (s) : 0.0
                                Secondary Shutter Pre Exposure Compensation (s) : 0.0
                                Shutter :
                                        Primary Shutter States : 0
                                        Primary Shutter States Mask : 0
                                        Secondary Shutter States : 0
                                        Secondary Shutter States Mask : 0
                                        Shutter Exposure : 0
                                        Shutter Index : 0
                                Shutter Post Exposure Compensation (s) : 0.0
                                Shutter Pre Exposure Compensation (s) : 0.0
                                Transform :
                                        Diagonal Flip : 0
                                        Horizontal Flip : 0
                                        Vertical Flip : 0
                        Objects :
                                0 :
                                        Class Name : cm_imgproc_finalcombine
                                        Frame Combine Style : Copy
                                        Parameter 1 : 1.0
                        Parameter Set Name : Acquire
                        Parameter Set Tag Path : Spectroscopy:Acquire:Acquire
                        Version : 33947648
        EELS :
                Acquisition :
                        Continuous mode : 0
                        Date : 12/14/2019
                        End time : 1:31:04 PM
                        Exposure (s) : 2.0
                        Integration time (s) : 20.0
                        Number of frames : 10
                        Saturation fraction : 0.21766255795955658
                        Start time : 1:30:41 PM
                Experimental Conditions :
                        Collection semi-angle (mrad) : 33.0
                        Convergence semi-angle (mrad) : 30.0
        EELS Spectrometer :
                Dispersion (eV/ch) : 0.25
                Dispersion index : 4
                Drift tube enabled : 1
                Drift tube voltage (V) : 400.0
                Energy loss (eV) : 400.0
                HT offset (V) : 0.0
                HT offset enabled : 0.0
                Instrument ID : 3977
                Instrument name : Enfinium ER NION
                Mode : 0
                Prism offset (V) : -0.0
                Prism offset enabled  : 1
        Meta Data :
                Acquisition Mode : Parallel dispersive
                Format : Spectrum
                Signal : EELS
        Microscope Info :
                Cs(mm) : 0.0
                Emission Current (A) : 0.0
                Formatted Indicated Mag : 100x
                Formatted Voltage : 200kV
                Illumination Mode : STEM
                Imaging Mode : IMAGING
                Indicated Magnification : 100.0
                Name : Unknown
                Operation Mode : SCANNING
                Probe Current (nA) : 0.0
                Probe Size (nm) : 0.0
                STEM Camera Length : 2.8
                Voltage : 200000.0
        Session Info :
                Items :
                        0 :
                                Data Type : 20
                                Label : Specimen
                                Precision : 0
                                Tag path : Session Info:Specimen
                                Units :
                                Value :
                        1 :
                                Data Type : 20
                                Label : Operator
                                Precision : 0
                                Tag path : Session Info:Operator
                                Units :
                                Value :
                        2 :
                                Data Type : 20
                                Label : Microscope
                                Precision : 0
                                Tag path : Session Info:Microscope
                                Units :
                                Value :
                Microscope :
                Operator :
                Specimen :
Name : 01-EELS Acquire_STO
UniqueID :
        0 : 774116825
        1 : 412555428
        2 : 1897604613
        3 : 952377132
DM :
        dm_version : 3
        file_size : 322611
        full_file_name : C:/Users/gduscher/Documents/Github/SciFiReaders/notebooks/01_using_readers/example_data/EELS_STO.dm3
original_filename : C:/Users/gduscher/Documents/Github/SciFiReaders/notebooks/01_using_readers/example_data/EELS_STO.dm3
ApplicationBounds : [0, 0, 1065, 1916]
DocumentObjectList :
        0 :
                AnnotationGroupList :
                AnnotationType : 20
                BackgroundColor : [-1, -1, -1]
                BackgroundMode : 2
                FillMode : 2
                ForegroundColor : [-1, 0, 0]
                HasBackground : 0
                ImageDisplayInfo :
                        BackgroundColor : [-5655, -5655, -5655]
                        BackgroundOn : 1
                        CalibrationSliceId :
                                0 : 0
                        CaptionAttributes : 7
                        CaptionColor : [0, 0, 0]
                        CaptionFaceName : Lucida Sans Unicode
                        CaptionOn : 1
                        CaptionSize : 10
                        CursorOn : 0
                        CursorPosition : 0.0
                        DimensionLabels :
                                0 :
                        DynamicContrast : 1
                        FrameOn : 1
                        GridColor : [0, -1, -1]
                        GridOn : 1
                        GroupId : 0
                        GroupList :
                                0 :
                                        DoAutoSurveyHigh : 1
                                        DoAutoSurveyLow : 1
                                        GroupToDisplay :
                                                Offset : [-0.0, -0.0]
                                                Scale : [0.00048828125, 4.16666489400086e-06]
                                        TrackStyleX : 0
                                        TrackStyleY : 0
                        LegendOn : 0
                        MainSliceId :
                                0 : 0
                        NumHorizontalTicks : 1
                        NumVerticalTicks : 1
                        SliceList :
                                0 :
                                        BaseIntensity : 0.0
                                        ComplexMode : 4
                                        DrawFill : 1
                                        DrawLine : 0
                                        DrawTransparent : 0
                                        FillColor : [23644, -16449, -16449]
                                        Horz Pos Fixed : 1
                                        Horz Scale Fixed : 1
                                        ImageToGroup :
                                                Offset : [0.0, 0.0]
                                                Scale : [1.0, 1.0]
                                        IsVisible : 1
                                        LineColor : [0, -32640, -16449]
                                        LineStyle : 0
                                        LineThickness : 1
                                        SliceGroup : 0
                                        SliceId :
                                                0 : 0
                                        Transparency : 0.0
                                        TransparencyStyle : 0
                                        Vert Pos Fixed : 1
                                        Vert Scale Fixed : 1
                        SurveyRegion : 1
                ImageDisplayType : 3
                ImageSource : 0
                IsMoveable : 1
                IsResizable : 1
                IsSelectable : 1
                IsTranslatable : 1
                IsVisible : 1
                ObjectTags :
                Rectangle : [0.0, 0.0, 342.0, 669.0]
                UniqueID : 8
DocumentTags :
HasWindowPosition : 1
Image Behavior :
        DoIntegralZoom : 0
        ImageDisplayBounds : [0.0, 0.0, 342.0, 669.0]
        IsZoomedToWindow : 1
        UnscaledTransform :
                Offset : [0.0, 0.0]
                Scale : [1.0, 1.0]
        ViewDisplayID : 8
        WindowRect : [0.0, 0.0, 342.0, 669.0]
        ZoomAndMoveTransform :
                Offset : [0.0, 0.0]
                Scale : [1.0, 1.0]
ImageSourceList :
        0 :
                ClassName : ImageSource:Simple
                Extra Slice Info :
                        0 :
                                Id :
                                        0 : 0
                                Label : Spectrum
                Id :
                        0 : 0
                ImageRef : 1
InImageMode : 1
MinVersionList :
        0 :
                RequiredVersion : 50659328
NextDocumentObjectID : 9
Page Behavior :
        DoIntegralZoom : 0
        DrawMargins : 1
        DrawPaper : 1
        IsFixedInPageMode : 0
        IsZoomedToWindow : 1
        LayedOut : 0
        PageTransform :
                Offset : [0.0, 0.0]
                Scale : [1.0, 1.0]
        RestoreImageDisplayBounds : [0.0, 0.0, 342.0, 669.5]
        RestoreImageDisplayID : 8
        TargetDisplayID : 4294967295
PageSetup :
        General : [1, 1000, 8500, 11000, 1000, 1000, -1000, -1000]
        Win32 : b'\x04\x00\x00\x004!\x00\x00\xf8*\x00\x00M\x01\x00\x00M\x01\x00\x00\xfa\x00\x00\x00\xfa\x00\x00\x00\xe8\x03\x00\x00\xe8\x03\x00\x00\xe8\x03\x00\x00\xe8\x03\x00\x00\x00\x00\x00\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x18\x00'
        Win32_DevModeW : b'S\x00e\x00n\x00d\x00 \x00T\x00o\x00 \x00O\x00n\x00e\x00N\x00o\x00t\x00e\x00 \x002\x000\x001\x000\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x04\x00\x06\xdc\x00\x0c\x03\x03\xff\x00\x00\x01\x00\x01\x00\xea\no\x08d\x00\x01\x00\x0f\x00X\x02\x02\x00\x01\x00X\x02\x02\x00\x00\x00L\x00e\x00t\x00t\x00e\x00r\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00DINU"\x00\xd0\x00\x0c\x03\x00\x00\xc2\xac\x90Q\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd0\x00\x00\x00SMTJ\x00\x00\x00\x00\x10\x00\xc0\x00S\x00e\x00n\x00d\x00 \x00T\x00o\x00 \x00M\x00i\x00c\x00r\x00o\x00s\x00o\x00f\x00t\x00 \x00O\x00n\x00e\x00N\x00o\x00t\x00e\x00 \x002\x000\x001\x000\x00 \x00D\x00r\x00i\x00v\x00e\x00r\x00\x00\x00RESDLL\x00UniresDLL\x00PaperSize\x00LETTER\x00Orientation\x00PORTRAIT\x00Resolution\x00DPI600\x00ColorMode\x0024bpp\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
        Win32_DevNamesW : b'\x04\x00*\x00?\x00\x00\x00S\x00e\x00n\x00d\x00 \x00T\x00o\x00 \x00M\x00i\x00c\x00r\x00o\x00s\x00o\x00f\x00t\x00 \x00O\x00n\x00e\x00N\x00o\x00t\x00e\x00 \x002\x000\x001\x000\x00 \x00D\x00r\x00i\x00v\x00e\x00r\x00\x00\x00S\x00e\x00n\x00d\x00 \x00T\x00o\x00 \x00O\x00n\x00e\x00N\x00o\x00t\x00e\x00 \x002\x000\x001\x000\x00\x00\x00n\x00u\x00l\x00:\x00\x00\x00'
SentinelList :
Thumbnails :
        0 :
                ImageIndex : 0
                SourceSize_Pixels : [669, 342]
WindowPosition : [410, 8, 752, 677]
[ ]: