51 lines
1.2 KiB
Python
Executable File
51 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
|
parser.add_argument("instrument")
|
|
parser.add_argument("pgroup")
|
|
clargs = parser.parse_args()
|
|
|
|
instrument = clargs.instrument
|
|
pgroup = clargs.pgroup
|
|
|
|
|
|
import os
|
|
from glob import glob
|
|
import json
|
|
|
|
|
|
print("globbing")
|
|
fns_pattern = "/sf/{}/data/{}/raw/scan_info/**.json".format(instrument, pgroup)
|
|
fns = sorted(glob(fns_pattern, recursive=True))
|
|
|
|
if not fns:
|
|
raise SystemExit("no file found for: {}".format(fns_pattern))
|
|
|
|
for fn_si in fns:
|
|
new_fn_si = fn_si.replace("/raw/", "/res/epics/")
|
|
print(fn_si, new_fn_si)
|
|
|
|
folder = os.path.dirname(new_fn_si)
|
|
os.makedirs(folder, exist_ok=True)
|
|
|
|
with open(fn_si, "r") as f:
|
|
data = json.load(f)
|
|
|
|
scan_files = data["scan_files"].copy()
|
|
for i, sfs in enumerate(scan_files):
|
|
for j, sf in enumerate(sfs):
|
|
if sf.endswith(".PVCHANNELS.h5"):
|
|
new_sf = sf.replace("/raw/", "/res/epics/").replace(".PVCHANNELS.h5", ".EPICSDATA.h5")
|
|
scan_files[i][j] = new_sf
|
|
|
|
new_data = data.copy()
|
|
new_data["scan_files"] = scan_files
|
|
|
|
with open(new_fn_si, "w") as f:
|
|
json.dump(new_data, f, indent=4)
|
|
|
|
|
|
|