Skip to content

Commit 60f6f44

Browse files
author
glass-ships
committed
convert defaults to dataclass, fix mypy test
1 parent 2b28005 commit 60f6f44

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

RefRed/interfaces/instrument_settings.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from dataclasses import dataclass
12
from typing import Any, Callable, Dict
23
from xml.dom.minidom import Document, Element
34

@@ -13,16 +14,17 @@
1314
from RefRed.configuration.global_settings import GlobalSettings
1415
from RefRed.interfaces import load_ui
1516

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
2628

2729

2830
class InstrumentSettingsEntryPoint(QGroupBox):
@@ -136,14 +138,14 @@ class InstrumentSettings(GlobalSettings):
136138
"""
137139

138140
# 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
147149

148150
# class variable, translates fields to XML tag names, same names as the lr_reduction package
149151
def to_xml(self, indent: str = "") -> str:
@@ -202,7 +204,7 @@ def from_xml(self, node: Element):
202204
setattr(self, field, converter(value))
203205
else:
204206
# 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])
206208

207209
return self
208210

0 commit comments

Comments
 (0)