Mercurial > repos > muon-spectroscopy-computational-project > larch_plot
comparison common.py @ 4:35d24102cefd draft
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_plot commit 3fe6078868efd0fcea0fb5eea8dcd4b152d9c0a8
author | muon-spectroscopy-computational-project |
---|---|
date | Thu, 11 Apr 2024 09:02:24 +0000 |
parents | 5b993aff09e3 |
children | 3584db5902b5 |
comparison
equal
deleted
inserted
replaced
3:5b993aff09e3 | 4:35d24102cefd |
---|---|
5 from larch.symboltable import Group | 5 from larch.symboltable import Group |
6 from larch.xafs import autobk, pre_edge, xftf | 6 from larch.xafs import autobk, pre_edge, xftf |
7 | 7 |
8 | 8 |
9 def get_group(athena_group: AthenaGroup, key: str = None) -> Group: | 9 def get_group(athena_group: AthenaGroup, key: str = None) -> Group: |
10 group_keys = list(athena_group._athena_groups.keys()) | 10 group_keys = list(athena_group.keys()) |
11 if key is None: | 11 if key is None: |
12 key = group_keys[0] | 12 key = group_keys[0] |
13 else: | 13 else: |
14 key = key.replace("-", "_") | 14 key = key.replace("-", "_") |
15 | 15 |
16 try: | 16 try: |
17 return extract_athenagroup(athena_group._athena_groups[key]) | 17 return extract_athenagroup(athena_group.groups[key]) |
18 except KeyError as e: | 18 except KeyError as e: |
19 raise KeyError(f"{key} not in {group_keys}") from e | 19 raise KeyError(f"{key} not in {group_keys}") from e |
20 | 20 |
21 | 21 |
22 def read_all_groups(dat_file: str, key: str = None) -> "dict[str, Group]": | 22 def read_all_groups(dat_file: str, key: str = None) -> "dict[str, Group]": |
26 do_preedge=False, | 26 do_preedge=False, |
27 do_bkg=False, | 27 do_bkg=False, |
28 do_fft=False, | 28 do_fft=False, |
29 ) | 29 ) |
30 all_groups = {} | 30 all_groups = {} |
31 for key in athena_group._athena_groups.keys(): | 31 for key in athena_group.keys(): |
32 print(f"\nExtracting group {key}") | 32 print(f"\nExtracting group {key}") |
33 group = get_group(athena_group, key) | 33 group = get_group(athena_group, key) |
34 pre_edge_with_defaults(group=group) | 34 pre_edge_with_defaults(group=group) |
35 xftf_with_defaults(group=group) | 35 xftf_with_defaults(group=group) |
36 all_groups[key] = group | 36 all_groups[key] = group |
50 pre_edge_with_defaults(group=group) | 50 pre_edge_with_defaults(group=group) |
51 xftf_with_defaults(group=group) | 51 xftf_with_defaults(group=group) |
52 return group | 52 return group |
53 | 53 |
54 | 54 |
55 def pre_edge_with_defaults(group: Group, settings: dict = None): | 55 def pre_edge_with_defaults( |
56 group: Group, settings: dict = None, ref_channel: str = None | |
57 ): | |
56 merged_settings = {} | 58 merged_settings = {} |
57 try: | 59 if ref_channel is not None: |
58 bkg_parameters = group.athena_params.bkg | 60 print(f"Performing pre-edge with reference channel {ref_channel}") |
59 except AttributeError as e: | 61 ref = getattr(group, ref_channel.lower()) |
60 print(f"Cannot load group.athena_params.bkg from group:\n{e}") | 62 group.e0 = None |
61 bkg_parameters = None | 63 pre_edge(energy=group.energy, mu=ref, group=group) |
64 bkg_parameters = group.pre_edge_details | |
65 else: | |
66 try: | |
67 bkg_parameters = group.athena_params.bkg | |
68 except AttributeError as e: | |
69 print(f"Cannot load group.athena_params.bkg from group:\n{e}") | |
70 bkg_parameters = None | |
62 | 71 |
63 keys = ( | 72 keys = ( |
64 ("e0", "e0", None), | 73 ("e0", "e0", None), |
65 ("pre1", "pre1", None), | 74 ("pre1", "pre1", None), |
66 ("pre2", "pre2", None), | 75 ("pre2", "pre2", None), |