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 1616)
1717from .default_models import load_config_from_toml_files
1818from .path_settings import create_default_package_dir_or_ask , InternalPathSettings
19+ from types import MappingProxyType
1920
2021
2122def get_default_models_and_peaks_from_definitions ():
@@ -36,5 +37,12 @@ class Settings(BaseSettings):
3637 init_var = False ,
3738 validate_default = False ,
3839 )
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+
3947 destination_dir : Path = Field (default_factory = create_default_package_dir_or_ask )
4048 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(
217217 for peak_name , peak_def in peak_type_defs .items ():
218218 peak_models [peak_name ] = BasePeak (** peak_def )
219219 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):
2828 return example_files
2929
3030
31+ @pytest .fixture (autouse = True )
32+ def default_definitions (internal_paths ):
33+ return settings .default_definitions
34+
35+
3136@pytest .fixture (autouse = True )
3237def default_models (internal_paths ):
3338 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