hyperspy.io_plugins.emd module¶
-
class
hyperspy.io_plugins.emd.
EMD
(signals=None, user=None, microscope=None, sample=None, comments=None)¶ Bases:
object
Class for storing electron microscopy datasets.
The
EMD
class can hold an arbitrary amount of datasets in the signals dictionary. These are saved as HyperSpySignal
instances. Global metadata are saved in four dictionaries (user, microscope, sample, comments). To print relevant information about the EMD instance use thelog_info()
function. EMD instances can be loaded from and saved to emd-files, an hdf5 standard developed at Lawrence Berkeley National Lab (https://emdatasets.com/).-
signals
¶ Dictionary which contains all datasets as
Signal
instances.- Type
dictionary
-
user
¶ Dictionary which contains user related metadata.
- Type
dictionary
-
microscope
¶ Dictionary which contains microscope related metadata.
- Type
dictionary
-
sample
¶ Dictionary which contains sample related metadata.
- Type
dictionary
-
comments
¶ Dictionary which contains additional commentary metadata.
- Type
dictionary
-
add_signal
(signal, name=None, metadata=None)¶ Add a HyperSpy signal to the EMD instance and make sure all metadata is present.
- Parameters
signal (
Signal
) – HyperSpy signal which should be added to the EMD instance.name (string, optional) – Name of the (used as a key for the signals dictionary). If not specified, signal.metadata.General.title will be used. If this is an empty string, both name and signal title are set to ‘dataset’ per default. If specified, name overwrites the signal title.
metadata (dictionary) – Dictionary which holds signal specific metadata which will be added to the signal.
- Returns
- Return type
Notes
This is the preferred way to add signals to the EMD instance. Directly adding to the signals dictionary is possible but does not make sure all metadata are correct. This method is also called in the standard constructor on all entries in the signals dictionary!
-
classmethod
load_from_emd
(filename, lazy=False, dataset_name=None)¶ Construct
EMD
object from an emd-file.- Parameters
filename (string) – The name of the emd-file from which to load the signals. Standard format is ‘*.emd’.
False (bool, optional) – If False (default) loads data to memory. If True, enables loading only if requested.
dataset_name (string or iterable, optional) – Only add dataset with specific name. Note, this has to be the full group path in the file. For example `/experimental/science_data’. If the dataset is not found, an IOError with the possible datasets will be raised. Several names can be specified in the form of a list.
- Returns
emd – A
EMD
object containing the loaded signals.- Return type
-
log_info
()¶ ( all relevant information about the EMD instance.
-
-
class
hyperspy.io_plugins.emd.
FeiEMDReader
(filename, select_type=None, first_frame=0, last_frame=None, sum_frames=True, sum_EDS_detectors=True, rebin_energy=1, SI_dtype=None, load_SI_image_stack=False, lazy=False)¶ Bases:
object
Class for reading FEI electron microscopy datasets.
The
FeiEMDReader
reads EMD files saved by the FEI Velox software package.-
im_type
¶ String specifying whether the data is an image, spectrum or spectrum image.
- Type
string
-
-
class
hyperspy.io_plugins.emd.
FeiSpectrumStream
(stream_group, reader)¶ Bases:
object
Read spectrum image stored in FEI’s stream format
Once initialized, the instance of this class supports numpy style indexing and slicing of the data stored in the stream format.
-
get_pixelsize_offset_unit
()¶
-
property
shape
¶
-
stream_to_array
(stream_data, spectrum_image=None)¶ Convert stream to array.
- Parameters
stream_data (array) –
spectrum_image (array or None) – If array, the data from the stream are added to the array. Otherwise it creates a new array and returns it.
-
stream_to_sparse_array
(stream_data)¶ Convert stream in sparse array
- Parameters
stream_data (array) –
-
-
hyperspy.io_plugins.emd.
calculate_chunks
(shape, dtype, chunk_size_mb=100)¶ Calculate chunks to get target chunk size.
The chunks are optimized for C-order reading speed.
- Parameters
shape (tuple of ints) – The shape of the array
dtype (string or numpy dtype) – The dtype of the array
chunk_size_mb (int) – The maximum size of the resulting chunks in MB. The default is 100MB as reccommended by the dask documentation.
-
hyperspy.io_plugins.emd.
fei_check
(filename)¶ Function to check if the EMD file is an FEI file.
- Parameters
filename (string) – The name of the emd-file from which to load the signals. Standard format is ‘*.emd’.
- Returns
- Return type
Boolean
-
hyperspy.io_plugins.emd.
file_reader
(filename, log_info=False, lazy=False, **kwds)¶
-
hyperspy.io_plugins.emd.
file_writer
(filename, signal, signal_metadata=None, user=None, microscope=None, sample=None, comments=None, **kwds)¶