plot meas spectrum

This commit is contained in:
Sebastien Bourdeauducq 2020-08-11 16:09:24 +08:00
parent c80e30d505
commit f82d5c18a1
3 changed files with 31 additions and 20 deletions

5
dmi.py
View File

@ -20,7 +20,7 @@ def main():
induction.start()
try:
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)
stabilizer = Stabilizer(freq_sample, block_size, 1088.1e6 - freq_base, stabilizer_cb)
@ -46,6 +46,9 @@ def main():
stabilizer.input(samples_ref)
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)
#print(np.sum(position)/len(position), leakage)
finally:

8
gui.py
View File

@ -54,8 +54,12 @@ class GUI:
os.path.join(os.path.dirname(os.path.abspath(__file__)), "gui_impl.py"),
str(freq_sample), str(freq_base), str(block_size)])
def update_beat_spectrum(self, block, peak_freq, locked):
obj = {"action": "update_beat_spectrum", "block": block, "peak_freq": peak_freq, "locked": locked}
def update_ref(self, block, peak_freq, 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)
def close(self):

View File

@ -4,6 +4,7 @@ import sys
import logging
import numpy as np
from scipy.signal import blackmanharris
from quamash import QEventLoop, QtWidgets, QtCore
import pyqtgraph as pg
from sipyco.pipe_ipc import AsyncioChildComm
@ -16,21 +17,13 @@ class SpectrogramItem(pg.ImageItem):
depth = 100
self.img_array = np.zeros((depth, block_size))
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.setImage(self.img_array, autoLevels=True, autoDownsample=True)
self.setRect(QtCore.QRectF(0.0, (freq_base-freq_sample/2)/1e6, float(depth), freq_sample/1e6))
def add_block(self, block):
self.img_array = np.roll(self.img_array, -1, 0)
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):
@ -40,18 +33,25 @@ class MainWindow(pg.GraphicsLayoutWidget):
self.freq_sample = freq_sample
self.freq_base = freq_base
self.block_size = block_size
self.text_ref = pg.LabelItem(size="24pt")
self.addItem(self.text_ref, row=0, col=0)
self.text_locked = pg.LabelItem(size="24pt")
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)
self.beat_spectrum = SpectrogramItem(freq_sample, freq_base, block_size)
p1.addItem(self.beat_spectrum)
self.ref_spectrum = SpectrogramItem(freq_sample, freq_base, block_size)
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:
self.text_ref.setText("REF: NO SIGNAL")
else:
@ -61,6 +61,10 @@ class MainWindow(pg.GraphicsLayoutWidget):
else:
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):
@ -76,12 +80,12 @@ class IPCClient(AsyncioChildComm):
obj = await self.read_pyon()
try:
action = obj["action"]
if action == "update_beat_spectrum":
main_window.beat_spectrum.add_block(obj["block"])
main_window.update_params(obj["peak_freq"], obj["locked"])
del obj["action"]
if action == "terminate":
self.close_cb()
return
else:
getattr(main_window, action)(**obj)
except:
logging.error("error processing parent message",
exc_info=True)