-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathload_scan.py
64 lines (53 loc) · 1.81 KB
/
load_scan.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from datetime import datetime
import numpy as np
import pandas as pd
from databroker.assets.handlers import AreaDetectorHDF5TimestampHandler
EPICS_EPOCH = datetime(1990, 1, 1, 0, 0)
def convert_AD_timestamps(ts):
return pd.to_datetime(ts, unit="s", origin=EPICS_EPOCH, utc=True).dt.tz_convert(
"US/Eastern"
)
def get_tomo_images(input_dict):
pos = input_dict['pos']
imgs = input_dict['imgs']
chunked_timestamps = input_dict['chunked_timestamps']
mot_pos = input_dict['mot_pos']
raw_timestamps = []
for chunk in chunked_timestamps:
raw_timestamps.extend(chunk.tolist())
timestamps = convert_AD_timestamps(pd.Series(raw_timestamps))
pos["time"] = pos["time"].dt.tz_localize("US/Eastern")
img_day, img_hour = (
timestamps.dt.day,
timestamps.dt.hour,
)
img_min, img_sec, img_msec = (
timestamps.dt.minute,
timestamps.dt.second,
timestamps.dt.microsecond,
)
img_time = (
img_day * 86400 + img_hour * 3600 + img_min * 60 + img_sec + img_msec * 1e-6
)
img_time = np.array(img_time)
mot_day, mot_hour = (
pos["time"].dt.day,
pos["time"].dt.hour,
)
mot_min, mot_sec, mot_msec = (
pos["time"].dt.minute,
pos["time"].dt.second,
pos["time"].dt.microsecond,
)
mot_time = (
mot_day * 86400 + mot_hour * 3600 + mot_min * 60 + mot_sec + mot_msec * 1e-6
)
mot_time = np.array(mot_time)
offset = np.min([np.min(img_time), np.min(mot_time)])
img_time -= offset
mot_time -= offset
mot_pos_interp = np.interp(img_time, mot_time, mot_pos)
pos2 = mot_pos_interp.argmax() + 1
img_angle = mot_pos_interp[: pos2 - chunk_size] # rotation angles
img_tomo = imgs[: pos2 - chunk_size] # tomo images
return img_tomo, img_angle