In [48]:
%matplotlib notebook

import pathlib
import json
import h5py
import numpy as np
import matplotlib.pyplot as plt

import ncempy.io as nio

Quick view FEI / Thermo Fischer Velox EMD file

  • Best for single scan STEM datasets with 1 or multiple detectors (HAADF, ADF, BF, ABF, etc.)
  • Set the directory name and then the file name
  • Show mutliple detector images in a 2xN set of columns
  • Save the pyplot figure for easy display and insertion into documents

In [49]:
# Setup file name
dName = pathlib.Path(r'C:\Users\linol\Downloads')
fName = pathlib.Path('1435 1.2 Mx STEM HAADF-DF4-DF2-BF.emd')

In [50]:
with nio.emdVelox.fileEMDVelox(str(dName / fName)) as emd0:
    print(emd0) # print out information about the emd dataset
    if len(emd0.list_data) > 1:
        multipleFlag = True
        fg1, ax1 = plt.subplots(nrows=round(len(dsetGroups)/2+0.1),ncols=2,figsize=(5,5)) #two columns
        ax1 = ax1.ravel()
    else:
        fg1, ax1 = plt.subplots(nrows=1,ncols=1,figsize=(5,5)) #two columns
    
    for ii,dset in enumerate(emd0.list_data):
        dd, md = emd0.get_dataset(dset)
        
        # Plot all of the images
        if multipleFlag:
            fovX = md['pixelSize'][0]*dd.shape[0]
            fovY = md['pixelSize'][1]*dd.shape[1]
            ax1[ii].imshow(dd,extent=[0,fovX,0,fovY],origin='lower')
            ax1[ii].set(xlabel='X (nm)',ylabel='Y (nm)',title=detectorName[ii])
        else:
            fovX = md['pixelSize'][0]*dd.shape[0]
            fovY = md['pixelSize'][1]*dd.shape[1]
            ax1.imshow(dd,extent=[0,fovX,0,fovY],origin='lower')
            ax1.set(xlabel='X (nm)',ylabel='Y (nm)',title=detectorName[ii])
fg1.tight_layout()


EMD file contains 4 data sets
Dataset #0 from detector: DF4
Dataset #1 from detector: HAADF
Dataset #2 from detector: DF2
Dataset #3 from detector: BF
pixel size = (0.0849, 0.0849) nm

Save the figure with a high dpi (for display only)

  • Note: The TIF file will look exactly like the figure above and is for convenience only.
  • Use ncempy.io.emdVelox to get the raw data for analysis.

In [51]:
fg1.savefig((dName / fName.with_suffix('.tif')).as_posix(),dpi=300)

Print and write out the metadata as text

  • In the EMD file, the metadata (experimental details like accelerating voltage, pixel size, apertures, extraction voltage, etc.) is stored in the format of a JSON file.

In [52]:
import pprint
pp = pprint.PrettyPrinter(indent=0)

#Print out the meta data
with nio.emdVelox.fileEMDVelox(str(dName / fName)) as emd0:
    emd0.parseMetaData(emd0.list_data[0])
    pp.pprint(emd0.metaDataJSON)

#Write to txt file with nice printing
with open(dName / fName.with_suffix('.txt'),'w') as f0:
    f0.write(pp.pformat(jj))


