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:
group (
h5py.Group
orzarr.hierarchy.Group
) – A group following hspy specification.lazy (bool, optional) – Return the data as dask array. The default is False.
- 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.
- 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:
group (
zarr.hierarchy.Group
orh5py.Group
) – The group to write the data to.data (Array-like) – The data to be written.
key (str) – The key for the dataset.
signal_axes (tuple) – The indexes of the signal axes.
chunks (tuple, None) – The chunks for the dataset. If
None
and saving lazy signal, the chunks of the dask array will be used otherwise the chunks will be determined by theget_signal_chunks()
function.kwds (dict) – Any additional keywords for to be passed to the
h5py.Group.require_dataset()
orzarr.hierarchy.Group.require_dataset()
method.
- 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