File tree Expand file tree Collapse file tree 4 files changed +47
-34
lines changed Expand file tree Collapse file tree 4 files changed +47
-34
lines changed Original file line number Diff line number Diff line change 16
16
)
17
17
from .default_models import load_config_from_toml_files
18
18
from .path_settings import create_default_package_dir_or_ask , InternalPathSettings
19
+ from types import MappingProxyType
19
20
20
21
21
22
def get_default_models_and_peaks_from_definitions ():
@@ -36,5 +37,12 @@ class Settings(BaseSettings):
36
37
init_var = False ,
37
38
validate_default = False ,
38
39
)
40
+ default_definitions : MappingProxyType | None = Field (
41
+ default_factory = load_config_from_toml_files ,
42
+ alias = "my_default_definitions" ,
43
+ init_var = False ,
44
+ validate_default = False ,
45
+ )
46
+
39
47
destination_dir : Path = Field (default_factory = create_default_package_dir_or_ask )
40
48
internal_paths : InternalPathSettings = Field (default_factory = InternalPathSettings )
Original file line number Diff line number Diff line change @@ -217,37 +217,3 @@ def get_peaks_from_peak_definitions(
217
217
for peak_name , peak_def in peak_type_defs .items ():
218
218
peak_models [peak_name ] = BasePeak (** peak_def )
219
219
return peak_models
220
-
221
-
222
- def _main ():
223
- model_definitions = load_config_from_toml_files ()
224
- print (model_definitions ["first_order" ]["models" ])
225
- peaks = {}
226
- peak_items = {
227
- ** model_definitions ["first_order" ]["peaks" ],
228
- ** model_definitions ["second_order" ]["peaks" ],
229
- }.items ()
230
- for k , v in peak_items :
231
- peaks .update ({k : BasePeak (** v )})
232
-
233
- peak_d = BasePeak (** model_definitions ["first_order" ]["peaks" ]["D" ])
234
- print (peak_d )
235
- model_items = {
236
- ** model_definitions ["first_order" ]["models" ],
237
- ** model_definitions ["second_order" ]["models" ],
238
- }.items ()
239
- models = {}
240
- for model_name , model_comp in model_items :
241
- print (k , v )
242
- comps = model_comp .split ("+" )
243
- peak_comps = [peaks [i ] for i in comps ]
244
- lmfit_comp_model = sum (
245
- map (lambda x : x .lmfit_model , peak_comps ), peak_comps .pop ().lmfit_model
246
- )
247
- models [model_name ] = lmfit_comp_model
248
- print (lmfit_comp_model )
249
- # breakpoint()
250
-
251
-
252
- if __name__ == "__main__" :
253
- _main ()
Original file line number Diff line number Diff line change @@ -28,6 +28,11 @@ def example_files(internal_paths):
28
28
return example_files
29
29
30
30
31
+ @pytest .fixture (autouse = True )
32
+ def default_definitions (internal_paths ):
33
+ return settings .default_definitions
34
+
35
+
31
36
@pytest .fixture (autouse = True )
32
37
def default_models (internal_paths ):
33
38
return settings .default_models
Original file line number Diff line number Diff line change
1
+ from raman_fitting .models .deconvolution .base_peak import BasePeak
2
+
3
+
4
+ def test_initialize_base_peaks (
5
+ default_definitions , default_models_first_order , default_models_second_order
6
+ ):
7
+ peaks = {}
8
+
9
+ peak_items = {
10
+ ** default_definitions ["first_order" ]["peaks" ],
11
+ ** default_definitions ["second_order" ]["peaks" ],
12
+ }.items ()
13
+ for k , v in peak_items :
14
+ peaks .update ({k : BasePeak (** v )})
15
+
16
+ peak_d = BasePeak (** default_definitions ["first_order" ]["peaks" ]["D" ])
17
+ assert (
18
+ peak_d .peak_name
19
+ == default_definitions ["first_order" ]["peaks" ]["D" ]["peak_name" ]
20
+ )
21
+ assert (
22
+ peak_d .peak_type
23
+ == default_definitions ["first_order" ]["peaks" ]["D" ]["peak_type" ]
24
+ )
25
+ assert (
26
+ peak_d .lmfit_model .components [0 ].prefix
27
+ == default_definitions ["first_order" ]["peaks" ]["D" ]["peak_name" ] + "_"
28
+ )
29
+ assert (
30
+ peak_d .param_hints ["center" ].value
31
+ == default_definitions ["first_order" ]["peaks" ]["D" ]["param_hints" ]["center" ][
32
+ "value"
33
+ ]
34
+ )
You can’t perform that action at this time.
0 commit comments