58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
import numpy as np
|
|
import json, os, glob, yaml
|
|
import argparse, pickle, h5py
|
|
from pathlib import Path
|
|
from sfdata import SFDataFile
|
|
|
|
from alvra_tools.load_data import *
|
|
from alvra_tools.channels import *
|
|
from alvra_tools.utils import *
|
|
|
|
#This is for 16M!
|
|
roi = [1100, 1300, 1100, 1300]
|
|
|
|
def get_acq_from_pth(path):
|
|
import re
|
|
return re.search(r"acq(\d+)", path).group(1).zfill(4)
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--input", "-i", required=True)
|
|
args = parser.parse_args()
|
|
|
|
filename = Path(args.input)
|
|
output_file = Path(str(filename).replace("/raw/", "/res/processed/").replace(".h5",".PROCESSED.h5") )
|
|
output_file.parent.mkdir(parents=True, exist_ok=True, mode=0o775)
|
|
|
|
acq = get_acq_from_pth(args.input)
|
|
acq_meta_pth = Path(str(filename).replace("/data/ac", "/meta/ac")).parent
|
|
acq_info_pth = acq_meta_pth.joinpath(f"acq{acq}.json")
|
|
|
|
with open(acq_info_pth, "r") as f:
|
|
acq_parameters = json.load(f)
|
|
rbk_value = acq_parameters.get("scan_info", {}).get("scan_readbacks", 0)
|
|
#xlabel = acq_parameters.get("scan_info", {}).get("name", None)
|
|
#units = acq_parameters.get("scan_info", {}).get("units", None)
|
|
|
|
with h5py.File(args.input, "r") as f:
|
|
cropped = crop_roi(f['data']['JF06T32V07']['data'], roi)
|
|
intensity = cropped.sum(axis=1).sum(axis=1)
|
|
|
|
with h5py.File(output_file, 'w') as f:
|
|
gr1 = f.create_group("data")
|
|
gr1['cropped'] = cropped
|
|
gr1['intensity'] = intensity
|
|
|
|
gr2 = f.create_group("meta")
|
|
gr2["readback_value"] = np.atleast_1d(rbk_value)
|
|
#gr2["xlabel"] = xlabel
|
|
#gr2["units"] = units
|
|
|
|
#with h5py.File(output_file, 'w') as f:
|
|
# f['cropped'] = cropped
|
|
# f['intensity'] = intensity
|
|
|
|
|
|
|
|
|
|
|