spvctrl.utility.setup.TspvSetupInfo#

class TspvSetupInfo(version: str = '1.0', buffer: str | None = None, buffer_capacitance_pF: float | None = None, laser_SHG_temp_C: float | None = None, laser_THG_temp_C: float | None = None, notes: str | None = None, metadata: dict[str, str]=<factory>)[source]#

Bases: SettingsClass

Dataclass representing the measurement setup.

Methods

as_dict

Return all fields of the settings class as a dictionary.

copy

Convenience method for copy.deepcopy(self)

fields

Return a tuple describing the fields of this dataclass.

from_dict

Recursively construct a SettingsClass from a dictionary.

get_dict

Return the data as dictionary, with some additional preprocessing.

load_yaml

save_yaml

Attributes

__annotations__ = {'buffer': typing.Optional[str], 'buffer_capacitance_pF': typing.Optional[float], 'laser_SHG_temp_C': typing.Optional[float], 'laser_THG_temp_C': typing.Optional[float], 'metadata': dict[str, str], 'notes': typing.Optional[str], 'version': <class 'str'>}#
__dataclass_fields__ = {'buffer': Field(name='buffer',type=typing.Optional[str],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'The name (date) of the connected buffer.'}),kw_only=False,_field_type=_FIELD), 'buffer_capacitance_pF': Field(name='buffer_capacitance_pF',type=typing.Optional[float],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'The capacitance of the connected buffer.'}),kw_only=False,_field_type=_FIELD), 'laser_SHG_temp_C': Field(name='laser_SHG_temp_C',type=typing.Optional[float],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': "The laser's SHG temperature."}),kw_only=False,_field_type=_FIELD), 'laser_THG_temp_C': Field(name='laser_THG_temp_C',type=typing.Optional[float],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': "The laser's THG temperature."}),kw_only=False,_field_type=_FIELD), 'metadata': Field(name='metadata',type=dict[str, str],default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'dict'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Extra key-value pairs'}),kw_only=False,_field_type=_FIELD), 'notes': Field(name='notes',type=typing.Optional[str],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Additional notes.'}),kw_only=False,_field_type=_FIELD), 'version': Field(name='version',type=<class 'str'>,default='1.0',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Setup version number/string.'}),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__': 'spvctrl.utility.setup', '__firstlineno__': 5, '__annotations__': {'version': <class 'str'>, 'buffer': typing.Optional[str], 'buffer_capacitance_pF': typing.Optional[float], 'laser_SHG_temp_C': typing.Optional[float], 'laser_THG_temp_C': typing.Optional[float], 'notes': typing.Optional[str], 'metadata': dict[str, str]}, '__doc__': 'Dataclass representing the measurement setup.', 'version': '1.0', 'buffer': None, 'buffer_capacitance_pF': None, 'laser_SHG_temp_C': None, 'laser_THG_temp_C': None, 'notes': None, 'get_dict': <function TspvSetupInfo.get_dict>, '__static_attributes__': (), '__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__': {'version': Field(name='version',type=<class 'str'>,default='1.0',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Setup version number/string.'}),kw_only=False,_field_type=_FIELD), 'buffer': Field(name='buffer',type=typing.Optional[str],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'The name (date) of the connected buffer.'}),kw_only=False,_field_type=_FIELD), 'buffer_capacitance_pF': Field(name='buffer_capacitance_pF',type=typing.Optional[float],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'The capacitance of the connected buffer.'}),kw_only=False,_field_type=_FIELD), 'laser_SHG_temp_C': Field(name='laser_SHG_temp_C',type=typing.Optional[float],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': "The laser's SHG temperature."}),kw_only=False,_field_type=_FIELD), 'laser_THG_temp_C': Field(name='laser_THG_temp_C',type=typing.Optional[float],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': "The laser's THG temperature."}),kw_only=False,_field_type=_FIELD), 'notes': Field(name='notes',type=typing.Optional[str],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Additional notes.'}),kw_only=False,_field_type=_FIELD), 'metadata': Field(name='metadata',type=dict[str, str],default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'dict'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Extra key-value pairs'}),kw_only=False,_field_type=_FIELD)}, '__replace__': <function _replace>, '__hash__': None, '__init__': <function TspvSetupInfo.__init__>, '__repr__': <function TspvSetupInfo.__repr__>, '__eq__': <function TspvSetupInfo.__eq__>, '__match_args__': ('version', 'buffer', 'buffer_capacitance_pF', 'laser_SHG_temp_C', 'laser_THG_temp_C', 'notes', 'metadata')})#
__eq__(other)#

Return self==value.

__firstlineno__ = 5#
__hash__ = None#
__init__(version: str = '1.0', buffer: str | None = None, buffer_capacitance_pF: float | None = None, laser_SHG_temp_C: float | None = None, laser_THG_temp_C: float | None = None, notes: str | None = None, metadata: dict[str, str]=<factory>) → None#
__match_args__ = ('version', 'buffer', 'buffer_capacitance_pF', 'laser_SHG_temp_C', 'laser_THG_temp_C', 'notes', 'metadata')#
__module__ = 'spvctrl.utility.setup'#
__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, tuple or set values.

  • remove_None – If True, remove all keys with a None value.

  • 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 of fields().

Walks the fields of self in parallel to d and recurses into nested SettingsClass instances. 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 like fields(): also the keys of nested SettingsClass instances (as field values and inside lists, tuples and dicts) are ordered by their fields. This way save_yaml() and other YAML exports write the fields in the same order as they are defined in the class (or reordered by metadata["order"], like in the GUI).

Returns:

Instance converted to dictionary.

buffer: str | None = None#
buffer_capacitance_pF: float | None = None#
copy() → Self#

Convenience method for copy.deepcopy(self)

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_dict(data: dict, strict: bool = False) → Self#

Recursively construct a SettingsClass from 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 data that are not field names of cls. Unknown keys are ignored otherwise.

Raises:
  • ValueError – If data contains a value that has the wrong type for the field of cls (ONLY if the type is a subclass of SettingsClass! Other types are not enforced)

  • KeyError – If strict is True and data contains a key that is not a field name of cls

get_dict(flatten_metadata: bool = False, remove_empty_fields: bool = True) → dict[source]#

Return the data as dictionary, with some additional preprocessing.

Parameters:
  • flatten_metadata – If True, move all key-value pairs from the “metadata” sub-dictionary into the main dictionary.

  • remove_empty_fields – If True, remove the metadata field if it is empty, and remove all optional keys with a None value.

Returns:

Instance converted to dictionary.

laser_SHG_temp_C: float | None = None#
laser_THG_temp_C: float | None = None#
classmethod load_yaml(yaml_path: str, loader=<class 'yaml.loader.Loader'>)#
metadata: dict[str, str]#
notes: str | None = None#
save_yaml(yaml_path: str)#
version: str = '1.0'#