HDFMapControlTemplate
- class bapsflib._hdf.maps.controls.templates.HDFMapControlTemplate(group: Group)
Bases:
HDFMapTemplate,ABCTemplate class for all control mapping classes to inherit from.
Note
If a control device is structured around a command list, then its mapping class should subclass
HDFMapControlCLTemplateinstead.To fully define a subclass there are several abstract methods that need to be defined, which includes
-
- abstractmethod _build_configs()
Inspect the HDF5 group and build the configuration dictionary,
configs.Functionality should specifically populate
self._configsinstead ofself.configs. If a mapping fails, then aHDFMappingErrorshould be raised.
If a subclass needs to initialize additional variables before
_build_configsis called in the__init__, then those routines can be defined in the_init_before_build_configsmethod.- _init_before_build_configs()
Any initialization that needs to be performed before executing
self._build_configsin__init__.By default we do nothing, but subclasses can override this for their specific purposes.
- Parameters:
group (
h5py.Group) – The HDF5 to apply the mapping to.
Attributes Summary
Dictionary containing all the relevant mapping information to translate the corresponding device data in the HDF5 file and provide a consistent user interface via
File.Control device type.
List of names of the HDF5 datasets within the mapped group, at the root level.
Name of Control device
Instance of the HDF5 group that was mapped.
Name of the mapped HDF5 group.
Path of the mapped HDF5 group in the HDF5 file.
Trueif the control device utilizes a command listMetadata information about the mapping type and the mapped group location in the HDF5 file.
Mapping class type (
MapTypes).Trueif each control configuration has its own datasetList of names of the HDF5 subgroups within the mapped group, at the root level.
Methods Summary
construct_dataset_name(*args)Constructs the dataset name corresponding to the input arguments.
get_config_column_value(config_name)For the given configuration name
config_nameget the associated configuration value that would be in the configuration column of the associated HDF5 datasets.process_config_name(config_name)Process a given configuration name
config_nameand return the conditioned configuration name.Attributes Documentation
- configs
Dictionary containing all the relevant mapping information to translate the corresponding device data in the HDF5 file and provide a consistent user interface via
File.Notes
The information stored in the
configsdictionary is used byHDFReadControlsto build thenumpydata array from the associated HDF5 dataset(s).The
configsdictis a nested dictionary where the first level of keys represents the control device configuration names. Each configuration name (dictkey) has an associateddictvalue that consists of a set of required keys and optional keys. Any optional key is considered as meta-info for the device and is added to theinfodictionary.The required keys are as follows:
Dictionary breakdown for config = configs['config name']Key
Description
config['dset paths']
Internal HDF5 path to the dataset associated with the control device configuration. For example,
config['dset paths'] = ('/foo/bar/Control/d1', )
config['shotnum']
Defines how the run shot numbers are stored in the associated HDF5 dataset, which are mapped to the
'shotnum'field of the constructednumpyarray. Should look like,config['shotnum'] = { 'dset paths': config['dset paths'], 'dset field': ('Shot number',), 'shape': (), 'dtype': numpy.int32, }
where
'dset paths'is the internal HDF5 path to the dataset,'dset field'is the field name of the dataset containing shot numbers,'shape'is the numpy shape of the shot number data, and'dtype'is the numpydtypeof the data. This all defines the numpydtypeof the'shotnum'field in theHDFReadControlsconstructed numpy array.If the
'dset paths'entry is defined asNone, then thebapsflibroutines will default to the'dset paths'defined for each of the'state values'entries.config['state values']
This is another dictionary defining
'state values'. For example,:config['state values'] = { 'xyz': { 'dset paths': config['dset paths'], 'dset field': ('x', 'y', 'z'), 'shape': (3,), 'dtype': numpy.float32, 'config column': 'Configuration name', }, }
will tell
HDFReadControlsto construct a numpy array with a'xyz'field. This field would be a 3-element array ofnumpy.float32, where the'x'field of the HDF5 dataset is mapped to the 1st index,'y'is mapped to the 2nd index, and'z'is mapped to the 3rd index.The
'config column'indicates the dataset column name that holds the configuration identification value (name, id, etc.). This field is optional, and will look for the column with ‘configuration’ in its name if the field is omitted.Note:
A state value field (key) can not be defined as
'signal'since this field is reserved for digitizer data constructed byHDFReadData.If state value data represents probe position data, then it should be given the field name (key)
'xyz'(like in the example above).
- contype
Control device type.
- dataset_names
List of names of the HDF5 datasets within the mapped group, at the root level.
- device_name
Name of Control device
- group
Instance of the HDF5 group that was mapped.
- group_name
Name of the mapped HDF5 group.
- group_path
Path of the mapped HDF5 group in the HDF5 file.
- has_command_list
Trueif the control device utilizes a command list
- info
Metadata information about the mapping type and the mapped group location in the HDF5 file.
Extended Summary
The dictionary will contain the following elements:
info = { "group name": "Device", # name of the mapped HDF5 group "group path": "/foo/bar/Device", # internal HDF5 path to the group "maptype": self.maptype, # mapping class type "contype": self.contype, # control device type }
- maptype
Mapping class type (
MapTypes).
- subgroup_names
List of names of the HDF5 subgroups within the mapped group, at the root level.
Methods Documentation
- abstractmethod construct_dataset_name(*args) str
Constructs the dataset name corresponding to the input arguments.
- Returns:
name of dataset
- Return type:
- get_config_column_value(config_name: str | int) str | None
For the given configuration name
config_nameget the associated configuration value that would be in the configuration column of the associated HDF5 datasets.Typically, the column value is just
config_name, but subclasses may override this to provide more sophisticated behavior. For example, ifconfig_nameis a mash-up of the column value and some other specifier, then this method can be used to do the properregexto pull out the column value fromconfig_name.
- process_config_name(config_name: str | int) str | int
Process a given configuration name
config_nameand return the conditioned configuration name.The conditioned configuration name is a key to the mapped
configsdictionary.Typically, the conditioned configuration name is just the given
config_name, but subclasses may override this method to allow desired “nicknames” to be conditioned into valid configuration names.Note
This method is integrated into
condition_controls, which is used byHDFReadDataandHDFReadControlsto condition the respective argumentsadd_controlsandcontrols. This integration is why the nickname mapping implemented here is available in theHDFReadDataandHDFReadControlsclasses, as well as the read data methods ofFile.