spvctrl.measurement.settings.TspvSettings#

class TspvSettings(general: MeasurementParameters = <factory>, laser: OpoSettings = <factory>, acquisition: GageScopeAcquisitionSettings = <factory>)[source]#

Bases: SettingsClass

All settings for a transient surface-photovoltage-type measurement.

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

Create settings from a dict, translating legacy measurement-parameter values.

get_dict

Return the settings as a dictionary.

get_metadata

Return the measurements settings converted to a metadata dictionary that contains only relevant information.

load_yaml

prepare

Validate the settings and resolve the acquisition configuration.

resolve_acquisition

Resolve the acquisition configuration, see prepare().

save_yaml

Attributes

__annotations__ = {'acquisition': <class 'spvctrl.measurement.settings.GageScopeAcquisitionSettings'>, 'general': <class 'spvctrl.measurement.settings.MeasurementParameters'>, 'laser': <class 'spvctrl.measurement.settings.OpoSettings'>}#
__dataclass_fields__ = {'acquisition': Field(name='acquisition',type=<class 'spvctrl.measurement.settings.GageScopeAcquisitionSettings'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'spvctrl.measurement.settings.GageScopeAcquisitionSettings'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'general': Field(name='general',type=<class 'spvctrl.measurement.settings.MeasurementParameters'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'spvctrl.measurement.settings.MeasurementParameters'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'laser': Field(name='laser',type=<class 'spvctrl.measurement.settings.OpoSettings'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'spvctrl.measurement.settings.OpoSettings'>,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__': 'spvctrl.measurement.settings', '__firstlineno__': 273, '__annotations__': {'general': <class 'spvctrl.measurement.settings.MeasurementParameters'>, 'laser': <class 'spvctrl.measurement.settings.OpoSettings'>, 'acquisition': <class 'spvctrl.measurement.settings.GageScopeAcquisitionSettings'>}, '__doc__': 'All settings for a transient surface-photovoltage-type measurement.\n    ', '__post_init__': <function TspvSettings.__post_init__>, 'from_dict': <classmethod(<function TspvSettings.from_dict>)>, 'prepare': <function TspvSettings.prepare>, 'resolve_acquisition': <function TspvSettings.resolve_acquisition>, '_resolve_from_acquisition_time': <function TspvSettings._resolve_from_acquisition_time>, '_resolve_explicit': <function TspvSettings._resolve_explicit>, 'get_metadata': <function TspvSettings.get_metadata>, '__static_attributes__': ('resolved_acquisition',), '__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__': {'general': Field(name='general',type=<class 'spvctrl.measurement.settings.MeasurementParameters'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'spvctrl.measurement.settings.MeasurementParameters'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'laser': Field(name='laser',type=<class 'spvctrl.measurement.settings.OpoSettings'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'spvctrl.measurement.settings.OpoSettings'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'acquisition': Field(name='acquisition',type=<class 'spvctrl.measurement.settings.GageScopeAcquisitionSettings'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'spvctrl.measurement.settings.GageScopeAcquisitionSettings'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD)}, '__replace__': <function _replace>, '__hash__': None, '__init__': <function TspvSettings.__init__>, '__repr__': <function TspvSettings.__repr__>, '__eq__': <function TspvSettings.__eq__>, '__match_args__': ('general', 'laser', 'acquisition')})#
__eq__(other)#

Return self==value.

__firstlineno__ = 273#
__hash__ = None#
__init__(general: MeasurementParameters = <factory>, laser: OpoSettings = <factory>, acquisition: GageScopeAcquisitionSettings = <factory>) → None#
__match_args__ = ('general', 'laser', 'acquisition')#
__module__ = 'spvctrl.measurement.settings'#
__or__(other)#

Merge with another settings class or a dictionary. Unknown keys in a dictionary are ignored.

__post_init__()[source]#
__replace__(**changes)#
__repr__()#

Return repr(self).

__static_attributes__ = ('resolved_acquisition',)#
__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().

_resolve_explicit(rate_spec: str | int, rates: ValidValues[int], record_limits: ValidValues[int], pre_trigger_limits: ValidValues[int]) → dict[source]#

Resolve the acquisition configuration.

The sampling rate, segment size and pre-trigger depth are used as given, snapped up to the device-supported values and capped at the device limits (with a warning and substituted in the settings) when an oscilloscope is given.

Parameters:
  • rate_spec – The sampling rate in Hz.

  • rates – Valid sampling rates of the oscilloscope, or None if unknown.

  • record_limits – Valid record lengths of the oscilloscope, or None if unknown.

  • pre_trigger_limits – Valid pre-trigger depths of the oscilloscope, or None if unknown.

Returns:

The resolved acquisition configuration dict.

_resolve_from_acquisition_time(rate_spec: str | int, acq_time_s: float, rates: ValidValues[int], record_limits: ValidValues[int], pre_trigger_limits: ValidValues[int]) → dict[source]#

Resolve the acquisition configuration from a desired acquisition time.

The sampling rate is snapped up to the next supported rate of the oscilloscope. The record length (depth) is the smallest value that yields an acquisition time equal or larger than the requested time, given the sampling rate; it is capped at the maximum record length of the oscilloscope, which shortens the acquisition time. The pre-trigger is snapped up to the pre-trigger increment and capped at the device’s maximum pre-trigger depth, so that the segment (pre-trigger + post-trigger samples) fits into the record length. All deviations from the requested values are logged and substituted in the settings.

Parameters:
  • rate_spec – The sampling rate in Hz, or ‘max’.

  • acq_time_s – Desired acquisition time in s.

  • rates – Valid sampling rates of the oscilloscope, or None if unknown.

  • record_limits – Valid record lengths of the oscilloscope, or None if unknown.

  • pre_trigger_limits – Valid pre-trigger depths of the oscilloscope, or None if unknown.

Returns:

The resolved acquisition configuration dict.

acquisition: GageScopeAcquisitionSettings#
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.

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) → TspvSettings[source]#

Create settings from a dict, translating legacy measurement-parameter values.

Tasklists saved before the data refactor stored store_individual_pulses as a 4-mode string (all-full, all-downsampled, averaged-full, averaged-downsampled). Those values are translated to the new store_individual_pulses (bool) and pulse_storage fields, and a warning is logged.

Parameters:
  • data – Settings dict as returned by SettingsClass.as_dict().

  • strict – Passed on to SettingsClass.from_dict().

Returns:

The settings instance.

general: MeasurementParameters#
get_dict() → dict#

Return the settings as a dictionary.

as_dict() returns the settings class with all fields, while get_dict() may be configured by subclasses to skip certain fields in the output. The default implementation returns all fields, like as_dict(). :return: Instance converted to dictionary.

get_metadata() → dict[str, Any][source]#

Return the measurements settings converted to a metadata dictionary that contains only relevant information.

laser: OpoSettings#
classmethod load_yaml(yaml_path: str, loader=<class 'yaml.loader.Loader'>)#
prepare(osci: Oscilloscope | None = None) → dict[source]#

Validate the settings and resolve the acquisition configuration.

Resolves general.pulse_interval_s to laser.frequency_divider, so that the actual pulse interval is equal or larger than the target, and computes the sampling rate, record length, pre-trigger samples and segment size from the requested acquisition time and the oscilloscope capabilities: the closest possible acquisition time that is equal or larger than the requested time is used. The resolved configuration is stored in resolved_acquisition, so that the metadata records the actual values.

Parameters:

osci – The oscilloscope device, used to query the sampling rate and record length capabilities. If None, or if the capabilities can not be queried, the requested values are used as-is without coercion to device-supported values.

Returns:

The resolved acquisition configuration.

resolve_acquisition(osci: Oscilloscope | None = None) → dict[source]#

Resolve the acquisition configuration, see prepare().

The device-supported values are queried directly from the oscilloscope via its valid_* capability queries and the requested values are snapped up to them.

Parameters:

osci – The oscilloscope device used to query the capabilities, or None to resolve without device-supported coercion.

Returns:

Dict with the keys ‘sampling_rate_Hz’, ‘depth’, ‘pre_trigger_samples’, ‘segment_size’ and ‘acquisition_time_s’.

save_yaml(yaml_path: str)#