ncempy.io.emdVelox module¶
Provides an interface to Velox EMD datasets. Not to be confused with Berkeley EMD data sets (see emd.py) instead.
The reader for EMD Berkeley and Velox files will be combined in the near future once they are fully tested separately.
Currently limited to only images. This file can not load spectra.
Note
- General users:
Use the simplified emdVelox.emdVeloxReader() function to load the data and meta data as a python dictionary.
- Advanced users and developers:
Access the file internals through the emd.fileEMDVelox() class.
- ncempy.io.emdVelox.emdVeloxReader(filename, dsetNum=0)[source]¶
A simple helper function to read in the data and metadata in a structured format similar to the other ncempy readers.
Note
Not fully implemented yet. Work in progress. Important metadata is missing, but you can get the data.
- Parameters:
filename (str or pathlib.Path) – The path to the file.
dsetNum (int, default = 0) – The index of the data set to load.
- Returns:
Data and metadata as a dictionary similar to other ncempy readers.
- Return type:
Example
- Load all data and metadata from a data set in an EMD file
>> import ncempy.io as nio >> emd0 = nio.emdVelox.emdVeloxReader(‘filename.emd’, dsetNum = 0)
- class ncempy.io.emdVelox.fileEMDVelox(filename)[source]¶
Bases:
objectClass to represent Velox EMD files. It uses the h5py caching functionality to increase the default cache size from 1MB to 10MB. This significantly improves file reading for EMDVelox files which are written with Fortran- style ordering and an inefficient choice of chunking.
- Variables:
list_data (list) – A list containing each h5py data group that can be loaded.
_file_hdl (h5py.File) – The File handle from h5py.File.
metaDataJSON (dict) – The full metadata for the most recently loaded data set. Note that you have to load a data set for this to be populated or run parseMetaData(num).
file_name (str) – The name of the file
file_path (pathlib.Path) – A pathlib.Path object for the open file
Examples
Open an EMD Velox file containing 1 image. >> import ncempy.io as nio >> with nio.emdVelox.fileEMDVelox(‘1435 1.2 Mx STEM HAADF-DF4-DF2-BF.emd’) as emd1: >> print(emd1) # print information about the file >> im0, metadata0 = emd1.get_dataset(0)
- getDataset(group, memmap=False)[source]¶
Get the data from a group and the associated metadata.
- Parameters:
group (HDF5 dataset or int) – The link to the HDF5 dataset in the file or an integer for the number of the dataset. The list of datasets is held in the list_data attribute populated on class init.
memmap (bool, default = False) – If False (default), then a numpy ndarray is returned. If True the HDF5 data set object is returned and data is loaded from disk as needed.
- Returns:
A tuple containing the data as a ndarray or a HDF5 dataset object. The second argument is a python dict of metadata.
- Return type:
- getMetadata(group)[source]¶
Reads important metadata from Velox EMD files.
- Parameters:
group (h5py.Group or int) – The h5py group to load the metadata from which is easily retrived from the list_data attribute. If input is an int then the group corresponding to list_data attribute is used. The string metadata is loaded and parsed by the json module into a dictionary.