Mercurial > repos > muon-spectroscopy-computational-project > larch_artemis
comparison larch_artemis.py @ 1:84c8e04bc1a1 draft
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_artemis commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
author | muon-spectroscopy-computational-project |
---|---|
date | Wed, 06 Dec 2023 13:03:46 +0000 |
parents | 2752b2dd7ad6 |
children | 39ab361e6d59 |
comparison
equal
deleted
inserted
replaced
0:2752b2dd7ad6 | 1:84c8e04bc1a1 |
---|---|
3 import gc | 3 import gc |
4 import json | 4 import json |
5 import os | 5 import os |
6 import sys | 6 import sys |
7 | 7 |
8 from common import get_group | 8 from common import read_group |
9 | 9 |
10 from larch.fitting import guess, param, param_group | 10 from larch.fitting import guess, param, param_group |
11 from larch.io import read_athena | |
12 from larch.symboltable import Group | 11 from larch.symboltable import Group |
13 from larch.xafs import ( | 12 from larch.xafs import ( |
14 FeffPathGroup, | 13 FeffPathGroup, |
15 FeffitDataSet, | 14 FeffitDataSet, |
16 TransformGroup, | 15 TransformGroup, |
17 autobk, | |
18 feffit, | 16 feffit, |
19 feffit_report, | 17 feffit_report, |
20 pre_edge, | |
21 xftf, | |
22 ) | 18 ) |
23 | 19 |
24 import matplotlib | 20 import matplotlib |
25 import matplotlib.pyplot as plt | 21 import matplotlib.pyplot as plt |
26 | 22 |
35 for row in reader: | 31 for row in reader: |
36 csv_data[int(row[id_field])] = row | 32 csv_data[int(row[id_field])] = row |
37 except FileNotFoundError: | 33 except FileNotFoundError: |
38 print("The specified file does not exist") | 34 print("The specified file does not exist") |
39 return csv_data | 35 return csv_data |
40 | |
41 | |
42 def calc_with_defaults(xafs_group: Group) -> Group: | |
43 """Calculate pre_edge and background with default arguments""" | |
44 pre_edge(xafs_group) | |
45 autobk(xafs_group) | |
46 xftf(xafs_group) | |
47 return xafs_group | |
48 | 36 |
49 | 37 |
50 def dict_to_gds(data_dict): | 38 def dict_to_gds(data_dict): |
51 dgs_group = param_group() | 39 dgs_group = param_group() |
52 for par_idx in data_dict: | 40 for par_idx in data_dict: |
207 ) -> Group: | 195 ) -> Group: |
208 report_path = f"report/fit_report{series_id}.txt" | 196 report_path = f"report/fit_report{series_id}.txt" |
209 rmr_path = f"rmr/rmr{series_id}.png" | 197 rmr_path = f"rmr/rmr{series_id}.png" |
210 chikr_path = f"chikr/chikr{series_id}.png" | 198 chikr_path = f"chikr/chikr{series_id}.png" |
211 | 199 |
212 athena_project = read_athena(prj_file) | |
213 athena_group = get_group(athena_project) | |
214 # calc_with_defaults will hang indefinitely (>6 hours recorded) if the | 200 # calc_with_defaults will hang indefinitely (>6 hours recorded) if the |
215 # data contains any NaNs - consider adding an early error here if this is | 201 # data contains any NaNs - consider adding an early error here if this is |
216 # not fixed in Larch? | 202 # not fixed in Larch? |
217 data_group = calc_with_defaults(athena_group) | 203 data_group = read_group(prj_file) |
218 | 204 |
219 print(f"Fitting project from file {data_group.filename}") | 205 print(f"Fitting project from file {data_group.filename}") |
220 | 206 |
221 gds = read_gds(gds_file) | 207 gds = read_gds(gds_file) |
222 selected_paths = read_selected_paths_list(sp_file) | 208 selected_paths = read_selected_paths_list(sp_file) |