-
Notifications
You must be signed in to change notification settings - Fork 0
/
spectrum_logger.py
75 lines (65 loc) · 1.99 KB
/
spectrum_logger.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
import numpy as np
import yaqc
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib.gridspec as gridspec
from matplotlib.widgets import Slider
import toml
import time
import pathlib
here = pathlib.Path(__file__).resolve().parent
plt.style.use("dark_background")
config = toml.load(here / "spectrum_logger.toml")
spec = yaqc.Client(config["yaq"]["spec_port"])
spec.measure(False)
while spec.busy():
time.sleep(0.1)
slice_args = [config["slice"].pop(k, None) for k in ["start", "stop", "step"]]
sl = slice(*slice_args)
wl = spec.get_mappings()["wavelengths"][sl]
wl = 1e7 / wl
fig = plt.figure("Tsunami")
gs = gridspec.GridSpec(2, 1, height_ratios=[10, 1])
ax = plt.subplot(gs[0])
hl, = plt.plot(wl, spec.get_measured()["intensities"][sl], lw=2)
ref_x, ref_y = np.genfromtxt(
config["reference"]["path"],
unpack=True,
skip_header=14,
skip_footer=1
)
ref_y *= config["reference"]["scalar"] / ref_y.max()
plt.plot(1e7/ref_x, ref_y, ls='--', linewidth=2)
ax.set_xlim(1e7/875, 1e7/725)
ax.grid()
plt.ylim(-100, 4096)
def update_line(y):
hl.set_ydata(y)
plt.draw()
def data_gen():
index = 0
start = time.time()
while True:
m_id = spec.get_measurement_id()
i = 0
if index < m_id:
measured = spec.get_measured()
index = measured["measurement_id"]
t_measure = time.time()
# print(f"get_measured: {t_measure-start}")
ax.set_title(f"{index}")
start = time.time()
spec.measure(False)
yield measured["intensities"][sl]
elif i > 150:
print("restarting")
spec.shutdown(True)
time.sleep(3)
else:
time.sleep(0.1)
ax = plt.subplot(gs[1])
slider = Slider(ax, "integration time", 3000, 1e6, valinit=spec.get_integration_time_micros())
slider.on_changed(spec.set_integration_time_micros)
# run animation
ani = animation.FuncAnimation(fig, update_line, data_gen, interval=100)
plt.show()