ncempy.io.emd module

This module provides an interface to the EMD file format.

See https://emdatasets.com/ for more details.

class ncempy.io.emd.fileEMD(filename, readonly=False)[source]

Bases: object

Class to represent EMD files.

Implemented for spec 0.2 using the recommended layout for metadata.

Meant to provide convenience functions for commonly occuring tasks. This means that you will still want to acces fileEMD.file_hdl to manipulate the HDF5 file for not so commonly occuring tasks.

Parameters:
  • filename (str) – Name of the EMD file.
  • readonly (bool) – Set to open in read only mode.
find_emdgroups(parent)[source]

Find all emd_data_type groups within the group parent and return a list of references to their HDF5 groups.

Parameters:parent (h5py._hl.group.Group) – Handle to the parent group.
Returns:A list of h5py._hl.group.Group handles to children groups being emd_data_type groups.
Return type:(list)
get_emdgroup(group)[source]

Get the emdtype data saved in in group.

Parameters:group (h5py._hl.group.Group) – Reference to the emdtype HDF5 group.
Returns:None or tuple containing:
np.ndarray: The data of the emdtype group.

list: List of dimension vectors plus labels and units.

Return type:(tuple/None)
put_comment(msg, timestamp=None)[source]

Create a comment in the EMD file.

If timestamp already exists, the msg is appended to existing comment.

Parameters:
  • msg (str) – String of the message to save.
  • timestamp (str/None) – Timestamp used as the key, defaults to the current UTC time.
put_emdgroup(label, data, dims, parent=None, overwrite=False)[source]

Put an emdtype dataset into the EMD file.

Parameters:
  • label (str) – Label for the emdtype group containing the dataset.
  • data (np.ndarray) – Numpy array containing the data.
  • dims (tuple) – Tuple containing the necessary dims as ((vec, name, units), (vec, name, units), …)
  • parent (h5py._hl.group.Group/None) – Parent for the emdtype group, if None it will be written to /data.
  • overwrite (bool) – Set to force overwriting entry in EMD file.
Returns:

Group referencing this emdtype dataset or None if failed.

Return type:

(h5py._hl.group.Group/None)

write_dim(label, dim, parent)[source]

Auxiliary function to write a dim dataset to parent.

Input is not checked for sanity, so handle exceptions in call.

Parameters:
  • label (str) – Label for dataset, usually dim1, dim2, dimN.
  • dim (tuple) – Tuple containing (data, name, units).
  • parent (h5py._hl.group.Group) – HDF5 handle to parent group.
Returns:

HDF5 dataset handle referencing this dim.

Return type:

(h5py._hl.group.Group)