ROI coordinates fixed

This commit is contained in:
2022-10-24 17:31:41 +02:00
parent c1c2472f7d
commit 8fbffc64d7

View File

@@ -68,7 +68,7 @@ def print_run_info(
break
def process_run(run_number, rois,detector='JF16T03V01', roi_img=True, calculate =None, only_shots=slice(None), n_jobs=cpu_count()):
def process_run(run_number, rois,detector='JF16T03V01', calculate =None, only_shots=slice(None), n_jobs=cpu_count()):
"""Process rois for a given detector. Save the results small data in the res/small_data/run...
By default only sum of rois is calculated, [mean,std,img] can be added to the "calculate" optional parameter.
"""
@@ -96,31 +96,29 @@ def process_run(run_number, rois,detector='JF16T03V01', roi_img=True, calculate
step = scan[i]
with step as data:
with SFProcFile(f"{path_with_run_folder}/acq{str(i+1).zfill(4)}.smalldata.h5", mode="w") as sd:
subset = data[detector]
# Calculate everything related to JF_rois
for roi in rois:
bottom, top, left, right = roi.bottom, roi.top, roi.left, roi.right
roi_name = roi.name
# Pulse ids for saving the new channels
det_pids = data[detector].pids
sd[roi.name] = (det_pids[only_shots], data[detector][only_shots, left:right, bottom:top].sum(axis=(1, 2)))
sd[roi.name] = det_pids[only_shots], data[detector][only_shots, bottom:top,left:right].sum(axis=(1, 2))
if calculate:
if 'mean' in calculate:
sd[roi.name+"_mean"] = (det_pids[only_shots], data[detector][only_shots, left:right, bottom:top].mean(axis=(1, 2)))
sd[roi.name+"_mean"] = (det_pids[only_shots], data[detector][only_shots, bottom:top,left:right].mean(axis=(1, 2)))
if 'std' in calculate:
sd[roi.name+"_std"] = (det_pids[only_shots], data[detector][only_shots, left:right, bottom:top].std(axis=(1, 2)))
sd[roi.name+"_std"] = (det_pids[only_shots], data[detector][only_shots, bottom:top,left:right].std(axis=(1, 2)))
if 'img' in calculate:
sd[f'{roi.name}_img'] = (det_pids[only_shots], data[detector][only_shots, left:right, bottom:top].data)
sd[f'{roi.name}_img'] = (det_pids[only_shots], data[detector][only_shots, bottom:top,left:right].data)
# Currently meta files can't be read by SFData, this will be modified by Sven and then we can use it. For now saving in roi_info
#sd.meta[roi.name+"_info"] = f"roi {roi.name}: {left},{right}; {bottom},{top} (left, right, bottom, top)"
# These channels have only one dataset per step of the scan, so we take the first pulseID
sd[roi.name + "_info"] =([det_pids[0]], [f"roi {roi.name}: {left},{right}; {bottom},{top} (left, right, bottom, top)"])
sd[roi.name + "_mean_img"] = ([det_pids[0]], [data[detector][:, left:right, bottom:top].mean(axis=(0))] )
sd[roi.name + "_mean_img"] = ([det_pids[0]], [data[detector][:, bottom:top,left:right].mean(axis=(0))] )
Parallel(n_jobs=n_jobs,verbose=10)(delayed(process_step)(i) for i in range(len(scan)))