8.6.1.4. pymodaq_data.h5modules.data_saving module

Created the 21/11/2022

@author: Sebastien Weber

exception pymodaq_data.h5modules.data_saving.AxisError[source]

Bases: Exception

class pymodaq_data.h5modules.data_saving.AxisSaverLoader(h5saver)[source]

Bases: DataManagement

Specialized Object to save and load Axis object to and from a h5file

Parameters:

h5saver (H5SaverLowLevel)

data_type

The enum for this type of data, here ‘axis’

Type:

DataType

Methods

add_axis(where, axis[, enlargeable])

Write Axis info at a given position within a h5 file

get_axes(where)

Return a list of Axis objects from the Axis Nodes hanging from (or among) a given Node

load_axis(where)

create an Axis object from the data and metadata at a given node if of data_type: 'axis

add_axis(where, axis, enlargeable=False)[source]

Write Axis info at a given position within a h5 file

Parameters:
  • where (Union[Node, str]) – the path of a given node or the node itself

  • axis (Axis) – the Axis object to add as a node in the h5file

  • enlargeable (bool) – Specify if the underlying array will be enlargebale

get_axes(where)[source]

Return a list of Axis objects from the Axis Nodes hanging from (or among) a given Node

Parameters:

where (Union[Node, str]) – the path of a given node or the node itself

Returns:

List[Axis]

Return type:

List[Axis]

load_axis(where)[source]

create an Axis object from the data and metadata at a given node if of data_type: ‘axis

Parameters:

where (Union[Node, str]) – the path of a given node or the node itself

Return type:

Axis

data_type: DataType = 'Axis'
class pymodaq_data.h5modules.data_saving.BkgSaver(h5saver)[source]

Bases: DataSaverLoader

Specialized Object to save and load DataWithAxes background object to and from a h5file

Parameters:

hsaver (H5SaverLowLevel)

data_type

The enum for this type of data, here ‘bkg’

Type:

DataType

data_type: DataType = 'Bkg'
class pymodaq_data.h5modules.data_saving.DataEnlargeableSaver(h5saver, enl_axis_names=('nav axis',), enl_axis_units=('',))[source]

Bases: DataSaverLoader

Specialized Object to save and load enlargeable DataWithAxes saved object to and from a h5file

Particular case of DataND with a single nav_indexes parameter will be appended as chunks of signal data

Parameters:

h5saver (Union[H5SaverLowLevel, Path])

data_type

The enum for this type of data, here ‘data_enlargeable’

Type:

DataType

Notes

To be used to save data from a timed logger (DAQViewer continuous saving or DAQLogger extension) or from an adaptive scan where the final shape is unknown or other module that need this feature

Methods

add_data(where, data[, axis_values])

Append data to an enlargeable array node

add_data(where, data, axis_values=None, **kwargs)[source]

Append data to an enlargeable array node

Data of dim (0, 1 or 2) will be just appended to the enlargeable array.

Uniform DataND with one navigation axis of length (Lnav) will be considered as a collection of Lnav signal data of dim (0, 1 or 2) and will therefore be appended as Lnav signal data

Parameters:
  • where (Union[Node, str]) – the path of a given node or the node itself

  • data (DataWithAxes)

  • axis_values (Iterable[float]) – the new spread axis values added to the data if None the axes are not added to the h5 file

data_type: DataType = 'EnlData'
class pymodaq_data.h5modules.data_saving.DataExtendedSaver(h5saver, extended_shape)[source]

Bases: DataSaverLoader

Specialized Object to save and load DataWithAxes saved object to and from a h5file in extended arrays

Parameters:
  • h5saver (H5SaverLowLevel)

  • extended_shape (Tuple[int]) – the extra shape compared to the data the h5array will have

data_type

The enum for this type of data, here ‘data’

Type:

DataType

Methods

add_data(where, data, indexes[, distribution])

Adds given DataWithAxes at a location within the initialized h5 array

add_data(where, data, indexes, distribution=DataDistribution.uniform)[source]

Adds given DataWithAxes at a location within the initialized h5 array

