-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdata_validation.py
More file actions
36 lines (28 loc) · 1.21 KB
/
data_validation.py
File metadata and controls
36 lines (28 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import time
from prefect import flow, get_run_logger, task
from prefect.blocks.system import Secret
from tiled.client import from_profile
from multiprocessing.pool import ThreadPool
import dask
num_concurrent_workers = 4
dask.config.set(pool=ThreadPool(num_concurrent_workers))
@task(retries=2, retry_delay_seconds=10)
def read_all_streams(uid, beamline_acronym="fxi"):
logger = get_run_logger()
api_key = Secret.load(f"tiled-{beamline_acronym}-api-key").get()
tiled_client = from_profile("nsls2", api_key=api_key)[beamline_acronym]
run = tiled_client["raw"][uid]
logger.info(f"Validating uid {run.start['uid']}")
start_time = time.monotonic()
for stream in run:
logger.info(f"{stream}...")
stream_start_time = time.monotonic()
stream_data = run[stream].read()
stream_elapsed_time = time.monotonic() - stream_start_time
logger.info(f"{stream} elapsed_time = {stream_elapsed_time}")
logger.info(f"{stream} nbytes = {stream_data.nbytes: _}")
elapsed_time = time.monotonic() - start_time
logger.info(f"{elapsed_time = }") # noqa: E202,E251
@flow
def general_data_validation(uid, beamline_acronym="fxi"):
read_all_streams(uid, beamline_acronym)