forked from SwissFEL/c365
added all before moving to /sf/alvra/ somewhere
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_ppYAG import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="YAG pp"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_c365 import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="Coffee 365"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_correlate import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="correlations"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_diff_2TT import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="diff 2TT"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
from slic.gui.persist import Persistence
|
||||
from bstrd import bsstream
|
||||
from panel_fftpbps import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="PBPS FFT"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_fluo import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="Fluo"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
+1802
File diff suppressed because it is too large
Load Diff
+1802
File diff suppressed because it is too large
Load Diff
+1802
File diff suppressed because it is too large
Load Diff
+1802
File diff suppressed because it is too large
Load Diff
+1802
File diff suppressed because it is too large
Load Diff
+1603
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_fluo import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="Fluo"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
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
|
||||
nshots = 10
|
||||
qlength = 100
|
||||
histlength = 50
|
||||
|
||||
# channels
|
||||
chname_pbpsint = "SAROP11-PBPS122:INTENSITY"
|
||||
chname_pbpsx = "SAROP11-PBPS122:XPOS"
|
||||
chname_pbpsy = "SAROP11-PBPS122:YPOS"
|
||||
chname_events = "SAR-CVME-TIFALL4:EvtSet"
|
||||
|
||||
# create channels
|
||||
ch_int = BS(chname_pbpsint)
|
||||
ch_x = BS(chname_pbpsx)
|
||||
ch_y = BS(chname_pbpsy)
|
||||
ch_events = BS(chname_events)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.int = np.empty(nshots)
|
||||
self.x = np.empty(nshots)
|
||||
self.y = np.empty(nshots)
|
||||
|
||||
self.ints = deque(maxlen=qlength)
|
||||
self.intstds = deque(maxlen=qlength)
|
||||
self.inthist = deque(maxlen=histlength)
|
||||
self.xs = deque(maxlen=qlength)
|
||||
self.xstds = deque(maxlen=qlength)
|
||||
self.xhist = deque(maxlen=histlength)
|
||||
self.ys = deque(maxlen=qlength)
|
||||
self.ystds = deque(maxlen=qlength)
|
||||
self.yhist = deque(maxlen=histlength)
|
||||
|
||||
self.plot_ints = plot_ints = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histI = plot_histI = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_posXs = plot_posXs = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histX = plot_histX = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_posYs = plot_posYs = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histY = plot_histY = PlotPanel(self, figsize=(2,3))
|
||||
|
||||
plots1 = (plot_ints, plot_histI)
|
||||
plots2 = (plot_posXs, plot_histX)
|
||||
plots3 = (plot_posYs, plot_histY)
|
||||
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
hb_plot3 = make_filled_hbox(plots3)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
hb_btns = make_filled_hbox(btns)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_plot3, hb_btns)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.int = np.empty(nshots)
|
||||
self.x = np.empty(nshots)
|
||||
self.y = np.empty(nshots)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_int.get()
|
||||
self.int[i] = tempb
|
||||
tempc = ch_x.get()
|
||||
self.x[i] = tempc
|
||||
tempd = ch_y.get()
|
||||
self.y[i] = tempd
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.ints.append(np.mean(self.int))
|
||||
self.intstds.append(np.std(self.int))
|
||||
self.xs.append(np.mean(self.x))
|
||||
self.xstds.append(np.std(self.x))
|
||||
self.ys.append(np.mean(self.y))
|
||||
self.ystds.append(np.std(self.y))
|
||||
|
||||
self.inthist.append(self.int)
|
||||
self.xhist.append(self.x)
|
||||
self.yhist.append(self.y)
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
|
||||
def draw_plot(self):
|
||||
self.plot_ints.clear()
|
||||
self.plot_histI.clear()
|
||||
self.plot_posXs.clear()
|
||||
self.plot_histX.clear()
|
||||
self.plot_posYs.clear()
|
||||
self.plot_histY.clear()
|
||||
|
||||
self.plot_ints.set_xlabel('time ago, a.u.')
|
||||
self.plot_ints.set_ylabel('intensity, a.u.')
|
||||
self.plot_histI.set_xlabel('intensity, a.u.')
|
||||
self.plot_histI.set_xlim(-0.1, 3)
|
||||
self.plot_posXs.set_xlabel('time ago, a.u.')
|
||||
self.plot_posXs.set_ylabel('position X, mm')
|
||||
self.plot_histX.set_xlabel('position X, mm')
|
||||
self.plot_histX.set_xlim(-0.5, 0.5)
|
||||
self.plot_posYs.set_xlabel('time ago, a.u.')
|
||||
self.plot_posYs.set_ylabel('position Y, mm')
|
||||
self.plot_histY.set_xlabel('position Y, mm')
|
||||
self.plot_histY.set_xlim(-0.5, 0.5)
|
||||
|
||||
self.plot_ints.fill_between(np.arange(0, len(self.ints)), np.asarray(self.intstds)+np.asarray(self.ints), -np.asarray(self.intstds)+np.asarray(self.ints), color='gold')
|
||||
self.plot_ints.plot(np.arange(0, len(self.ints)), self.ints, '-', color='orangered')
|
||||
self.plot_ints.axhline(y=1, color='k', linestyle="--")
|
||||
|
||||
self.plot_posXs.fill_between(np.arange(0, len(self.xs)), np.asarray(self.xstds)+np.asarray(self.xs), -np.asarray(self.xstds)+np.asarray(self.xs), color='lightskyblue')
|
||||
self.plot_posXs.plot(np.arange(0, len(self.xs)), self.xs, '-', color='dodgerblue')
|
||||
self.plot_posXs.axhline(y=0, color='k', linestyle="--")
|
||||
|
||||
self.plot_posYs.fill_between(np.arange(0, len(self.ys)), np.asarray(self.ystds)+np.asarray(self.ys), -np.asarray(self.ystds)+np.asarray(self.ys), color='lightgreen')
|
||||
self.plot_posYs.plot(np.arange(0, len(self.ys)), self.ys, '-', color='green')
|
||||
self.plot_posYs.axhline(y=0, color='k', linestyle="--")
|
||||
|
||||
#if (len(self.int) > 0):
|
||||
#self.plot_histI.hist(self.int, facecolor='orangered')#, edgecolor='black')
|
||||
self.plot_histI.hist(np.ravel(self.inthist), facecolor='orangered', edgecolor='black')
|
||||
self.plot_histI.axvline(x=np.mean(self.inthist), color='k', linestyle="--")
|
||||
self.plot_histI.set_title('Intensity: {:.4f} a.u.'.format(np.nanmean(self.inthist)))
|
||||
self.plot_histX.hist(np.ravel(self.xhist), facecolor='dodgerblue', edgecolor='black')
|
||||
self.plot_histX.set_title('Position X: {:.4f} mm'.format(np.nanmean(self.xhist)))
|
||||
self.plot_histX.axvline(x=np.mean(self.xhist), color='k', linestyle="--")
|
||||
self.plot_histY.hist(np.ravel(self.yhist), facecolor='green', edgecolor='black')
|
||||
self.plot_histY.set_title('Position Y: {:.4f} mm'.format(np.nanmean(self.yhist)))
|
||||
self.plot_histY.axvline(x=np.mean(self.yhist), color='k', linestyle="--")
|
||||
|
||||
self.plot_ints.draw()
|
||||
self.plot_posXs.draw()
|
||||
self.plot_posYs.draw()
|
||||
|
||||
self.plot_histI.draw()
|
||||
self.plot_histX.draw()
|
||||
self.plot_histY.draw()
|
||||
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
|
||||
self.ints.clear()
|
||||
self.intstds.clear()
|
||||
self.xs.clear()
|
||||
self.xstds.clear()
|
||||
self.ys.clear()
|
||||
self.ystds.clear()
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
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
|
||||
nshots = 500
|
||||
mm2fs = 6671.2 # light speed and delay stages
|
||||
ttThreshold = 5
|
||||
iZeroThreshold = 0.15
|
||||
|
||||
# spectrometer axis in time
|
||||
timeAx = -2.31*(np.arange(0, 2048)-1024)
|
||||
|
||||
# channels
|
||||
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-PBPS122:INTENSITY"
|
||||
|
||||
# create channels
|
||||
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)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
def goodshots(events, iZero, amps, *arrays):
|
||||
#def goodshots(events, amps, *arrays):
|
||||
fel = events[:, 13]
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
pulsePicking = events[:,200]
|
||||
iZero = iZero
|
||||
amplitudes = amps
|
||||
# pumped_shots = np.logical_and.reduce((fel, laser, np.logical_not(darkShot), amps > ttThreshold))
|
||||
pumped_shots = np.logical_and.reduce((fel, laser, np.logical_not(darkShot), iZero > iZeroThreshold, amps > ttThreshold))
|
||||
# pumped_shots = np.logical_and.reduce((fel, laser, np.logical_not(darkShot)))
|
||||
return [a[pumped_shots] for a in arrays]
|
||||
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.jitter = np.empty(nshots)
|
||||
self.amp = np.empty(nshots)
|
||||
self.iZero = np.empty(nshots)
|
||||
self.deriv = np.empty((nshots,2048))
|
||||
self.edge = np.empty((nshots,2048))
|
||||
|
||||
self.stagePos = deque(maxlen=1000)
|
||||
self.jitters = deque(maxlen=1000)
|
||||
self.jstds = deque(maxlen=1000)
|
||||
self.amps = deque(maxlen=1000)
|
||||
self.astds = deque(maxlen=1000)
|
||||
|
||||
self.plot_jitters = plot_jitters = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_amps = plot_amps = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_edges = plot_edges = PlotPanel(self, figsize=(6,5))
|
||||
|
||||
plots1 = (plot_edges,)
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
|
||||
plots2 = (plot_jitters, plot_amps)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
# hb_btns = make_filled_hbox(btns)
|
||||
|
||||
self.plot_stage = plot_stage = PlotPanel(self, figsize=(6,2))
|
||||
self.plot_timeseries_jitters = plot_timeseries_jitters = PlotPanel(self, figsize=(6,2))
|
||||
self.plot_timeseries_amps = plot_timeseries_amps = PlotPanel(self, figsize=(6,2))
|
||||
plots3 = (plot_timeseries_jitters,)
|
||||
plots4 = (plot_timeseries_amps,)
|
||||
plots5 = (plot_stage,)
|
||||
hb_plot3 = make_filled_hbox(plots3)
|
||||
hb_plot4 = make_filled_hbox(plots4)
|
||||
hb_plot5 = make_filled_hbox(plots5)
|
||||
|
||||
self.chkbx_feedback = chkbx_feedback = wx.CheckBox(self, label="feedback")
|
||||
chkbxs = (btn_clearQ, chkbx_feedback)
|
||||
hb_chkbx = make_filled_hbox(chkbxs)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_plot3, hb_plot4, hb_plot5, hb_chkbx)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.jitter = np.empty(nshots)
|
||||
self.amp = np.empty(nshots)
|
||||
self.iZero = np.empty(nshots)
|
||||
self.deriv = np.empty((nshots,2048))
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_jitter.get()
|
||||
self.jitter[i] = tempb
|
||||
tempc = ch_amp.get()
|
||||
self.amp[i] = tempc
|
||||
tempd = ch_iZero.get()
|
||||
self.iZero[i] = tempd
|
||||
tempe = ch_deriv.get()
|
||||
self.deriv[i] = tempe
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.deriv, self.amp, self.jitter = goodshots(self.evts, self.iZero, self.amp, self.deriv, self.amp, self.jitter)
|
||||
#self.deriv, self.amp, self.jitter = goodshots(self.evts, self.amp, self.deriv, self.amp, self.jitter)
|
||||
|
||||
if (len(np.asarray(self.jitter)) > 1):
|
||||
self.jitters.append(np.mean(self.jitter))
|
||||
self.jstds.append(np.std(self.jitter))
|
||||
self.amps.append(np.mean(self.amp))
|
||||
self.astds.append(np.std(self.amp))
|
||||
|
||||
if (self.chkbx_feedback.IsChecked()) & (np.abs(np.mean(self.jitter)) > 50) & (np.abs(np.mean(self.jitter)) < 750):
|
||||
moveTo = STAGEpv.get()*mm2fs - np.mean(self.jitter)
|
||||
STAGEpv.put(moveTo/mm2fs)
|
||||
|
||||
self.stagePos.append(STAGEpv.get())
|
||||
|
||||
else:
|
||||
print("{} Where are my X-rays?".format(self.time))
|
||||
self.jitters.append(np.nan)
|
||||
self.jstds.append(np.nan)
|
||||
self.amps.append(np.nan)
|
||||
self.astds.append(np.nan)
|
||||
self.stagePos.append(np.nan)
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
|
||||
def draw_plot(self):
|
||||
self.plot_jitters.clear()
|
||||
self.plot_amps.clear()
|
||||
self.plot_edges.clear()
|
||||
self.plot_timeseries_jitters.clear()
|
||||
self.plot_timeseries_amps.clear()
|
||||
self.plot_stage.clear()
|
||||
|
||||
self.plot_edges.set_xlabel('relative arrival time, fs')
|
||||
self.plot_edges.set_xlim(-10000,10000)
|
||||
#self.plot_edges.set_ylim(-5, )
|
||||
self.plot_edges.set_ylabel('transmission change, %')
|
||||
|
||||
self.plot_timeseries_jitters.set_xlabel('time ago, a.u.')
|
||||
self.plot_timeseries_jitters.set_ylabel('arrival time, fs')
|
||||
|
||||
self.plot_timeseries_amps.set_xlabel('time ago, a.u.')
|
||||
self.plot_timeseries_amps.set_ylabel('edge amplitude, %')
|
||||
|
||||
self.plot_stage.set_xlabel('time ago, a.u.')
|
||||
self.plot_stage.set_ylabel('m452 position, mm')
|
||||
|
||||
self.plot_edges.set_xlabel('relative arrival time, fs')
|
||||
self.plot_edges.set_xlim(-1500,1500)
|
||||
self.plot_edges.set_ylabel('transmission change, %')
|
||||
|
||||
self.plot_jitters.set_xlabel('relative arrival time, fs')
|
||||
self.plot_jitters.set_ylabel('counts')
|
||||
|
||||
self.plot_amps.set_xlabel('edge amplitudes, %')
|
||||
self.plot_amps.set_ylabel('counts')
|
||||
|
||||
if (len(self.deriv) > 0):
|
||||
self.plot_edges.plot(timeAx, self.deriv[random.randrange(0, len(self.deriv))], color='grey')
|
||||
self.plot_edges.plot(timeAx, self.deriv[random.randrange(0, len(self.deriv))], color='grey')
|
||||
self.plot_edges.plot(timeAx, self.deriv[random.randrange(0, len(self.deriv))], color='grey')
|
||||
self.plot_edges.plot(timeAx, self.deriv[random.randrange(0, len(self.deriv))], color='grey')
|
||||
self.plot_edges.plot(timeAx, self.deriv[random.randrange(0, len(self.deriv))], color='grey')
|
||||
self.plot_edges.plot(timeAx, np.mean(self.deriv, axis=0), color='orangered')
|
||||
self.plot_edges.set_title("{}, offset of {}$\,$fs, jitter of {}$\,$fs rms".format(self.time,np.round(np.mean(self.jitter),1), np.round((np.std(self.jitter)),1)))
|
||||
self.plot_edges.axvline(x=np.mean(self.jitter), color='k', linestyle="--")
|
||||
self.plot_jitters.hist(self.jitter, facecolor='orangered', edgecolor='black')
|
||||
self.plot_amps.hist(self.amp, facecolor='orangered', edgecolor='black')
|
||||
|
||||
self.plot_stage.plot(self.stagePos, 'o-')
|
||||
self.plot_timeseries_jitters.fill_between(np.arange(0, len(self.jitters)), np.asarray(self.jstds)+np.asarray(self.jitters), -np.asarray(self.jstds)+np.asarray(self.jitters), color='gold')
|
||||
self.plot_timeseries_jitters.plot(np.arange(0, len(self.jitters)), self.jitters, 'o-', color='orangered')
|
||||
self.plot_timeseries_amps.plot(np.arange(0, len(self.amps)), self.amps, 'o-', color='orangered')
|
||||
self.plot_timeseries_amps.fill_between(np.arange(0, len(self.amps)), np.asarray(self.astds)+np.asarray(self.amps), -np.asarray(self.astds)+np.asarray(self.amps), color='gold')
|
||||
|
||||
self.plot_edges.draw()
|
||||
self.plot_jitters.draw()
|
||||
self.plot_amps.draw()
|
||||
self.plot_timeseries_jitters.draw()
|
||||
self.plot_timeseries_amps.draw()
|
||||
self.plot_stage.draw()
|
||||
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
self.jitters.clear()
|
||||
self.jstds.clear()
|
||||
self.amps.clear()
|
||||
self.astds.clear()
|
||||
self.stagePos.clear()
|
||||
@@ -0,0 +1,163 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
from slic.gui.widgets import make_filled_hbox, make_filled_vbox, EXPANDING
|
||||
from slic.gui.widgets.plotting import PlotPanel
|
||||
|
||||
from bstrd import BS, bsstream
|
||||
from scipy.stats.stats import pearsonr
|
||||
|
||||
# config
|
||||
nshots = 200
|
||||
ttThreshold = 10
|
||||
iZeroThreshold = 0.3
|
||||
|
||||
# channels
|
||||
chname_jitter = "SARES11-SPEC125-M1.edge_position"
|
||||
chname_jitter2 = "SARES11-SPEC125-M1.edge_position2"
|
||||
chname_events = "SAR-CVME-TIFALL4:EvtSet"
|
||||
chname_iZero = "SAROP11-PBPS122:INTENSITY"
|
||||
|
||||
# create channels
|
||||
ch_jitter = BS(chname_jitter)
|
||||
ch_jitter2 = BS(chname_jitter2)
|
||||
ch_events = BS(chname_events)
|
||||
ch_iZero = BS(chname_iZero)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
def goodshots(events, iZero, *arrays):
|
||||
fel = events[:, 13]
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
pulsePicking = events[:,200]
|
||||
iZero = iZero
|
||||
pumped_shots = np.logical_and.reduce((fel, laser, np.logical_not(darkShot), iZero > iZeroThreshold))
|
||||
return [a[pumped_shots] for a in arrays]
|
||||
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.jitter = np.empty(nshots)
|
||||
self.jitter2 = np.empty(nshots)
|
||||
self.iZero = np.empty(nshots)
|
||||
|
||||
self.jitters = deque(maxlen=1)
|
||||
self.jitters2 = deque(maxlen=1)
|
||||
self.corrs = deque(maxlen=1000)
|
||||
self.diffs = deque(maxlen=10000)
|
||||
|
||||
self.plot_jitters_corr = plot_jitters_corr = PlotPanel(self, figsize=(5,5))
|
||||
self.plot_corrs_time = plot_corrs_time = PlotPanel(self, figsize=(5,2))
|
||||
self.plot_diffs_time = plot_diffs_time = PlotPanel(self, figsize=(5,2))
|
||||
|
||||
plots1 = (plot_jitters_corr,)
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
|
||||
plots2 = (plot_corrs_time,)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
|
||||
plots3 = (plot_diffs_time,)
|
||||
hb_plot3 = make_filled_hbox(plots3)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
hb_btns = make_filled_hbox(btns)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_plot3, hb_btns)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.jitter = np.empty(nshots)
|
||||
self.jitter2 = np.empty(nshots)
|
||||
self.iZero = np.empty(nshots)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_jitter.get()
|
||||
self.jitter[i] = tempb
|
||||
tempc = ch_jitter2.get()
|
||||
self.jitter2[i] = tempc
|
||||
tempd = ch_iZero.get()
|
||||
self.iZero[i] = tempd
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.jitter, self.jitter2 = goodshots(self.evts, self.iZero, self.jitter, self.jitter2)
|
||||
|
||||
if (len(np.asarray(self.jitter)) > 1):
|
||||
self.jitters.append(self.jitter)
|
||||
self.jitters2.append(np.roll(self.jitter2, 0))
|
||||
|
||||
self.pearscoeff1, _ = pearsonr(np.ravel(self.jitters), np.ravel(self.jitters2))
|
||||
self.corrs.append(self.pearscoeff1)
|
||||
self.diffs.append(np.mean(np.ravel(self.jitters)) - np.mean(np.ravel(self.jitters2)))
|
||||
|
||||
else:
|
||||
print("{} Where are my X-rays?".format(self.time))
|
||||
self.jitters.append(np.nan)
|
||||
self.jitters2.append(np.nan)
|
||||
self.corrs.append(np.nan)
|
||||
self.diffs.append(np.nan)
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
|
||||
def draw_plot(self):
|
||||
self.plot_jitters_corr.clear()
|
||||
self.plot_corrs_time.clear()
|
||||
self.plot_diffs_time.clear()
|
||||
|
||||
self.plot_jitters_corr.set_xlabel(chname_jitter)
|
||||
self.plot_jitters_corr.set_ylabel(chname_jitter2)
|
||||
self.plot_jitters_corr.grid(True, linestyle='--')
|
||||
self.plot_jitters_corr.axline((np.mean(np.ravel(self.jitters)),np.mean(np.ravel(self.jitters2))), slope=1, linestyle='--', color='black')
|
||||
self.plot_jitters_corr.set_title('Correlation: {:.4f}'.format(pearsonr(np.ravel(self.jitters), np.ravel(self.jitters2))[0]))
|
||||
|
||||
self.plot_corrs_time.set_xlabel('time ago, a.u.')
|
||||
self.plot_corrs_time.set_ylabel('correlation')
|
||||
self.plot_corrs_time.grid(True, linestyle='--')
|
||||
|
||||
self.plot_diffs_time.set_xlabel('')
|
||||
self.plot_diffs_time.set_ylabel('')
|
||||
self.plot_diffs_time.grid(True, linestyle='--')
|
||||
|
||||
self.plot_jitters_corr.scatter(np.ravel(self.jitters), np.ravel(self.jitters2), color='orangered')
|
||||
self.plot_corrs_time.plot(self.corrs, 'o-', color='orangered')
|
||||
self.plot_diffs_time.plot(self.diffs)
|
||||
|
||||
self.plot_jitters_corr.draw()
|
||||
self.plot_corrs_time.draw()
|
||||
self.plot_diffs_time.draw()
|
||||
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
self.jitters.clear()
|
||||
self.jitters2.clear()
|
||||
self.corrs.clear()
|
||||
self.diffs.clear()
|
||||
@@ -0,0 +1,192 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
from scipy.stats.stats import pearsonr
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
from slic.gui.widgets import make_filled_hbox, make_filled_vbox, EXPANDING
|
||||
from slic.gui.widgets.plotting import PlotPanel
|
||||
|
||||
from bstrd import BS, bsstream
|
||||
|
||||
def pumped(events, i0, *arrays):
|
||||
fel = events[:, 13]
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot), i0 > i0thres))
|
||||
return [a[pumped_shots] for a in arrays]
|
||||
|
||||
# config
|
||||
nshots = 100
|
||||
qlength = 10000
|
||||
histlength = 1
|
||||
i0thres = 0.2
|
||||
|
||||
# channels
|
||||
chname_tt1 = "SARES11-SPEC125-M1.edge_position"
|
||||
chname_tt2 = "SARES11-SPEC125-M1.edge_position2"
|
||||
chname_i0 = "SAROP11-PBPS122:INTENSITY"
|
||||
chname_events = "SAR-CVME-TIFALL4:EvtSet"
|
||||
|
||||
# create channels
|
||||
ch_tt1 = BS(chname_tt1)
|
||||
ch_tt2 = BS(chname_tt2)
|
||||
ch_int = BS(chname_i0)
|
||||
ch_i0 = BS(chname_i0)
|
||||
ch_events = BS(chname_events)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.tt1 = np.empty(nshots)
|
||||
self.tt2 = np.empty(nshots)
|
||||
self.i0 = np.empty(nshots)
|
||||
|
||||
self.tt1hist = deque(maxlen=histlength)
|
||||
self.tt2hist = deque(maxlen=histlength)
|
||||
self.tt1s = deque(maxlen=qlength)
|
||||
self.tt2s = deque(maxlen=qlength)
|
||||
self.ttdiff = deque(maxlen=qlength)
|
||||
|
||||
self.plot_hist_tt1 = plot_hist_tt1 = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_hist_tt2 = plot_hist_tt2 = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_corr = plot_corr = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_diff = plot_diff = PlotPanel(self, figsize=(2,3))
|
||||
|
||||
plots1 = (plot_hist_tt1, plot_hist_tt2)
|
||||
plots2 = (plot_corr,)
|
||||
plots3 = (plot_diff,)
|
||||
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
hb_plot3 = make_filled_hbox(plots3)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
hb_btns = make_filled_hbox(btns)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_plot3, hb_btns)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.tt1 = np.empty(nshots)
|
||||
self.tt2 = np.empty(nshots)
|
||||
self.int = np.empty(nshots)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_i0.get()
|
||||
self.i0[i] = tempb
|
||||
tempc = ch_tt1.get()
|
||||
self.tt1[i] = tempc
|
||||
tempd = ch_tt2.get()
|
||||
self.tt2[i] = tempd
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.tt1p = np.ravel(pumped(self.evts, self.i0, self.tt1))
|
||||
self.tt2p = np.ravel(pumped(self.evts, self.i0, self.tt2))
|
||||
|
||||
if (len(self.tt1p) > 1):
|
||||
print ('{} -- {} = {:.2f} a.u.'.format(self.time, chname_i0, np.nanmean(self.i0)))
|
||||
|
||||
self.tt1hist.append(self.tt1p)
|
||||
self.tt2hist.append(self.tt2p)
|
||||
self.tt1s.append(np.mean(self.tt1p))
|
||||
self.tt2s.append(np.mean(self.tt2p))
|
||||
#self.ttdiff.append(np.array(self.tt1s) - np.array(self.tt2s))
|
||||
self.ttdiff.append(np.nanmean(np.array(self.tt1p) - np.array(self.tt2p)))
|
||||
|
||||
else:
|
||||
print ('{} -- {} = {:.2f} a.u. --> No Xrays'.format(self.time, chname_i0, np.nanmean(self.int)))
|
||||
self.tt1hist.append(np.nan)
|
||||
self.tt2hist.append(np.nan)
|
||||
self.tt1s.append(np.nan)
|
||||
self.tt2s.append(np.nan)
|
||||
self.ttdiff.append(np.nan)
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
def draw_plot(self):
|
||||
self.plot_hist_tt1.clear()
|
||||
self.plot_hist_tt2.clear()
|
||||
self.plot_corr.clear()
|
||||
self.plot_diff.clear()
|
||||
|
||||
self.plot_hist_tt1.set_xlabel('Arr time tt (fs)')
|
||||
self.plot_hist_tt2.set_xlabel('Arr time tt2 (fs)')
|
||||
self.plot_corr.set_xlabel('Arr time tt1 (fs)')
|
||||
self.plot_corr.set_ylabel('Arr time tt2 (fs)')
|
||||
self.plot_diff.set_xlabel('time ago, a.u.')
|
||||
self.plot_diff.set_ylabel('Difference (fs)')
|
||||
|
||||
if (len(self.tt1p) > 1):
|
||||
self.plot_hist_tt1.set_title('tt1: {:.2f} fs, jitter: {:.2f}'.format(np.nanmean(self.tt1p), np.nanstd(self.tt1p)))
|
||||
self.plot_hist_tt2.set_title('tt2: {:.2f} fs, jitter: {:.2f}'.format(np.nanmean(self.tt2p), np.nanstd(self.tt2p)))
|
||||
|
||||
self.plot_hist_tt1.hist(np.ravel(self.tt1hist), facecolor='dodgerblue', edgecolor='black')
|
||||
self.plot_hist_tt2.hist(np.ravel(self.tt2hist), facecolor='green', edgecolor='black')
|
||||
|
||||
self.plot_corr.set_title('Corr: {:.4f}'.format(pearsonr(np.ravel(self.tt1p), np.ravel(self.tt2p))[0]))
|
||||
self.plot_corr.plot(np.ravel(self.tt1p), np.ravel(self.tt2p), '.', color='purple')
|
||||
self.plot_corr.grid()
|
||||
|
||||
#self.plot_diff.plot(np.arange(0, len(self.tt1s)), np.array(self.tt1p) - np.array(self.tt2p), '.', color='orangered')
|
||||
#self.plot_diff.plot(np.array(self.tt1p) - np.array(self.tt2p), '.', color='orangered')
|
||||
|
||||
self.plot_diff.set_title('Diff: {:.2f} fs'.format(self.ttdiff[-1]))
|
||||
self.plot_diff.plot(np.arange(0, len(self.ttdiff)), np.array(self.ttdiff), '.', color='orangered')
|
||||
|
||||
self.plot_hist_tt1.draw()
|
||||
self.plot_hist_tt2.draw()
|
||||
self.plot_corr.draw()
|
||||
self.plot_diff.draw()
|
||||
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
|
||||
self.tt1s.clear()
|
||||
self.tt2s.clear()
|
||||
self.ttdiff.clear()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
from datetime import datetime
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
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
|
||||
nshots = 1000
|
||||
x_axis=np.arange(0,100,0.05)
|
||||
quantile = 0.9
|
||||
|
||||
# channels
|
||||
ch_xpos = 'SAROP11-PBPS122:XPOS'
|
||||
ch_ypos = 'SAROP11-PBPS122:YPOS'
|
||||
ch_intensity = 'SAROP11-PBPS122:INTENSITY'
|
||||
|
||||
bs_xpos = BS(ch_xpos)
|
||||
bs_ypos = BS(ch_ypos)
|
||||
bs_intensity = BS(ch_intensity)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
def filter_outliers(quantile, a):
|
||||
low = np.nanquantile(a, 0.5 - quantile/2)
|
||||
high = np.nanquantile(a, 0.5 + quantile/2)
|
||||
|
||||
cond_low = a > low
|
||||
cond_high = a < high
|
||||
cond = cond_low & cond_high
|
||||
|
||||
return a[cond]
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.x = np.empty(nshots)
|
||||
self.y = np.empty(nshots)
|
||||
|
||||
self.powerx50Hztimeseries = deque(maxlen=1000)
|
||||
self.powerxlowfreqtimeseries = deque(maxlen=1000)
|
||||
self.powerxtrainfrequencies = deque(maxlen=1000)
|
||||
self.powerx33hz = deque(maxlen=1000)
|
||||
|
||||
self.plot_xy = plot_xy = PlotPanel(self, figsize=(6,2))
|
||||
self.plot_fft = plot_fft = PlotPanel(self, figsize=(6,2))
|
||||
self.plot_timeseries = plot_timeseries = PlotPanel(self, figsize=(6,2))
|
||||
plots1 = (plot_xy, plot_fft, plot_timeseries)
|
||||
vb_plots1 = make_filled_vbox(plots1)
|
||||
|
||||
widgets = (vb_plots1,)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.x = np.empty(nshots)
|
||||
self.y = np.empty(nshots)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = bs_xpos.get()
|
||||
self.x[i] = tempa
|
||||
tempb = bs_ypos.get()
|
||||
self.y[i] = tempb
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.x = filter_outliers(quantile, self.x)
|
||||
self.y = filter_outliers(quantile, self.y)
|
||||
|
||||
if (len(np.asarray(self.x)) > 1):
|
||||
self.valsdiode = np.hstack((self.x-np.mean(self.x), np.zeros_like(self.x)))
|
||||
self.vals2diode = np.hstack((self.y - np.mean(self.y), np.zeros_like(self.y)))
|
||||
self.powerx = np.abs(np.fft.fft(self.valsdiode))**2
|
||||
self.powery = np.abs(np.fft.fft(self.vals2diode))**2
|
||||
|
||||
self.powerxlowfreqtimeseries.append(np.sum(self.powerx[0:200]))
|
||||
self.powerx50Hztimeseries.append(np.sum(self.powerx[900:1100]))
|
||||
self.powerxtrainfrequencies.append(np.sum(self.powerx[250:400]))
|
||||
|
||||
else:
|
||||
print("{} Where are my X-rays?".format(self.time))
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
|
||||
def draw_plot(self):
|
||||
self.plot_xy.clear()
|
||||
self.plot_fft.clear()
|
||||
self.plot_timeseries.clear()
|
||||
|
||||
self.plot_xy.set_xlabel('shots at 100 Hz')
|
||||
self.plot_xy.set_ylabel('position in mm')
|
||||
self.plot_xy.set_xlim(0,min(len(self.x),len(self.y)))
|
||||
self.plot_xy.grid(True, linestyle='--')
|
||||
|
||||
self.plot_xy.plot(self.valsdiode + 0.05)
|
||||
self.plot_xy.plot(self.vals2diode - 0.05)
|
||||
|
||||
self.plot_fft.set_xlabel('frequency, Hz')
|
||||
self.plot_fft.set_ylabel('power, a.u.')
|
||||
self.plot_fft.set_xlim(0,55)
|
||||
self.plot_fft.grid(True, linestyle='--')
|
||||
self.plot_fft.axhline(y=-5, xmin=0, xmax=0.175, color='r')
|
||||
self.plot_fft.axhline(y=-5, xmin=0.8, xmax=1, color='k')
|
||||
self.plot_fft.axhline(y=-5, xmin=0.25, xmax=0.35, color='g')
|
||||
|
||||
x_axis1=np.linspace(0,100,len(self.powerx))
|
||||
x_axis2=np.linspace(0,100,len(self.powery))
|
||||
|
||||
self.plot_fft.plot(x_axis1, self.powerx)
|
||||
self.plot_fft.plot(x_axis2, self.powery)
|
||||
|
||||
self.plot_timeseries.set_xlabel('time ago, a.u.')
|
||||
self.plot_timeseries.set_ylabel('power, a.u.')
|
||||
self.plot_timeseries.set_ylim(0, 2000)
|
||||
self.plot_timeseries.grid(True, linestyle='--')
|
||||
|
||||
self.plot_timeseries.plot(self.powerxlowfreqtimeseries, color='r')
|
||||
self.plot_timeseries.plot(self.powerx50Hztimeseries, color='k')
|
||||
self.plot_timeseries.plot(self.powerxtrainfrequencies, color='g')
|
||||
|
||||
self.plot_xy.draw()
|
||||
self.plot_fft.draw()
|
||||
self.plot_timeseries.draw()
|
||||
+240
@@ -0,0 +1,240 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
from scipy.stats.stats import pearsonr
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
from slic.gui.widgets import make_filled_hbox, make_filled_vbox, EXPANDING
|
||||
from slic.gui.widgets.plotting import PlotPanel
|
||||
|
||||
from bstrd import BS, bsstream
|
||||
|
||||
def unpumped(events, *arrays):
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
background_shots = np.logical_and.reduce((laser, darkShot))
|
||||
return [a[background_shots] for a in arrays]
|
||||
|
||||
def pumped(events, *arrays):
|
||||
fel = events[:, 13]
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
|
||||
return [a[pumped_shots] for a in arrays]
|
||||
|
||||
|
||||
# config
|
||||
nshots = 50
|
||||
qlength = 100
|
||||
histlength = 1
|
||||
|
||||
# channels
|
||||
#chname_pbpsint = "SARES11-GES1:PR1_CH1_VAL_GET"
|
||||
chname_pbpsint = "SAROP11-PBPS122:INTENSITY"
|
||||
#chname_pbpsint = "SARES11-SPEC125-M1.edge_amplitude"
|
||||
#chname_pbpsint = "SARES30-LSCP1-FNS:CH0:VAL_GET"
|
||||
|
||||
###--- FLEX Keysight ---###
|
||||
#chname_fluo1 = "SARES12-GES1:PR1_CH1_VAL_GET"
|
||||
#chname_fluo2 = "SARES12-GES1:PR1_CH2_VAL_GET"
|
||||
|
||||
###--- PRIME Keysight ---###
|
||||
chname_fluo1 = "SARES11-GES1:PR1_CH1_VAL_GET"
|
||||
chname_fluo2 = "SARES11-GES1:PR1_CH2_VAL_GET"
|
||||
|
||||
###--- PALM Keysight ---###
|
||||
#chname_fluo1 = "SAROP11-GES1:PR1_CH1_VAL_GET"
|
||||
#chname_fluo2 = "SAROP11-GES1:PR1_CH2_VAL_GET"
|
||||
|
||||
chname_events = "SAR-CVME-TIFALL4:EvtSet"
|
||||
|
||||
# create channels
|
||||
ch_int = BS(chname_pbpsint)
|
||||
ch_fluo1 = BS(chname_fluo1)
|
||||
ch_fluo2 = BS(chname_fluo2)
|
||||
ch_events = BS(chname_events)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.iZero = np.empty(nshots)
|
||||
self.fluo1 = np.empty(nshots)
|
||||
self.fluo2 = np.empty(nshots)
|
||||
|
||||
self.iZerosP = deque(maxlen=qlength)
|
||||
self.iZerosU = deque(maxlen=qlength)
|
||||
self.fluo1s = deque(maxlen=qlength)
|
||||
self.fluo2s = deque(maxlen=qlength)
|
||||
#self.fluo1sU = deque(maxlen=qlength)
|
||||
#self.fluo2sU = deque(maxlen=qlength)
|
||||
|
||||
self.corrTime1sP = deque(maxlen=qlength)
|
||||
self.corrTime1sU = deque(maxlen=qlength)
|
||||
self.corrTime2sP = deque(maxlen=qlength)
|
||||
self.corrTime2sU = deque(maxlen=qlength)
|
||||
|
||||
self.fluo1stds = deque(maxlen=qlength)
|
||||
self.fluo2stds = deque(maxlen=qlength)
|
||||
|
||||
self.iZerocorrsP = deque(maxlen=histlength)
|
||||
self.fluocorr1sP = deque(maxlen=histlength)
|
||||
self.fluocorr2sP = deque(maxlen=histlength)
|
||||
self.iZerocorrsU = deque(maxlen=histlength)
|
||||
self.fluocorr1sU = deque(maxlen=histlength)
|
||||
self.fluocorr2sU = deque(maxlen=histlength)
|
||||
|
||||
self.plot_fluo1s = plot_fluo1s = PlotPanel(self, figsize=(4,3))
|
||||
self.plot_corr1 = plot_corr1 = PlotPanel(self, figsize=(3,3))
|
||||
self.plot_timecorr1 = plot_timecorr1 = PlotPanel(self, figsize=(4,3))
|
||||
self.plot_fluo2s = plot_fluo2s = PlotPanel(self, figsize=(4,3))
|
||||
self.plot_corr2 = plot_corr2 = PlotPanel(self, figsize=(3,3))
|
||||
self.plot_timecorr2 = plot_timecorr2 = PlotPanel(self, figsize=(4,3))
|
||||
|
||||
plots1 = (plot_fluo1s, plot_corr1, plot_timecorr1)
|
||||
plots2 = (plot_fluo2s, plot_corr2, plot_timecorr2)
|
||||
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
hb_btns = make_filled_hbox(btns)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_btns)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.iZero = np.empty(nshots)
|
||||
self.fluo1 = np.empty(nshots)
|
||||
self.fluo2 = np.empty(nshots)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_int.get()
|
||||
self.iZero[i] = tempb
|
||||
tempc = ch_fluo1.get()
|
||||
self.fluo1[i] = tempc
|
||||
tempd = ch_fluo2.get()
|
||||
self.fluo2[i] = tempd
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.iZeroP = pumped(self.evts, self.iZero)
|
||||
self.fluo1P = pumped(self.evts, self.fluo1)
|
||||
self.fluo2P = pumped(self.evts, self.fluo2)
|
||||
|
||||
self.iZeroU = unpumped(self.evts, self.iZero)
|
||||
self.fluo1U = unpumped(self.evts, self.fluo1)
|
||||
self.fluo2U = unpumped(self.evts, self.fluo2)
|
||||
|
||||
self.iZerosP.append(np.mean(self.iZeroP))
|
||||
self.iZerosU.append(np.mean(self.iZeroU))
|
||||
|
||||
self.iZerocorrsP.append(self.iZeroP)
|
||||
self.fluocorr1sP.append(self.fluo1P)
|
||||
self.fluocorr2sP.append(self.fluo2P)
|
||||
self.iZerocorrsU.append(self.iZeroU)
|
||||
self.fluocorr1sU.append(self.fluo1U)
|
||||
self.fluocorr2sU.append(self.fluo2U)
|
||||
|
||||
self.fluo1s.append(np.mean(self.fluo1U))
|
||||
self.fluo1stds.append(np.std(self.fluo1U))
|
||||
self.fluo2s.append(np.mean(self.fluo2U))
|
||||
self.fluo2stds.append(np.std(self.fluo2U))
|
||||
|
||||
self.corrTime1sP.append(pearsonr(np.ravel(self.iZerocorrsP), np.ravel(self.fluocorr1sP))[0])
|
||||
self.corrTime2sP.append(pearsonr(np.ravel(self.iZerocorrsP), np.ravel(self.fluocorr2sP))[0])
|
||||
self.corrTime1sU.append(pearsonr(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr1sU))[0])
|
||||
self.corrTime2sU.append(pearsonr(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr2sU))[0])
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
|
||||
def draw_plot(self):
|
||||
|
||||
self.plot_fluo1s.clear()
|
||||
self.plot_corr1.clear()
|
||||
self.plot_timecorr1.clear()
|
||||
self.plot_fluo2s.clear()
|
||||
self.plot_corr2.clear()
|
||||
self.plot_timecorr2.clear()
|
||||
|
||||
self.plot_fluo1s.set_xlabel('time ago, a.u.')
|
||||
self.plot_fluo1s.set_ylabel('Diode 1 OFF, a.u.')
|
||||
self.plot_corr1.set_xlabel('Izero, a.u.')
|
||||
self.plot_corr1.set_ylabel('Diode 1, a.u.')
|
||||
self.plot_timecorr1.set_xlabel('time ago, a.u.')
|
||||
self.plot_timecorr1.set_ylabel('Correlation 1')
|
||||
self.plot_fluo2s.set_xlabel('time ago, a.u.')
|
||||
self.plot_fluo2s.set_ylabel('Diode 2 OFF, a.u.')
|
||||
self.plot_corr2.set_xlabel('Izero, a.u.')
|
||||
self.plot_corr2.set_ylabel('Diode 2, a.u.')
|
||||
self.plot_timecorr2.set_xlabel('time ago, a.u.')
|
||||
self.plot_timecorr2.set_ylabel('Correlation 2')
|
||||
|
||||
self.plot_fluo1s.fill_between(np.arange(0, len(self.fluo1s)), np.asarray(self.fluo1stds)+np.asarray(self.fluo1s), -np.asarray(self.fluo1stds)+np.asarray(self.fluo1s), color='lightgreen')
|
||||
self.plot_fluo1s.set_title('Intensity: {:.4f} a.u.'.format(np.nanmean(self.fluo1U)))
|
||||
self.plot_fluo1s.plot(np.arange(0, len(self.fluo1s)), self.fluo1s, '-', color='green')
|
||||
|
||||
|
||||
self.plot_fluo2s.fill_between(np.arange(0, len(self.fluo2s)), np.asarray(self.fluo2stds)+np.asarray(self.fluo2s), -np.asarray(self.fluo2stds)+np.asarray(self.fluo2s), color='lavender')
|
||||
self.plot_fluo2s.set_title('Intensity: {:.4f} a.u.'.format(np.nanmean(self.fluo2U)))
|
||||
self.plot_fluo2s.plot(np.arange(0, len(self.fluo2s)), self.fluo2s, '-', color='purple')
|
||||
|
||||
if (len(self.corrTime1sP) > histlength):
|
||||
self.plot_timecorr1.plot(np.arange(0, len(self.corrTime1sP)), np.asarray(self.corrTime1sP), color='limegreen')
|
||||
self.plot_timecorr1.plot(np.arange(0, len(self.corrTime1sU)), np.asarray(self.corrTime1sU), color='green')
|
||||
self.plot_timecorr2.plot(np.arange(0, len(self.corrTime2sP)), np.asarray(self.corrTime2sP), color='violet')
|
||||
self.plot_timecorr2.plot(np.arange(0, len(self.corrTime2sU)), np.asarray(self.corrTime2sU), color='purple')
|
||||
|
||||
self.plot_corr1.plot(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr1sU), '.', color='green', label='OFF')
|
||||
self.plot_corr1.plot(np.ravel(self.iZerocorrsP), np.ravel(self.fluocorr1sP), '.', color='limegreen', label='ON')
|
||||
self.plot_corr1.set_title('Corr 1 on: {:.4f} - Corr 1 off: {:.4f}'.format(pearsonr(np.ravel(self.iZerocorrsP), np.ravel(self.fluocorr1sP))[0], pearsonr(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr1sU))[0]))
|
||||
self.plot_corr1.legend(loc='lower right')
|
||||
|
||||
self.plot_corr2.plot(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr2sU), '.', color='purple', label='OFF')
|
||||
self.plot_corr2.plot(np.ravel(self.iZerocorrsP), np.ravel(self.fluocorr2sP), '.', color='violet', label='ON')
|
||||
self.plot_corr2.set_title('Corr 2 on: {:.4f} - Corr 1 off: {:.4f}'.format(pearsonr(np.ravel(self.iZerocorrsP), np.ravel(self.fluocorr2sP))[0], pearsonr(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr2sU))[0]))
|
||||
self.plot_corr2.legend(loc='lower right')
|
||||
|
||||
self.plot_fluo1s.draw()
|
||||
self.plot_corr1.draw()
|
||||
self.plot_timecorr1.draw()
|
||||
self.plot_fluo2s.draw()
|
||||
self.plot_corr2.draw()
|
||||
self.plot_timecorr2.draw()
|
||||
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
|
||||
self.plot_fluo1s.clear()
|
||||
self.plot_corr1.clear()
|
||||
self.plot_timecorr1.clear()
|
||||
self.plot_fluo2s.clear()
|
||||
self.plot_corr2.clear()
|
||||
self.plot_timecorr2.clear()
|
||||
@@ -0,0 +1,241 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
from scipy.stats.stats import pearsonr
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
from slic.gui.widgets import make_filled_hbox, make_filled_vbox, EXPANDING
|
||||
from slic.gui.widgets.plotting import PlotPanel
|
||||
|
||||
from bstrd import BS, bsstream
|
||||
|
||||
def unpumped(events, *arrays):
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
background_shots = np.logical_and.reduce((laser, darkShot))
|
||||
return [a[background_shots] for a in arrays]
|
||||
|
||||
def pumped(events, *arrays):
|
||||
fel = events[:, 13]
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
|
||||
return [a[pumped_shots] for a in arrays]
|
||||
|
||||
|
||||
# config
|
||||
nshots = 50
|
||||
qlength = 100
|
||||
histlength = 1
|
||||
|
||||
# channels
|
||||
chname_pbpsint = "SAROP11-PBPS122:INTENSITY"
|
||||
#chname_pbpsint = "SARES11-SPEC125-M1.edge_amplitude"
|
||||
#chname_pbpsint = "SARES30-LSCP1-FNS:CH0:VAL_GET"
|
||||
|
||||
###--- FLEX Keysight ---###
|
||||
#chname_fluo1 = "SARES12-GES1:PR1_CH1_VAL_GET"
|
||||
#chname_fluo2 = "SARES12-GES1:PR1_CH2_VAL_GET"
|
||||
|
||||
###--- PRIME Keysight ---###
|
||||
chname_fluo1 = "SARES11-GES1:PR1_CH1_VAL_GET"
|
||||
chname_fluo2 = "SARES11-GES1:PR1_CH2_VAL_GET"
|
||||
|
||||
###--- PALM Keysight ---###
|
||||
#chname_fluo1 = "SAROP11-GES1:PR1_CH1_VAL_GET"
|
||||
#chname_fluo2 = "SAROP11-GES1:PR1_CH2_VAL_GET"
|
||||
|
||||
chname_events = "SAR-CVME-TIFALL4:EvtSet"
|
||||
|
||||
# create channels
|
||||
ch_int = BS(chname_pbpsint)
|
||||
ch_fluo1 = BS(chname_fluo1)
|
||||
ch_fluo2 = BS(chname_fluo2)
|
||||
ch_events = BS(chname_events)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.iZero = np.empty(nshots)
|
||||
self.fluo1 = np.empty(nshots)
|
||||
self.fluo2 = np.empty(nshots)
|
||||
|
||||
self.iZerosP = deque(maxlen=qlength)
|
||||
self.iZerosU = deque(maxlen=qlength)
|
||||
self.fluo1s = deque(maxlen=qlength)
|
||||
self.fluo2s = deque(maxlen=qlength)
|
||||
#self.fluo1sU = deque(maxlen=qlength)
|
||||
#self.fluo2sU = deque(maxlen=qlength)
|
||||
|
||||
self.corrTime1sP = deque(maxlen=qlength)
|
||||
self.corrTime1sU = deque(maxlen=qlength)
|
||||
self.corrTime2sP = deque(maxlen=qlength)
|
||||
self.corrTime2sU = deque(maxlen=qlength)
|
||||
|
||||
self.fluo1stds = deque(maxlen=qlength)
|
||||
self.fluo2stds = deque(maxlen=qlength)
|
||||
|
||||
self.iZerocorrsP = deque(maxlen=histlength)
|
||||
self.fluocorr1sP = deque(maxlen=histlength)
|
||||
self.fluocorr2sP = deque(maxlen=histlength)
|
||||
self.iZerocorrsU = deque(maxlen=histlength)
|
||||
self.fluocorr1sU = deque(maxlen=histlength)
|
||||
self.fluocorr2sU = deque(maxlen=histlength)
|
||||
|
||||
self.plot_fluo1s = plot_fluo1s = PlotPanel(self, figsize=(4,3))
|
||||
self.plot_corr1 = plot_corr1 = PlotPanel(self, figsize=(3,3))
|
||||
self.plot_timecorr1 = plot_timecorr1 = PlotPanel(self, figsize=(4,3))
|
||||
self.plot_fluo2s = plot_fluo2s = PlotPanel(self, figsize=(4,3))
|
||||
self.plot_corr2 = plot_corr2 = PlotPanel(self, figsize=(3,3))
|
||||
self.plot_timecorr2 = plot_timecorr2 = PlotPanel(self, figsize=(4,3))
|
||||
|
||||
plots1 = (plot_fluo1s, plot_corr1, plot_timecorr1)
|
||||
plots2 = (plot_fluo2s, plot_corr2, plot_timecorr2)
|
||||
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
hb_btns = make_filled_hbox(btns)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_btns)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.iZero = np.empty(nshots)
|
||||
self.fluo1 = np.empty(nshots)
|
||||
self.fluo2 = np.empty(nshots)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_int.get()
|
||||
self.iZero[i] = tempb
|
||||
tempc = ch_fluo1.get()
|
||||
self.fluo1[i] = tempc
|
||||
tempd = ch_fluo2.get()
|
||||
self.fluo2[i] = tempd
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
#self.iZeroP = pumped(self.evts, self.iZero)
|
||||
#self.fluo1P = pumped(self.evts, self.fluo1)
|
||||
#self.fluo2P = pumped(self.evts, self.fluo2)
|
||||
|
||||
self.iZeroU = unpumped(self.evts, self.iZero)
|
||||
self.fluo1U = unpumped(self.evts, self.fluo1)
|
||||
self.fluo2U = unpumped(self.evts, self.fluo2)
|
||||
|
||||
#self.iZerosP.append(np.mean(self.iZeroP))
|
||||
self.iZerosU.append(np.mean(self.iZeroU))
|
||||
|
||||
#self.iZerocorrsP.append(self.iZeroP)
|
||||
#self.fluocorr1sP.append(self.fluo1P)
|
||||
#self.fluocorr2sP.append(self.fluo2P)
|
||||
self.iZerocorrsU.append(self.iZeroU)
|
||||
self.fluocorr1sU.append(self.fluo1U)
|
||||
self.fluocorr2sU.append(self.fluo2U)
|
||||
|
||||
self.fluo1s.append(np.mean(self.fluo1U))
|
||||
self.fluo1stds.append(np.std(self.fluo1U))
|
||||
self.fluo2s.append(np.mean(self.fluo2U))
|
||||
self.fluo2stds.append(np.std(self.fluo2U))
|
||||
|
||||
#self.corrTime1sP.append(pearsonr(np.ravel(self.iZerocorrsP), np.ravel(self.fluocorr1sP))[0])
|
||||
#self.corrTime2sP.append(pearsonr(np.ravel(self.iZerocorrsP), np.ravel(self.fluocorr2sP))[0])
|
||||
self.corrTime1sU.append(pearsonr(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr1sU))[0])
|
||||
self.corrTime2sU.append(pearsonr(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr2sU))[0])
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
|
||||
def draw_plot(self):
|
||||
|
||||
self.plot_fluo1s.clear()
|
||||
self.plot_corr1.clear()
|
||||
self.plot_timecorr1.clear()
|
||||
self.plot_fluo2s.clear()
|
||||
self.plot_corr2.clear()
|
||||
self.plot_timecorr2.clear()
|
||||
|
||||
self.plot_fluo1s.set_xlabel('time ago, a.u.')
|
||||
self.plot_fluo1s.set_ylabel('Diode 1 OFF, a.u.')
|
||||
self.plot_corr1.set_xlabel('Izero, a.u.')
|
||||
self.plot_corr1.set_ylabel('Diode 1, a.u.')
|
||||
self.plot_timecorr1.set_xlabel('time ago, a.u.')
|
||||
self.plot_timecorr1.set_ylabel('Correlation 1')
|
||||
self.plot_fluo2s.set_xlabel('time ago, a.u.')
|
||||
self.plot_fluo2s.set_ylabel('Diode 2 OFF, a.u.')
|
||||
self.plot_corr2.set_xlabel('Izero, a.u.')
|
||||
self.plot_corr2.set_ylabel('Diode 2, a.u.')
|
||||
self.plot_timecorr2.set_xlabel('time ago, a.u.')
|
||||
self.plot_timecorr2.set_ylabel('Correlation 2')
|
||||
|
||||
self.plot_fluo1s.fill_between(np.arange(0, len(self.fluo1s)), np.asarray(self.fluo1stds)+np.asarray(self.fluo1s), -np.asarray(self.fluo1stds)+np.asarray(self.fluo1s), color='lightgreen')
|
||||
self.plot_fluo1s.set_title('Intensity: {:.4f} a.u.'.format(np.nanmean(self.fluo1U)))
|
||||
self.plot_fluo1s.plot(np.arange(0, len(self.fluo1s)), self.fluo1s, '-', color='green')
|
||||
|
||||
|
||||
self.plot_fluo2s.fill_between(np.arange(0, len(self.fluo2s)), np.asarray(self.fluo2stds)+np.asarray(self.fluo2s), -np.asarray(self.fluo2stds)+np.asarray(self.fluo2s), color='lavender')
|
||||
self.plot_fluo2s.set_title('Intensity: {:.4f} a.u.'.format(np.nanmean(self.fluo2U)))
|
||||
self.plot_fluo2s.plot(np.arange(0, len(self.fluo2s)), self.fluo2s, '-', color='purple')
|
||||
|
||||
if (len(self.corrTime1sP) > histlength):
|
||||
#self.plot_timecorr1.plot(np.arange(0, len(self.corrTime1sP)), np.asarray(self.corrTime1sP), color='limegreen')
|
||||
self.plot_timecorr1.plot(np.arange(0, len(self.corrTime1sU)), np.asarray(self.corrTime1sU), color='green')
|
||||
#self.plot_timecorr2.plot(np.arange(0, len(self.corrTime2sP)), np.asarray(self.corrTime2sP), color='violet')
|
||||
self.plot_timecorr2.plot(np.arange(0, len(self.corrTime2sU)), np.asarray(self.corrTime2sU), color='purple')
|
||||
|
||||
self.plot_corr1.plot(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr1sU), '.', color='green', label='OFF')
|
||||
#self.plot_corr1.plot(np.ravel(self.iZerocorrsP), np.ravel(self.fluocorr1sP), '.', color='limegreen', label='ON')
|
||||
#self.plot_corr1.set_title('Corr 1 on: {:.4f} - Corr 1 off: {:.4f}'.format(pearsonr(np.ravel(self.iZerocorrsP), np.ravel(self.fluocorr1sP))[0], pearsonr(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr1sU))[0]))
|
||||
self.plot_corr1.set_title('Corr 1: {:.4f}'.format(pearsonr(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr1sU))[0]))
|
||||
self.plot_corr1.legend(loc='lower right')
|
||||
|
||||
self.plot_corr2.plot(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr2sU), '.', color='purple', label='OFF')
|
||||
#self.plot_corr2.plot(np.ravel(self.iZerocorrsP), np.ravel(self.fluocorr2sP), '.', color='violet', label='ON')
|
||||
#self.plot_corr2.set_title('Corr 2 on: {:.4f} - Corr 1 off: {:.4f}'.format(pearsonr(np.ravel(self.iZerocorrsP), np.ravel(self.fluocorr2sP))[0], pearsonr(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr2sU))[0]))
|
||||
self.plot_corr2.set_title('Corr 2: {:.4f}'.format(pearsonr(np.ravel(self.iZerocorrsU), np.ravel(self.fluocorr2sU))[0]))
|
||||
self.plot_corr2.legend(loc='lower right')
|
||||
|
||||
self.plot_fluo1s.draw()
|
||||
self.plot_corr1.draw()
|
||||
self.plot_timecorr1.draw()
|
||||
self.plot_fluo2s.draw()
|
||||
self.plot_corr2.draw()
|
||||
self.plot_timecorr2.draw()
|
||||
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
|
||||
self.plot_fluo1s.clear()
|
||||
self.plot_corr1.clear()
|
||||
self.plot_timecorr1.clear()
|
||||
self.plot_fluo2s.clear()
|
||||
self.plot_corr2.clear()
|
||||
self.plot_timecorr2.clear()
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
from scipy.stats.stats import pearsonr
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
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
|
||||
nshots = 50
|
||||
qlength = 100
|
||||
histlength = 1
|
||||
|
||||
# channels
|
||||
chname_pbpsint = "SAROP11-PBPS122:INTENSITY"
|
||||
#chname_fluo1 = "SARES11-GES1:PR1_CH1_VAL_GET"
|
||||
chname_fluo1 = "SAROP11-PBPS110:INTENSITY"
|
||||
chname_fluo2 = "SARES11-GES1:PR1_CH2_VAL_GET"
|
||||
chname_events = "SAR-CVME-TIFALL4:EvtSet"
|
||||
|
||||
# create channels
|
||||
ch_int = BS(chname_pbpsint)
|
||||
ch_fluo1 = BS(chname_fluo1)
|
||||
ch_fluo2 = BS(chname_fluo2)
|
||||
ch_events = BS(chname_events)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.iZero = np.empty(nshots)
|
||||
self.fluo1 = np.empty(nshots)
|
||||
self.fluo2 = np.empty(nshots)
|
||||
|
||||
self.iZeros = deque(maxlen=qlength)
|
||||
self.fluo1s = deque(maxlen=qlength)
|
||||
self.fluo2s = deque(maxlen=qlength)
|
||||
|
||||
self.corrTime1s = deque(maxlen=qlength)
|
||||
self.corrTime2s = deque(maxlen=qlength)
|
||||
|
||||
self.fluo1stds = deque(maxlen=qlength)
|
||||
self.fluo2stds = deque(maxlen=qlength)
|
||||
|
||||
self.iZerocorrs = deque(maxlen=histlength)
|
||||
self.fluocorr1s = deque(maxlen=histlength)
|
||||
self.fluocorr2s = deque(maxlen=histlength)
|
||||
|
||||
self.plot_fluo1s = plot_fluo1s = PlotPanel(self, figsize=(4,3))
|
||||
self.plot_corr1 = plot_corr1 = PlotPanel(self, figsize=(3,3))
|
||||
self.plot_timecorr1 = plot_timecorr1 = PlotPanel(self, figsize=(4,3))
|
||||
self.plot_fluo2s = plot_fluo2s = PlotPanel(self, figsize=(4,3))
|
||||
self.plot_corr2 = plot_corr2 = PlotPanel(self, figsize=(3,3))
|
||||
self.plot_timecorr2 = plot_timecorr2 = PlotPanel(self, figsize=(4,3))
|
||||
|
||||
plots1 = (plot_fluo1s, plot_corr1, plot_timecorr1)
|
||||
plots2 = (plot_fluo2s, plot_corr2, plot_timecorr2)
|
||||
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
hb_btns = make_filled_hbox(btns)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_btns)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.iZero = np.empty(nshots)
|
||||
self.fluo1 = np.empty(nshots)
|
||||
self.fluo2 = np.empty(nshots)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_int.get()
|
||||
self.iZero[i] = tempb
|
||||
tempc = ch_fluo1.get()
|
||||
self.fluo1[i] = tempc
|
||||
tempd = ch_fluo2.get()
|
||||
self.fluo2[i] = tempd
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.iZeros.append(np.mean(self.iZero))
|
||||
|
||||
self.iZerocorrs.append(self.iZero)
|
||||
self.fluocorr1s.append(self.fluo1)
|
||||
self.fluocorr2s.append(self.fluo2)
|
||||
|
||||
self.fluo1s.append(np.mean(self.fluo1))
|
||||
self.fluo1stds.append(np.std(self.fluo1))
|
||||
self.fluo2s.append(np.mean(self.fluo2))
|
||||
self.fluo2stds.append(np.std(self.fluo2))
|
||||
|
||||
self.corrTime1s.append(pearsonr(np.ravel(self.iZerocorrs), np.ravel(self.fluocorr1s))[0])
|
||||
self.corrTime2s.append(pearsonr(np.ravel(self.iZerocorrs), np.ravel(self.fluocorr2s))[0])
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
|
||||
def draw_plot(self):
|
||||
|
||||
self.plot_fluo1s.clear()
|
||||
self.plot_corr1.clear()
|
||||
self.plot_timecorr1.clear()
|
||||
self.plot_fluo2s.clear()
|
||||
self.plot_corr2.clear()
|
||||
self.plot_timecorr2.clear()
|
||||
|
||||
self.plot_fluo1s.set_xlabel('time ago, a.u.')
|
||||
self.plot_fluo1s.set_ylabel('Diode 1, a.u.')
|
||||
self.plot_corr1.set_xlabel('Izero, a.u.')
|
||||
self.plot_corr1.set_ylabel('Diode 1, a.u.')
|
||||
self.plot_timecorr1.set_xlabel('time ago, a.u.')
|
||||
self.plot_timecorr1.set_ylabel('Correlation 1')
|
||||
self.plot_fluo2s.set_xlabel('time ago, a.u.')
|
||||
self.plot_fluo2s.set_ylabel('Diode 2, a.u.')
|
||||
self.plot_corr2.set_xlabel('Izero, a.u.')
|
||||
self.plot_corr2.set_ylabel('Diode 2, a.u.')
|
||||
self.plot_timecorr2.set_xlabel('time ago, a.u.')
|
||||
self.plot_timecorr2.set_ylabel('Correlation 2')
|
||||
|
||||
self.plot_fluo1s.fill_between(np.arange(0, len(self.fluo1s)), np.asarray(self.fluo1stds)+np.asarray(self.fluo1s), -np.asarray(self.fluo1stds)+np.asarray(self.fluo1s), color='lightgreen')
|
||||
self.plot_fluo1s.set_title('Intensity: {:.4f} a.u.'.format(np.nanmean(self.fluo1s)))
|
||||
self.plot_fluo1s.plot(np.arange(0, len(self.fluo1s)), self.fluo1s, '-', color='green')
|
||||
|
||||
|
||||
self.plot_fluo2s.fill_between(np.arange(0, len(self.fluo2s)), np.asarray(self.fluo2stds)+np.asarray(self.fluo2s), -np.asarray(self.fluo2stds)+np.asarray(self.fluo2s), color='lavender')
|
||||
self.plot_fluo2s.set_title('Intensity: {:.4f} a.u.'.format(np.nanmean(self.fluo2s)))
|
||||
self.plot_fluo2s.plot(np.arange(0, len(self.fluo2s)), self.fluo2s, '-', color='purple')
|
||||
|
||||
if (len(self.corrTime1s) > histlength):
|
||||
self.plot_timecorr1.plot(np.arange(0, len(self.corrTime1s)), np.asarray(self.corrTime1s), color='green')
|
||||
self.plot_timecorr2.plot(np.arange(0, len(self.corrTime2s)), np.asarray(self.corrTime2s), color='purple')
|
||||
|
||||
self.plot_corr1.plot(np.ravel(self.iZerocorrs), np.ravel(self.fluocorr1s), '.', color='green')
|
||||
self.plot_corr1.set_title('Correlation 1: {:.4f}'.format(pearsonr(np.ravel(self.iZerocorrs), np.ravel(self.fluocorr1s))[0]))
|
||||
self.plot_corr2.plot(np.ravel(self.iZerocorrs), np.ravel(self.fluocorr2s), '.', color='purple')
|
||||
self.plot_corr2.set_title('Correlation 2: {:.4f}'.format(pearsonr(np.ravel(self.iZerocorrs), np.ravel(self.fluocorr2s))[0]))
|
||||
|
||||
self.plot_fluo1s.draw()
|
||||
self.plot_corr1.draw()
|
||||
self.plot_timecorr1.draw()
|
||||
self.plot_fluo2s.draw()
|
||||
self.plot_corr2.draw()
|
||||
self.plot_timecorr2.draw()
|
||||
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
|
||||
self.plot_fluo1s.clear()
|
||||
self.plot_corr1.clear()
|
||||
self.plot_timecorr1.clear()
|
||||
self.plot_fluo2s.clear()
|
||||
self.plot_corr2.clear()
|
||||
self.plot_timecorr2.clear()
|
||||
@@ -0,0 +1,191 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
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
|
||||
nshots = 10
|
||||
qlength = 100
|
||||
histlength = 50
|
||||
|
||||
# channels
|
||||
#chname_pbpsint = "SARFE10-PBPS053:INTENSITY"
|
||||
#chname_pbpsx = "SARFE10-PBPS053:XPOS"
|
||||
#chname_pbpsy = "SARFE10-PBPS053:YPOS"
|
||||
|
||||
chname_pbpsint = "SAROP31-PBPS113:INTENSITY"
|
||||
chname_pbpsx = "SAROP31-PBPS113:XPOS"
|
||||
chname_pbpsy = "SAROP31-PBPS113:YPOS"
|
||||
|
||||
chname_events = "SAR-CVME-TIFALL4:EvtSet"
|
||||
|
||||
# create channels
|
||||
ch_int = BS(chname_pbpsint)
|
||||
ch_x = BS(chname_pbpsx)
|
||||
ch_y = BS(chname_pbpsy)
|
||||
ch_events = BS(chname_events)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.int = np.empty(nshots)
|
||||
self.x = np.empty(nshots)
|
||||
self.y = np.empty(nshots)
|
||||
|
||||
self.ints = deque(maxlen=qlength)
|
||||
self.intstds = deque(maxlen=qlength)
|
||||
self.inthist = deque(maxlen=histlength)
|
||||
self.xs = deque(maxlen=qlength)
|
||||
self.xstds = deque(maxlen=qlength)
|
||||
self.xhist = deque(maxlen=histlength)
|
||||
self.ys = deque(maxlen=qlength)
|
||||
self.ystds = deque(maxlen=qlength)
|
||||
self.yhist = deque(maxlen=histlength)
|
||||
|
||||
self.plot_ints = plot_ints = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histI = plot_histI = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_posXs = plot_posXs = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histX = plot_histX = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_posYs = plot_posYs = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histY = plot_histY = PlotPanel(self, figsize=(2,3))
|
||||
|
||||
plots1 = (plot_ints, plot_histI)
|
||||
plots2 = (plot_posXs, plot_histX)
|
||||
plots3 = (plot_posYs, plot_histY)
|
||||
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
hb_plot3 = make_filled_hbox(plots3)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
hb_btns = make_filled_hbox(btns)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_plot3, hb_btns)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.int = np.empty(nshots)
|
||||
self.x = np.empty(nshots)
|
||||
self.y = np.empty(nshots)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_int.get()
|
||||
self.int[i] = tempb
|
||||
tempc = ch_x.get()
|
||||
self.x[i] = tempc
|
||||
tempd = ch_y.get()
|
||||
self.y[i] = tempd
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.ints.append(np.mean(self.int))
|
||||
self.intstds.append(np.std(self.int))
|
||||
self.xs.append(np.mean(self.x))
|
||||
self.xstds.append(np.std(self.x))
|
||||
self.ys.append(np.mean(self.y))
|
||||
self.ystds.append(np.std(self.y))
|
||||
|
||||
self.inthist.append(self.int)
|
||||
self.xhist.append(self.x)
|
||||
self.yhist.append(self.y)
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
|
||||
def draw_plot(self):
|
||||
self.plot_ints.clear()
|
||||
self.plot_histI.clear()
|
||||
self.plot_posXs.clear()
|
||||
self.plot_histX.clear()
|
||||
self.plot_posYs.clear()
|
||||
self.plot_histY.clear()
|
||||
|
||||
self.plot_ints.set_xlabel('time ago, a.u.')
|
||||
self.plot_ints.set_ylabel('intensity, a.u.')
|
||||
self.plot_histI.set_xlabel('intensity, a.u.')
|
||||
self.plot_histI.set_xlim(-0.1, 3)
|
||||
self.plot_posXs.set_xlabel('time ago, a.u.')
|
||||
self.plot_posXs.set_ylabel('position X, mm')
|
||||
self.plot_histX.set_xlabel('position X, mm')
|
||||
self.plot_histX.set_xlim(-0.5, 0.5)
|
||||
self.plot_posYs.set_xlabel('time ago, a.u.')
|
||||
self.plot_posYs.set_ylabel('position Y, mm')
|
||||
self.plot_histY.set_xlabel('position Y, mm')
|
||||
self.plot_histY.set_xlim(-0.5, 0.5)
|
||||
|
||||
self.plot_ints.fill_between(np.arange(0, len(self.ints)), np.asarray(self.intstds)+np.asarray(self.ints), -np.asarray(self.intstds)+np.asarray(self.ints), color='gold')
|
||||
self.plot_ints.plot(np.arange(0, len(self.ints)), self.ints, '-', color='orangered')
|
||||
|
||||
self.plot_posXs.fill_between(np.arange(0, len(self.xs)), np.asarray(self.xstds)+np.asarray(self.xs), -np.asarray(self.xstds)+np.asarray(self.xs), color='lightskyblue')
|
||||
self.plot_posXs.plot(np.arange(0, len(self.xs)), self.xs, '-', color='dodgerblue')
|
||||
self.plot_posXs.axhline(y=0, color='k', linestyle="--")
|
||||
|
||||
self.plot_posYs.fill_between(np.arange(0, len(self.ys)), np.asarray(self.ystds)+np.asarray(self.ys), -np.asarray(self.ystds)+np.asarray(self.ys), color='lightgreen')
|
||||
self.plot_posYs.plot(np.arange(0, len(self.ys)), self.ys, '-', color='green')
|
||||
self.plot_posYs.axhline(y=0, color='k', linestyle="--")
|
||||
|
||||
#if (len(self.int) > 0):
|
||||
#self.plot_histI.hist(self.int, facecolor='orangered')#, edgecolor='black')
|
||||
self.plot_histI.hist(np.ravel(self.inthist), facecolor='orangered', edgecolor='black')
|
||||
self.plot_histI.axvline(x=np.mean(self.inthist), color='k', linestyle="--")
|
||||
self.plot_histI.set_title('Intensity: {:.4f} a.u.'.format(np.nanmean(self.inthist)))
|
||||
self.plot_histX.hist(np.ravel(self.xhist), facecolor='dodgerblue', edgecolor='black')
|
||||
self.plot_histX.set_title('Position X: {:.4f} mm'.format(np.nanmean(self.xhist)))
|
||||
self.plot_histX.axvline(x=np.mean(self.xhist), color='k', linestyle="--")
|
||||
self.plot_histY.hist(np.ravel(self.yhist), facecolor='green', edgecolor='black')
|
||||
self.plot_histY.set_title('Position Y: {:.4f} mm'.format(np.nanmean(self.yhist)))
|
||||
self.plot_histY.axvline(x=np.mean(self.yhist), color='k', linestyle="--")
|
||||
|
||||
self.plot_ints.draw()
|
||||
self.plot_posXs.draw()
|
||||
self.plot_posYs.draw()
|
||||
|
||||
self.plot_histI.draw()
|
||||
self.plot_histX.draw()
|
||||
self.plot_histY.draw()
|
||||
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
|
||||
self.ints.clear()
|
||||
self.intstds.clear()
|
||||
self.xs.clear()
|
||||
self.xstds.clear()
|
||||
self.ys.clear()
|
||||
self.ystds.clear()
|
||||
self.inthist.clear()
|
||||
self.xhist.clear()
|
||||
self.yhist.clear()
|
||||
@@ -0,0 +1,209 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
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
|
||||
nshots = 100
|
||||
qlength = 100
|
||||
histlength = 100
|
||||
quantile = 0.8
|
||||
|
||||
# channels
|
||||
chname_pbpsint = "SAROP11-PBPS110:INTENSITY"
|
||||
chname_pbpsx = "SAROP11-PBPS110:XPOS"
|
||||
chname_pbpsy = "SAROP11-PBPS110:YPOS"
|
||||
chname_events = "SAR-CVME-TIFALL4:EvtSet"
|
||||
|
||||
# create channels
|
||||
ch_int = BS(chname_pbpsint)
|
||||
ch_x = BS(chname_pbpsx)
|
||||
ch_y = BS(chname_pbpsy)
|
||||
ch_events = BS(chname_events)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
def filter_outliers(quantile, a):
|
||||
low = np.nanquantile(a, 0.5 - quantile/2)
|
||||
high = np.nanquantile(a, 0.5 + quantile/2)
|
||||
|
||||
cond_low = a > low
|
||||
cond_high = a < high
|
||||
cond = cond_low & cond_high
|
||||
|
||||
return a[cond]
|
||||
|
||||
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.int = np.empty(nshots)
|
||||
self.x = np.empty(nshots)
|
||||
self.y = np.empty(nshots)
|
||||
|
||||
self.ints = deque(maxlen=qlength)
|
||||
self.intstds = deque(maxlen=qlength)
|
||||
self.inthist = deque(maxlen=histlength)
|
||||
self.xs = deque(maxlen=qlength)
|
||||
self.xstds = deque(maxlen=qlength)
|
||||
self.xhist = deque(maxlen=histlength)
|
||||
self.ys = deque(maxlen=qlength)
|
||||
self.ystds = deque(maxlen=qlength)
|
||||
self.yhist = deque(maxlen=histlength)
|
||||
|
||||
self.plot_ints = plot_ints = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histI = plot_histI = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_posXs = plot_posXs = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histX = plot_histX = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_posYs = plot_posYs = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histY = plot_histY = PlotPanel(self, figsize=(2,3))
|
||||
|
||||
plots1 = (plot_ints, plot_histI)
|
||||
plots2 = (plot_posXs, plot_histX)
|
||||
plots3 = (plot_posYs, plot_histY)
|
||||
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
hb_plot3 = make_filled_hbox(plots3)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
hb_btns = make_filled_hbox(btns)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_plot3, hb_btns)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.int = np.empty(nshots, dtype=object)
|
||||
self.x = np.empty(nshots, dtype=object)
|
||||
self.y = np.empty(nshots, dtype=object)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_int.get()
|
||||
self.int[i] = tempb
|
||||
tempc = ch_x.get()
|
||||
self.x[i] = tempc
|
||||
tempd = ch_y.get()
|
||||
self.y[i] = tempd
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.x = filter_outliers(quantile, self.x)
|
||||
self.y = filter_outliers(quantile, self.y)
|
||||
|
||||
self.ints.append(np.mean(self.int))
|
||||
self.intstds.append(np.std(self.int))
|
||||
self.xs.append(np.mean(self.x))
|
||||
self.xstds.append(np.std(self.x))
|
||||
self.ys.append(np.mean(self.y))
|
||||
self.ystds.append(np.std(self.y))
|
||||
|
||||
self.inthist.extend(self.int)
|
||||
self.xhist.extend(self.x)
|
||||
self.yhist.extend(self.y)
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
|
||||
def draw_plot(self):
|
||||
self.plot_ints.clear()
|
||||
self.plot_histI.clear()
|
||||
self.plot_posXs.clear()
|
||||
self.plot_histX.clear()
|
||||
self.plot_posYs.clear()
|
||||
self.plot_histY.clear()
|
||||
|
||||
self.plot_ints.set_xlabel('time ago, a.u.')
|
||||
self.plot_ints.set_ylabel('intensity, a.u.')
|
||||
self.plot_histI.set_xlabel('intensity, a.u.')
|
||||
self.plot_histI.set_xlim(-0.1, 3)
|
||||
self.plot_posXs.set_xlabel('time ago, a.u.')
|
||||
self.plot_posXs.set_ylabel('position X, mm')
|
||||
self.plot_histX.set_xlabel('position X, mm')
|
||||
self.plot_histX.set_xlim(-0.2, 0.2)
|
||||
self.plot_posYs.set_xlabel('time ago, a.u.')
|
||||
self.plot_posYs.set_ylabel('position Y, mm')
|
||||
self.plot_histY.set_xlabel('position Y, mm')
|
||||
self.plot_histY.set_xlim(-0.2, 0.2)
|
||||
|
||||
self.plot_ints.fill_between(np.arange(0, len(self.ints)), np.asarray(self.intstds)+np.asarray(self.ints), -np.asarray(self.intstds)+np.asarray(self.ints), color='gold')
|
||||
self.plot_ints.plot(np.arange(0, len(self.ints)), self.ints, '-', color='orangered')
|
||||
self.plot_ints.axhline(y=1, color='k', linestyle="--")
|
||||
|
||||
self.plot_posXs.fill_between(np.arange(0, len(self.xs)), np.asarray(self.xstds)+np.asarray(self.xs), -np.asarray(self.xstds)+np.asarray(self.xs), color='lightskyblue')
|
||||
self.plot_posXs.plot(np.arange(0, len(self.xs)), self.xs, '-', color='dodgerblue')
|
||||
self.plot_posXs.axhline(y=0, color='k', linestyle="--")
|
||||
|
||||
self.plot_posYs.fill_between(np.arange(0, len(self.ys)), np.asarray(self.ystds)+np.asarray(self.ys), -np.asarray(self.ystds)+np.asarray(self.ys), color='lightgreen')
|
||||
self.plot_posYs.plot(np.arange(0, len(self.ys)), self.ys, '-', color='green')
|
||||
self.plot_posYs.axhline(y=0, color='k', linestyle="--")
|
||||
|
||||
#if (len(self.int) > 0):
|
||||
#self.plot_histI.hist(self.int, facecolor='orangered')#, edgecolor='black')
|
||||
|
||||
#self.plot_histI.hist(np.ravel(self.inthist), facecolor='orangered', edgecolor='black')
|
||||
self.inthist2plot = np.array(self.inthist, dtype=object)
|
||||
self.xhist2plot = np.array(self.xhist, dtype=object)
|
||||
self.yhist2plot = np.array(self.yhist, dtype=object)
|
||||
|
||||
self.plot_histI.hist(np.ravel(self.inthist2plot), facecolor='orangered', edgecolor='black')
|
||||
self.plot_histI.axvline(x=np.mean(self.inthist), color='k', linestyle="--")
|
||||
self.plot_histI.set_title('Intensity: {:.4f} a.u.'.format(np.mean(np.ravel(self.inthist2plot))))
|
||||
#self.plot_histX.hist(np.ravel(self.xhist), facecolor='dodgerblue', edgecolor='black')
|
||||
self.plot_histX.hist(np.ravel(self.xhist2plot), facecolor='dodgerblue', edgecolor='black')
|
||||
self.plot_histX.set_title('Position X: {:.2f} +/- {:.2f} um'.format(np.mean(np.ravel(self.xhist2plot))*1000, np.std(self.xhist)*1000))
|
||||
self.plot_histX.axvline(x=np.mean(self.xhist), color='k', linestyle="--")
|
||||
#self.plot_histY.hist(np.ravel(self.yhist), facecolor='green', edgecolor='black')
|
||||
self.plot_histY.hist(np.ravel(self.yhist2plot), facecolor='green', edgecolor='black')
|
||||
self.plot_histY.set_title('Position Y: {:.2f} +/- {:.2f} um'.format(np.mean(np.ravel(self.yhist2plot))*1000, np.std(self.yhist)*1000))
|
||||
self.plot_histY.axvline(x=np.mean(self.yhist), color='k', linestyle="--")
|
||||
|
||||
self.plot_ints.draw()
|
||||
self.plot_posXs.draw()
|
||||
self.plot_posYs.draw()
|
||||
|
||||
self.plot_histI.draw()
|
||||
self.plot_histX.draw()
|
||||
self.plot_histY.draw()
|
||||
|
||||
print ('{} -- X = {:.2f} -- Y = {:.2f} -- Int = {:.4f}'.format(self.time, np.mean(np.ravel(self.xhist2plot))*1000, np.mean(np.ravel(self.yhist2plot))*1000, np.mean(np.ravel(self.inthist2plot))))
|
||||
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
|
||||
self.ints.clear()
|
||||
self.intstds.clear()
|
||||
self.xs.clear()
|
||||
self.xstds.clear()
|
||||
self.ys.clear()
|
||||
self.ystds.clear()
|
||||
@@ -0,0 +1,209 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
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
|
||||
nshots = 100
|
||||
qlength = 100
|
||||
histlength = 100
|
||||
quantile = 0.8
|
||||
|
||||
# channels
|
||||
chname_pbpsint = "SAROP11-PBPS122:INTENSITY"
|
||||
chname_pbpsx = "SAROP11-PBPS122:XPOS"
|
||||
chname_pbpsy = "SAROP11-PBPS122:YPOS"
|
||||
chname_events = "SAR-CVME-TIFALL4:EvtSet"
|
||||
|
||||
# create channels
|
||||
ch_int = BS(chname_pbpsint)
|
||||
ch_x = BS(chname_pbpsx)
|
||||
ch_y = BS(chname_pbpsy)
|
||||
ch_events = BS(chname_events)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
def filter_outliers(quantile, a):
|
||||
low = np.nanquantile(a, 0.5 - quantile/2)
|
||||
high = np.nanquantile(a, 0.5 + quantile/2)
|
||||
|
||||
cond_low = a > low
|
||||
cond_high = a < high
|
||||
cond = cond_low & cond_high
|
||||
|
||||
return a[cond]
|
||||
|
||||
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.int = np.empty(nshots)
|
||||
self.x = np.empty(nshots)
|
||||
self.y = np.empty(nshots)
|
||||
|
||||
self.ints = deque(maxlen=qlength)
|
||||
self.intstds = deque(maxlen=qlength)
|
||||
self.inthist = deque(maxlen=histlength)
|
||||
self.xs = deque(maxlen=qlength)
|
||||
self.xstds = deque(maxlen=qlength)
|
||||
self.xhist = deque(maxlen=histlength)
|
||||
self.ys = deque(maxlen=qlength)
|
||||
self.ystds = deque(maxlen=qlength)
|
||||
self.yhist = deque(maxlen=histlength)
|
||||
|
||||
self.plot_ints = plot_ints = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histI = plot_histI = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_posXs = plot_posXs = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histX = plot_histX = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_posYs = plot_posYs = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histY = plot_histY = PlotPanel(self, figsize=(2,3))
|
||||
|
||||
plots1 = (plot_ints, plot_histI)
|
||||
plots2 = (plot_posXs, plot_histX)
|
||||
plots3 = (plot_posYs, plot_histY)
|
||||
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
hb_plot3 = make_filled_hbox(plots3)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
hb_btns = make_filled_hbox(btns)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_plot3, hb_btns)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.int = np.empty(nshots, dtype=object)
|
||||
self.x = np.empty(nshots, dtype=object)
|
||||
self.y = np.empty(nshots, dtype=object)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_int.get()
|
||||
self.int[i] = tempb
|
||||
tempc = ch_x.get()
|
||||
self.x[i] = tempc
|
||||
tempd = ch_y.get()
|
||||
self.y[i] = tempd
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.x = filter_outliers(quantile, self.x)
|
||||
self.y = filter_outliers(quantile, self.y)
|
||||
|
||||
self.ints.append(np.mean(self.int))
|
||||
self.intstds.append(np.std(self.int))
|
||||
self.xs.append(np.mean(self.x))
|
||||
self.xstds.append(np.std(self.x))
|
||||
self.ys.append(np.mean(self.y))
|
||||
self.ystds.append(np.std(self.y))
|
||||
|
||||
self.inthist.extend(self.int)
|
||||
self.xhist.extend(self.x)
|
||||
self.yhist.extend(self.y)
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
|
||||
def draw_plot(self):
|
||||
self.plot_ints.clear()
|
||||
self.plot_histI.clear()
|
||||
self.plot_posXs.clear()
|
||||
self.plot_histX.clear()
|
||||
self.plot_posYs.clear()
|
||||
self.plot_histY.clear()
|
||||
|
||||
self.plot_ints.set_xlabel('time ago, a.u.')
|
||||
self.plot_ints.set_ylabel('intensity, a.u.')
|
||||
self.plot_histI.set_xlabel('intensity, a.u.')
|
||||
self.plot_histI.set_xlim(-0.1, 3)
|
||||
self.plot_posXs.set_xlabel('time ago, a.u.')
|
||||
self.plot_posXs.set_ylabel('position X, mm')
|
||||
self.plot_histX.set_xlabel('position X, mm')
|
||||
self.plot_histX.set_xlim(-0.2, 0.2)
|
||||
self.plot_posYs.set_xlabel('time ago, a.u.')
|
||||
self.plot_posYs.set_ylabel('position Y, mm')
|
||||
self.plot_histY.set_xlabel('position Y, mm')
|
||||
self.plot_histY.set_xlim(-0.2, 0.2)
|
||||
|
||||
self.plot_ints.fill_between(np.arange(0, len(self.ints)), np.asarray(self.intstds)+np.asarray(self.ints), -np.asarray(self.intstds)+np.asarray(self.ints), color='gold')
|
||||
self.plot_ints.plot(np.arange(0, len(self.ints)), self.ints, '-', color='orangered')
|
||||
self.plot_ints.axhline(y=1, color='k', linestyle="--")
|
||||
|
||||
self.plot_posXs.fill_between(np.arange(0, len(self.xs)), np.asarray(self.xstds)+np.asarray(self.xs), -np.asarray(self.xstds)+np.asarray(self.xs), color='lightskyblue')
|
||||
self.plot_posXs.plot(np.arange(0, len(self.xs)), self.xs, '-', color='dodgerblue')
|
||||
self.plot_posXs.axhline(y=0, color='k', linestyle="--")
|
||||
|
||||
self.plot_posYs.fill_between(np.arange(0, len(self.ys)), np.asarray(self.ystds)+np.asarray(self.ys), -np.asarray(self.ystds)+np.asarray(self.ys), color='lightgreen')
|
||||
self.plot_posYs.plot(np.arange(0, len(self.ys)), self.ys, '-', color='green')
|
||||
self.plot_posYs.axhline(y=0, color='k', linestyle="--")
|
||||
|
||||
#if (len(self.int) > 0):
|
||||
#self.plot_histI.hist(self.int, facecolor='orangered')#, edgecolor='black')
|
||||
|
||||
#self.plot_histI.hist(np.ravel(self.inthist), facecolor='orangered', edgecolor='black')
|
||||
self.inthist2plot = np.array(self.inthist, dtype=object)
|
||||
self.xhist2plot = np.array(self.xhist, dtype=object)
|
||||
self.yhist2plot = np.array(self.yhist, dtype=object)
|
||||
|
||||
self.plot_histI.hist(np.ravel(self.inthist2plot), facecolor='orangered', edgecolor='black')
|
||||
self.plot_histI.axvline(x=np.mean(self.inthist), color='k', linestyle="--")
|
||||
self.plot_histI.set_title('Intensity: {:.4f} a.u.'.format(np.mean(np.ravel(self.inthist2plot))))
|
||||
#self.plot_histX.hist(np.ravel(self.xhist), facecolor='dodgerblue', edgecolor='black')
|
||||
self.plot_histX.hist(np.ravel(self.xhist2plot), facecolor='dodgerblue', edgecolor='black')
|
||||
self.plot_histX.set_title('Position X: {:.2f} +/- {:.2f} um'.format(np.mean(np.ravel(self.xhist2plot))*1000, np.std(self.xhist)*1000))
|
||||
self.plot_histX.axvline(x=np.mean(self.xhist), color='k', linestyle="--")
|
||||
#self.plot_histY.hist(np.ravel(self.yhist), facecolor='green', edgecolor='black')
|
||||
self.plot_histY.hist(np.ravel(self.yhist2plot), facecolor='green', edgecolor='black')
|
||||
self.plot_histY.set_title('Position Y: {:.2f} +/- {:.2f} um'.format(np.mean(np.ravel(self.yhist2plot))*1000, np.std(self.yhist)*1000))
|
||||
self.plot_histY.axvline(x=np.mean(self.yhist), color='k', linestyle="--")
|
||||
|
||||
self.plot_ints.draw()
|
||||
self.plot_posXs.draw()
|
||||
self.plot_posYs.draw()
|
||||
|
||||
self.plot_histI.draw()
|
||||
self.plot_histX.draw()
|
||||
self.plot_histY.draw()
|
||||
|
||||
print ('{} -- X = {:.2f} -- Y = {:.2f} -- Int = {:.4f}'.format(self.time, np.mean(np.ravel(self.xhist2plot))*1000, np.mean(np.ravel(self.yhist2plot))*1000, np.mean(np.ravel(self.inthist2plot))))
|
||||
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
|
||||
self.ints.clear()
|
||||
self.intstds.clear()
|
||||
self.xs.clear()
|
||||
self.xstds.clear()
|
||||
self.ys.clear()
|
||||
self.ystds.clear()
|
||||
@@ -0,0 +1,209 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
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
|
||||
nshots = 100
|
||||
qlength = 100
|
||||
histlength = 100
|
||||
quantile = 0.8
|
||||
|
||||
# channels
|
||||
chname_pbpsint = "SAROP31-PBPS149:INTENSITY"
|
||||
chname_pbpsx = "SAROP31-PBPS149:XPOS"
|
||||
chname_pbpsy = "SAROP31-PBPS149:YPOS"
|
||||
chname_events = "SAR-CVME-TIFALL6:EvtSet"
|
||||
|
||||
# create channels
|
||||
ch_int = BS(chname_pbpsint)
|
||||
ch_x = BS(chname_pbpsx)
|
||||
ch_y = BS(chname_pbpsy)
|
||||
ch_events = BS(chname_events)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
def filter_outliers(quantile, a):
|
||||
low = np.nanquantile(a, 0.5 - quantile/2)
|
||||
high = np.nanquantile(a, 0.5 + quantile/2)
|
||||
|
||||
cond_low = a > low
|
||||
cond_high = a < high
|
||||
cond = cond_low & cond_high
|
||||
|
||||
return a[cond]
|
||||
|
||||
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.int = np.empty(nshots)
|
||||
self.x = np.empty(nshots)
|
||||
self.y = np.empty(nshots)
|
||||
|
||||
self.ints = deque(maxlen=qlength)
|
||||
self.intstds = deque(maxlen=qlength)
|
||||
self.inthist = deque(maxlen=histlength)
|
||||
self.xs = deque(maxlen=qlength)
|
||||
self.xstds = deque(maxlen=qlength)
|
||||
self.xhist = deque(maxlen=histlength)
|
||||
self.ys = deque(maxlen=qlength)
|
||||
self.ystds = deque(maxlen=qlength)
|
||||
self.yhist = deque(maxlen=histlength)
|
||||
|
||||
self.plot_ints = plot_ints = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histI = plot_histI = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_posXs = plot_posXs = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histX = plot_histX = PlotPanel(self, figsize=(2,3))
|
||||
self.plot_posYs = plot_posYs = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_histY = plot_histY = PlotPanel(self, figsize=(2,3))
|
||||
|
||||
plots1 = (plot_ints, plot_histI)
|
||||
plots2 = (plot_posXs, plot_histX)
|
||||
plots3 = (plot_posYs, plot_histY)
|
||||
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
hb_plot3 = make_filled_hbox(plots3)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
hb_btns = make_filled_hbox(btns)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_plot3, hb_btns)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.int = np.empty(nshots, dtype=object)
|
||||
self.x = np.empty(nshots, dtype=object)
|
||||
self.y = np.empty(nshots, dtype=object)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_int.get()
|
||||
self.int[i] = tempb
|
||||
tempc = ch_x.get()
|
||||
self.x[i] = tempc
|
||||
tempd = ch_y.get()
|
||||
self.y[i] = tempd
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.x = filter_outliers(quantile, self.x)
|
||||
self.y = filter_outliers(quantile, self.y)
|
||||
|
||||
self.ints.append(np.mean(self.int))
|
||||
self.intstds.append(np.std(self.int))
|
||||
self.xs.append(np.mean(self.x))
|
||||
self.xstds.append(np.std(self.x))
|
||||
self.ys.append(np.mean(self.y))
|
||||
self.ystds.append(np.std(self.y))
|
||||
|
||||
self.inthist.extend(self.int)
|
||||
self.xhist.extend(self.x)
|
||||
self.yhist.extend(self.y)
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
|
||||
def draw_plot(self):
|
||||
self.plot_ints.clear()
|
||||
self.plot_histI.clear()
|
||||
self.plot_posXs.clear()
|
||||
self.plot_histX.clear()
|
||||
self.plot_posYs.clear()
|
||||
self.plot_histY.clear()
|
||||
|
||||
self.plot_ints.set_xlabel('time ago, a.u.')
|
||||
self.plot_ints.set_ylabel('intensity, a.u.')
|
||||
self.plot_histI.set_xlabel('intensity, a.u.')
|
||||
self.plot_histI.set_xlim(-0.1, 3)
|
||||
self.plot_posXs.set_xlabel('time ago, a.u.')
|
||||
self.plot_posXs.set_ylabel('position X, mm')
|
||||
self.plot_histX.set_xlabel('position X, mm')
|
||||
self.plot_histX.set_xlim(-0.2, 0.2)
|
||||
self.plot_posYs.set_xlabel('time ago, a.u.')
|
||||
self.plot_posYs.set_ylabel('position Y, mm')
|
||||
self.plot_histY.set_xlabel('position Y, mm')
|
||||
self.plot_histY.set_xlim(-0.2, 0.2)
|
||||
|
||||
self.plot_ints.fill_between(np.arange(0, len(self.ints)), np.asarray(self.intstds)+np.asarray(self.ints), -np.asarray(self.intstds)+np.asarray(self.ints), color='gold')
|
||||
self.plot_ints.plot(np.arange(0, len(self.ints)), self.ints, '-', color='orangered')
|
||||
self.plot_ints.axhline(y=1, color='k', linestyle="--")
|
||||
|
||||
self.plot_posXs.fill_between(np.arange(0, len(self.xs)), np.asarray(self.xstds)+np.asarray(self.xs), -np.asarray(self.xstds)+np.asarray(self.xs), color='lightskyblue')
|
||||
self.plot_posXs.plot(np.arange(0, len(self.xs)), self.xs, '-', color='dodgerblue')
|
||||
self.plot_posXs.axhline(y=0, color='k', linestyle="--")
|
||||
|
||||
self.plot_posYs.fill_between(np.arange(0, len(self.ys)), np.asarray(self.ystds)+np.asarray(self.ys), -np.asarray(self.ystds)+np.asarray(self.ys), color='lightgreen')
|
||||
self.plot_posYs.plot(np.arange(0, len(self.ys)), self.ys, '-', color='green')
|
||||
self.plot_posYs.axhline(y=0, color='k', linestyle="--")
|
||||
|
||||
#if (len(self.int) > 0):
|
||||
#self.plot_histI.hist(self.int, facecolor='orangered')#, edgecolor='black')
|
||||
|
||||
#self.plot_histI.hist(np.ravel(self.inthist), facecolor='orangered', edgecolor='black')
|
||||
self.inthist2plot = np.array(self.inthist, dtype=object)
|
||||
self.xhist2plot = np.array(self.xhist, dtype=object)
|
||||
self.yhist2plot = np.array(self.yhist, dtype=object)
|
||||
|
||||
self.plot_histI.hist(np.ravel(self.inthist2plot), facecolor='orangered', edgecolor='black')
|
||||
self.plot_histI.axvline(x=np.mean(self.inthist), color='k', linestyle="--")
|
||||
self.plot_histI.set_title('Intensity: {:.4f} a.u.'.format(np.mean(np.ravel(self.inthist2plot))))
|
||||
#self.plot_histX.hist(np.ravel(self.xhist), facecolor='dodgerblue', edgecolor='black')
|
||||
self.plot_histX.hist(np.ravel(self.xhist2plot), facecolor='dodgerblue', edgecolor='black')
|
||||
self.plot_histX.set_title('Position X: {:.2f} +/- {:.2f} um'.format(np.mean(np.ravel(self.xhist2plot))*1000, np.std(self.xhist)*1000))
|
||||
self.plot_histX.axvline(x=np.mean(self.xhist), color='k', linestyle="--")
|
||||
#self.plot_histY.hist(np.ravel(self.yhist), facecolor='green', edgecolor='black')
|
||||
self.plot_histY.hist(np.ravel(self.yhist2plot), facecolor='green', edgecolor='black')
|
||||
self.plot_histY.set_title('Position Y: {:.2f} +/- {:.2f} um'.format(np.mean(np.ravel(self.yhist2plot))*1000, np.std(self.yhist)*1000))
|
||||
self.plot_histY.axvline(x=np.mean(self.yhist), color='k', linestyle="--")
|
||||
|
||||
self.plot_ints.draw()
|
||||
self.plot_posXs.draw()
|
||||
self.plot_posYs.draw()
|
||||
|
||||
self.plot_histI.draw()
|
||||
self.plot_histX.draw()
|
||||
self.plot_histY.draw()
|
||||
|
||||
print ('{} -- X = {:.2f} -- Y = {:.2f} -- Int = {:.4f}'.format(self.time, np.mean(np.ravel(self.xhist2plot))*1000, np.mean(np.ravel(self.yhist2plot))*1000, np.mean(np.ravel(self.inthist2plot))))
|
||||
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
|
||||
self.ints.clear()
|
||||
self.intstds.clear()
|
||||
self.xs.clear()
|
||||
self.xstds.clear()
|
||||
self.ys.clear()
|
||||
self.ystds.clear()
|
||||
@@ -0,0 +1,176 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
from slic.gui.widgets import make_filled_hbox, make_filled_vbox, EXPANDING
|
||||
from slic.gui.widgets.plotting import PlotPanel
|
||||
|
||||
from bstrd import BS, bsstream
|
||||
|
||||
def unpumped(events, *arrays):
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
background_shots = np.logical_and.reduce((laser, darkShot))
|
||||
return [a[background_shots] for a in arrays]
|
||||
|
||||
def pumped(events, *arrays):
|
||||
fel = events[:, 13]
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
|
||||
return [a[pumped_shots] for a in arrays]
|
||||
|
||||
|
||||
# config
|
||||
nshots = 1000
|
||||
qlength = 100
|
||||
|
||||
# channels
|
||||
|
||||
chname_diode = "SARES11-GES1:PR1_CH1_VAL_GET" #Prime Keysight
|
||||
#chname_diode = "SARES12-GES1:PR1_CH1_VAL_GET" #Flex Keysight
|
||||
#chname_diode = "SLAAR11-LSCP1-FNS:CH0:VAL_GET" #Laser IoXos
|
||||
|
||||
chname_energy = "SARES11-CVME-EVR0:DUMMY_PV3_NBS"
|
||||
chname_i0 = "SAROP11-PBPS110:INTENSITY"
|
||||
chname_events = "SAR-CVME-TIFALL4:EvtSet"
|
||||
|
||||
ENERGYpv = epics.PV('SAROP11-ARAMIS:ENERGY')
|
||||
|
||||
# create channels
|
||||
ch_diode = BS(chname_diode)
|
||||
ch_i0 = BS(chname_i0)
|
||||
ch_events = BS(chname_events)
|
||||
ch_energy = BS(chname_energy)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.diode = np.empty(nshots)
|
||||
self.i0 = np.empty(nshots)
|
||||
self.energy = np.empty(nshots)
|
||||
self.diode_p_norm = np.empty(nshots)
|
||||
self.diode_u_norm = np.empty(nshots)
|
||||
|
||||
self.nrgs_p = deque(maxlen=qlength)
|
||||
self.diodes_p = deque(maxlen=qlength)
|
||||
self.diodes_pstd = deque(maxlen=qlength)
|
||||
self.diodes_u = deque(maxlen=qlength)
|
||||
self.diodes_ustd = deque(maxlen=qlength)
|
||||
self.pp = deque(maxlen=qlength)
|
||||
self.ppstd = deque(maxlen=qlength)
|
||||
|
||||
self.plot_diodes = plot_diodes = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_pp = plot_pp = PlotPanel(self, figsize=(6,3))
|
||||
|
||||
plots1 = (plot_diodes,)
|
||||
plots2 = (plot_pp,)
|
||||
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
hb_btns = make_filled_hbox(btns)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_btns)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.diode = np.empty(nshots)
|
||||
self.i0 = np.empty(nshots)
|
||||
self.energy = np.empty(nshots)
|
||||
|
||||
self.current_energy = ENERGYpv.get()
|
||||
#self.energy_axis_pv.append(self.current_energy)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_diode.get()
|
||||
self.diode[i] = tempb
|
||||
tempc = ch_i0.get()
|
||||
self.i0[i] = tempc
|
||||
tempd = ch_energy.get()
|
||||
self.energy[i] = tempd
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.nrg_p = pumped(self.evts, self.energy)
|
||||
self.diode_p = pumped(self.evts, self.diode)
|
||||
self.diode_u = unpumped(self.evts, self.diode)
|
||||
self.i0_p = pumped(self.evts, self.i0)
|
||||
self.i0_u = unpumped(self.evts, self.i0)
|
||||
|
||||
self.diode_p_norm = np.asarray(self.diode_p)/np.asarray(self.i0_p)
|
||||
self.diode_u_norm = np.asarray(self.diode_u)/np.asarray(self.i0_u)
|
||||
pump = np.nanmean(self.diode_p_norm)
|
||||
unpump = np.nanmean(self.diode_u_norm)
|
||||
pump_e = np.nanstd(self.diode_p_norm)
|
||||
unpump_e = np.nanstd(self.diode_u_norm)
|
||||
pp_e = np.sqrt((pump_e/pump)**2+(unpump_e/unpump)**2)
|
||||
|
||||
self.nrgs_p.append(np.nanmean(self.nrg_p))
|
||||
self.diodes_p.append(pump)
|
||||
self.diodes_pstd.append(pump_e)
|
||||
self.diodes_u.append(unpump)
|
||||
self.diodes_ustd.append(unpump_e)
|
||||
#self.pp.append(-np.log10(pump/unpump))
|
||||
self.pp.append(pump - unpump)
|
||||
|
||||
#self.ppstd.append(pp_e/((pump/unpump)*np.log(10)))
|
||||
self.ppstd.append(np.sqrt(pump**2+unpump**2))
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
def draw_plot(self):
|
||||
self.plot_diodes.clear()
|
||||
self.plot_pp.clear()
|
||||
|
||||
self.plot_diodes.set_xlabel('Energy (eV)')
|
||||
self.plot_diodes.set_ylabel('intensity, a.u.')
|
||||
|
||||
self.plot_pp.set_xlabel('Energy (eV)')
|
||||
self.plot_pp.set_ylabel('Absorbance')
|
||||
|
||||
self.plot_diodes.plot(self.nrgs_p, self.diodes_p, '-', color='royalblue', label='on')
|
||||
self.plot_diodes.plot(self.nrgs_p, self.diodes_u, '-', color='orange', label='off')
|
||||
self.plot_diodes.legend(loc='lower left')
|
||||
self.plot_pp.plot(self.nrgs_p, self.pp, '-', color='green')
|
||||
#self.plot_pp.fill_between(np.arange(0, len(self.pp)), np.asarray(self.ppstd)+np.asarray(self.pp), -np.asarray(self.ppstd)+np.asarray(self.pp), color='lightgreen')
|
||||
#self.plot_pp.set_ylim(-1)
|
||||
self.plot_pp.grid()
|
||||
|
||||
self.plot_diodes.draw()
|
||||
self.plot_pp.draw()
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
|
||||
self.diodes_p.clear()
|
||||
self.diodes_u.clear()
|
||||
self.pp.clear()
|
||||
self.ppstd.clear()
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
from collections import deque
|
||||
import random
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
from slic.gui.widgets import make_filled_hbox, make_filled_vbox, EXPANDING
|
||||
from slic.gui.widgets.plotting import PlotPanel
|
||||
|
||||
from bstrd import BS, bsstream
|
||||
|
||||
def unpumped(events, *arrays):
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
background_shots = np.logical_and.reduce((laser, darkShot))
|
||||
return [a[background_shots] for a in arrays]
|
||||
|
||||
def pumped(events, *arrays):
|
||||
fel = events[:, 13]
|
||||
laser = events[:, 18]
|
||||
darkShot = events[:, 21]
|
||||
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
|
||||
return [a[pumped_shots] for a in arrays]
|
||||
|
||||
|
||||
# config
|
||||
nshots = 50
|
||||
qlength = 100
|
||||
|
||||
# channels
|
||||
#chname_diode = "SLAAR11-LSCP1-FNS:CH0:VAL_GET"
|
||||
chname_diode = "SAROP11-GES1:PR1_CH1_VAL_GET"
|
||||
#chname_diode = "SARES11-GES1:PR1_CH1_VAL_GET"
|
||||
chname_i0 = "SAROP11-PBPS110:INTENSITY"
|
||||
chname_events = "SAR-CVME-TIFALL5:EvtSet"
|
||||
|
||||
# create channels
|
||||
ch_diode = BS(chname_diode)
|
||||
ch_i0 = BS(chname_i0)
|
||||
ch_events = BS(chname_events)
|
||||
|
||||
iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.diode = np.empty(nshots)
|
||||
self.i0 = np.empty(nshots)
|
||||
self.diode_p_norm = np.empty(nshots)
|
||||
self.diode_u_norm = np.empty(nshots)
|
||||
|
||||
self.diodes_p = deque(maxlen=qlength)
|
||||
self.diodes_pstd = deque(maxlen=qlength)
|
||||
self.diodes_u = deque(maxlen=qlength)
|
||||
self.diodes_ustd = deque(maxlen=qlength)
|
||||
self.pp = deque(maxlen=qlength)
|
||||
self.ppstd = deque(maxlen=qlength)
|
||||
|
||||
self.plot_diodes = plot_diodes = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_pp = plot_pp = PlotPanel(self, figsize=(6,3))
|
||||
|
||||
plots1 = (plot_diodes,)
|
||||
plots2 = (plot_pp,)
|
||||
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
hb_btns = make_filled_hbox(btns)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_btns)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.diode = np.empty(nshots)
|
||||
self.i0 = np.empty(nshots)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_diode.get()
|
||||
self.diode[i] = tempb
|
||||
tempc = ch_i0.get()
|
||||
self.i0[i] = tempc
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.diode_p = pumped(self.evts, self.diode)
|
||||
self.diode_u = unpumped(self.evts, self.diode)
|
||||
self.i0_p = pumped(self.evts, self.i0)
|
||||
self.i0_u = unpumped(self.evts, self.i0)
|
||||
|
||||
self.diode_p_norm = np.asarray(self.diode_p)#/np.asarray(self.i0_p)
|
||||
self.diode_u_norm = np.asarray(self.diode_u)#/np.asarray(self.i0_u)
|
||||
pump = np.nanmean(self.diode_p_norm)
|
||||
unpump = np.nanmean(self.diode_u_norm)
|
||||
pump_e = np.nanstd(self.diode_p_norm)
|
||||
unpump_e = np.nanstd(self.diode_u_norm)
|
||||
pp_e = np.sqrt((pump_e/pump)**2+(unpump_e/unpump)**2)
|
||||
|
||||
self.diodes_p.append(pump)
|
||||
self.diodes_pstd.append(pump_e)
|
||||
self.diodes_u.append(unpump)
|
||||
self.diodes_ustd.append(unpump_e)
|
||||
self.pp.append(-np.log10(pump/unpump))
|
||||
self.ppstd.append(pp_e/((pump/unpump)*np.log(10)))
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
def draw_plot(self):
|
||||
self.plot_diodes.clear()
|
||||
self.plot_pp.clear()
|
||||
|
||||
self.plot_diodes.set_xlabel('time ago, a.u.')
|
||||
self.plot_diodes.set_ylabel('intensity, a.u.')
|
||||
|
||||
self.plot_pp.set_xlabel('time ago, a.u.')
|
||||
self.plot_pp.set_ylabel('Absorbance')
|
||||
|
||||
self.plot_diodes.plot(np.arange(0, len(self.diodes_p)), self.diodes_p, '-', color='royalblue', label='on')
|
||||
self.plot_diodes.plot(np.arange(0, len(self.diodes_u)), self.diodes_u, '-', color='orange', label='off')
|
||||
self.plot_diodes.legend(loc='lower left')
|
||||
self.plot_pp.plot(np.arange(0, len(self.pp)), self.pp, '-', color='green')
|
||||
#self.plot_pp.fill_between(np.arange(0, len(self.pp)), np.asarray(self.ppstd)+np.asarray(self.pp), -np.asarray(self.ppstd)+np.asarray(self.pp), color='lightgreen')
|
||||
#self.plot_pp.set_ylim(-1)
|
||||
self.plot_pp.grid()
|
||||
|
||||
self.plot_diodes.draw()
|
||||
self.plot_pp.draw()
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
|
||||
self.diodes_p.clear()
|
||||
self.diodes_u.clear()
|
||||
self.pp.clear()
|
||||
self.ppstd.clear()
|
||||
+377
@@ -0,0 +1,377 @@
|
||||
from collections import deque
|
||||
import random, os
|
||||
import wx
|
||||
import numpy as np
|
||||
import epics
|
||||
|
||||
from datetime import datetime
|
||||
from scipy.stats.stats import pearsonr
|
||||
|
||||
#from epics.wx import MotorPanel
|
||||
|
||||
from slic.gui.widgets import LabeledMathEntry
|
||||
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
|
||||
nshots = 50
|
||||
qlength = 100
|
||||
qlength2 =500
|
||||
histlength = 1
|
||||
qchecklen = 10
|
||||
|
||||
offset = 0 #in eV
|
||||
Int_threshold = 100
|
||||
DeltaE2move = 3
|
||||
|
||||
# channels
|
||||
ENERGYpv = epics.PV('SARFE10-PSSS059:ENERGY')
|
||||
CRYSTALpv = epics.PV('SARFE10-PSSS059:CRYSTAL_SP')
|
||||
GRATINGpv = epics.PV('SARFE10-PSSS055:GRATING_SP')
|
||||
SPECXpv = epics.PV('SARFE10-PSSS059:SPECTRUM_X')
|
||||
SPECYpv = epics.PV('SARFE10-PSSS059:SPECTRUM_Y')
|
||||
DCMpv = epics.PV('SAROP11-ARAMIS:ENERGY')
|
||||
FELINTpv = epics.PV('SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-AVG')
|
||||
|
||||
camArmRotpv = epics.PV('SARFE10-PSSS059:MOTOR_ROT_X4')
|
||||
cristBendRotpv = epics.PV('SARFE10-PSSS059:MOTOR_ROT_X3')
|
||||
cristBendRotpv_move = epics.PV('SARFE10-PSSS059:MOTOR_ROT_X3.MOVN')
|
||||
camPosXpv = epics.PV('SARFE10-PSSS059:MOTOR_X5')
|
||||
|
||||
chname_pbpsint = "SAROP11-PBPS110:INTENSITY"
|
||||
#chname_pbpsint = "SAROP21-PBPS103:INTENSITY"
|
||||
#chname_pbpsint = "SAROP31-PBPS113:INTENSITY"
|
||||
|
||||
chname_psss_y = "SARFE10-PSSS059:SPECTRUM_Y"
|
||||
chname_psss_x = "SARFE10-PSSS059:SPECTRUM_X"
|
||||
chname_psss_com = "SARFE10-PSSS059:SPECT-COM"
|
||||
#chname_psss_fwhm = "SARFE10-PSSS059:FIT-FWHM"
|
||||
chname_psss_fwhm = "SARFE10-PSSS059:AVG-FIT-FWHM"
|
||||
|
||||
chname_events = "SAR-CVME-TIFALL4:EvtSet"
|
||||
|
||||
# create channels
|
||||
ch_int = BS(chname_pbpsint)
|
||||
ch_psssX = BS(chname_psss_x)
|
||||
ch_psssY = BS(chname_psss_y)
|
||||
ch_psssC = BS(chname_psss_com)
|
||||
ch_psssW = BS(chname_psss_fwhm)
|
||||
ch_events = BS(chname_events)
|
||||
|
||||
#iso_format = "%Y-%m-%d %H:%M:%S"
|
||||
iso_format = "%H:%M:%S"
|
||||
|
||||
|
||||
class MainPanel(wx.Panel):
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.iZero = np.empty(nshots)
|
||||
self.psssX = np.empty((nshots,2560))
|
||||
self.psssY = np.empty((nshots,2560))
|
||||
self.psssC = np.empty(nshots)
|
||||
self.psssW = np.empty(nshots)
|
||||
|
||||
self.energyAxis = np.empty(2560)
|
||||
self.offset = 0
|
||||
|
||||
self.psssYs = deque(maxlen=qlength)
|
||||
self.psssCs = deque(maxlen=qlength2)
|
||||
self.psssCstds = deque(maxlen=qlength2)
|
||||
self.psssWs = deque(maxlen=qlength)
|
||||
self.checks = deque(maxlen=qchecklen)
|
||||
|
||||
self.iZeros = deque(maxlen=histlength)
|
||||
self.psssIs = deque(maxlen=histlength)
|
||||
|
||||
self.plot_spectra = plot_spectra = PlotPanel(self, figsize=(6,3))
|
||||
self.plot_center = plot_center = PlotPanel(self, figsize=(3,3))
|
||||
self.plot_int = plot_int = PlotPanel(self, figsize=(3,3))
|
||||
self.plot_width = plot_width = PlotPanel(self, figsize=(3,3))
|
||||
|
||||
plots1 = (plot_spectra, )
|
||||
plots2 = (plot_center, )
|
||||
plots3 = (plot_int, plot_width)
|
||||
|
||||
hb_plot1 = make_filled_hbox(plots1)
|
||||
hb_plot2 = make_filled_hbox(plots2)
|
||||
hb_plot3 = make_filled_hbox(plots3)
|
||||
|
||||
btn_clearQ = wx.Button(self, label="Clear plots")
|
||||
btns = (btn_clearQ,)
|
||||
#hb_btns = make_filled_hbox(btns)
|
||||
|
||||
self.chkbx_follow = chkbx_follow = wx.CheckBox(self, label="follow")
|
||||
chkbxs = (btn_clearQ, chkbx_follow)
|
||||
hb_chkbx = make_filled_hbox(chkbxs)
|
||||
|
||||
widgets = (hb_plot1, hb_plot2, hb_plot3, hb_chkbx)
|
||||
box = make_filled_vbox(widgets, border=1)
|
||||
self.SetSizerAndFit(box)
|
||||
|
||||
btn_clearQ.Bind(wx.EVT_BUTTON, self.on_click_clearQ)
|
||||
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.on_update, self.timer)
|
||||
self.timer.Start(100)
|
||||
|
||||
|
||||
def on_update(self, _event):
|
||||
|
||||
self.time = datetime.now().strftime(iso_format)
|
||||
|
||||
self.evts = np.empty((nshots,256))
|
||||
self.iZero = np.empty(nshots)
|
||||
self.psssX = np.empty((nshots,2560)) #2560 for narrow bandwidth camera
|
||||
self.psssY = np.empty((nshots,2560))
|
||||
self.psssC = np.empty(nshots)
|
||||
self.psssW = np.empty(nshots)
|
||||
|
||||
for i in range(nshots):
|
||||
tempa = ch_events.get()
|
||||
self.evts[i] = tempa
|
||||
tempb = ch_int.get()
|
||||
self.iZero[i] = tempb
|
||||
tempc = ch_psssX.get()
|
||||
self.psssX[i] = tempc
|
||||
tempd = ch_psssY.get()
|
||||
self.psssY[i] = tempd
|
||||
tempe = ch_psssC.get()
|
||||
self.psssC[i] = tempe
|
||||
tempf = ch_psssW.get()
|
||||
self.psssW[i] = tempf
|
||||
next(bsstream)
|
||||
wx.GetApp().Yield()
|
||||
|
||||
self.current_energy = ENERGYpv.get()
|
||||
self.current_crystal = CRYSTALpv.get()
|
||||
self.current_grating = GRATINGpv.get()
|
||||
self.current_dcm = DCMpv.get()
|
||||
self.current_Int = FELINTpv.get()
|
||||
|
||||
fnXtlLst=(None,"Si111R155","Si220R75","Si220R145","Si220R200","Si333R155")
|
||||
base=os.path.dirname(__file__)
|
||||
fn=os.path.join(base,'lut'+fnXtlLst[CRYSTALpv.get()]+'.txt')
|
||||
lut= np.genfromtxt(fn, delimiter='\t',names=True)
|
||||
#print (fn)
|
||||
|
||||
camPosX='CamPosX'
|
||||
if self.current_grating in(1,2):camPosX+='_100nm'
|
||||
elif self.current_grating==3:camPosX+='_150nm'
|
||||
elif self.current_grating==4:camPosX+='_200nm'
|
||||
|
||||
camArmRot =np.interp(self.current_energy,lut['Energy'],lut['CamArmRot'])
|
||||
cristBendRot=np.interp(self.current_energy,lut['Energy'],lut['CristBendRot'])
|
||||
camPosX =np.interp(self.current_energy,lut['Energy'],lut[camPosX])
|
||||
evPerPix =np.interp(self.current_energy,lut['Energy'],lut['EvPerPix'])
|
||||
|
||||
self.psssYs = np.mean(self.psssY, axis=0)
|
||||
self.psssXs = np.mean(self.psssX, axis=0)
|
||||
|
||||
#print (max(self.psssYs), self.current_Int, Int_threshold)
|
||||
|
||||
if (self.current_Int > Int_threshold):# & (max(self.psssYs)>1000):
|
||||
|
||||
self.iZeros.append(self.iZero)
|
||||
self.psssIs.append(np.sum(self.psssY, axis=1))
|
||||
self.psssCs.append(np.mean(self.psssC))
|
||||
self.psssCstds.append(np.std(self.psssC))
|
||||
self.psssWs.append(np.mean(self.psssW))
|
||||
|
||||
#print (current_energy, current_crystal, current_grating)
|
||||
|
||||
self.offset = np.mean(self.psssC) - self.current_dcm
|
||||
|
||||
self.howfar = abs(np.mean(self.psssC) - self.current_energy)
|
||||
self.check = abs(np.mean(self.psssC) - self.current_energy) > DeltaE2move
|
||||
self.checks.append(self.check)
|
||||
|
||||
print (self.time, np.mean(self.psssC), self.current_energy, self.howfar)
|
||||
#print (np.sum(self.checks))
|
||||
moving = cristBendRotpv_move.get()
|
||||
#print (moving)
|
||||
|
||||
n=2560
|
||||
i=np.arange(n)-n/2
|
||||
spctr_x = (self.current_energy)+i*evPerPix
|
||||
#spctr_x = (np.mean(self.psssC))+i*evPerPix
|
||||
SPECXpv.put(spctr_x)
|
||||
self.energyAxis=SPECXpv.get()
|
||||
|
||||
if (self.chkbx_follow.IsChecked()):
|
||||
if (np.sum(self.checks)==qchecklen) & (moving==0) & (self.current_Int > Int_threshold):
|
||||
#if (abs((np.mean(self.psssC) - self.current_dcm))>DeltaE2move) & (self.current_Int > Int_threshold):
|
||||
print ('-----------------------')
|
||||
print ("Off by {} eV: move!".format(self.howfar))
|
||||
|
||||
energy2go = int(np.mean(self.psssC))
|
||||
#print (int(energy2go))
|
||||
|
||||
camArmRot =np.interp(energy2go,lut['Energy'],lut['CamArmRot'])
|
||||
cristBendRot=np.interp(energy2go,lut['Energy'],lut['CristBendRot'])
|
||||
#camPosX =np.interp(energy2go,lut['Energy'],lut[camPosX])
|
||||
#camPosX =np.interp(energy2go,lut['Energy'],lut['camPosX'])
|
||||
evPerPix =np.interp(energy2go,lut['Energy'],lut['EvPerPix'])
|
||||
|
||||
ENERGYpv.put(energy2go)
|
||||
camArmRotpv.put(camArmRot)
|
||||
cristBendRotpv.put(cristBendRot)
|
||||
camPosXpv.put(camPosX)
|
||||
print (energy2go, camArmRot, cristBendRot, camPosX, evPerPix)
|
||||
print ('-----------------------')
|
||||
|
||||
self.current_energy = ENERGYpv.get()
|
||||
self.current_crystal = CRYSTALpv.get()
|
||||
self.current_grating = GRATINGpv.get()
|
||||
#print (self.current_energy, camArmRot, cristBendRot, camPosX, evPerPix)
|
||||
|
||||
else:
|
||||
print("{}: FEL intensity = {:.1f} uJ, No signal".format(self.time, self.current_Int))
|
||||
self.iZeros.append(np.nan)
|
||||
self.psssIs.append(np.nan)
|
||||
self.psssCs.append(np.nan)
|
||||
self.psssCstds.append(np.nan)
|
||||
self.psssWs.append(np.nan)
|
||||
|
||||
self.draw_plot()
|
||||
|
||||
|
||||
|
||||
def draw_plot(self):
|
||||
|
||||
self.plot_spectra.clear()
|
||||
self.plot_center.clear()
|
||||
self.plot_int.clear()
|
||||
self.plot_width.clear()
|
||||
|
||||
self.plot_spectra.set_xlabel('Energy (eV)')
|
||||
self.plot_spectra.set_ylabel('Intensity, a.u.')
|
||||
self.plot_center.set_xlabel('time ago, a.u.')
|
||||
self.plot_center.set_ylabel('Energy (eV)')
|
||||
self.plot_int.set_xlabel('PSSS Int')
|
||||
self.plot_int.set_ylabel('{}'.format(chname_pbpsint))
|
||||
self.plot_width.set_xlabel('time ago, a.u.')
|
||||
self.plot_width.set_ylabel('Energy (eV)')
|
||||
|
||||
if len(self.psssCs)>3:
|
||||
self.plot_spectra.plot(self.energyAxis, self.psssY[random.randrange(0, len(self.psssY))], color='limegreen', linewidth=0.5)
|
||||
self.plot_spectra.plot(self.energyAxis, self.psssY[random.randrange(0, len(self.psssY))], color='limegreen', linewidth=0.5)
|
||||
self.plot_spectra.plot(self.energyAxis, self.psssY[random.randrange(0, len(self.psssY))], color='limegreen', linewidth=0.5)
|
||||
#self.plot_spectra.plot(self.energyAxis, self.psssY[random.randrange(0, len(self.psssY))], color='limegreen', linewidth=0.5)
|
||||
#self.plot_spectra.plot(self.energyAxis, self.psssY[random.randrange(0, len(self.psssY))], color='limegreen', linewidth=0.5)
|
||||
|
||||
if np.isnan(np.array(self.psssCs)).all() != True:
|
||||
self.plot_spectra.axvline(x=self.psssCs[-1], color = 'black', linestyle = '--')
|
||||
self.plot_spectra.axvline(x=self.psssCs[-2], color = 'dimgrey', linestyle = '--')
|
||||
self.plot_spectra.axvline(x=self.psssCs[-3], color = 'grey', linestyle = '--')
|
||||
self.plot_spectra.axvline(x=self.psssCs[-4], color = 'silver', linestyle = '--')
|
||||
self.plot_spectra.axvline(x=self.psssCs[-5], color = 'lightgrey', linestyle = '--')
|
||||
|
||||
self.plot_spectra.set_title('Central energy: {:.2f} eV'.format(self.psssCs[-1]))
|
||||
self.plot_center.set_title('Central energy')
|
||||
self.plot_width.set_title('Width: {:.4f}%'.format(self.psssWs[-1]/self.psssCs[-1]*100))
|
||||
|
||||
try: #np.isnan(np.array(self.psssCs)).all() != True:
|
||||
#self.plot_spectra.axvline(x=self.psssCs[-1], color = 'black', linestyle = '--')
|
||||
#self.plot_spectra.axvline(x=self.psssCs[-2], color = 'dimgrey', linestyle = '--')
|
||||
#self.plot_spectra.axvline(x=self.psssCs[-3], color = 'grey', linestyle = '--')
|
||||
#self.plot_spectra.axvline(x=self.psssCs[-4], color = 'silver', linestyle = '--')
|
||||
#self.plot_spectra.axvline(x=self.psssCs[-5], color = 'lightgrey', linestyle = '--')
|
||||
self.plot_int.set_title('Correlation: {:.4f}'.format(pearsonr(np.roll(np.ravel(self.psssIs), 0), np.ravel(self.iZeros))[0]))
|
||||
self.plot_center.set_ylim(self.current_energy-np.asarray(np.nanmean(self.psssWs)), self.current_energy+np.asarray(np.nanmean(self.psssWs)))
|
||||
self.plot_spectra.axvline(x=(self.current_dcm+self.offset), color = 'red', linestyle = '--')
|
||||
self.plot_center.fill_between(np.arange(0, len(self.psssCs)), np.asarray(self.psssCstds)+np.asarray(self.psssCs), -np.asarray(self.psssCstds)+np.asarray(self.psssCs), color='gold')
|
||||
except:
|
||||
self.plot_int.set_title('Correlation: NaN')
|
||||
|
||||
self.plot_center.grid()
|
||||
|
||||
self.plot_spectra.plot(self.energyAxis, self.psssYs, '-', color='green')
|
||||
self.plot_center.plot(np.arange(0, len(self.psssCs)), self.psssCs, color='orangered' )
|
||||
self.plot_int.plot(np.ravel(self.psssIs), np.ravel(self.iZeros), '.', color='purple')
|
||||
self.plot_width.plot(np.arange(0, len(self.psssWs)), self.psssWs, color='royalblue', linewidth=0.5)
|
||||
|
||||
self.plot_spectra.draw()
|
||||
self.plot_center.draw()
|
||||
self.plot_int.draw()
|
||||
self.plot_width.draw()
|
||||
|
||||
|
||||
def on_click_clearQ(self, _event):
|
||||
|
||||
self.plot_spectra.clear()
|
||||
self.plot_center.clear()
|
||||
self.plot_int.clear()
|
||||
self.plot_width.clear()
|
||||
|
||||
|
||||
def set_energy_motor(self,energy2motor,scan=False, rotWait=False):
|
||||
|
||||
if CRYSTALpv==0: return
|
||||
|
||||
#load lut
|
||||
fnXtlLst=(None,"Si111R155","Si220R75","Si220R145","Si220R200","Si333R155")
|
||||
#print(__file__)
|
||||
base=os.path.dirname(__file__)
|
||||
fn=os.path.join(base,'lut'+fnXtlLst[CRYSTALpv]+'.txt')
|
||||
lut= np.genfromtxt(fn, delimiter='\t',names=True)
|
||||
#lut
|
||||
#lut.dtype
|
||||
#lut[1]['Energy']
|
||||
#lut['Energy']
|
||||
#lut=np.genfromtxt(fn, delimiter='\t',skip_header=1)
|
||||
if energy2motor:
|
||||
energy = ENERGYpv.get()# self.getPv('PSSS059:ENERGY').getw()
|
||||
#energy =6000
|
||||
gratingType=self.getPv('PSSS055:GRATING_SP').getw()
|
||||
#gratingType=3
|
||||
camPosX='CamPosX'
|
||||
if gratingType in(1,2):camPosX+='_100nm'
|
||||
elif gratingType==3:camPosX+='_150nm'
|
||||
elif gratingType==4:camPosX+='_200nm'
|
||||
|
||||
camArmRot =np.interp(energy,lut['Energy'],lut['CamArmRot'])
|
||||
cristBendRot=np.interp(energy,lut['Energy'],lut['CristBendRot'])
|
||||
camPosX =np.interp(energy,lut['Energy'],lut[camPosX])
|
||||
evPerPix =np.interp(energy,lut['Energy'],lut['EvPerPix'])
|
||||
else:
|
||||
camArmRot=self.getPv('PSSS059:MOTOR_ROT_X4').getw()
|
||||
idx=~np.isnan(lut['CamArmRot'])
|
||||
lutCamArmRot=lut['CamArmRot'][idx]
|
||||
energy =np.interp(camArmRot,lutCamArmRot[::-1],lut['Energy'][idx][::-1])
|
||||
evPerPix =np.interp(camArmRot,lutCamArmRot[::-1],lut['EvPerPix'][idx][::-1])
|
||||
|
||||
#camera: 2560 x 2160
|
||||
n=2560
|
||||
i=np.arange(n)-n/2
|
||||
spctr_x=energy+i*evPerPix
|
||||
pv=self.getPv('PSSS059:SPECTRUM_X')
|
||||
pv.putw(spctr_x)
|
||||
|
||||
pv=self.getPv('PSSS059:SPECTRUM_Y')
|
||||
mu=2560./2
|
||||
sigma=100.
|
||||
x=np.arange(2560.)
|
||||
spctr_y= 1000.*np.exp(-( (x-mu)**2 / ( 2.0 * sigma**2 ) ) )
|
||||
pv.putw(spctr_y)
|
||||
|
||||
if energy2motor:
|
||||
print('energy2motor: camArmRot: %g cristBendRot: %g camPosX:%g evPerPix:%g'%(camArmRot,cristBendRot,camPosX,evPerPix))
|
||||
pv=self.getPv('PSSS059:MOTOR_ROT_X4')
|
||||
pv.putw(camArmRot)
|
||||
pv=self.getPv('PSSS059:MOTOR_ROT_X3')
|
||||
pv.putw(cristBendRot)
|
||||
if rotWait == True:
|
||||
self.waitMotionDone('PSSS059:MOTOR_ROT_X3')
|
||||
if scan == False: # if True the camera X position will not be changed
|
||||
pv=self.getPv('PSSS059:MOTOR_X5')
|
||||
pv.putw(camPosX)
|
||||
else:
|
||||
print('motor2energy: energy: %g evPerPix:%g'%(energy,evPerPix))
|
||||
pv=self.getPv('PSSS059:ENERGY')
|
||||
pv.putw(energy)
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_pbps053 import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="PBSP 053"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_pbps110 import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="PBSP 110"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_pbps122 import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="PBSP 122"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_pbps149 import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="PBSP 122"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_ppPrime import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="Prime pp"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_ppPrime_xas import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="Prime pp XAS"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import wx
|
||||
|
||||
from slic.gui.persist import Persistence
|
||||
|
||||
from bstrd import bsstream
|
||||
|
||||
from panel_psss import MainPanel
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
app = wx.App()
|
||||
wx.Yield = app.Yield
|
||||
frame = MainFrame(*args, **kwargs)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
app.Yield() #TODO: without this, wxPython segfaults locking a mutex
|
||||
|
||||
|
||||
def get_wx_icon(fname="icon.png"):
|
||||
iname = os.path.dirname(__file__)
|
||||
iname = os.path.join(iname, fname)
|
||||
return wx.Icon(iname)
|
||||
|
||||
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self, title="PSSS"):
|
||||
super().__init__(None, title=title)
|
||||
self.SetIcon(get_wx_icon())
|
||||
|
||||
main = MainPanel(self)
|
||||
|
||||
# make sure the window is large enough
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(main, proportion=1, flag=wx.EXPAND)
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
self.persist = persist = Persistence(".coffee365", self)
|
||||
persist.load()
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
||||
|
||||
|
||||
def on_close(self, event):
|
||||
print("bye")
|
||||
bsstream.stop()
|
||||
self.persist.save()
|
||||
event.Skip() # forward the close event
|
||||
wx.GetApp().Yield()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user