-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_most_recent_file.py
102 lines (89 loc) · 3.21 KB
/
plot_most_recent_file.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from glob import glob
import os
import zeustools as zt
import numpy as np
import matplotlib.pyplot as plt
def get_recent_file():
path = "/data/cryo/current_data/"
files = glob(path + "*.run")
modtimes = [os.path.getmtime(file) for file in files]
most_recent_modtime = max(modtimes)
file = modtimes.index(most_recent_modtime)
return files[file].replace(".run","")
if __name__ == "__main__":
am = zt.ArrayMapper()
last_iplot = None
f=""
while True:
x = get_recent_file()
if x==f:
#print("sleeping")
plt.gcf().canvas.draw_idle()
plt.gcf().canvas.start_event_loop(5)
continue
try:
mce = zt.mce_data.SmallMCEFile(x)
except:
plt.gcf().canvas.draw_idle()
plt.gcf().canvas.start_event_loop(5)
continue
nframes = int(mce.runfile.data["FRAMEACQ"]["DATA_FRAMECOUNT"].strip())
if mce.Read(row_col=True).data.shape[2]<nframes-1:
plt.gcf().canvas.draw_idle()
plt.gcf().canvas.start_event_loop(5)
continue
else:
f = x
print(f"reading {f}")
if "bias_step" in f:
iplot = zt.bs_interactive_plotter_factory(mce,didi=True)
elif "iv" in f:
iplot = zt.iv_tools.InteractiveIVPlotter(f)
else:
mcedata = mce.Read(row_col=True)
cube = mcedata.data
chop = mcedata.chop
cube = np.ma.array(cube)
try:
chops = zt.numba_reduction.offset_data_reduction(chop,cube)
det_array = np.median(chops, axis=2)
print("chopped")
except Exception as e:
print(e)
det_array = np.std(cube, axis=2)
print(cube[am.phys_to_mce(30,0,400)])
cube[:,:,chop==1] = zt.nd_reject_outliers(cube[:,:,chop==1],MAD_chop=20)
cube[:,:,chop==0] = zt.nd_reject_outliers(cube[:,:,chop==0],MAD_chop=20)
print(cube[am.phys_to_mce(30,0,400)])
cube.fill_value=np.nan
iplot = zt.plotting.ZeusInteractivePlotter(det_array,cube)
if last_iplot is not None:
#print(np.ma.array(det_array))
# iplot.data = np.ma.array(det_array)
# iplot.cube = cube
# iplot.ts=np.arange(cube.shape[2])
last_iplot.ax2.clear()
last_iplot.ax.clear()
last_iplot.cb.remove()
# iplot.redraw_top_plot()
# iplot.bottom_plot()
#print(iplot.data)
iplot.fig = last_iplot.fig
iplot.ax = last_iplot.ax
iplot.ax2 = last_iplot.ax2
iplot.click_loc=last_iplot.click_loc
iplot.markersize = 45
iplot.linewidth=0.5
iplot.interactive_plot()
iplot.bottom_plot()
last_iplot = iplot
print(iplot.check_for_errors())
else:
last_iplot = iplot
last_iplot.debug=True
last_iplot.figsize = (6,6)
last_iplot.markersize = 45
iplot.linewidth=0.5
last_iplot.interactive_plot()
plt.ion()
last_iplot.fig.show()