Mercurial > repos > muon-spectroscopy-computational-project > larch_plot
comparison common.py @ 6:0339eb694129 draft default tip
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_plot commit 7f52c8654581d23a2acffc818e0c197cf8e04504
author | muon-spectroscopy-computational-project |
---|---|
date | Tue, 03 Sep 2024 11:51:45 +0000 |
parents | 3584db5902b5 |
children |
comparison
equal
deleted
inserted
replaced
5:3584db5902b5 | 6:0339eb694129 |
---|---|
73 except AttributeError as e: | 73 except AttributeError as e: |
74 print(f"Cannot load group.athena_params.bkg from group:\n{e}") | 74 print(f"Cannot load group.athena_params.bkg from group:\n{e}") |
75 bkg_parameters = None | 75 bkg_parameters = None |
76 | 76 |
77 keys = ( | 77 keys = ( |
78 ("e0", "e0", None), | 78 ("e0", ("e0"), None), |
79 ("pre1", "pre1", None), | 79 ("pre1", ("pre1"), None), |
80 ("pre2", "pre2", None), | 80 ("pre2", ("pre2"), None), |
81 ("norm1", "nor1", None), | 81 ("norm1", ("nor1"), None), |
82 ("norm2", "nor2", None), | 82 ("norm2", ("nor2"), None), |
83 ("nnorm", "nnorm", None), | 83 ("nnorm", ("nnorm"), None), |
84 ("make_flat", "flatten", None), | 84 ("make_flat", ("flatten"), None), |
85 ("step", "step", None), | 85 ("step", ("step"), None), |
86 ("nvict", "nvict", None), | 86 ("nvict", ("nvict"), None), |
87 ) | 87 ) |
88 for key, parameters_key, default in keys: | 88 for key, parameter_keys, default in keys: |
89 extract_attribute( | 89 extract_attribute( |
90 merged_settings=merged_settings, | 90 merged_settings=merged_settings, |
91 key=key, | 91 key=key, |
92 parameters_group=bkg_parameters, | 92 parameters_group=bkg_parameters, |
93 parameters_key=parameters_key, | 93 parameter_keys=parameter_keys, |
94 default=default, | 94 default=default, |
95 ) | 95 ) |
96 | 96 |
97 if settings: | 97 if settings: |
98 for k, v in settings.items(): | 98 for k, v in settings.items(): |
123 except AttributeError as e: | 123 except AttributeError as e: |
124 print(f"Cannot load group.athena_params.fft from group:\n{e}") | 124 print(f"Cannot load group.athena_params.fft from group:\n{e}") |
125 fft_parameters = None | 125 fft_parameters = None |
126 | 126 |
127 keys = ( | 127 keys = ( |
128 ("kmin", "kmin", 0), | 128 ("kmin", ("kmin",), 0), |
129 ("kmax", "kmax", 20), | 129 ("kmax", ("kmax",), 20), |
130 ("dk", "dk", 1), | 130 ("dk", ("dk",), 1), |
131 ("kweight", "kw", 2), | 131 ("kweight", ("kw", "kweight"), 2), |
132 ("kweight", "kweight", 2), | 132 ("window", ("kwindow",), "kaiser"), |
133 ("window", "kwindow", "kaiser"), | |
134 ) | 133 ) |
135 for key, parameters_key, default in keys: | 134 for key, parameter_keys, default in keys: |
136 extract_attribute( | 135 extract_attribute( |
137 merged_settings=merged_settings, | 136 merged_settings=merged_settings, |
138 key=key, | 137 key=key, |
139 parameters_group=fft_parameters, | 138 parameters_group=fft_parameters, |
140 parameters_key=parameters_key, | 139 parameter_keys=parameter_keys, |
141 default=default, | 140 default=default, |
142 ) | 141 ) |
143 | 142 |
144 if settings: | 143 if settings: |
145 for k, v in settings.items(): | 144 for k, v in settings.items(): |
154 | 153 |
155 def extract_attribute( | 154 def extract_attribute( |
156 merged_settings: dict, | 155 merged_settings: dict, |
157 key: str, | 156 key: str, |
158 parameters_group: Group, | 157 parameters_group: Group, |
159 parameters_key: str, | 158 parameter_keys: "tuple[str]", |
160 default: "str|int" = None, | 159 default: "str|int" = None, |
161 ): | 160 ): |
162 if parameters_group is not None: | 161 if parameters_group is not None: |
163 try: | 162 values = [] |
164 merged_settings[key] = getattr(parameters_group, parameters_key) | 163 for parameter_key in parameter_keys: |
164 try: | |
165 values.append(getattr(parameters_group, parameter_key)) | |
166 except AttributeError: | |
167 pass | |
168 | |
169 if len(values) > 1: | |
170 print( | |
171 f"WARNING: values {values} for for keys {parameter_keys}, " | |
172 "using first entry" | |
173 ) | |
174 | |
175 if len(values) > 0: | |
176 merged_settings[key] = values[0] | |
165 return | 177 return |
166 except AttributeError: | |
167 pass | |
168 | 178 |
169 if default is not None: | 179 if default is not None: |
170 merged_settings[key] = default | 180 merged_settings[key] = default |
171 | 181 |
172 | 182 |