{'Acquisition': {'AcquisitionDatetime': {'DateTime': '0'},
               'AcquisitionStartDatetime': {'DateTime': '1524605728'},
               'BeamType': '',
               'SourceType': 'XFEG'},
'BinaryResult': {'AcquisitionUnit': '',
                'CompositionType': '',
                'Detector': 'DF4',
                'DetectorIndex': '3',
                'Encoding': '',
                'Offset': {'x': '-4.3477386684438299e-008',
                          'y': '-4.3477386684438299e-008'},
                'PixelSize': {'height': '8.4916770868043554e-011',
                             'width': '8.4916770868043554e-011'},
                'PixelUnitX': 'm',
                'PixelUnitY': 'm'},
'Core': {'MetadataDefinitionVersion': '7.9',
        'MetadataSchemaVersion': 'v1/2013/07',
        'guid': '00000000000000000000000000000000'},
'CustomProperties': {'Aperture[C1].Name': {'type': 'string', 'value': '2000'},
                    'Aperture[C2].Name': {'type': 'string', 'value': '50'},
                    'Aperture[C3].Name': {'type': 'string', 'value': 'None'},
                    'Aperture[OBJ].Name': {'type': 'string', 'value': 'None'},
                    'Aperture[SA].Name': {'type': 'string', 'value': 'None'},
                    'Detectors[SuperXG21].BilatThresholdHi': {'type': 'double',
                                                             'value': '0.00321471'},
                    'Detectors[SuperXG21].KMax': {'type': 'double',
                                                 'value': '180'},
                    'Detectors[SuperXG21].KMin': {'type': 'double',
                                                 'value': '120'},
                    'Detectors[SuperXG21].PulsePairResolutionTime': {'type': 'double',
                                                                    'value': '5e-007'},
                    'Detectors[SuperXG21].SpectrumBeginEnergy': {'type': 'long',
                                                                'value': '120'},
                    'Detectors[SuperXG22].BilatThresholdHi': {'type': 'double',
                                                             'value': '0.00326512'},
                    'Detectors[SuperXG22].KMax': {'type': 'double',
                                                 'value': '180'},
                    'Detectors[SuperXG22].KMin': {'type': 'double',
                                                 'value': '120'},
                    'Detectors[SuperXG22].PulsePairResolutionTime': {'type': 'double',
                                                                    'value': '5e-007'},
                    'Detectors[SuperXG22].SpectrumBeginEnergy': {'type': 'long',
                                                                'value': '120'},
                    'Detectors[SuperXG23].BilatThresholdHi': {'type': 'double',
                                                             'value': '0.00339845'},
                    'Detectors[SuperXG23].KMax': {'type': 'double',
                                                 'value': '180'},
                    'Detectors[SuperXG23].KMin': {'type': 'double',
                                                 'value': '120'},
                    'Detectors[SuperXG23].PulsePairResolutionTime': {'type': 'double',
                                                                    'value': '5e-007'},
                    'Detectors[SuperXG23].SpectrumBeginEnergy': {'type': 'long',
                                                                'value': '120'},
                    'Detectors[SuperXG24].BilatThresholdHi': {'type': 'double',
                                                             'value': '0.00327348'},
                    'Detectors[SuperXG24].KMax': {'type': 'double',
                                                 'value': '180'},
                    'Detectors[SuperXG24].KMin': {'type': 'double',
                                                 'value': '120'},
                    'Detectors[SuperXG24].PulsePairResolutionTime': {'type': 'double',
                                                                    'value': '5e-007'},
                    'Detectors[SuperXG24].SpectrumBeginEnergy': {'type': 'long',
                                                                'value': '120'},
                    'MaxPossiblePixelValue': {'type': 'double',
                                             'value': '65535'},
                    'Scan.ScanTransformation.A11': {'type': 'double',
                                                   'value': '1'},
                    'Scan.ScanTransformation.A12': {'type': 'double',
                                                   'value': '0'},
                    'Scan.ScanTransformation.A13': {'type': 'double',
                                                   'value': '0'},
                    'Scan.ScanTransformation.A21': {'type': 'double',
                                                   'value': '0'},
                    'Scan.ScanTransformation.A22': {'type': 'double',
                                                   'value': '1'},
                    'Scan.ScanTransformation.A23': {'type': 'double',
                                                   'value': '0'},
                    'StemMagnification': {'type': 'double', 'value': '910000'}},
'Detectors': {'Detector-0': {'CollectionAngleRange': {'begin': '0',
                                                   'end': '0.0071570493100233251'},
                           'DetectorName': 'BF',
                           'DetectorType': 'ScanningDetector',
                           'Enabled': 'true',
                           'Gain': '35.938200000000002',
                           'Inserted': 'true',
                           'Offset': '0'},
             'Detector-1': {'Binning': {'height': '4', 'width': '4'},
                           'DarkGainCorrectionType': '3',
                           'DetectorName': 'BM-Ceta',
                           'DetectorType': 'ImagingDetector',
                           'ExposureMode': '',
                           'ExposureTime': '0.5',
                           'ReadOutArea': {'bottom': '1024',
                                          'left': '0',
                                          'right': '1024',
                                          'top': '0'},
                           'Shutters': {'Shutter-0': {'Position': 'PostSpecimen',
                                                    'Type': 'Electrostatic'}}},
             'Detector-2': {'CollectionAngleRange': {'begin': '0.0096829294176655981',
                                                   'end': '0.015759366233659311'},
                           'DetectorName': 'DF2',
                           'DetectorType': 'ScanningDetector',
                           'Enabled': 'true',
                           'Gain': '31.900200000000002',
                           'Inserted': 'true',
                           'Offset': '0'},
             'Detector-3': {'CollectionAngleRange': {'begin': '0.018314407572795014',
                                                   'end': '0.0735345123137464'},
                           'DetectorName': 'DF4',
                           'DetectorType': 'ScanningDetector',
                           'Enabled': 'true',
                           'Gain': '36.543900000000001',
                           'Inserted': 'true',
                           'Offset': '0'},
             'Detector-4': {'CollectionAngleRange': {'begin': '0.078112293235793648',
                                                   'end': '0.44709913884082586'},
                           'DetectorName': 'HAADF',
                           'DetectorType': 'ScanningDetector',
                           'Enabled': 'true',
                           'Gain': '43.067348948262875',
                           'Inserted': 'true',
                           'Offset': '-1.5601593017578121'},
             'Detector-5': {'AnalyticalDetectorShutterState': '0',
                           'AzimuthAngle': '0.78539816339744828',
                           'BeginEnergy': '120',
                           'CollectionAngle': '0.17499999999999999',
                           'DetectorName': 'SuperXG21',
                           'DetectorType': 'AnalyticalDetector',
                           'Dispersion': '10',
                           'ElectronicsNoise': '31',
                           'ElevationAngle': '0.31415926999999999',
                           'Enabled': 'false',
                           'Inserted': 'true',
                           'OffsetEnergy': '-1000',
                           'PulseProcessTime': '3.0000000000000001e-006'},
             'Detector-6': {'AnalyticalDetectorShutterState': '0',
                           'AzimuthAngle': '2.3561944901923448',
                           'BeginEnergy': '120',
                           'CollectionAngle': '0.17499999999999999',
                           'DetectorName': 'SuperXG22',
                           'DetectorType': 'AnalyticalDetector',
                           'Dispersion': '10',
                           'ElectronicsNoise': '31',
                           'ElevationAngle': '0.31415926999999999',
                           'Enabled': 'false',
                           'Inserted': 'true',
                           'OffsetEnergy': '-1000',
                           'PulseProcessTime': '3.0000000000000001e-006'},
             'Detector-7': {'AnalyticalDetectorShutterState': '0',
                           'AzimuthAngle': '3.9269908169872414',
                           'BeginEnergy': '120',
                           'CollectionAngle': '0.17499999999999999',
                           'DetectorName': 'SuperXG23',
                           'DetectorType': 'AnalyticalDetector',
                           'Dispersion': '10',
                           'ElectronicsNoise': '31',
                           'ElevationAngle': '0.31415926999999999',
                           'Enabled': 'false',
                           'Inserted': 'true',
                           'OffsetEnergy': '-1000',
                           'PulseProcessTime': '3.0000000000000001e-006'},
             'Detector-8': {'AnalyticalDetectorShutterState': '0',
                           'AzimuthAngle': '5.497787143782138',
                           'BeginEnergy': '120',
                           'CollectionAngle': '0.17499999999999999',
                           'DetectorName': 'SuperXG24',
                           'DetectorType': 'AnalyticalDetector',
                           'Dispersion': '10',
                           'ElectronicsNoise': '31',
                           'ElevationAngle': '0.31415926999999999',
                           'Enabled': 'false',
                           'Inserted': 'true',
                           'OffsetEnergy': '-1000',
                           'PulseProcessTime': '3.0000000000000001e-006'}},
'EnergyFilter': {'EntranceApertureType': ''},
'GasInjectionSystems': '',
'Instrument': {'ComputerName': 'THEMISX',
              'ControlSoftwareVersion': '2.9.1',
              'InstrumentClass': 'Titan',
              'InstrumentId': '3580',
              'InstrumentModel': 'Titan',
              'Manufacturer': 'FEI Company'},
'Optics': {'AccelerationVoltage': '300000',
          'Apertures': {'Aperture-0': {'Diameter': '0.002',
                                     'Enabled': '0',
                                     'MechanismType': 'Motorized',
                                     'Name': 'C1',
                                     'Number': '1',
                                     'PositionOffset': {'x': '0.0010425600000000001',
                                                       'y': '0.00158176'},
                                     'Type': 'Circular'},
                       'Aperture-1': {'Diameter': '5.0000000000000002e-005',
                                     'Enabled': '3',
                                     'MechanismType': 'Motorized',
                                     'Name': 'C2',
                                     'Number': '2',
                                     'PositionOffset': {'x': '0.0099441600000000005',
                                                       'y': '0.00023664000000000004'},
                                     'Type': 'Circular'},
                       'Aperture-2': {'MechanismType': 'Manual',
                                     'Name': 'C3',
                                     'Number': '3',
                                     'Type': 'None'},
                       'Aperture-3': {'MechanismType': 'Motorized',
                                     'Name': 'OBJ',
                                     'Number': '4',
                                     'PositionOffset': {'x': '9.9999999999999991e-005',
                                                       'y': '-0.00015008'},
                                     'Type': 'None'},
                       'Aperture-4': {'MechanismType': 'Motorized',
                                     'Name': 'SA',
                                     'Number': '5',
                                     'PositionOffset': {'x': '7.3919999999999997e-005',
                                                       'y': '-1.8879999999999999e-005'},
                                     'Type': 'None'}},
          'BeamConvergence': '0.01',
          'C1LensIntensity': '-0.50836926698684692',
          'C2LensIntensity': '0.22035744786262512',
          'C3LensIntensity': '0.13393138349056244',
          'CameraLength': '0.10199999999999999',
          'Defocus': '-3.5820494987697384e-007',
          'DiffractionLensIntensity': '0.39608421921730042',
          'EFTEMOn': 'false',
          'ExtractorVoltage': '4150',
          'Focus': '0',
          'FullScanFieldOfView': {'x': '8.6954773368876599e-008',
                                 'y': '8.6954773368876599e-008'},
          'GunLensSetting': '3',
          'HighMagnificationMode': 'None',
          'IlluminationMode': 'Probe',
          'IntermediateLensIntensity': '-0.21312436461448669',
          'LastMeasuredScreenCurrent': '1.6197265761556708e-011',
          'LorentzLensIntensity': '-0.66694682836532593',
          'MiniCondenserLensIntensity': '-0.97886407375335693',
          'ObjectiveLensIntensity': '0.88309943675994873',
          'ObjectiveLensMode': 'HM',
          'OperatingMode': '2',
          'ProbeMode': '1',
          'Projector1LensIntensity': '-0.33902254700660706',
          'Projector2LensIntensity': '-0.96843445301055908',
          'ProjectorMode': '1',
          'ScreenCurrent': '0',
          'SpotIndex': '8',
          'StemFocus': '-0.00035820494987697383',
          'TemOperatingSubMode': 'None'},
'Sample': '',
'Scan': {'DwellTime': '2.0000000000000002e-005',
        'FrameTime': '22.589440000000003',
        'LineIntegrationCount': '1',
        'LineInterlacing': '1',
        'LineTime': '0.022060000000000003',
        'MainsLockOn': 'true',
        'ScanArea': {'bottom': '1', 'left': '0', 'right': '1', 'top': '0'},
        'ScanRotation': '-0.13962634015954478',
        'ScanSize': {'height': '1024', 'width': '1024'}},
'Stage': {'AlphaTilt': '-0.07557447699999989',
         'BetaTilt': '-0.011455650902539491',
         'HolderType': 'FEI Double Tilt UT',
         'Position': {'x': '0.00028377424499999982',
                     'y': '4.9019376000000062e-005',
                     'z': '-0.00017327400000000004'}},
'Vacuum': {'VacuumMode': 'Ready'}}