Averager devices

This commit is contained in:
gac-bernina
2021-05-03 09:59:40 +02:00
parent 89562f457f
commit 2bcbb2b157
17 changed files with 154 additions and 61 deletions

View File

@@ -1,3 +1,4 @@
psss_fwhm_avg=ch.psi.pshell.epics.ChannelDouble|SARFE10-PSSS059:REL-E-SPREAD|||true
dispatcher=ch.psi.pshell.bs.Dispatcher|https://dispatcher-api.psi.ch/sf|||
cam_server=ch.psi.pshell.bs.PipelineServer|sf-daqsync-01:8889|||
cam_n=ch.psi.pshell.imaging.MjpegSource|http://bernina-cam-n/axis-cgi/mjpg/video.cgi reopen||-200|false
@@ -14,3 +15,6 @@ psss_roi_min=ch.psi.pshell.epics.ChannelInteger|SARFE10-PSSS059:SPC_ROI_YMIN|||t
psss_roi_max=ch.psi.pshell.epics.ChannelInteger|SARFE10-PSSS059:SPC_ROI_YMAX|||true
histo_center=ch.psi.pshell.device.HistogramGenerator|psss_center|||true
histo_fwhm=ch.psi.pshell.device.HistogramGenerator|psss_fwhm|||true
psss_spectrum_y_average=ch.psi.pshell.device.ArrayAverager|psss_spectrum_y|||true
psss_center_average=ch.psi.pshell.device.Averager|psss_center|||true
psss_fwhm_average=ch.psi.pshell.device.Averager|psss_fwhm|||true

View File

@@ -1,4 +1,4 @@
#Tue Apr 27 16:17:59 CEST 2021
LastRunDate=210415
FileSequentialNumber=81
DaySequentialNumber=0
#Thu Apr 29 13:47:57 CEST 2021
LastRunDate=210429
FileSequentialNumber=86
DaySequentialNumber=5

View File

@@ -1,21 +1,21 @@
#Mon Apr 26 11:55:34 CEST 2021
#Sun May 02 17:34:36 CEST 2021
\u0000\u0000\u0000\u0000=
=0
spatialCalOffsetY=-211.42799182512672
spatialCalOffsetX=-274.41641995560866
spatialCalOffsetY=-92.49729632739741
spatialCalOffsetX=-96.48730927109395
colormapLogarithmic=false
scale=1.0
grayscale=false
spatialCalScaleX=-2.0325203289739266
spatialCalScaleY=-2.024291558875032
colormapMax=220.0
spatialCalScaleX=-13.33686325150698
spatialCalScaleY=-11.627907252956081
colormapMax=81.0
Y=0
rescaleOffset=0.0
roiWidth=-1
colormap=Temperature
imageWidth=1280
invert=false
colormapMin=6.0
colormapMin=0.0
rotation=0.0
rotationCrop=false
rescaleFactor=1.0

View File

@@ -1,25 +1,25 @@
#Thu Feb 25 15:32:21 CET 2021
#Sun May 02 17:05:06 CEST 2021
spatialCalOffsetY=-50.02315886984715
spatialCalOffsetX=-50.01953888237593
colormapLogarithmic=false
scale=1.0
grayscale=false
spatialCalScaleX=-1.0
spatialCalScaleY=-1.0
colormapMax=255.0
rescaleOffset=0.0
roiWidth=-1
colormap=Grayscale
colormap=Temperature
invert=false
colormapMin=0.0
rotationCrop=false
roiHeight=-1
colormapAutomatic=false
roiY=0
roiX=0
spatialCalOffsetY=-50.02315886984715
spatialCalOffsetX=-50.01953888237593
scale=1.0
grayscale=false
colormapMax=255.0
rotation=0.0
rescaleFactor=1.0
spatialCalUnits=mm
flipVertically=false
roiHeight=-1
flipHorizontally=false
colormapAutomatic=false
roiY=0
roiX=0
transpose=false

View File

@@ -1,6 +1,6 @@
#Tue Apr 27 16:40:07 CEST 2021
bins=100
min=11340.0
max=11260.0
#Fri Apr 30 14:09:41 CEST 2021
bins=1000
min=11240.0
max=11160.0
precision=-1
numberOfSamples=100
numberOfSamples=10000

