Reading a Nion File with ScopeReader

Gerd Duscher

12/05/2020

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

UNDER CONSTRUCTION

Introduction

Swift from Nion runs on all of Nion’s STEMs for 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.

[5]:
%pylab notebook
%gui qt
import os
import sys
from sidpy.io.interface_utils import openfile_dialog
sys.path.append('../')
from SciFiReaders import NionReader
import SciFiReaders
print('SciFiReaders version: ', SciFiReaders.__version__)
import sidpy
print('sidpy version: ', sidpy.__version__)
Populating the interactive namespace from numpy and matplotlib
SciFiReaders version:  0.0.1
sidpy version:  0.0.5

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]:
file_name = openfile_dialog()
print(file_name)
/home/o2d/Dropbox (ORNL)/TEM data/2021/2021-04-16-Cr-graphene-US100-60kV-60pA/Nion Swift Project 20210416 Data/2021/04/16/20210416-142215/data_0UEJQVTQ9X8OQYF8HJO70C8CB.ndata

Catch a bad selection or cancelling of file selection

[3]:
if len(file_name) < 3:
    print('No valid file selected')
else:
    path, base_file_name = os.path.split(file_name)
    basename, extension = os.path.splitext(base_file_name)
    if extension not in ['.ndata', '.h5']:
        print('File not supported')

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 Nion File you get a TypeError.

[6]:
nion_reader = NionReader(file_name)
dataset = nion_reader.read()

print(dataset)
dataset
sidpy.Dataset of type IMAGE with:
 dask.array<generic, shape=(256, 256), dtype=float32, chunksize=(256, 256), chunktype=numpy.ndarray>
 data contains: intensity (counts)
 and Dimensions:
y:  distance (nm) of size (256,)
x:  distance (nm) of size (256,)
[6]:
Array Chunk
Bytes 262.14 kB 262.14 kB
Shape (256, 256) (256, 256)
Count 1 Tasks 1 Chunks
Type float32 numpy.ndarray
256 256

Plot File

Only one command is necessary to plot the file.

[7]:
dataset.plot()

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.

[8]:
dataset.view_original_metadata()
type : data-item
uuid : 1242c2e8-618b-49c2-aea7-f5a5dbd03373
created : 2021-04-16T20:40:19.416463
is_sequence : False
intensity_calibration :
        offset : 0.0
        scale : 1.0
        units :
