-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdata_validation.py
More file actions
38 lines (31 loc) · 1.17 KB
/
data_validation.py
File metadata and controls
38 lines (31 loc) · 1.17 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
37
38
from prefect import task, flow, get_run_logger
import time as ttime
from tiled.client import from_uri
@task(retries=2, retry_delay_seconds=10)
def get_run(uid, api_key=None):
tiled_client = from_uri("https://tiled.nsls2.bnl.gov", api_key=api_key)
run = tiled_client["smi/raw"][uid]
return run
@task
def read_stream(run, stream):
stream_data = run[stream].read()
return stream_data
# this is a task to enable being run by a ConcurrentTaskRunner
@task
def read_all_streams(uid, api_key=None):
logger = get_run_logger()
start_time = ttime.monotonic()
run = get_run(uid, api_key=api_key)
logger.info(f"Validating uid {uid}")
for stream in run:
logger.info(f"{stream}:")
stream_start_time = ttime.monotonic()
stream_data = read_stream(run, stream)
stream_elapsed_time = ttime.monotonic() - stream_start_time
logger.info(f"{stream} elapsed_time = {stream_elapsed_time}")
logger.info(f"{stream} nbytes = {stream_data.nbytes:_}")
elapsed_time = ttime.monotonic() - start_time
logger.info(f"{elapsed_time = }")
@flow
def data_validation(uid, api_key=None):
read_all_streams(uid, api_key=api_key)