prsctrl.measurement.pump_power_calibration.PowerCalibration#

class PowerCalibration(light_source_type: Literal['led', 'laser'], light_source_name: str, power_meter_name: str, wavelength_nm: float, beam_area_cm2: float, calibration_data: ndarray[tuple[Any, ...], dtype[_ScalarT]], method: Literal['interpolate', 'polyfit'] = 'interpolate', polyfit_degree: int = 2)[source]#

Bases: SettingsClass

Class holding calibration data for converting an LED current in A or a laser power in mW to the effective power density in mW/cm^2 (and back).

Methods

as_dict

Convenience wrapper for dataclasses.asdict(self)

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 settings as a dictionary.

laser_power_mW_to_power_density_mWcm2

led_current_A_to_power_density_mWcm2

load_yaml

plot

power_density_mWcm2_to_laser_power_mW

power_density_mWcm2_to_led_current_A

power_density_mWcm2_to_setting

save_yaml

setting_to_power_density_mWcm2

Attributes

__annotations__ = {'beam_area_cm2': <class 'float'>, 'calibration_data': numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]], 'light_source_name': <class 'str'>, 'light_source_type': typing.Literal['led', 'laser'], 'method': typing.Literal['interpolate', 'polyfit'], 'polyfit_degree': <class 'int'>, 'power_meter_name': <class 'str'>, 'wavelength_nm': <class 'float'>}#
__dataclass_fields__ = {'beam_area_cm2': Field(name='beam_area_cm2',type=<class 'float'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Beam area in cm^2 for calibration (or active detector area).'}),kw_only=False,_field_type=_FIELD), 'calibration_data': Field(name='calibration_data',type=numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]],default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Calibration data with shape (n_steps, 2).\nFirst column is either laser power in mW or led current in A.\nSecond column is measured power density in mW/cm^2.'}),kw_only=False,_field_type=_FIELD), 'light_source_name': Field(name='light_source_name',type=<class 'str'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Name of the light source.'}),kw_only=False,_field_type=_FIELD), 'light_source_type': Field(name='light_source_type',type=typing.Literal['led', 'laser'],default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'method': Field(name='method',type=typing.Literal['interpolate', 'polyfit'],default='interpolate',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Method to use for conversion (both directions):\ninterpolate: linearly interpolate the data\npolyfit: fit a polynomial to the data (polynomial degree is set by polyfit_degree).'}),kw_only=False,_field_type=_FIELD), 'polyfit_degree': Field(name='polyfit_degree',type=<class 'int'>,default=2,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': "The degree of the polynomial to fit the calibration data (if method is polyfit').", 'valid': (1, 10)}),kw_only=False,_field_type=_FIELD), 'power_meter_name': Field(name='power_meter_name',type=<class 'str'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Name of the power meter that was used.'}),kw_only=False,_field_type=_FIELD), 'wavelength_nm': Field(name='wavelength_nm',type=<class 'float'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Wavelength of the light source in nm.'}),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__': 'prsctrl.measurement.pump_power_calibration', '__firstlineno__': 17, '__annotations__': {'light_source_type': typing.Literal['led', 'laser'], 'light_source_name': <class 'str'>, 'power_meter_name': <class 'str'>, 'wavelength_nm': <class 'float'>, 'beam_area_cm2': <class 'float'>, 'calibration_data': numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]], 'method': typing.Literal['interpolate', 'polyfit'], 'polyfit_degree': <class 'int'>}, '__doc__': 'Class holding calibration data for converting an LED current in A or a laser power in mW to the effective power density in mW/cm^2 (and back).', 'method': 'interpolate', 'polyfit_degree': 2, 'setting_to_power_density_mWcm2': <function PowerCalibration.setting_to_power_density_mWcm2>, 'power_density_mWcm2_to_setting': <function PowerCalibration.power_density_mWcm2_to_setting>, 'led_current_A_to_power_density_mWcm2': <function PowerCalibration.led_current_A_to_power_density_mWcm2>, 'power_density_mWcm2_to_led_current_A': <function PowerCalibration.power_density_mWcm2_to_led_current_A>, 'laser_power_mW_to_power_density_mWcm2': <function PowerCalibration.laser_power_mW_to_power_density_mWcm2>, 'power_density_mWcm2_to_laser_power_mW': <function PowerCalibration.power_density_mWcm2_to_laser_power_mW>, '_assert_device_type': <function PowerCalibration._assert_device_type>, 'plot': <function PowerCalibration.plot>, '__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__': {'light_source_type': Field(name='light_source_type',type=typing.Literal['led', 'laser'],default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'light_source_name': Field(name='light_source_name',type=<class 'str'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Name of the light source.'}),kw_only=False,_field_type=_FIELD), 'power_meter_name': Field(name='power_meter_name',type=<class 'str'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Name of the power meter that was used.'}),kw_only=False,_field_type=_FIELD), 'wavelength_nm': Field(name='wavelength_nm',type=<class 'float'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Wavelength of the light source in nm.'}),kw_only=False,_field_type=_FIELD), 'beam_area_cm2': Field(name='beam_area_cm2',type=<class 'float'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Beam area in cm^2 for calibration (or active detector area).'}),kw_only=False,_field_type=_FIELD), 'calibration_data': Field(name='calibration_data',type=numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]],default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Calibration data with shape (n_steps, 2).\nFirst column is either laser power in mW or led current in A.\nSecond column is measured power density in mW/cm^2.'}),kw_only=False,_field_type=_FIELD), 'method': Field(name='method',type=typing.Literal['interpolate', 'polyfit'],default='interpolate',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': 'Method to use for conversion (both directions):\ninterpolate: linearly interpolate the data\npolyfit: fit a polynomial to the data (polynomial degree is set by polyfit_degree).'}),kw_only=False,_field_type=_FIELD), 'polyfit_degree': Field(name='polyfit_degree',type=<class 'int'>,default=2,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'doc': "The degree of the polynomial to fit the calibration data (if method is polyfit').", 'valid': (1, 10)}),kw_only=False,_field_type=_FIELD)}, '__replace__': <function _replace>, '__hash__': None, '__init__': <function PowerCalibration.__init__>, '__repr__': <function PowerCalibration.__repr__>, '__eq__': <function PowerCalibration.__eq__>, '__match_args__': ('light_source_type', 'light_source_name', 'power_meter_name', 'wavelength_nm', 'beam_area_cm2', 'calibration_data', 'method', 'polyfit_degree')})#
__eq__(other)#

Return self==value.

__firstlineno__ = 17#
__hash__ = None#
__init__(light_source_type: Literal['led', 'laser'], light_source_name: str, power_meter_name: str, wavelength_nm: float, beam_area_cm2: float, calibration_data: ndarray[tuple[Any, ...], dtype[_ScalarT]], method: Literal['interpolate', 'polyfit'] = 'interpolate', polyfit_degree: int = 2) → None#
__match_args__ = ('light_source_type', 'light_source_name', 'power_meter_name', 'wavelength_nm', 'beam_area_cm2', 'calibration_data', 'method', 'polyfit_degree')#
__module__ = 'prsctrl.measurement.pump_power_calibration'#
__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

_assert_device_type(device_type)[source]#
_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().

as_dict() → dict#

Convenience wrapper for dataclasses.asdict(self)

Returns all fields of the settings class. For a dictionary where certain fields may be skipped, see get_dict().

beam_area_cm2: float#
calibration_data: ndarray[tuple[Any, ...], dtype[_ScalarT]]#
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() → 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.

laser_power_mW_to_power_density_mWcm2(power_mW: float) → float[source]#
Parameters:

power_mW – Laser power in mW

Returns:

Power density in mW/cm^2

led_current_A_to_power_density_mWcm2(current_A: float) → float[source]#
Parameters:

current_A – LED current in A

Returns:

Power density in mW/cm^2

light_source_name: str#
light_source_type: Literal['led', 'laser']#
classmethod load_yaml(yaml_path: str, loader=<class 'yaml.loader.Loader'>)#
method: Literal['interpolate', 'polyfit'] = 'interpolate'#
plot(fig=None, axs=None)[source]#
polyfit_degree: int = 2#
power_density_mWcm2_to_laser_power_mW(power_density_mWcm2: float) → float[source]#
Parameters:

power_density_mWcm2 – Power density in mW/cm^2

Returns:

Laser power in mW

power_density_mWcm2_to_led_current_A(power_density_mWcm2: float) → float[source]#
Parameters:

power_density_mWcm2 – Power density in mW/cm^2

Returns:

LED current in A

power_density_mWcm2_to_setting(p_mWcm2: float) → float[source]#
Parameters:

p – Power density in mW/cm^2

Returns:

Power setting, either LED current in A or laser power in mW

power_meter_name: str#
save_yaml(yaml_path: str)#
setting_to_power_density_mWcm2(x: float) → float[source]#
Parameters:

x – LED current or laser power density

Returns:

Power density in mW/cm^2

wavelength_nm: float#