dimensional_calibrations : [{'offset': -10.0, 'scale': 0.078125, 'units': 'nm'}, {'offset': -10.0, 'scale': 0.078125, 'units': 'nm'}]
timezone : America/New_York
timezone_offset : -0400
metadata :
        instrument :
                high_tension : 60000.0
                defocus : 3.3413595086161986e-10
                ImageScanned :
                        C1 ConstW : 0.535
                        C10 : 3.3413595086161986e-10
                        C10Control : 0.0
                        C12.a : 7.790575877604827e-09
                        C12.b : -9.344480956695125e-09
                        C2 ConstW : 0.759
                        C21.a : 2.3036487004760242e-07
                        C21.b : 1.580289523538976e-07
                        C23.a : 2.8574413811668664e-08
                        C23.b : 2.6551966593848706e-08
                        C3 ConstW : 0.971829
                        C30 : 1.986602299690654e-06
                        C32.a : 6.5178947510754046e-06
                        C32.b : 9.143814019988201e-06
                        C34.a : 3.281084172769262e-06
                        C34.b : 2.3774745854848426e-06
                        C41.a : -0.0003642179172182993
                        C41.b : -0.0002498513591704886
                        C43.a : -6.776627974180181e-05
                        C43.b : -6.296990054644458e-05
                        C45.a : -0.00026451435339213097
                        C45.b : -6.462188328094359e-05
                        C50 : -0.0052123977838471015
                        C52.a : -0.011348718258983872
                        C52.b : -0.002997953401518279
                        C54.a : -0.005022485544683429
                        C54.b : -0.0015520939749976963
                        C56.a : 0.0010483179923364597
                        C56.b : -0.00016883886847779785
                        EHT : 60000.0
                        PMTBF_gain : 4096000.0
                        PMTDF_gain : 1024000.0
                        SShft.sx : -0.00012910587277402402
                        SShft.sy : -0.00019696069461356278
                        SShftZ : -3.4789550834968264e-05
                        StageCoordU : 0.0004952773115228157
                        StageCoordV : 0.0017437740677182785
                        StageOutA : -3.5118041570771e-08
                        StageOutB : 3.114038584183673e-08
                        StageOutX : -0.00012910587277402402
                        StageOutY : -0.00019696069461356278
                        StageOutZ : -3.4789550834968264e-05
                        PL1 : 0.54036
                        PL2 : 0.0
                        PL3 : 0.8263
                        PL4 : 1.241
        scan :
                hardware_source_id : superscan
                hardware_source_name : SuperScan
                scan_id : 02a1025e-d701-415f-ac1e-7472c803906a
                center_x_nm : 0.0
                center_y_nm : 0.0
                fov_nm : 20.0
                rotation : 0.21293016874330817
                rotation_deg : 12.199999999999998
                scan_context_size : [256, 256]
                subscan_fractional_size : [1.0, 1.0]
                scan_size : [256, 256]
                subscan_fractional_center : [0.5, 0.5]
                scan_device_parameters :
                        size : [256, 256]
                        center_nm : [0.0, 0.0]
                        pixel_time_us : 750
                        fov_nm : 20.0
                        rotation_rad : 0.21293016874330817
                        ac_line_sync : False
                        ac_frame_sync : False
                        flyback_time_us : 300
                        external_clock_mode : 1
                        external_clock_wait_time_ms : 20000
                        external_scan_mode : 0
                        external_scan_ratio : 1.0
                        subscan_pixel_size : [256, 256]
                        subscan_fractional_size : [1.0, 1.0]
                        subscan_fractional_center : [0.5, 0.5]
                        subscan_rotation : 0.0
                        scan_id : 02a1025e-d701-415f-ac1e-7472c803906a
                        section_rect : [[0, 0], [256, 256]]
                        data_shape_override : [256, 256]
                        state_override : complete
                        top_left_override : [0, 0]
                scan_device_properties :
                        ac_line_sync : 2.0
                        center_x_nm : 0.0
                        center_y_nm : 0.0
                        flyback_time_us : 1500.0
                        fov_nm : 20.0
                        line_time_us : 193500.0
                        pixel_time_us : 750.0
                        pixels_x : 256.0
                        pixels_y : 256.0
                        requested_pixel_time_us : 750.000006519258
                        rotation_deg : 12.2
                        rotation_rad : 0.212930168743308
                        mag_boards :
                                MagBoard 0 DAC 0 : 0.0
                                MagBoard 0 DAC 1 : 0.0
                                MagBoard 0 DAC 10 : 40403.0
                                MagBoard 0 DAC 11 : 16709.0
                                MagBoard 0 DAC 2 : 0.0
                                MagBoard 0 DAC 3 : 0.0
                                MagBoard 0 DAC 4 : 40433.0
                                MagBoard 0 DAC 5 : 17084.0
                                MagBoard 0 DAC 6 : 1434.0
                                MagBoard 0 DAC 7 : 64215.0
                                MagBoard 0 DAC 8 : 64586.0
                                MagBoard 0 DAC 9 : 866.0
                                MagBoard 0 Relay : 32.0
                                MagBoard 1 DAC 0 : 0.0
                                MagBoard 1 DAC 1 : 0.0
                                MagBoard 1 DAC 10 : 0.0
                                MagBoard 1 DAC 11 : 0.0
                                MagBoard 1 DAC 2 : 0.0
                                MagBoard 1 DAC 3 : 0.0
                                MagBoard 1 DAC 4 : 0.0
                                MagBoard 1 DAC 5 : 0.0
                                MagBoard 1 DAC 6 : 0.0
                                MagBoard 1 DAC 7 : 0.0
                                MagBoard 1 DAC 8 : 0.0
                                MagBoard 1 DAC 9 : 0.0
                                MagBoard 1 Relay : 32.0
                valid_rows : 256
        hardware_source :
                hardware_source_id : superscan
                hardware_source_name : SuperScan
                exposure : 49.152
                frame_index : 0
                channel_id : a
                channel_name : a
                pixel_time_us : 750.0
                line_time_us : 193500.0
                valid_rows : 256
                channel_index : 0
                reference_key : superscan_a
                view_id : fd80be9e-5016-4b24-9aa3-6600cc176395
title : Spectrum Image (a)
session_id : 20210416-142215
session :
        site : Oak Ridge National Laboratory
        instrument : NION UltraSTEM 100
        task :
        microscopist :
        sample :
        sample_area :
category : persistent
version : 13
modified : 2021-04-16T20:40:31.628236
data_shape : [256, 256]
data_dtype : float32
collection_dimension_count : 0
datum_dimension_count : 2
data_modified : 2021-04-16T20:40:31.399368
[ ]: