7.5.2.2. pymodaq_gui.h5modules.saving module

Created the 15/11/2022

@author: Sebastien Weber

class pymodaq_gui.h5modules.saving.H5Saver(*args, **kwargs)[source]

Bases: H5SaverBase, QObject

status_sig: Signal

emits a signal of type Threadcommand in order to senf log information to a main UI

new_file_sig: Signal

emits a boolean signal to let the program know when the user pressed the new file button on the UI

Methods

emit_new_file(status)

Emits the new_file_sig

close

new_file_sig

show_file_content

status_sig

close()[source]
emit_new_file(status)[source]

Emits the new_file_sig

Parameters:

status (bool) – emits True if a new file has been asked by the user pressing the new file button on the UI

show_file_content()[source]
new_file_sig

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

status_sig

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

class pymodaq_gui.h5modules.saving.H5SaverBase(save_type='scan', backend='tables')[source]

Bases: H5SaverLowLevel, ParameterManager

Object containing all methods in order to save datas in a hdf5 file with a hierarchy compatible with the H5Browser. The saving parameters are contained within a Parameter object: self.settings that can be displayed on a UI using the widget self.settings_tree. At the creation of a new file, a node group named Raw_data and represented by the attribute raw_group is created and set with a metadata attribute:

  • ‘type’ given by the save_type class parameter

The root group of the file is then set with a few metadata:

  • ‘pymodaq_version’ the current pymodaq version, e.g. 1.6.2

  • ‘pymodaq_data_version’ the current pymodaq_data version, e.g. 0.0.1

  • ‘file’ the file name

  • ‘date’ the current date

  • ‘time’ the current time

All data will then be saved under this node in various groups

See also

H5Browser

Parameters:
  • h5_file (pytables hdf5 file) – object used to save all datas and metadas

  • h5_file_path (str or Path) – Signal signal represented by a float. Is emitted each time the hardware reached the target position within the epsilon precision (see comon_parameters variable)

  • save_type (str) – an element of the enum module attribute SaveType * ‘scan’ is used for DAQScan module and should be used for similar application * ‘detector’ is used for DAQ_Viewer module and should be used for similar application * ‘custom’ should be used for customized applications

settings

Parameter instance (pyqtgraph) containing all settings (could be represented using the settings_tree widget)

Type:

Parameter

settings_tree

Widget representing as a Tree structure, all the settings defined in the class preamble variable params

Type:

ParameterTree

Methods

find_part_in_path_and_subpath(base_dir[, ...])

Find path from part time.

get_last_scan()

Gets the last scan node within the h5_file and under the raw_group

get_scan_index()

return the scan group index in the "scan templating": Scan000, Scan001 as an integer

init_file([update_h5, custom_naming, ...])

Initializes a new h5 file.

load_file([base_path, file_path])

Opens a file dialog to select a h5file saved on disk to be used

set_current_scan_path(base_dir[, base_name, ...])

param base_dir:

update_file_paths([update_h5])

param update_h5:

if True, will increment the file name and eventually the current scan index

value_changed(param)

Non-mandatory method to be subclassed for actions to perform (methods to call) when one of the param's value in self._settings is changed

get_scan_groups

save_file

show_settings

update_status

classmethod find_part_in_path_and_subpath(base_dir, part='', create=False, increment=True)[source]

Find path from part time.

Parameters

Type

Description

base_dir

Path object

The directory to browse

part

string

The date of the directory to find/create

create

boolean

Indicate the creation flag of the directory

Returns:

found path from part

Return type:

Path object

get_last_scan()[source]

Gets the last scan node within the h5_file and under the raw_group

Returns:

scan_group

Return type:

pytables group or None

get_scan_groups()[source]
get_scan_index()[source]

return the scan group index in the “scan templating”: Scan000, Scan001 as an integer

init_file(update_h5=False, custom_naming=False, addhoc_file_path=None, metadata={})[source]

Initializes a new h5 file. Could set the h5_file attributes as:

  • a file with a name following a template if custom_naming is False and addhoc_file_path is None

  • a file within a name set using a file dialog popup if custom_naming is True

  • a file with a custom name if addhoc_file_path is a Path object or a path string

Parameters:
  • update_h5 (bool) – create a new h5 file with name specified by other parameters if false try to open an existing file and will append new data to it

  • custom_naming (bool) – if True, a selection file dialog opens to set a new file name

  • addhoc_file_path (Path or str) – supplied name by the user for the new file

  • metadata (dict) – dictionnary with pair of key, value that should be saved as attributes of the root group

