Mercurial > repos > muon-spectroscopy-computational-project > larch_athena
comparison larch_athena.py @ 6:30cdfd70f28d draft
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_athena commit 71cee2ed96b69a2e78a1eb3dadbd2e81bf332798
| author | muon-spectroscopy-computational-project |
|---|---|
| date | Mon, 17 Jun 2024 13:54:39 +0000 |
| parents | 27015eaf9a78 |
| children |
comparison
equal
deleted
inserted
replaced
| 5:27015eaf9a78 | 6:30cdfd70f28d |
|---|---|
| 1 import gc | 1 import gc |
| 2 import json | 2 import json |
| 3 import os | 3 import os |
| 4 import re | |
| 5 import sys | 4 import sys |
| 6 | 5 |
| 7 from common import ( | 6 from common import ( |
| 8 pre_edge_with_defaults, | 7 pre_edge_with_defaults, |
| 9 read_all_groups, | 8 read_all_groups, |
| 10 read_group, | 9 read_group, |
| 10 sorting_key, | |
| 11 xftf_with_defaults, | 11 xftf_with_defaults, |
| 12 ) | 12 ) |
| 13 | 13 |
| 14 from larch.io import ( | 14 from larch.io import ( |
| 15 create_athena, | 15 create_athena, |
| 140 xafs_group = Group(data=np.array([energy[:], mu[:]])) | 140 xafs_group = Group(data=np.array([energy[:], mu[:]])) |
| 141 set_array_labels(xafs_group, ["energy", "mu"]) | 141 set_array_labels(xafs_group, ["energy", "mu"]) |
| 142 return xafs_group | 142 return xafs_group |
| 143 | 143 |
| 144 def load_zipped_files(self) -> "dict[str, Group]": | 144 def load_zipped_files(self) -> "dict[str, Group]": |
| 145 def sorting_key(filename: str) -> str: | |
| 146 return re.findall(r"\d+", filename)[-1] | |
| 147 | |
| 148 all_paths = list(os.walk("dat_files")) | 145 all_paths = list(os.walk("dat_files")) |
| 149 all_paths.sort(key=lambda x: x[0]) | 146 all_paths.sort(key=lambda x: x[0]) |
| 150 file_total = sum([len(f) for _, _, f in all_paths]) | 147 file_total = sum([len(f) for _, _, f in all_paths]) |
| 151 print(f"{file_total} files found") | 148 print(f"{file_total} files found") |
| 152 keyed_data = {} | 149 keyed_data = {} |
| 153 for dirpath, _, filenames in all_paths: | 150 for dirpath, _, filenames in all_paths: |
| 151 if dirpath.endswith("__MACOSX"): | |
| 152 print(f"Skipping {dirpath}") | |
| 153 continue | |
| 154 | |
| 154 try: | 155 try: |
| 155 filenames.sort(key=sorting_key) | 156 filenames.sort(key=sorting_key) |
| 156 except IndexError as e: | 157 except IndexError as e: |
| 157 print( | 158 print( |
| 158 "WARNING: Unable to sort files numerically, " | 159 "WARNING: Unable to sort files numerically, " |
