Files
apocalypse/res/rerun.py
woznic_n 177d8777c1
All checks were successful
Run apocalypse tests / Explore-Gitea-Actions (push) Successful in 10s
first commit
2025-09-08 18:53:14 +02:00

67 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python
from pathlib import Path
from logzero import logger
from apocalypse.logcfg import set_loglvl
from res.load import load_many, product
from res.rerun_args import get_rerun_input
from res.send_redo_msg import send_msg
from utils.helpers import get_acq_from_pth
def re_run():
set_loglvl()
args = get_rerun_input()
args.paths = [
f"{s}/meta"
for s in load_many(instrument="*", pgroup=args.pgroup, run=args.run, debug=False)
]
args.files_meta, args.files = get_files(args)
check_files(args)
send_msg(args)
def get_files(args):
"""
args(argparse.Namespace): object from rerun_args
"""
files = []
files_meta = []
for p, a in product(args.paths, args.acq):
if pth := Path(p).glob(f"acq{a}.json"):
tmp = list(pth)
acq = [get_acq_from_pth(str(pt)) for pt in tmp]
files_meta.extend(tmp)
for ac in acq:
name_pattern = f"acq{ac}.{args.file_suffix}.h5"
tmp = Path(p.replace("/meta", "/data")).glob(name_pattern)
tmp = [list(tmp)]
files.extend(tmp)
return files_meta, files
def check_files(args):
"""
args(argparse.Namespace): object from rerun_args
"""
if not args.files_meta:
msg = "missing metadata files, exiting"
logger.error(msg)
raise SystemExit(msg)
if not args.files:
msg = "missing files to re-send, exiting"
logger.error(msg)
raise SystemExit(msg)
if __name__ == "__main__":
re_run()