Mercurial > repos > muon-spectroscopy-computational-project > larch_lcf
comparison common.py @ 0:f59731986b61 draft
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_lcf commit 5be486890442dedfb327289d597e1c8110240735
author | muon-spectroscopy-computational-project |
---|---|
date | Tue, 14 Nov 2023 15:35:22 +0000 |
parents | |
children | 6c28339b73f7 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f59731986b61 |
---|---|
1 from typing import Iterable | |
2 | |
3 from larch.io import extract_athenagroup, read_athena | |
4 from larch.io.athena_project import AthenaGroup | |
5 from larch.symboltable import Group | |
6 from larch.xafs import autobk, pre_edge, xftf | |
7 | |
8 | |
9 def get_group(athena_group: AthenaGroup, key: str = None) -> Group: | |
10 if key is None: | |
11 group_keys = list(athena_group._athena_groups.keys()) | |
12 key = group_keys[0] | |
13 return extract_athenagroup(athena_group._athena_groups[key]) | |
14 | |
15 | |
16 def read_group(dat_file: str, key: str = None, xftf_params: dict = None): | |
17 athena_group = read_athena(dat_file) | |
18 group = get_group(athena_group, key) | |
19 bkg_parameters = group.athena_params.bkg | |
20 print(group.athena_params.fft) | |
21 print(group.athena_params.fft.__dict__) | |
22 pre_edge( | |
23 group, | |
24 e0=bkg_parameters.e0, | |
25 pre1=bkg_parameters.pre1, | |
26 pre2=bkg_parameters.pre2, | |
27 norm1=bkg_parameters.nor1, | |
28 norm2=bkg_parameters.nor2, | |
29 nnorm=bkg_parameters.nnorm, | |
30 make_flat=bkg_parameters.flatten, | |
31 ) | |
32 autobk(group) | |
33 if xftf_params is None: | |
34 xftf(group) | |
35 else: | |
36 print(xftf_params) | |
37 xftf(group, **xftf_params) | |
38 xftf_details = Group() | |
39 setattr(xftf_details, "call_args", xftf_params) | |
40 group.xftf_details = xftf_details | |
41 return group | |
42 | |
43 | |
44 def read_groups(dat_files: "list[str]", key: str = None) -> Iterable[Group]: | |
45 for dat_file in dat_files: | |
46 yield read_group(dat_file=dat_file, key=key) |