View File

@@ -1,6 +1,6 @@
#Fri Feb 26 14:09:58 CET 2021
bins=100
#Fri Apr 30 07:45:13 CEST 2021
bins=1000
min=0.0
max=200.0
max=40.0
precision=-1
numberOfSamples=100
numberOfSamples=10000

View File

@@ -0,0 +1,4 @@
#Mon May 03 09:21:35 CEST 2021
measures=10
precision=-1
interval=-1

View File

@@ -0,0 +1,4 @@
#Mon May 03 09:21:52 CEST 2021
measures=10
precision=-1
interval=-1

View File

@@ -0,0 +1,5 @@
#Mon May 03 09:15:04 CEST 2021
measures=10
precision=-1
interval=-1
integrate=false

View File

@@ -19,7 +19,9 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="111" max="-2" attributes="0"/>
<Component id="jRadioButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="213" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="cameraPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -28,7 +30,12 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="49" max="-2" attributes="0"/>
<Component id="jRadioButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="65" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="cameraPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -39,5 +46,7 @@
<Property name="text" type="java.lang.String" value="jRadioButton1"/>
</Properties>
</Component>
<Component class="ch.psi.pshell.swing.CameraPanel" name="cameraPanel1">
</Component>
</SubComponents>
</Form>

View File

