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 HyperSpy Signal instances. Global metadata are saved in four dictionaries (user, microscope, sample, comments). To print relevant information about the EMD instance use the log_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 – Dictionary which contains all datasets as Signal instances.

user

dictionary – Dictionary which contains user related metadata.

microscope

dictionary – Dictionary which contains microscope related metadata.

sample

dictionary – Dictionary which contains sample related metadata.

comments

dictionary – Dictionary which contains additional commentary metadata.

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:

None

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)

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.
Returns:

emd – A EMD object containing the loaded signals.

Return type:

EMD

log_info()

Print all relevant information about the EMD instance.

save_to_emd(filename='datacollection.emd')

Save EMD data in a file with emd(hdf5)-format.

Parameters:filename (string, optional) – The name of the emd-file in which to store the signals. The default is ‘datacollection.emd’.
Returns:
Return type:None
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)