comparison common.py @ 7:351f2cce19d1 draft

planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_athena commit 4814f53888643f1d3667789050914675fffb7d59
author muon-spectroscopy-computational-project
date Fri, 23 Aug 2024 14:10:30 +0000
parents 30cdfd70f28d
children 6e94ae7d1ca1
comparison
equal deleted inserted replaced
6:30cdfd70f28d 7:351f2cce19d1
9 9
10 def get_group(athena_group: AthenaGroup, key: str = None) -> Group: 10 def get_group(athena_group: AthenaGroup, key: str = None) -> Group:
11 group_keys = list(athena_group.keys()) 11 group_keys = list(athena_group.keys())
12 if key is None: 12 if key is None:
13 key = group_keys[0] 13 key = group_keys[0]
14 else:
15 key = key.replace("-", "_")
16 14
17 try: 15 try:
18 return extract_athenagroup(athena_group.groups[key]) 16 return extract_athenagroup(athena_group.groups[key])
19 except KeyError as e: 17 except KeyError as e:
20 raise KeyError(f"{key} not in {group_keys}") from e 18 raise KeyError(f"{key} not in {group_keys}") from e
21 19
22 20
23 def read_all_groups(dat_file: str, key: str = None) -> "dict[str, Group]": 21 def read_all_groups(dat_file: str) -> "dict[str, Group]":
24 # Cannot rely on do_ABC as _larch is None 22 # Cannot rely on do_ABC as _larch is None
25 athena_group = read_athena( 23 athena_group = read_athena(
26 dat_file, 24 dat_file,
27 do_preedge=False, 25 do_preedge=False,
28 do_bkg=False, 26 do_bkg=False,
38 36
39 return all_groups 37 return all_groups
40 38
41 39
42 def read_group(dat_file: str, key: str = None): 40 def read_group(dat_file: str, key: str = None):
41 if key:
42 match_ = key.replace(" ", "_").replace("-", "_").replace(".", "_")
43 else:
44 match_ = None
45
43 # Cannot rely on do_ABC as _larch is None 46 # Cannot rely on do_ABC as _larch is None
44 athena_group = read_athena( 47 athena_group = read_athena(
45 dat_file, 48 dat_file,
49 match=match_,
46 do_preedge=False, 50 do_preedge=False,
47 do_bkg=False, 51 do_bkg=False,
48 do_fft=False, 52 do_fft=False,
49 ) 53 )
50 group = get_group(athena_group, key) 54 group = get_group(athena_group, match_)
51 pre_edge_with_defaults(group=group) 55 pre_edge_with_defaults(group=group)
52 xftf_with_defaults(group=group) 56 xftf_with_defaults(group=group)
53 return group 57 return group
54 58
55 59