@@ -36,6 +36,7 @@ public class Chris extends Panel {
private void initComponents() {
jRadioButton1 = new javax.swing.JRadioButton();
cameraPanel1 = new ch.psi.pshell.swing.CameraPanel();
jRadioButton1.setText("jRadioButton1");
@@ -46,18 +47,25 @@ public class Chris extends Panel {
.addGroup(layout.createSequentialGroup()
.addGap(111, 111, 111)
.addComponent(jRadioButton1)
.addContainerGap(213, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cameraPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(49, 49, 49)
.addComponent(jRadioButton1)
.addContainerGap(65, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cameraPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private ch.psi.pshell.swing.CameraPanel cameraPanel1;
private javax.swing.JRadioButton jRadioButton1;
// End of variables declaration//GEN-END:variables
}

View File

@@ -113,6 +113,9 @@
<SpinnerModel initial="1" maximum="100" minimum="1" numberType="java.lang.Integer" stepSize="1" type="number"/>
</Property>
</Properties>
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="spinnerAverageStateChanged"/>
</Events>
</Component>
<Component class="ch.psi.pshell.swing.HistogramGeneratorPanel" name="histogramGeneratorPanelCenter">
<Properties>

View File

@@ -22,7 +22,7 @@ public class PSSS extends Panel {
final String CAMERA_NAME = "SARFE10-PSSS059";
PipelineServer pipelineServer;
volatile boolean updatingPlot;
volatile boolean updatingImage;
volatile boolean updatingImage;
public PSSS() {
initComponents();
@@ -39,7 +39,7 @@ public class PSSS extends Panel {
try {
setGlobalVar("PSSS_PLOT", plot);
setGlobalVar("HISTORY_PLOT", history);
setGlobalVar("PSSS_RENDERER", renderer);
setGlobalVar("PSSS_RENDERER", renderer);
pipelineServer = (PipelineServer) getDevice("cam_server");
((LinePlotJFree)histogramGeneratorPanelCenter.getPlot()).setLegendVisible(true);
@@ -48,6 +48,8 @@ public class PSSS extends Panel {
histogramGeneratorFwhm.getPlot().getAxis(Plot.AxisId.Y).setRange(0, 100);
//setImageEnabled(true);
tabStateChanged(null);
spinnerAverage.setValue(( (Number) eval("get_psss_averaging()", true)).intValue());
} catch (Exception ex) {
getLogger().log(Level.WARNING, null, ex);
@@ -74,7 +76,8 @@ public class PSSS extends Panel {
try {
if (!updatingPlot){
updatingPlot = true;
evalAsync("plot_psss(PSSS_PLOT, HISTORY_PLOT, " + spinnerAverage.getValue() + ")", true).handle((ret,ex)->{
//evalAsync("plot_psss(PSSS_PLOT, HISTORY_PLOT, " + spinnerAverage.getValue() + ")", true).handle((ret,ex)->{
evalAsync("plot_psss(PSSS_PLOT, HISTORY_PLOT)", true).handle((ret,ex)->{
updatingPlot = false;
return ret;
});
@@ -195,6 +198,11 @@ public class PSSS extends Panel {
jLabel1.setText("Average:");
spinnerAverage.setModel(new javax.swing.SpinnerNumberModel(1, 1, 100, 1));
spinnerAverage.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
spinnerAverageStateChanged(evt);
}
});
histogramGeneratorPanelCenter.setDeviceName("histo_center");
@@ -632,7 +640,7 @@ public class PSSS extends Panel {
private void btAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAbortActionPerformed
try {
abort();
} catch (InterruptedException ex) {
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_btAbortActionPerformed
@@ -677,6 +685,14 @@ public class PSSS extends Panel {
((CardLayout)panelScan.getLayout()).show(panelScan, "crystal");
}//GEN-LAST:event_radioCrystalScanActionPerformed
private void spinnerAverageStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerAverageStateChanged
try {
eval("set_psss_averaging(" + spinnerAverage.getValue() + ")", true);
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_spinnerAverageStateChanged
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btAbort;
private javax.swing.JButton btStartCam;

View File

@@ -1,7 +1,7 @@
import ch.psi.pshell.device.HistogramGenerator as HistogramGenerator
#CAMERA_NAME = "SAROP21-PPRM102"
CAMERA_NAME = "SAROP21-PPRM138"
CAMERA_NAME = "SAROP21-PPRM102"
#CAMERA_NAME = "SAROP21-PPRM138"
cam_server.start(CAMERA_NAME + "_sp", CAMERA_NAME + "_sp1") #Start or connect to ScreenPanel pipeline
cam_server.stream.waitCacheChange(2000)

View File

@@ -24,10 +24,11 @@ def fit_energy(e_from, e_to, steps, num_shots, data):
def fit_crystal_height(xstal_from, xstal_to, steps, data):
xstal_range = np.linspace(xstal_from, xstal_to, steps)
projection = data.mean(axis=1).mean(axis=1)
offset = np.mean(projection[0:100])
signal_centre = xstal_range[np.argmax(projection)]
xstal_range_fit = np.linspace(xstal_range[0], xstal_range[-1], len(xstal_range)*10)
try:
popt,pcov = curve_fit(gaus,xstal_range,projection,p0=[100,signal_centre,-0.2,100])
popt,pcov = curve_fit(gaus,xstal_range,projection,p0=[100,signal_centre,-0.2,offset])
except:
raise Exception('Fit failed: spectrum might not be near scan range center \n' + str(sys.exc_info()[1]))
#print('Fit failed: spectrum might not be near scan range center')

View File

@@ -20,7 +20,7 @@ run("cpython/wrapper")
#Setup and functions setup¶
if not is_dry_run():
xstal_height=Channel("ARFE10-PSSS059:MOTOR_Y3.VAL", name="xstal_height")
xstal_height=Channel("SARFE10-PSSS059:MOTOR_Y3.VAL", name="xstal_height")
else:
xstal_height=DummyRegister("xstal_height")
@@ -36,7 +36,7 @@ average, samples, xstal_range = r.getReadable(0), r.getReadable(1), r.getPositi
#return maxium position
[amp, mean_val, sigma, offset], projection = fit_crystal_height(RANGE_FROM, RANGE_TO, STEPS+1, samples)
print(mean_val)
if not (RANGE_FROM < mean_val < RANGE_TO or RANGE_TO < mean_val < RANGE_FROM):
raise Exception ("Invalid fit mean: " + str(mean_val))

View File

@@ -2,7 +2,7 @@ import org.jfree.ui.RectangleAnchor as RectangleAnchor
import org.jfree.ui.TextAnchor as TextAnchor
import ch.psi.pshell.imaging.Overlay as Overlay
import ch.psi.pshell.plot.RangeSelectionPlot as RangeSelectionPlot
from collections import deque
PSSS_CAMERA_NAME = "SARFE10-PSSS059";
@@ -21,6 +21,7 @@ def average_arrays(arrays):
ret = [x/s for x in ret]
return ret
def get_psss_data(average=1):
ax,ay,ac,af=[],[],[],[]
x = psss_spectrum_x.take()
@@ -37,13 +38,13 @@ def get_psss_data(average=1):
psss_spectrum_y.waitCacheChange(2000)
#psss_center.waitCacheChange(1)
#psss_fwhm.waitCacheChange(1)
#x=average_arrays(ax)
#x=average_arrays(ax)
y=average_arrays(ay)
center=mean(ac)
fwhm=mean(af)
return x,y,center,fwhm
def plot_psss(p, h=None, average = 1):
def plot_psss(p, h=None, average = None):
"""
if len(p.getMarkers())==0:
m1=p.addMarker(0,None,"",Color.WHITE)
@@ -56,11 +57,20 @@ def plot_psss(p, h=None, average = 1):
#Manipulate axis (use PSSS_PLOT for the global object):
#p.getAxis(LinePlot.AxisId.X).
# Setup queues
if p.getNumberOfSeries()==0:
center_queue = deque(maxlen=100)
fwhm_queue = deque(maxlen=100)
# Setup figures
if p.getNumberOfSeries()==0:
p.addSeries(LinePlotSeries("spectrum"))
p.addSeries(LinePlotSeries("average"))
p.setLegendVisible(True)
p.getAxis(LinePlot.AxisId.X)
p.getAxis(LinePlot.AxisId.X).setLabel("Energy [eV]")
p.getAxis(LinePlot.AxisId.Y).setLabel("Sum counts")
if len(p.getMarkers())==0:
paint = RangeSelectionPlot().getSelectionColor() #p.chart.getBackgroundPaint()
m=p.addIntervalMarker(0,0, None,"", paint)
@@ -69,31 +79,52 @@ def plot_psss(p, h=None, average = 1):
m.setLabelPaint(Color.WHITE)
else:
m = p.getMarkers()[0]
x,y, center,fwhm = get_psss_data(average)
x,y, = psss_spectrum_x.take(), psss_spectrum_y.take()
# update spectral plot
if (x is None) or (y is None):
p.getSeries(0).clear()
else:
p.getSeries(0).setData(x,y)
if (x is None) or (y is None):
p.getSeries(0).clear()
else:
p.getSeries(0).setData(x,y)
if average is not None:
print "Average: ", average
x,y, center,fwhm = get_psss_data(average)
else:
y = psss_spectrum_y_average.take()
center = psss_center_average.take()
fwhm = psss_fwhm_average.take()
if (x is None) or (y is None):
p.getSeries(1).clear()
else:
p.getSeries(1).setData(x,y)
x,y, _,_ = get_psss_data(1)
if (x is None) or (y is None):
p.getSeries(0).clear()
else:
p.getSeries(0).setData(x,y)
if (center!= None) and (fwhm!=None):
m.startValue, m.endValue = center - fwhm, center + fwhm
center=center.doubleValue()
fwhm=fwhm.doubleValue()
m.startValue, m.endValue = center - fwhm/2, center + fwhm/2
m.label = str(center)
if h:
if h.getNumberOfSeries()==0:
h.addSeries(TimePlotSeries("center"))
h.addSeries(TimePlotSeries("fwhm",2))
h.addSeries(TimePlotSeries("centre"))
h.addSeries(TimePlotSeries("Energy spread SS",2))
h.addSeries(TimePlotSeries("Energy spread cum avg",2))
h.setLegendVisible(True)
h.setTimeAxisLabel("")
h.getAxis(Timeplot.AxisId.Y1).setLabel("Central energy [eV]")
per_mil = (fwhm/center)*1e3
per_mil_avg = psss_fwhm_avg.take()
h.getSeries(0).appendData(center)
h.getSeries(1).appendData(fwhm)
h.getSeries(1).appendData(per_mil)
h.getSeries(2).appendData(per_mil_avg)
return center,fwhm
ovmin, ovmax, ovavg = None, None, None
@@ -146,4 +177,12 @@ def enable_psss_image(enabled, renderer):
cam_server.stop()
except:
log(sys.exc_info()[1])
def get_psss_averaging():
return psss_spectrum_y_average.config.measures
def set_psss_averaging(measures):
psss_spectrum_y_average.config.measures=measures
psss_center_average.config.measures=measures
psss_fwhm_average.config.measures=measures