plot meas spectrum
This commit is contained in:
parent
c80e30d505
commit
f82d5c18a1
5
dmi.py
5
dmi.py
|
@ -20,7 +20,7 @@ def main():
|
||||||
induction.start()
|
induction.start()
|
||||||
try:
|
try:
|
||||||
def stabilizer_cb(spectrum, peak_freq, locked, tuning):
|
def stabilizer_cb(spectrum, peak_freq, locked, tuning):
|
||||||
gui.update_beat_spectrum(spectrum, peak_freq, locked)
|
gui.update_ref(spectrum, peak_freq, locked)
|
||||||
induction.set(tuning)
|
induction.set(tuning)
|
||||||
|
|
||||||
stabilizer = Stabilizer(freq_sample, block_size, 1088.1e6 - freq_base, stabilizer_cb)
|
stabilizer = Stabilizer(freq_sample, block_size, 1088.1e6 - freq_base, stabilizer_cb)
|
||||||
|
@ -46,6 +46,9 @@ def main():
|
||||||
stabilizer.input(samples_ref)
|
stabilizer.input(samples_ref)
|
||||||
stabilizer_throttle = 0
|
stabilizer_throttle = 0
|
||||||
|
|
||||||
|
# Update the MEAS GUI at the same time so it's synchronized
|
||||||
|
gui.update_meas(samples_meas)
|
||||||
|
|
||||||
#position, leakage = position_tracker.input(samples_ref, samples_meas)
|
#position, leakage = position_tracker.input(samples_ref, samples_meas)
|
||||||
#print(np.sum(position)/len(position), leakage)
|
#print(np.sum(position)/len(position), leakage)
|
||||||
finally:
|
finally:
|
||||||
|
|
8
gui.py
8
gui.py
|
@ -54,8 +54,12 @@ class GUI:
|
||||||
os.path.join(os.path.dirname(os.path.abspath(__file__)), "gui_impl.py"),
|
os.path.join(os.path.dirname(os.path.abspath(__file__)), "gui_impl.py"),
|
||||||
str(freq_sample), str(freq_base), str(block_size)])
|
str(freq_sample), str(freq_base), str(block_size)])
|
||||||
|
|
||||||
def update_beat_spectrum(self, block, peak_freq, locked):
|
def update_ref(self, block, peak_freq, locked):
|
||||||
obj = {"action": "update_beat_spectrum", "block": block, "peak_freq": peak_freq, "locked": locked}
|
obj = {"action": "update_ref", "block": block, "peak_freq": peak_freq, "locked": locked}
|
||||||
|
self.impl.write_pyon(obj)
|
||||||
|
|
||||||
|
def update_meas(self, block):
|
||||||
|
obj = {"action": "update_meas", "block": block}
|
||||||
self.impl.write_pyon(obj)
|
self.impl.write_pyon(obj)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|
38
gui_impl.py
38
gui_impl.py
|
@ -4,6 +4,7 @@ import sys
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from scipy.signal import blackmanharris
|
||||||
from quamash import QEventLoop, QtWidgets, QtCore
|
from quamash import QEventLoop, QtWidgets, QtCore
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from sipyco.pipe_ipc import AsyncioChildComm
|
from sipyco.pipe_ipc import AsyncioChildComm
|
||||||
|
@ -16,21 +17,13 @@ class SpectrogramItem(pg.ImageItem):
|
||||||
|
|
||||||
depth = 100
|
depth = 100
|
||||||
self.img_array = np.zeros((depth, block_size))
|
self.img_array = np.zeros((depth, block_size))
|
||||||
|
self.setImage(self.img_array, autoLevels=True, autoDownsample=True)
|
||||||
self.setImage(self.img_array, autoLevels=True)
|
|
||||||
|
|
||||||
pos = np.array([0., 1., 0.5, 0.25, 0.75])
|
|
||||||
color = np.array([[0,255,255,255], [255,255,0,255], [0,0,0,255], (0, 0, 255, 255), (255, 0, 0, 255)], dtype=np.ubyte)
|
|
||||||
cmap = pg.ColorMap(pos, color)
|
|
||||||
lut = cmap.getLookupTable(0.0, 1.0, 256)
|
|
||||||
self.setLookupTable(lut)
|
|
||||||
|
|
||||||
self.setRect(QtCore.QRectF(0.0, (freq_base-freq_sample/2)/1e6, float(depth), freq_sample/1e6))
|
self.setRect(QtCore.QRectF(0.0, (freq_base-freq_sample/2)/1e6, float(depth), freq_sample/1e6))
|
||||||
|
|
||||||
def add_block(self, block):
|
def add_block(self, block):
|
||||||
self.img_array = np.roll(self.img_array, -1, 0)
|
self.img_array = np.roll(self.img_array, -1, 0)
|
||||||
self.img_array[-1:] = np.fft.fftshift(block)
|
self.img_array[-1:] = np.fft.fftshift(block)
|
||||||
self.setImage(self.img_array, autoLevels=True)
|
self.setImage(self.img_array, autoLevels=True, autoDownsample=True)
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(pg.GraphicsLayoutWidget):
|
class MainWindow(pg.GraphicsLayoutWidget):
|
||||||
|
@ -40,18 +33,25 @@ class MainWindow(pg.GraphicsLayoutWidget):
|
||||||
|
|
||||||
self.freq_sample = freq_sample
|
self.freq_sample = freq_sample
|
||||||
self.freq_base = freq_base
|
self.freq_base = freq_base
|
||||||
|
self.block_size = block_size
|
||||||
|
|
||||||
self.text_ref = pg.LabelItem(size="24pt")
|
self.text_ref = pg.LabelItem(size="24pt")
|
||||||
self.addItem(self.text_ref, row=0, col=0)
|
self.addItem(self.text_ref, row=0, col=0)
|
||||||
self.text_locked = pg.LabelItem(size="24pt")
|
self.text_locked = pg.LabelItem(size="24pt")
|
||||||
self.addItem(self.text_locked, row=0, col=1)
|
self.addItem(self.text_locked, row=0, col=1)
|
||||||
self.update_params(None, False)
|
self.update_ref(None, None, False)
|
||||||
|
|
||||||
p1 = self.addPlot(row=1, col=0, colspan=2)
|
p1 = self.addPlot(row=1, col=0, colspan=2)
|
||||||
self.beat_spectrum = SpectrogramItem(freq_sample, freq_base, block_size)
|
self.ref_spectrum = SpectrogramItem(freq_sample, freq_base, block_size)
|
||||||
p1.addItem(self.beat_spectrum)
|
p1.addItem(self.ref_spectrum)
|
||||||
|
|
||||||
def update_params(self, peak_freq, locked):
|
p2 = self.addPlot(row=2, col=0, colspan=2)
|
||||||
|
self.meas_spectrum = SpectrogramItem(freq_sample, freq_base, block_size)
|
||||||
|
p2.addItem(self.meas_spectrum)
|
||||||
|
|
||||||
|
def update_ref(self, block, peak_freq, locked):
|
||||||
|
if block is not None:
|
||||||
|
self.ref_spectrum.add_block(block)
|
||||||
if peak_freq is None:
|
if peak_freq is None:
|
||||||
self.text_ref.setText("REF: NO SIGNAL")
|
self.text_ref.setText("REF: NO SIGNAL")
|
||||||
else:
|
else:
|
||||||
|
@ -61,6 +61,10 @@ class MainWindow(pg.GraphicsLayoutWidget):
|
||||||
else:
|
else:
|
||||||
self.text_locked.setText("REF LASER UNLOCKED", color="FF0000")
|
self.text_locked.setText("REF LASER UNLOCKED", color="FF0000")
|
||||||
|
|
||||||
|
def update_meas(self, block):
|
||||||
|
assert len(block) == self.block_size
|
||||||
|
spectrum = np.abs(np.fft.fft(block*blackmanharris(self.block_size)))
|
||||||
|
self.meas_spectrum.add_block(spectrum)
|
||||||
|
|
||||||
|
|
||||||
class IPCClient(AsyncioChildComm):
|
class IPCClient(AsyncioChildComm):
|
||||||
|
@ -76,12 +80,12 @@ class IPCClient(AsyncioChildComm):
|
||||||
obj = await self.read_pyon()
|
obj = await self.read_pyon()
|
||||||
try:
|
try:
|
||||||
action = obj["action"]
|
action = obj["action"]
|
||||||
if action == "update_beat_spectrum":
|
del obj["action"]
|
||||||
main_window.beat_spectrum.add_block(obj["block"])
|
|
||||||
main_window.update_params(obj["peak_freq"], obj["locked"])
|
|
||||||
if action == "terminate":
|
if action == "terminate":
|
||||||
self.close_cb()
|
self.close_cb()
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
getattr(main_window, action)(**obj)
|
||||||
except:
|
except:
|
||||||
logging.error("error processing parent message",
|
logging.error("error processing parent message",
|
||||||
exc_info=True)
|
exc_info=True)
|
||||||
|
|
Loading…
Reference in New Issue