annotate common.py @ 1:6c28339b73f7 draft

planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
author muon-spectroscopy-computational-project
date Wed, 06 Dec 2023 13:04:01 +0000
parents f59731986b61
children 85284c3e1354
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
1 from typing import Iterable
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
2
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
3 from larch.io import extract_athenagroup, read_athena
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
4 from larch.io.athena_project import AthenaGroup
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
5 from larch.symboltable import Group
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
6 from larch.xafs import autobk, pre_edge, xftf
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
7
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
8
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
9 def get_group(athena_group: AthenaGroup, key: str = None) -> Group:
1
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
10 group_keys = list(athena_group._athena_groups.keys())
0
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
11 if key is None:
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
12 key = group_keys[0]
1
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
13 else:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
14 key = key.replace("-", "_")
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
15
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
16 try:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
17 return extract_athenagroup(athena_group._athena_groups[key])
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
18 except KeyError as e:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
19 raise KeyError(f"{key} not in {group_keys}") from e
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
20
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
21
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
22 def read_all_groups(dat_file: str, key: str = None) -> "dict[str, Group]":
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
23 # Cannot rely on do_ABC as _larch is None
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
24 athena_group = read_athena(
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
25 dat_file,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
26 do_preedge=False,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
27 do_bkg=False,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
28 do_fft=False,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
29 )
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
30 all_groups = {}
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
31 for key in athena_group._athena_groups.keys():
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
32 group = get_group(athena_group, key)
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
33 pre_edge_with_defaults(group=group)
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
34 xftf_with_defaults(group=group)
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
35 all_groups[key] = group
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
36
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
37 return all_groups
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
38
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
39
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
40 def read_group(dat_file: str, key: str = None):
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
41 # Cannot rely on do_ABC as _larch is None
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
42 athena_group = read_athena(
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
43 dat_file,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
44 do_preedge=False,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
45 do_bkg=False,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
46 do_fft=False,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
47 )
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
48 group = get_group(athena_group, key)
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
49 pre_edge_with_defaults(group=group)
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
50 xftf_with_defaults(group=group)
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
51 return group
0
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
52
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
53
1
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
54 def pre_edge_with_defaults(group: Group, settings: dict = None):
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
55 merged_settings = {}
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
56 try:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
57 bkg_parameters = group.athena_params.bkg
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
58 except AttributeError as e:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
59 print(f"Cannot load group.athena_params.bkg from group:\n{e}")
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
60 bkg_parameters = None
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
61
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
62 keys = (
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
63 ("e0", "e0", None),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
64 ("pre1", "pre1", None),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
65 ("pre2", "pre2", None),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
66 ("norm1", "nor1", None),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
67 ("norm2", "nor2", None),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
68 ("nnorm", "nnorm", None),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
69 ("make_flat", "flatten", None),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
70 ("step", "step", None),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
71 # This cannot be read from file as it is not stored by Larch (0.9.71)
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
72 # ("nvict", "nvict", None),
0
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
73 )
1
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
74 for key, parameters_key, default in keys:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
75 extract_attribute(
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
76 merged_settings, key, bkg_parameters, parameters_key, default
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
77 )
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
78
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
79 if settings:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
80 for k, v in settings.items():
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
81 if k == "nvict":
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
82 print(
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
83 "WARNING: `nvict` can be used for pre-edge but is not "
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
84 "saved to file, so value used will not be accessible in "
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
85 "future operations using this Athena .prj"
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
86 )
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
87 merged_settings[k] = v
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
88
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
89 print(f"Pre-edge normalization with {merged_settings}")
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
90 try:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
91 pre_edge(group, **merged_settings)
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
92 except Warning as e:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
93 raise Warning(
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
94 "Unable to perform pre-edge fitting with:\n\n"
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
95 f"energy:\n{group.energy}\n\nmu:{group.mu}\n\n"
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
96 "Consider checking the correct columns have been extracted"
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
97 ) from e
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
98 autobk(group, pre_edge_kws=merged_settings)
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
99
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
100
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
101 def xftf_with_defaults(group: Group, settings: dict = None):
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
102 merged_settings = {}
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
103 try:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
104 fft_parameters = group.athena_params.fft
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
105 except AttributeError as e:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
106 print(f"Cannot load group.athena_params.fft from group:\n{e}")
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
107 fft_parameters = None
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
108
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
109 keys = (
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
110 ("kmin", "kmin", 0),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
111 ("kmax", "kmax", 20),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
112 ("dk", "dk", 1),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
113 ("kweight", "kw", 2),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
114 ("kweight", "kweight", 2),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
115 ("window", "kwindow", "kaiser"),
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
116 )
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
117 for key, parameters_key, default in keys:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
118 extract_attribute(
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
119 merged_settings, key, fft_parameters, parameters_key, default
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
120 )
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
121
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
122 if settings:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
123 for k, v in settings.items():
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
124 merged_settings[k] = v
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
125
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
126 print(f"XFTF with {merged_settings}")
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
127 xftf(group, **merged_settings)
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
128 xftf_details = Group()
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
129 setattr(xftf_details, "call_args", merged_settings)
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
130 group.xftf_details = xftf_details
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
131
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
132
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
133 def extract_attribute(
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
134 merged_settings: dict,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
135 key: str,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
136 parameters_group: Group,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
137 parameters_key: str,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
138 default: "str|int" = None,
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
139 ):
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
140 if parameters_group is not None:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
141 try:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
142 merged_settings[key] = getattr(parameters_group, parameters_key)
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
143 return
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
144 except AttributeError:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
145 pass
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
146
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
147 if default is not None:
6c28339b73f7 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
148 merged_settings[key] = default
0
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
149
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
150
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
151 def read_groups(dat_files: "list[str]", key: str = None) -> Iterable[Group]:
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
152 for dat_file in dat_files:
f59731986b61 planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
153 yield read_group(dat_file=dat_file, key=key)