Averager devices
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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))
|
||||
|
||||
+56
-17
@@ -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
|
||||
Reference in New Issue
Block a user