Parameters:
  • where (Union[Node, str]) – the path of a given node or the node itself

  • data (DataWithAxes)

  • indexes (List[int]) – indexes where to save data in the init h5array (should have the same length as extended_shape and with values coherent with this shape

data_type: DataType = 'Data'
class pymodaq_data.h5modules.data_saving.DataLoader(h5saver)[source]

Bases: object

Specialized Object to load DataWithAxes object from a h5file

On the contrary to DataSaverLoader, does include navigation axes stored elsewhere in the h5file (for instance if saved from the DAQ_Scan)

Parameters:

h5saver (Union[H5SaverLowLevel, Path])

Attributes:
h5saver

Methods

get_nav_group(where)

get_node(where[, name])

Convenience method to get node

load_data(where[, with_bkg, load_all])

Load data from a node (or channel node)

walk_nodes([where])

Return a Node generator iterating over the h5file content

close_file

load_all

close_file()[source]
get_nav_group(where)[source]
Parameters:

where (Union[Node, str]) – the path of a given node or the node itself

Return type:

Optional[Node]

Returns:

  • GROUP (returns the group named SPECIAL_GROUP_NAMES[``’nav_axes’``] holding all NavAxis for)

  • those data

See also

SPECIAL_GROUP_NAMES

get_node(where, name=None)[source]

Convenience method to get node

Return type:

Node

load_all(where, data=None, with_bkg=False)[source]
Return type:

DataToExport

load_data(where, with_bkg=False, load_all=False)[source]

Load data from a node (or channel node)

Loaded data contains also nav_axes if any and with optional background subtraction

Parameters:
  • where (Union[Node, str]) – the path of a given node or the node itself

  • with_bkg (bool) – If True will attempt to substract a background data node before loading

  • load_all (bool) – If True, will load all data hanging from the same parent node

Return type:

DataWithAxes

walk_nodes(where='/')[source]

Return a Node generator iterating over the h5file content

property h5saver
class pymodaq_data.h5modules.data_saving.DataManagement(*args, **kwargs)[source]

Bases: object

Base abstract class to be used for all specialized object saving and loading data to/from a h5file

data_type

The enum for this type of data, here abstract and should be redefined

Type:

DataType

Methods

get_last_node_name(where)

Get the last node name among the ones already saved

close

close_file

get_index_from_node_name

get_node_from_index

close()[source]
close_file()[source]
get_index_from_node_name(where)[source]
get_last_node_name(where)[source]

Get the last node name among the ones already saved

Parameters:

where (Union[str, Node]) – the path of a given node or the node itself

Returns:

str

Return type:

Optional[str]

get_node_from_index(where, index)[source]
Return type:

Node

data_type: DataType = <pymodaq_utils.abstract.DummyAttribute object>
class pymodaq_data.h5modules.data_saving.DataSaverLoader(h5saver)[source]

Bases: DataManagement

Specialized Object to save and load DataWithAxes object to and from a h5file

Parameters:

h5saver (Union[H5SaverLowLevel, Path])

data_type

The enum for this type of data, here ‘data’

Type:

DataType

Methods

add_data(where, data[, save_axes])

Adds Array nodes to a given location adding eventually axes as others nodes and metadata

get_axes(where)

get_data_arrays(where[, with_bkg, load_all])

isopen()

Get the opened status of the underlying hdf5 file

load_data(where[, with_bkg, load_all])

Return a DataWithAxes object from the Data and Axis Nodes hanging from (or among) a given Node

get_bkg_nodes

add_data(where, data, save_axes=True, **kwargs)[source]

Adds Array nodes to a given location adding eventually axes as others nodes and metadata

Parameters:
get_axes(where)[source]
Parameters:

where (Union[Node, str]) – the path of a given node or the node itself

Return type:

List[Axis]

get_bkg_nodes(where)[source]
get_data_arrays(where, with_bkg=False, load_all=False)[source]
Parameters:
  • where (Union[Node, str]) – the path of a given node or the node itself

  • with_bkg (bool) – If True try to load background node and return the array with background subtraction

  • load_all (bool) – If True load all similar nodes hanging from a parent

Return type:

List[ndarray]

isopen()[source]

Get the opened status of the underlying hdf5 file

Return type:

bool

load_data(where, with_bkg=False, load_all=False)[source]

Return a DataWithAxes object from the Data and Axis Nodes hanging from (or among) a given Node

Does not include navigation axes stored elsewhere in the h5file. The node path is stored in the DatWithAxis using the attribute path

Parameters:
  • where (Union[Node, str]) – the path of a given node or the node itself

  • with_bkg (bool) – If True try to load background node and return the data with background subtraction

  • load_all (bool) – If True, will load all data hanging from the same parent node

See also

load_data

Return type:

DataWithAxes

data_type: DataType = 'Data'
class pymodaq_data.h5modules.data_saving.DataToExportEnlargeableSaver(h5saver, enl_axis_names=None, enl_axis_units=None, axis_name='nav axis', axis_units='')[source]

Bases: DataToExportSaver

Generic object to save DataToExport objects in an enlargeable h5 array

The next enlarged value should be specified in the add_data method

Parameters:
  • h5saver (H5SaverLowLevel)

  • enl_axis_names (Iterable[str]) – The names of the enlargeable axis, default [‘nav_axis’]

  • enl_axis_units (Iterable[str]) – The names of the enlargeable axis, default [‘’]

  • axis_name (str) – the name of the enlarged axis array

  • axis_units (str) – the units of the enlarged axis array

Methods

add_data(where, data[, axis_values, ...])

add_data(where, data, axis_values=None, axis_value=None, settings_as_xml='', **kwargs)[source]
Parameters:
  • where (Union[Node, str]) – the path of a given node or the node itself

  • data (DataToExport) – The data to be saved into an enlargeable array

  • axis_values (List[Union[float, ndarray]]) – The next value (or values) of the enlarged axis

  • axis_value (Union[float, ndarray]) – The next value (or values) of the enlarged axis

  • settings_as_xml (str) – The settings parameter as an XML string

  • Arguments (Keyword) – all extra metadata to be saved in the group node where data will be saved

class pymodaq_data.h5modules.data_saving.DataToExportExtendedSaver(h5saver, extended_shape)[source]

Bases: DataToExportSaver

Object to save DataToExport at given indexes within arrays including extended shape

Mostly used for data generated from the DAQScan

Parameters:
  • h5saver (H5SaverLowLevel)

  • extended_shape (Tuple[int]) – the extra shape compared to the data the h5array will have

Methods

add_data(where, data, indexes[, ...])

add_nav_axes(where, axes)

Used to add navigation axes related to the extended array

add_data(where, data, indexes, distribution=DataDistribution.uniform, settings_as_xml='', **kwargs)[source]
Parameters:
  • where (Union[Node, str]) – the path of a given node or the node itself

  • data (DataToExport)

  • indexes (Iterable[int]) – indexes where to save data in the init h5array (should have the same length as extended_shape and with values coherent with this shape

  • settings_as_xml (str) – The settings parameter as an XML string

  • Arguments (Keyword) – all extra metadata to be saved in the group node where data will be saved

add_nav_axes(where, axes)[source]

Used to add navigation axes related to the extended array

Notes

For instance the scan axes in the DAQScan

class pymodaq_data.h5modules.data_saving.DataToExportSaver(h5saver, save_type=SaveType.scan)[source]

Bases: object

Object used to save DataToExport object into a h5file following the PyMoDAQ convention

Parameters:

h5saver (Union[H5SaverLowLevel, Path, str])

Methods

add_data(where, data[, settings_as_xml])

channel_formatter(ind)

All DataWithAxes included in the DataToExport will be saved into a channel group indexed and formatted as below

isopen()

Get the opened status of the underlying hdf5 file

add_bkg

add_error

close

close_file

static channel_formatter(ind)[source]

All DataWithAxes included in the DataToExport will be saved into a channel group indexed and formatted as below

add_bkg(where, data)[source]
add_data(where, data, settings_as_xml='', **kwargs)[source]
Parameters:
  • where (Union[Node, str]) – the path of a given node or the node itself

  • data (DataToExport)

  • settings_as_xml (str) – The settings parameter as an XML string

  • Arguments (Keyword) – all extra metadata to be saved in the group node where data will be saved

add_error(where, data)[source]
close()[source]
close_file()[source]
isopen()[source]

Get the opened status of the underlying hdf5 file

Return type:

bool

class pymodaq_data.h5modules.data_saving.DataToExportTimedSaver(h5saver)[source]

Bases: DataToExportEnlargeableSaver

Specialized DataToExportEnlargeableSaver to save data as a function of a time axis

Only one element ca be added at a time, the time axis value are enlarged using the data to be added timestamp

Notes

This object is made for continuous saving mode of DAQViewer and logging to h5file for DAQLogger

Methods

add_data(where, data[, settings_as_xml])

add_data(where, data, settings_as_xml='', **kwargs)[source]
class pymodaq_data.h5modules.data_saving.ErrorSaverLoader(h5saver)[source]

Bases: DataSaverLoader

Specialized Object to save and load DataWithAxes errors bars to and from a h5file

Parameters:

hsaver (H5SaverLowLevel)

data_type

The enum for this type of data, here ‘error’

Type:

DataType

data_type: DataType = 'ErrorBar'