prsctrl.data.merge.MergeOptions#

class MergeOptions(method: Literal['fit_overlap', 'fit_overlap_or_gradient', 'overwrite'] = 'overwrite', prefer: Literal['most_points', 'small_wl', 'large_wl'] = 'most_points', gradient_n_vals: int = 3)[source]#

Bases: SettingsClass

Options for merging spectra.

Parameters:
  • method – “fit_overlap” fits a scale factor in the overlapping region; “fit_overlap_or_gradient” additionally falls back to gradient extrapolation if there is no overlap.

  • prefer – Which data to prefer when determining the merge order and the data whose values are kept.

  • gradient_n_vals – Number of points used for the gradient extrapolation. Defaults to 3.

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.

load_yaml

save_yaml

Attributes

__annotations__ = {'gradient_n_vals': <class 'int'>, 'method': typing.Literal['fit_overlap', 'fit_overlap_or_gradient', 'overwrite'], 'prefer': typing.Literal['most_points', 'small_wl', 'large_wl']}#
__dataclass_fields__ = {'gradient_n_vals': Field(name='gradient_n_vals',type=<class 'int'>,default=3,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['fit_overlap', 'fit_overlap_or_gradient', 'overwrite'],default='overwrite',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'prefer': Field(name='prefer',type=typing.Literal['most_points', 'small_wl', 'large_wl'],default='most_points',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__': 'prsctrl.data.merge', '__firstlineno__': 21, '__annotations__': {'method': typing.Literal['fit_overlap', 'fit_overlap_or_gradient', 'overwrite'], 'prefer': typing.Literal['most_points', 'small_wl', 'large_wl'], 'gradient_n_vals': <class 'int'>}, '__doc__': 'Options for merging spectra.\n\n:param method: "fit_overlap" fits a scale factor in the overlapping region; "fit_overlap_or_gradient" additionally\n    falls back to gradient extrapolation if there is no overlap.\n:param prefer: Which data to prefer when determining the merge order and the data whose values are kept.\n:param gradient_n_vals: Number of points used for the gradient extrapolation. Defaults to 3.\n', 'method': 'overwrite', 'prefer': 'most_points', 'gradient_n_vals': 3, '__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__': {'method': Field(name='method',type=typing.Literal['fit_overlap', 'fit_overlap_or_gradient', 'overwrite'],default='overwrite',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'prefer': Field(name='prefer',type=typing.Literal['most_points', 'small_wl', 'large_wl'],default='most_points',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'gradient_n_vals': Field(name='gradient_n_vals',type=<class 'int'>,default=3,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 MergeOptions.__init__>, '__repr__': <function MergeOptions.__repr__>, '__eq__': <function MergeOptions.__eq__>, '__match_args__': ('method', 'prefer', 'gradient_n_vals')})#
__eq__(other)#

Return self==value.

__firstlineno__ = 21#
__hash__ = None#
__init__(method: Literal['fit_overlap', 'fit_overlap_or_gradient', 'overwrite'] = 'overwrite', prefer: Literal['most_points', 'small_wl', 'large_wl'] = 'most_points', gradient_n_vals: int = 3) → None#
__match_args__ = ('method', 'prefer', 'gradient_n_vals')#
__module__ = 'prsctrl.data.merge'#
__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().

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().

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.

gradient_n_vals: int = 3#
classmethod load_yaml(yaml_path: str, loader=<class 'yaml.loader.Loader'>)#
method: Literal['fit_overlap', 'fit_overlap_or_gradient', 'overwrite'] = 'overwrite'#
prefer: Literal['most_points', 'small_wl', 'large_wl'] = 'most_points'#
save_yaml(yaml_path: str)#