Returns:

update_h5 – True if new file has been created, False otherwise

Return type:

bool

load_file(base_path=None, file_path=None)[source]

Opens a file dialog to select a h5file saved on disk to be used

Parameters:
  • base_path

  • file_path

See also

init_file()

save_file(filename=None)[source]
classmethod set_current_scan_path(base_dir, base_name='Scan', update_h5=False, next_scan_index=0, create_scan_folder=False, create_dataset_folder=True, curr_date=None, ind_dataset=None)[source]
Parameters:
  • base_dir

  • base_name

  • update_h5

  • next_scan_index

  • create_scan_folder

  • create_dataset_folder

show_settings(show=True)[source]
update_file_paths(update_h5=False)[source]
Parameters:

update_h5 (bool) – if True, will increment the file name and eventually the current scan index if False, get the current scan index in the h5 file

Returns:

  • scan_path (Path)

  • current_filename (str)

  • dataset_path (Path)

update_status(status)[source]
value_changed(param)[source]

Non-mandatory method to be subclassed for actions to perform (methods to call) when one of the param’s value in self._settings is changed

For this to be triggered, the Parameter method: setValue should be used

Parameters:

param (Parameter) – the parameter whose value just changed

Examples

>>> if param.name() == 'do_something':
>>>     if param.value():
>>>         print('Do something')
>>>         self.settings.child('main_settings', 'something_done').setValue(False)
params = [{'title': 'Save type:', 'name': 'save_type', 'type': 'list', 'limits': ['scan', 'detector', 'logger', 'custom', 'actuator'], 'readonly': True}, {'title': 'Save 2D datas and above:', 'name': 'save_2D', 'type': 'bool', 'value': True}, {'title': 'Save raw datas only:', 'name': 'save_raw_only', 'type': 'bool', 'value': True, 'tooltip': 'if True, will not save extracted ROIs used to do live plotting, only raw datas will be saved'}, {'title': 'Do Save:', 'name': 'do_save', 'type': 'bool', 'default': False, 'value': False}, {'title': 'N saved:', 'name': 'N_saved', 'type': 'int', 'default': 0, 'value': 0, 'visible': False}, {'title': 'Backend:', 'name': 'backend', 'type': 'group', 'children': [{'title': 'Backend type:', 'name': 'backend_type', 'type': 'list', 'limits': ['tables'], 'readonly': True}, {'title': 'HSDS Server:', 'name': 'hsds_options', 'type': 'group', 'visible': False, 'children': [{'title': 'Endpoint:', 'name': 'endpoint', 'type': 'str', 'value': 'http://hsds.sebastienweber.fr', 'readonly': False}, {'title': 'User:', 'name': 'user', 'type': 'str', 'value': 'pymodaq_user', 'readonly': False}, {'title': 'password:', 'name': 'password', 'type': 'str', 'value': 'pymodaq', 'readonly': False}]}]}, {'title': 'custom_name?:', 'name': 'custom_name', 'type': 'bool', 'default': False, 'value': False}, {'title': 'show file content?', 'name': 'show_file', 'type': 'bool_push', 'default': False, 'value': False}, {'title': 'Base path:', 'name': 'base_path', 'type': 'browsepath', 'value': 'C:\\Data', 'filetype': False, 'readonly': True}, {'title': 'Base name:', 'name': 'base_name', 'type': 'str', 'value': 'Scan', 'readonly': True}, {'title': 'Current scan:', 'name': 'current_scan_name', 'type': 'str', 'value': '', 'readonly': True}, {'title': 'Current path:', 'name': 'current_scan_path', 'type': 'text', 'value': 'C:\\Data', 'readonly': True, 'visible': False}, {'title': 'h5file:', 'name': 'current_h5_file', 'type': 'text', 'value': '', 'readonly': True}, {'title': 'New file', 'name': 'new_file', 'type': 'action'}, {'title': 'Saving dynamic', 'name': 'dynamic', 'type': 'list', 'limits': ['uint8', 'int8', 'uint16', 'int16', 'uint32', 'int32', 'uint64', 'int64', 'float64'], 'value': 'float64'}, {'title': 'Compression options:', 'name': 'compression_options', 'type': 'group', 'children': [{'title': 'Compression library:', 'name': 'h5comp_library', 'type': 'list', 'value': 'zlib', 'limits': ['zlib', 'gzip']}, {'title': 'Compression level:', 'name': 'h5comp_level', 'type': 'int', 'value': 5, 'min': 0, 'max': 9}]}]
settings_name = 'h5saver_settings'