hyperspy.io_plugins.usid_hdf5 module

hyperspy.io_plugins.usid_hdf5._assemble_dim_list(dim_dict, dim_names)

Assembles a list of dictionary objects (axes) in the same order as specified in dim_names

Parameters
  • dim_dict (dict) – Dictionary of dictionaries that correspond to axes for HyperSpy Signal objects

  • dim_names (list) – List of strings denoting the names of the dimension

Returns

List of dictionaries that correspond to axes for HyperSpy Signal objects

Return type

list

hyperspy.io_plugins.usid_hdf5._convert_to_signal_dict(ndim_form, quantity, units, dim_dict_list, h5_path, h5_dset_path, name, sig_type='', group_attrs={})

Packages required components that make up a Signal object

Parameters
  • ndim_form (numpy.ndarray) – N-dimensional form of the main dataset

  • quantity (str) – Physical quantity of the measurement

  • units (str) – Corresponding units

  • dim_dict_list (list) – List of dictionaries that instruct the axes corresponding to the main dataset

  • h5_path (str) – Absolute path of the original USID HDF5 file

  • h5_dset_path (str) – Absolute path of the USIDataset within the HDF5 file

  • name (str) – Name of the HDF5 dataset

  • sig_type (str, Optional) – Type of measurement

  • group_attrs (dict, Optional. Default = {}) – Any attributes at the channel and group levels

hyperspy.io_plugins.usid_hdf5._flatten_dict(nested_dict, parent_key='', sep='-')

Flattens a nested dictionary

Parameters
  • nested_dict (dict) – Nested dictionary

  • parent_key (str, Optional) – Name of current parent

  • sep (str, Optional. Default='-') – Separator between the keys of different levels

Returns

Dictionary whose keys are flattened to a single level

Return type

dict

Notes

Taken from https://stackoverflow.com/questions/6027558/flatten-nested- dictionaries-compressing-keys

hyperspy.io_plugins.usid_hdf5._get_dim_dict(labels, units, val_func, ignore_non_uniform_dims=True)

Gets a list of dictionaries that correspond to axes for HyperSpy Signal objects

Parameters
  • labels (list) – List of strings denoting the names of the dimension

  • units (list) – List of strings denoting the units for the dimensions

  • val_func (callable) – Function that will return the values over which a dimension was varied

  • ignore_non_uniform_dims (bool, Optional. Default = True) – If set to True, a warning will be raised instead of a ValueError when a dimension is encountered which was non-uniformly.

Returns

Dictionary of dictionaries that correspond to axes for HyperSpy Signal objects

Return type

dict

Notes

For a future release of HyperSpy: If a dimension was varied non-uniformly, one would need to set the appropriate quantity in the quantity equal to dim_vals. At that point, the typical offset and scale parameters would be (hopefully) ignored.

hyperspy.io_plugins.usid_hdf5._split_descriptor(desc)

Splits a string such as “Quantity [units]” or “Quantity (units)” into the quantity and unit strings

Parameters

desc (str) – Descriptor of a dimension or the main dataset itself

Returns

  • quant (str) – Name of the physical quantity

  • units (str) – Units corresponding to the physical quantity

hyperspy.io_plugins.usid_hdf5._usidataset_to_signal(h5_main, ignore_non_uniform_dims=True, lazy=True, *kwds)

Converts a single specified USIDataset object to one or more Signal objects

Parameters
  • h5_main (pyUSID.USIDataset object) – USID Main dataset

  • ignore_non_uniform_dims (bool, Optional) – If True, parameters that were varied non-uniformly in the desired dataset will result in Exceptions. Else, all such non-uniformly varied parameters will be treated as uniformly varied parameters and a Signal object will be generated.

  • lazy (bool, Optional) – If set to True, data will be read as a Dask array. Else, data will be read in as a numpy array

Returns

USIDatasets with compound datatypes are broken down to multiple Signal objects.

Return type

list of hyperspy.signals.BaseSignal objects

hyperspy.io_plugins.usid_hdf5.file_reader(filename, dataset_path=None, ignore_non_uniform_dims=True, lazy=False, **kwds)

Reads a USID Main dataset present in an HDF5 file into a HyperSpy Signal

Parameters
  • filename (str) – path to HDF5 file

  • dataset_path (str, Optional) – Absolute path of USID Main HDF5 dataset. Default - None - all Main Datasets will be read. Given that HDF5 files can accommodate very large datasets, lazy reading is strongly recommended. If a string like '/Measurement_000/Channel_000/My_Dataset' is provided, the specific dataset will be loaded.

  • ignore_non_uniform_dims (bool, Optional) – If True, parameters that were varied non-uniformly in the desired dataset will result in Exceptions. Else, all such non-uniformly varied parameters will be treated as uniformly varied parameters and a Signal object will be generated.

Return type

list of hyperspy.signals.Signal object

hyperspy.io_plugins.usid_hdf5.file_writer(filename, object2save, **kwds)

Writes a HyperSpy Signal object to a HDF5 file formatted according to USID

Parameters
  • filename (str) – Path to target HDF5 file

  • object2save (hyperspy.signals.Signal) – A HyperSpy signal