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/).


dictionary – Dictionary which contains all datasets as Signal instances.


dictionary – Dictionary which contains user related metadata.


dictionary – Dictionary which contains microscope related metadata.


dictionary – Dictionary which contains sample related metadata.


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.

  • 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.

Return type:



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.

  • 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.

emd – A EMD object containing the loaded signals.

Return type:



Print all relevant information about the EMD instance.


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’.
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)