annotate common.py @ 3:5b993aff09e3 draft

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