|
| 1 | +from dataclasses import dataclass |
1 | 2 | from typing import Any, Callable, Dict |
2 | 3 | from xml.dom.minidom import Document, Element |
3 | 4 |
|
|
13 | 14 | from RefRed.configuration.global_settings import GlobalSettings |
14 | 15 | from RefRed.interfaces import load_ui |
15 | 16 |
|
16 | | -DEFAULT_INSTRUMENT_SETTINGS = { |
17 | | - "apply_instrument_settings": False, |
18 | | - "source_detector_distance": 15.75, |
19 | | - "sample_detector_distance": 1.83, |
20 | | - "num_x_pixels": 256, |
21 | | - "num_y_pixels": 304, |
22 | | - "pixel_width": 0.70, |
23 | | - "xi_reference": 445, |
24 | | - "s1_sample_distance": 1.485, |
25 | | -} |
| 17 | + |
| 18 | +@dataclass |
| 19 | +class DEFAULT_INSTRUMENT_SETTINGS: |
| 20 | + apply_instrument_settings: bool = False |
| 21 | + source_detector_distance: float = 15.75 |
| 22 | + sample_detector_distance: float = 1.83 |
| 23 | + num_x_pixels: int = 256 |
| 24 | + num_y_pixels: int = 304 |
| 25 | + pixel_width: float = 0.70 |
| 26 | + xi_reference: float = 445 |
| 27 | + s1_sample_distance: float = 1.485 |
26 | 28 |
|
27 | 29 |
|
28 | 30 | class InstrumentSettingsEntryPoint(QGroupBox): |
@@ -136,14 +138,14 @@ class InstrumentSettings(GlobalSettings): |
136 | 138 | """ |
137 | 139 |
|
138 | 140 | # pydantic fields |
139 | | - apply_instrument_settings: bool = DEFAULT_INSTRUMENT_SETTINGS["apply_instrument_settings"] |
140 | | - source_detector_distance: float = DEFAULT_INSTRUMENT_SETTINGS["source_detector_distance"] |
141 | | - sample_detector_distance: float = DEFAULT_INSTRUMENT_SETTINGS["sample_detector_distance"] |
142 | | - num_x_pixels: int = DEFAULT_INSTRUMENT_SETTINGS["num_x_pixels"] |
143 | | - num_y_pixels: int = DEFAULT_INSTRUMENT_SETTINGS["num_y_pixels"] |
144 | | - pixel_width: float = DEFAULT_INSTRUMENT_SETTINGS["pixel_width"] |
145 | | - xi_reference: float = DEFAULT_INSTRUMENT_SETTINGS["xi_reference"] |
146 | | - s1_sample_distance: float = DEFAULT_INSTRUMENT_SETTINGS["s1_sample_distance"] |
| 141 | + apply_instrument_settings: bool = DEFAULT_INSTRUMENT_SETTINGS.apply_instrument_settings |
| 142 | + source_detector_distance: float = DEFAULT_INSTRUMENT_SETTINGS.source_detector_distance |
| 143 | + sample_detector_distance: float = DEFAULT_INSTRUMENT_SETTINGS.sample_detector_distance |
| 144 | + num_x_pixels: int = DEFAULT_INSTRUMENT_SETTINGS.num_x_pixels |
| 145 | + num_y_pixels: int = DEFAULT_INSTRUMENT_SETTINGS.num_y_pixels |
| 146 | + pixel_width: float = DEFAULT_INSTRUMENT_SETTINGS.pixel_width |
| 147 | + xi_reference: float = DEFAULT_INSTRUMENT_SETTINGS.xi_reference |
| 148 | + s1_sample_distance: float = DEFAULT_INSTRUMENT_SETTINGS.s1_sample_distance |
147 | 149 |
|
148 | 150 | # class variable, translates fields to XML tag names, same names as the lr_reduction package |
149 | 151 | def to_xml(self, indent: str = "") -> str: |
@@ -202,7 +204,7 @@ def from_xml(self, node: Element): |
202 | 204 | setattr(self, field, converter(value)) |
203 | 205 | else: |
204 | 206 | # if the field is not found in the XML, we use the default value |
205 | | - setattr(self, field, DEFAULT_INSTRUMENT_SETTINGS[field]) |
| 207 | + setattr(self, field, DEFAULT_INSTRUMENT_SETTINGS.__dict__[field]) |
206 | 208 |
|
207 | 209 | return self |
208 | 210 |
|
|
0 commit comments