added JF frame checker, small cleanup

This commit is contained in:
2024-04-23 18:05:52 +02:00
parent 2efbf3a64a
commit 1d33e86f76

View File

@@ -3,11 +3,14 @@ import os
import json
import re
from pathlib import Path
from collections import defaultdict
import requests
import subprocess
from collections import defaultdict
import time
import datetime
from json import JSONDecodeError
import requests
import logging
@@ -311,6 +314,25 @@ def is_processed_JF_file(filepath, detector="JF16T03V01"):
raise ValueError(f"{filepath} does not seem to be an Jungfrau file from the detector {detector}.")
return "meta" in f["data"][detector].keys()
def check_JF_frames(JF_file_path):
""" Simple check if all frames in a given Jungfrau .h5 file are OK or if
there are missing or invalid frames.
Raises an error if invalid frames are found, else returns True.
"""
pattern = r"\.(JF[0-9].*)\.h5"
m = re.search(pattern, str(fpath))
if m is None:
raise LookupError("Cannot match Jungfrau detector name from file path.")
JF_name = m.groups()[0]
with SFDataFiles(JF_file_path) as data:
JF = data[JF_name]
if JF.nvalid != JF.ntotal:
raise ValueError("Jungfrau frames invalid, this should not happen.")
else:
return True
def get_step_time(step: SFDataFiles):
"""Returns the start and end time as a unix timestamp (in seconds)
@@ -326,26 +348,26 @@ def get_step_time(step: SFDataFiles):
) / np.timedelta64(1, "s")
# TODO: Clean this up
import time
import subprocess
from pathlib import Path
def wait_for_run(run_number, total_length=15):
def wait_for_run(run_number, total_num_steps, snd_file_path="/tmp/CantinaBand3.wav"):
""" Busy wait loop until run has completed all steps. Plays sound
when all files are written to disk.
"""
base_path = cr.utils.heuristic_extract_base_path()
data_path = Path(base_path) / f"run{run_number:0>4}/data"
while True:
pvfiles = data_path.glob("acq*.PVDATA.h5")
length = len(list(pvfiles))
if length == total_length:
if length == total_num_steps:
break
else:
print(f"Waiting for run {run_number} to complete, only {length} steps so far ...")
time.sleep(5)
subprocess.run(["paplay", "/tmp/CantinaBand3.wav"])
subprocess.run(["paplay", snd_file_path])
class ROI: