Coverage for src/spectroflat/base/config.py: 96%
25 statements
« prev ^ index » next coverage.py v7.3.2, created at 2024-03-28 07:59 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2024-03-28 07:59 +0000
1from dataclasses import dataclass, field
3from qollib.strings import parse_shape
5from .sensor_flat_config import SensorFlatConfig
6from .smile_config import SmileConfig
9@dataclass
10class Config:
11 """
12 Configuration DataItem
13 """
15 #: Flag to indicate if the pre-flat shall be applied.
16 apply_sensor_flat: bool = True
18 #: [y0:y1,x0:x1] Region of interest in numpy notation (everything outside will be ignored)
19 roi: tuple = None
21 #: refine hard flat by iterating it to become self-consistent
22 sensor_flat_iterations: int = 5
24 #: The specific configuration for the pre-flat.
25 sensor_flat: SensorFlatConfig = field(default_factory=SensorFlatConfig)
27 #: The configuration for the smile detection.
28 smile: SmileConfig = field(default_factory=SmileConfig)
30 @staticmethod
31 def from_dict(data: dict):
32 """
33 Create a config from a dictionary.
35 All instance variable names are supported as keywords.
36 All keywords are optional, if the keyword is not present the default will be used.
38 """
39 sc = data.pop('smile') if 'smile' in data.keys() else None
40 sfc = data.pop('sensor_flat') if 'sensor_flat' in data.keys() else None
41 data['roi'] = parse_shape(data['roi']) if 'roi' in data else None
43 c = Config(**data)
44 if sc is not None:
45 c.smile = SmileConfig.from_dict(sc)
46 if sfc is not None:
47 c.sensor_flat = SensorFlatConfig.from_dict(sfc)
48 if c.roi is not None:
49 c.smile.roi = c.roi
50 c.sensor_flat.roi = c.roi
51 return c