hyperspy.io_plugins._hierarchical module

class hyperspy.io_plugins._hierarchical.HierarchicalReader(file)

Bases: object

A generic Reader class for reading data from hierarchical file types.

Initializes a general reader for hierarchical signals.

Parameters:

file (str) – A file to be read.

get_format_version()

Return the format version.

group2signaldict(group, lazy=False)

Reads a h5py/zarr group and returns a signal dictionary.

Parameters:
Raises:

IOError – Raise an IOError when the group can’t be read, if the group doesn’t follow hspy format specification, etc.

read(lazy)

Read all data, metadata, models.

Parameters:

lazy (bool) – Return data as lazy signal.

Raises:

IOError – Raise an IOError when the file can’t be read, if the file doesn’t follow hspy format specification, etc.

Returns:

A list of dictionary, which can be used to create a hspy signal.

Return type:

list of dict

class hyperspy.io_plugins._hierarchical.HierarchicalWriter(file, signal, group, **kwds)

Bases: object

An object used to simplify and organize the process for writing a Hierarchical signal, such as hspy/zspy format.

Initialize a generic file writer for hierachical data storage types.

Parameters:
  • file (str) – The file where the signal is to be saved

  • signal (BaseSignal) – A BaseSignal to be saved

  • group (Group) – A group to where the experimental data will be saved.

  • kwds – Any additional keywords used for saving the data.

dict2group(dictionary, group, **kwds)

Recursive writer of dicts and signals

classmethod overwrite_dataset(group, data, key, signal_axes=None, chunks=None, **kwds)

Overwrites a dataset into a hierarchical structure following the h5py API.

Parameters:
write_signal(signal, group, write_dataset=True, chunks=None, **kwds)

Writes a hyperspy signal to a hdf5 group

hyperspy.io_plugins._hierarchical.get_signal_chunks(shape, dtype, signal_axes=None, target_size=1000000.0)

Function that calculates chunks for the signal, preferably at least one chunk per signal space.

Parameters:
  • shape (tuple) – The shape of the dataset to be stored / chunked.

  • dtype ({dtype, string}) – The numpy dtype of the data.

  • signal_axes ({None, iterable of ints}) – The axes defining “signal space” of the dataset. If None, the default h5py chunking is performed.

  • target_size (int) – The target number of bytes for one chunk