some intermediate state
This commit is contained in:
90
panel.py
90
panel.py
@ -1,18 +1,46 @@
|
||||
from collections import deque
|
||||
from random import random
|
||||
import wx
|
||||
import numpy as np
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
from slic.gui.widgets import make_filled_hbox, make_filled_vbox
|
||||
from slic.gui.widgets import make_filled_hbox, make_filled_vbox, EXPANDING
|
||||
from slic.gui.widgets.plotting import PlotPanel
|
||||
|
||||
from bstrd import BS, bsstream
|
||||
|
||||
# config
|
||||
#STAGEpv = epics.PV('SLAAR11-LMOT-M452:MOTOR_1.VAL') # global globi
|
||||
chname_amplitude = "SARES11-SPEC125-M1.edge_amplitude"
|
||||
chname_jitter = "SARES11-SPEC125-M1.edge_position"
|
||||
chname_deriv = "SARES11-SPEC125-M1.edge_derivative"
|
||||
chname_events = "SAR-CVME-TIFALL4:EvtSet"
|
||||
chname_iZero = "SAROP11-PBPS110:INTENSITY"
|
||||
length = 500
|
||||
mm2fs = 6671.2 # lightspeed and delay stages
|
||||
threshold = 7
|
||||
|
||||
# create channel
|
||||
ch_amp = BS(chname_amplitude)
|
||||
ch_jitter = BS(chname_jitter)
|
||||
ch_events = BS(chname_events)
|
||||
ch_iZero = BS(chname_iZero)
|
||||
ch_deriv = BS(chname_deriv)
|
||||
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.beans = []
|
||||
self.spilled = []
|
||||
self.evts = np.empty((1000,256))
|
||||
self.jitter = np.empty(1000)
|
||||
self.amp = np.empty(1000)
|
||||
self.iZero = np.empty(1000)
|
||||
self.deriv = np.empty((1000,2048))
|
||||
|
||||
self.beans = deque(maxlen=10)
|
||||
self.spilled = deque(maxlen=10)
|
||||
|
||||
btn_minus = wx.Button(self, label="-")
|
||||
btn_plus = wx.Button(self, label="+")
|
||||
@ -31,7 +59,7 @@ class MainPanel(wx.Panel):
|
||||
plots = (plot_beans, plot_spilled)
|
||||
hb_plots = make_filled_hbox(plots)
|
||||
|
||||
widgets = (hb_btns, le_beans, le_spilled, hb_plots)
|
||||
widgets = (hb_btns, le_beans, le_spilled, EXPANDING, hb_plots)
|
||||
box = make_filled_vbox(widgets, border=10)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
@ -40,13 +68,13 @@ class MainPanel(wx.Panel):
|
||||
btn_check.Bind(wx.EVT_BUTTON, self.on_click_check)
|
||||
|
||||
|
||||
|
||||
def on_click_minus(self, _event):
|
||||
le = self.le_beans
|
||||
current = le.GetValue()
|
||||
le.SetValue(current - 1)
|
||||
self.update_plot()
|
||||
|
||||
|
||||
def on_click_plus(self, _event):
|
||||
if random() < 0.9:
|
||||
le = self.le_beans
|
||||
@ -56,12 +84,40 @@ class MainPanel(wx.Panel):
|
||||
le.SetValue(current + 1)
|
||||
self.update_plot()
|
||||
|
||||
|
||||
def on_click_check(self, _event):
|
||||
percent = self.get_percentage()
|
||||
msg = f"You spilled {percent:.2}% of the beans."
|
||||
self.le_beans.SetValue(0)
|
||||
self.le_spilled.SetValue(0)
|
||||
wx.MessageBox(msg, "Spillage Stats", wx.OK|wx.ICON_WARNING)
|
||||
|
||||
self.evts = np.empty((1000,256))
|
||||
self.jitter = np.empty(1000)
|
||||
self.amp = np.empty(1000)
|
||||
self.iZero = np.empty(1000)
|
||||
self.deriv = np.empty((1000,2048))
|
||||
|
||||
|
||||
def goodshots(events, *arrays):
|
||||
fel = events[:, 13]
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
pumped_shots = np.logical_and.reduce((fel, laser, np.logical_not(darkShot)))
|
||||
return [a[pumped_shots] for a in arrays]
|
||||
|
||||
|
||||
# percent = self.get_percentage()
|
||||
# msg = f"You spilled {percent:.2}% of the beans."
|
||||
# self.le_beans.SetValue(0)
|
||||
# self.le_spilled.SetValue(0)
|
||||
# wx.MessageBox(msg, "Spillage Stats", wx.OK|wx.ICON_WARNING)
|
||||
for i in range(1000):
|
||||
self.evts[i] = ch_events.get()
|
||||
self.jitter[i] = ch_jitter.get()
|
||||
self.amp[i] = ch_amp.get()
|
||||
self.iZero[i] = ch_iZero.get()
|
||||
self.deriv[i] = ch_deriv.get()
|
||||
next(bsstream)
|
||||
|
||||
self.deriv, self.amp, self.jitter, self.iZero = goodshots(self.evts, self.deriv, self.amp, self.jitter, self.iZero)
|
||||
self.update_plot()
|
||||
|
||||
|
||||
def get_percentage(self):
|
||||
b = self.le_beans.GetValue() or 0
|
||||
@ -82,10 +138,20 @@ class MainPanel(wx.Panel):
|
||||
def draw_plot(self):
|
||||
self.plot_beans.clear()
|
||||
self.plot_spilled.clear()
|
||||
self.plot_beans.plot(self.beans)
|
||||
self.plot_spilled.plot(self.spilled)
|
||||
self.plot_beans.plot(self.deriv[0], color='grey')
|
||||
self.plot_beans.plot(self.deriv[-1], color='grey')
|
||||
self.plot_beans.plot(self.deriv[10], color='grey')
|
||||
self.plot_beans.plot(self.deriv[-10], color='grey')
|
||||
self.plot_beans.plot(np.mean(self.deriv, axis=0), color='orangered')
|
||||
self.plot_spilled.plot(self.jitter)
|
||||
self.plot_beans.draw()
|
||||
self.plot_spilled.draw()
|
||||
|
||||
|
||||
def goodshots(events, *arrays):
|
||||
fel = events[:, 13]
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
pumped_shots = np.logical_and.reduce((fel, laser, np.logical_not(darkShot)))
|
||||
return [a[pumped_shots] for a in arrays]
|
||||
|
||||
|
Reference in New Issue
Block a user