devctrl.data.data.DataAttributes#
- class DataAttributes(writer: str | None = None, writer_version: str | None = None, data_type: str | None = None, data_version: str | None = None, time_created: float | None = None, time_modified: float | None = None, series: str | None = None)[source]#
Bases:
SettingsClassMethods
Return all fields of the settings class as a dictionary.
Convenience method for copy.deepcopy(self)
Return a tuple describing the fields of this dataclass.
Build attributes from the class constants of a
Datasubclass.Recursively construct a
SettingsClassfrom a dictionary.Return the settings as a dictionary.
Read the data attributes from the root of an HDF5 file, without raising.
Write these attributes as root attributes of an HDF5 file.
Attributes
Canonical type label of the data, value of the root
data_typeHDF5 attribute.Version string
"<major>.<minor>"of the data format that is saved.Name of the measurement series the data belongs to (optional root
seriesattribute).Unix timestamp from when this data was initially written.
Unix timestamp from when this data was last modified.
Name of the software module which wrote this data.
Version of the software module which wrote this data.
- __annotations__ = {'data_type': str | None, 'data_version': str | None, 'series': str | None, 'time_created': float | None, 'time_modified': float | None, 'writer': str | None, 'writer_version': str | None}#
- __dataclass_fields__ = {'data_type': Field(name='data_type',type=str | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'data_version': Field(name='data_version',type=str | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'series': Field(name='series',type=str | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'time_created': Field(name='time_created',type=float | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'time_modified': Field(name='time_modified',type=float | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'writer': Field(name='writer',type=str | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'writer_version': Field(name='writer_version',type=str | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD)}#
- __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False,match_args=True,kw_only=False,slots=False,weakref_slot=False)#
- __dict__ = mappingproxy({'__module__': 'devctrl.data.data', '__firstlineno__': 28, '__annotations__': {'writer': str | None, 'writer_version': str | None, 'data_type': str | None, 'data_version': str | None, 'time_created': float | None, 'time_modified': float | None, 'series': str | None}, 'writer': None, 'writer_version': None, 'data_type': None, 'data_version': None, 'time_created': None, 'time_modified': None, 'series': None, 'stamp': <function DataAttributes.stamp>, 'read': <classmethod(<function DataAttributes.read>)>, 'from_data_class': <classmethod(<function DataAttributes.from_data_class>)>, '__static_attributes__': (), '__doc__': 'DataAttributes(writer: str | None = None, writer_version: str | None = None, data_type: str | None = None, data_version: str | None = None, time_created: float | None = None, time_modified: float | None = None, series: str | None = None)', '__dataclass_params__': _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False,match_args=True,kw_only=False,slots=False,weakref_slot=False), '__dataclass_fields__': {'writer': Field(name='writer',type=str | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'writer_version': Field(name='writer_version',type=str | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'data_type': Field(name='data_type',type=str | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'data_version': Field(name='data_version',type=str | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'time_created': Field(name='time_created',type=float | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'time_modified': Field(name='time_modified',type=float | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'series': Field(name='series',type=str | None,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD)}, '__replace__': <function _replace>, '__hash__': None, '__init__': <function DataAttributes.__init__>, '__repr__': <function DataAttributes.__repr__>, '__eq__': <function DataAttributes.__eq__>, '__match_args__': ('writer', 'writer_version', 'data_type', 'data_version', 'time_created', 'time_modified', 'series')})#
- __eq__(other)#
Return self==value.
- __firstlineno__ = 28#
- __hash__ = None#
- __init__(writer: str | None = None, writer_version: str | None = None, data_type: str | None = None, data_version: str | None = None, time_created: float | None = None, time_modified: float | None = None, series: str | None = None) None#
- __match_args__ = ('writer', 'writer_version', 'data_type', 'data_version', 'time_created', 'time_modified', 'series')#
- __module__ = 'devctrl.data.data'#
- __or__(other)#
Merge with another settings class or a dictionary. Unknown keys in a dictionary are ignored.
- __replace__(**changes)#
- __repr__()#
Return repr(self).
- __static_attributes__ = ()#
- __weakref__#
list of weak references to the object
- _get_dict(remove_empty_containers: bool = False, remove_None: bool = False, remove_if_None: list[str] | None = None) dict#
Return the settings as a dictionary, optionally cleaning up the output.
Base implementation for
get_dict(). Subclasses may call it with different arguments to configure the output.- Parameters:
remove_empty_containers – If True, remove empty
dict,list,tupleorsetvalues.remove_None – If True, remove all keys with a
Nonevalue.remove_if_None – If given, remove these keys only if their value is
None(absent keys are ignored).
- Returns:
Instance converted to dictionary, see
as_dict().
- _reorder_dict(d: dict) dict#
Reorder the keys of a dictionary created by
dataclasses.asdict()to the order offields().Walks the fields of
selfin parallel todand recurses into nestedSettingsClassinstances. All other values are kept as-is.- Parameters:
d – Dictionary as returned by
dataclasses.asdict()for this instance.- Returns:
Dictionary with the same values, but keys ordered like
fields().
- as_dict() dict#
Return all fields of the settings class as a dictionary.
Like
dataclasses.asdict(), but the keys are ordered likefields(): also the keys of nested SettingsClass instances (as field values and inside lists, tuples and dicts) are ordered by their fields. This waysave_yaml()and other YAML exports write the fields in the same order as they are defined in the class (or reordered bymetadata["order"], like in the GUI).- Returns:
Instance converted to dictionary.
- copy() Self#
Convenience method for copy.deepcopy(self)
- data_type: str | None = None#
Canonical type label of the data, value of the root
data_typeHDF5 attribute.
- data_version: str | None = None#
Version string
"<major>.<minor>"of the data format that is saved.
- fields()#
Return a tuple describing the fields of this dataclass.
Adapted version of dataclass.fields that applies additional sorting of the fields according to the field’s metadata[“order”] parameter.
Accepts a dataclass or an instance of one. Tuple elements are of type Field.
- classmethod from_data_class(data_class: type[Data]) DataAttributes[source]#
Build attributes from the class constants of a
Datasubclass.Uses
DATA_TYPE_NAME,DATA_FORMAT_VERSION,WRITER_NAMEandWRITER_VERSION; constants that are None (unset) are kept as None.- Parameters:
data_class – The
Datasubclass.- Returns:
The attributes describing the data written by
data_class.
- classmethod from_dict(data: dict, strict: bool = False) Self#
Recursively construct a
SettingsClassfrom a dictionary.If the value of a field is another SettingsClass,
from_dict()will be called for that field as well. Handled are:SettingsClass
list[SettingsClass]
dict[<any>, SettingsClass]
all of the above as Optional (Union with
None)a Union with any handled types
- Parameters:
strict – If True, raise a KeyError on keys in
datathat are not field names ofcls. Unknown keys are ignored otherwise.- Raises:
- get_dict() dict#
Return the settings as a dictionary.
as_dict()returns the settings class with all fields, whileget_dict()may be configured by subclasses to skip certain fields in the output. The default implementation returns all fields, likeas_dict(). :return: Instance converted to dictionary.
- classmethod load_yaml(yaml_path: str, loader=<class 'yaml.loader.Loader'>)#
- classmethod read(file: File | Group | str | Path) DataAttributes[source]#
Read the data attributes from the root of an HDF5 file, without raising.
Missing attributes are None, see
read_data_attrs().- Parameters:
file – Open
h5py.File/h5py.Groupor a path to an HDF5 file.- Returns:
The attributes read from the file.
- save_yaml(yaml_path: str)#
- series: str | None = None#
Name of the measurement series the data belongs to (optional root
seriesattribute).
- stamp(file: File | Group | str | Path) None[source]#
Write these attributes as root attributes of an HDF5 file.
Thin wrapper around
stamp_data_attrs(), which is idempotent: an already storedtime_createdis kept andtime_modifiedis refreshed.- Parameters:
file – Open
h5py.File/h5py.Groupor a path to an HDF5 file.
- time_created: float | None = None#
Unix timestamp from when this data was initially written.
- time_modified: float | None = None#
Unix timestamp from when this data was last modified.
- writer: str | None = None#
Name of the software module which wrote this data.
- writer_version: str | None = None#
Version of the software module which wrote this data.