Add PSSS panel
This commit is contained in:
73
psss-panel/src/main/pkg/script/psss/CameraScan.py
Executable file
73
psss-panel/src/main/pkg/script/psss/CameraScan.py
Executable file
@@ -0,0 +1,73 @@
|
||||
#Scan the PSSS camera position
|
||||
#Purpose:
|
||||
#To set or confirm the camera is positioned with the measured spectrum in the centre of the spectral integration window
|
||||
|
||||
#If running from editor
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
#User inputs - define travel range of camera
|
||||
RANGE_FROM = -17
|
||||
RANGE_TO = -11
|
||||
STEPS = 20
|
||||
NUM_SHOTS= 10 #100
|
||||
PLOT=None
|
||||
p = plot(None, title="Data")[0] if (PLOT is None) else PLOT
|
||||
p.clear()
|
||||
p.removeMarker(None)
|
||||
p.setLegendVisible(True)
|
||||
p.addSeries(LinePlotSeries("PSSS Spectrum Average"))
|
||||
|
||||
|
||||
run("cpython/wrapper")
|
||||
|
||||
if not is_dry_run():
|
||||
cam_x=Channel("SARFE10-PSSS059:MOTOR_X5.VAL", name="cam_x")
|
||||
else:
|
||||
cam_x=DummyRegister("cam_x")
|
||||
|
||||
av = create_averager(psss_spectrum_y, NUM_SHOTS, interval=-1, name="spectrum_average")
|
||||
av_samples = av.samples
|
||||
av_samples.alias = "spectrum_samples"
|
||||
|
||||
|
||||
#Scan and take data
|
||||
def after_read(record, scan):
|
||||
p.getSeries(0).setData(psss_spectrum_x.take(), record[av])
|
||||
p.setTitle("Cam X = %1.3f" %(record[cam_x]))
|
||||
|
||||
r = lscan(cam_x, (av, av_samples), RANGE_FROM, RANGE_TO, STEPS, latency=0.0, after_read = after_read, save=False)
|
||||
average, samples, cam_range = r.getReadable(0), r.getReadable(1), r.getPositions(0)
|
||||
|
||||
signal_centre, projection = get_signal_centre(samples, cam_range)
|
||||
|
||||
#Set max position
|
||||
cam_x.write(signal_centre)
|
||||
cam_x.close()
|
||||
|
||||
|
||||
|
||||
"""
|
||||
plt.figure(figsize=[10,5])
|
||||
plt.subplot(121)
|
||||
plt.title('PSSS scan of camera position')
|
||||
plt.pcolormesh(np.arange(0,Scan_spec.shape[2]), Cam_range, Scan_spec.mean(axis=1),cmap='CMRmap')
|
||||
plt.xlim([0,Scan_spec.shape[2]])
|
||||
plt.xlabel('Camera pixel dispersive direction')
|
||||
plt.ylabel('Set PSSS cam_x _pos [mm] \n'+PSSS_cam_x_PV_name[0:-4])
|
||||
plt.subplot(122)
|
||||
plt.plot(projection,Cam_range,linewidth = 2, color = 'orange',label ='projected signal')
|
||||
plt.title('Spectrum centred at %.1f [mm] (from signal max) \n trace should have hard edges'%signal_centre)
|
||||
plt.xticks([])
|
||||
plt.legend()
|
||||
plt.grid(True)
|
||||
"""
|
||||
#PLOT.clear()
|
||||
#plot_data(PLOT, projection, "Data", xdata=cam_range, show_points = True, color=Color.BLUE)
|
||||
#p,pars = plot_gauss_fit(cam_range, projection, gauss_pars=None, p=PLOT, title = "Data")
|
||||
|
||||
p.clear()
|
||||
p.setTitle("")
|
||||
plot_data(p, projection, "Projection", xdata=cam_range, show_points = True, color=Color.BLUE)
|
||||
p.addMarker(signal_centre, None, "Signal Centre=" + str(round(signal_centre,2)), Color.LIGHT_GRAY)
|
||||
|
||||
|
||||
set_return(signal_centre)
|
||||
73
psss-panel/src/main/pkg/script/psss/CrystalHeightScan.py
Executable file
73
psss-panel/src/main/pkg/script/psss/CrystalHeightScan.py
Executable file
@@ -0,0 +1,73 @@
|
||||
###############################################################################
|
||||
#Scan the PSSS crystal height
|
||||
#Purpose:
|
||||
#The PSSS signal level is very sensitive to the crystal height. This script will scan the height and set the position to the maximum signal
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
#User inputs - define travel range of camera
|
||||
RANGE_FROM = -0.8
|
||||
RANGE_TO = -1.7
|
||||
STEPS = 10 #20
|
||||
NUM_SHOTS= 10 # 100
|
||||
PLOT=None
|
||||
# get current camera ROIs and then set to max for scan
|
||||
roi_min = psss_roi_min.read()
|
||||
roi_max = psss_roi_max.read()
|
||||
psss_roi_min.write(1)
|
||||
psss_roi_max.write(2000)
|
||||
|
||||
p = plot(None, title="Data")[0] if (PLOT is None) else PLOT
|
||||
p.clear()
|
||||
p.removeMarker(None)
|
||||
p.setLegendVisible(True)
|
||||
p.addSeries(LinePlotSeries("PSSS Spectrum Average"))
|
||||
|
||||
run("cpython/wrapper")
|
||||
|
||||
|
||||
#Setup and functions setup¶
|
||||
#if not is_dry_run(): # C.arrell commented out 20.01.21
|
||||
xstal_height=Channel("SARFE10-PSSS059:MOTOR_Y3.VAL", name="xstal_height")
|
||||
#else:
|
||||
# xstal_height=DummyRegister("xstal_height")
|
||||
|
||||
av = create_averager(psss_spectrum_y, NUM_SHOTS, interval=-1, name="spectrum_average")
|
||||
av_samples = av.samples
|
||||
av_samples.alias = "spectrum_samples"
|
||||
|
||||
#Scan and take data
|
||||
def after_read(record, scan):
|
||||
p.getSeries(0).setData(psss_spectrum_x.take(), record[av])
|
||||
p.setTitle("Xtal Height = %1.3f" %(record[xstal_height]))
|
||||
|
||||
r = lscan(xstal_height, (av, av_samples), RANGE_FROM, RANGE_TO, STEPS, latency=2.0, after_read = after_read, save=False)
|
||||
|
||||
#User inputs - define travel range of crystal
|
||||
#It is unlikely these values need to be changed
|
||||
average, samples, xstal_range = r.getReadable(0), r.getReadable(1), r.getPositions(0)
|
||||
|
||||
#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))
|
||||
|
||||
|
||||
#Set max position
|
||||
#Cell below will push the maximum position to the xstal height
|
||||
xstal_height.write(mean_val)
|
||||
xstal_height.close()
|
||||
|
||||
# return ROI to inital value
|
||||
psss_roi_min.write(roi_min)
|
||||
psss_roi_max.write(roi_max)
|
||||
|
||||
#Plots
|
||||
|
||||
p.clear()
|
||||
p.setTitle("")
|
||||
plot_gauss_fit(xstal_range, projection, gauss_pars=(offset, amp, mean_val, sigma), p=p, title = "Data")
|
||||
|
||||
|
||||
set_return(mean_val)
|
||||
89
psss-panel/src/main/pkg/script/psss/EnergyScan.py
Executable file
89
psss-panel/src/main/pkg/script/psss/EnergyScan.py
Executable file
@@ -0,0 +1,89 @@
|
||||
###############################################################################
|
||||
#Scan the PSSS photon energy
|
||||
#Purpose: To find and centre the PSSS photon energy so the measured spectrum is centred on the camera chip
|
||||
|
||||
#PARAMETERS
|
||||
#User inputs - define energy range to scan below by running the appropiate cell
|
||||
#Below is for a large scan range assuming offset from machine upto $\pm$ 300 eV
|
||||
|
||||
#If running from editor
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
RANGE_OFF = None
|
||||
RANGE_FROM = 11100
|
||||
RANGE_TO = 11300
|
||||
STEPS = 5 #60
|
||||
NUM_SHOTS= 10 #100
|
||||
PLOT=None
|
||||
p = plot(None, title="Data")[0] if (PLOT is None) else PLOT
|
||||
p.clear()
|
||||
p.removeMarker(None)
|
||||
p.setLegendVisible(True)
|
||||
p.addSeries(LinePlotSeries("PSSS Spectrum Average"))
|
||||
|
||||
if RANGE_OFF is not None:
|
||||
RANGE_FROM = energy_machine.read()-RANGE_OFF
|
||||
RANGE_TO = energy_machine.read()+RANGE_OFF
|
||||
|
||||
run("cpython/wrapper")
|
||||
|
||||
# get current camera ROIs and then set to max for scan
|
||||
roi_min = psss_roi_min.read()
|
||||
roi_max = psss_roi_max.read()
|
||||
psss_roi_min.write(1)
|
||||
psss_roi_max.write(2000)
|
||||
|
||||
|
||||
#Scan and take data
|
||||
class PSSS_energy(Writable):
|
||||
def write(self, value):
|
||||
#if not is_dry_run():
|
||||
psss_energy.write(value)
|
||||
exec_cpython("/ioc/modules/qt/PSSS_motion.py", args = ["-m1", "SARFE10-PSSS059"])
|
||||
# python / ioc / modules / qt / PSSS_motion.py - m1 SARFE10 - PSSS059
|
||||
time.sleep(1)
|
||||
print(value)
|
||||
|
||||
en = PSSS_energy()
|
||||
en.alias = "energy"
|
||||
|
||||
av = create_averager(psss_spectrum_y, NUM_SHOTS, interval=-1, name="spectrum_average")
|
||||
av_samples = av.samples
|
||||
av_samples.alias = "spectrum_samples"
|
||||
|
||||
|
||||
def after_read(record, scan):
|
||||
p.getSeries(0).setData(psss_spectrum_x.take(), record[av])
|
||||
p.setTitle("Energy = %1.3f" %(record[en]))
|
||||
|
||||
r = lscan(en, (av, av_samples), RANGE_FROM, RANGE_TO, STEPS, latency=0.0, after_read = after_read, save=False )
|
||||
average, samples, energy_range = r.getReadable(0), r.getReadable(1), r.getPositions(0)
|
||||
# return ROI to inital value
|
||||
psss_roi_min.write(roi_min)
|
||||
psss_roi_max.write(roi_max)
|
||||
|
||||
[amp, mean_val, sigma, offset],centre_line_out = fit_energy(RANGE_FROM, RANGE_TO, STEPS+1, NUM_SHOTS, samples)
|
||||
|
||||
if not (RANGE_FROM < mean_val < RANGE_TO or RANGE_TO < mean_val < RANGE_FROM):
|
||||
|
||||
raise Exception ("Invalid fit mean: " + str(mean_val))
|
||||
|
||||
|
||||
measured_offset = energy_machine.read() - mean_val
|
||||
#Set fitted energy
|
||||
print "measured offset", measured_offset
|
||||
|
||||
en.write(mean_val)
|
||||
|
||||
|
||||
p.clear()
|
||||
p.setTitle("")
|
||||
plot_gauss_fit(energy_range, centre_line_out, gauss_pars=(offset, amp, mean_val, sigma), p=PLOT, title = "Data")
|
||||
|
||||
|
||||
set_return(mean_val)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
184
psss-panel/src/main/pkg/script/psss/psss.py
Executable file
184
psss-panel/src/main/pkg/script/psss/psss.py
Executable file
@@ -0,0 +1,184 @@
|
||||
from collections import deque
|
||||
|
||||
PSSS_CAMERA_NAME = "SARFE10-PSSS059";
|
||||
|
||||
def integrate_arrays(arrays):
|
||||
if arrays is None or (len(arrays)==0):
|
||||
return None
|
||||
ret = arrays[0]
|
||||
for a in arrays[1:]:
|
||||
ret=arradd(ret, a)
|
||||
return ret
|
||||
|
||||
def average_arrays(arrays):
|
||||
ret = integrate_arrays(arrays)
|
||||
if ret is not None:
|
||||
s=len(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()
|
||||
for i in range(average):
|
||||
y = psss_spectrum_y.take()
|
||||
center,fwhm = psss_center.take(), psss_fwhm.take()
|
||||
if average==1:
|
||||
return x,y,center,fwhm
|
||||
#ax.append(x)
|
||||
ay.append(y)
|
||||
ac.append(center)
|
||||
af.append(fwhm)
|
||||
if i < (average-1):
|
||||
psss_spectrum_y.waitCacheChange(2000)
|
||||
#psss_center.waitCacheChange(1)
|
||||
#psss_fwhm.waitCacheChange(1)
|
||||
#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 = None):
|
||||
"""
|
||||
if len(p.getMarkers())==0:
|
||||
m1=p.addMarker(0,None,"",Color.WHITE)
|
||||
m2=p.addMarker(0,None,"",Color.WHITE)
|
||||
m2.setLabelAnchor(RectangleAnchor.TOP)
|
||||
else:
|
||||
m1,m2 = p.getMarkers()
|
||||
"""
|
||||
|
||||
#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)
|
||||
m.setLabelAnchor(RectangleAnchor.BOTTOM)
|
||||
m.alpha=0.2
|
||||
m.setLabelPaint(Color.WHITE)
|
||||
else:
|
||||
m = p.getMarkers()[0]
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
if (center!= None) and (fwhm!=None):
|
||||
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("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(per_mil)
|
||||
h.getSeries(2).appendData(per_mil_avg)
|
||||
return center,fwhm
|
||||
|
||||
ovmin, ovmax, ovavg = None, None, None
|
||||
|
||||
def update_psss_image(renderer):
|
||||
global ovmin, ovmax
|
||||
#if ovmin: ovmin.update(Point(0,psss_roi_min.take()))
|
||||
#if ovmax: ovmax.update(Point(0,psss_roi_max.take()))
|
||||
|
||||
|
||||
width=psss_spectrum_x.size
|
||||
if ovmin: ovmin.update(Point(0,psss_roi_min.take()), Point(width, psss_roi_min.take()))
|
||||
if ovmax: ovmax.update(Point(0,psss_roi_max.take()), Point(width, psss_roi_max.take()))
|
||||
try:
|
||||
data = renderer.data
|
||||
av = "%1.2f" %(data.integrate(False)/data.width/data.height)
|
||||
except:
|
||||
av = ""
|
||||
if ovavg: ovavg.update(av)
|
||||
|
||||
def enable_psss_image(enabled, renderer):
|
||||
global ovmin, ovmax, ovavg
|
||||
try:
|
||||
if (enabled):
|
||||
#Start or connect to ScreenPanel pipeline
|
||||
renderer.setDevice(cam_server)
|
||||
renderer.setProfile(renderer.Profile.Both)
|
||||
renderer.setShowProfileLimits(False)
|
||||
|
||||
#Changing colormap
|
||||
#print Colormap.values() #Check values
|
||||
cam_server.config.colormap=Colormap.Temperature
|
||||
|
||||
|
||||
cam_server.start(PSSS_CAMERA_NAME + "_sp", True)
|
||||
#ovmin, ovmax= Overlays.Crosshairs(renderer.getPenMarker(), Dimension(-1,1)), \
|
||||
# Overlays.Crosshairs(renderer.getPenMarker(), Dimension(-1,1))
|
||||
ovmin, ovmax= Overlays.Line(renderer.getPenMarker()), Overlays.Line(renderer.getPenMarker())
|
||||
|
||||
ovavg = Overlays.Text(Pen(java.awt.Color.GREEN.darker()), "", \
|
||||
java.awt.Font("Verdana", java.awt.Font.PLAIN, 12), java.awt.Point(-50,20))
|
||||
ovavg.fixed=True
|
||||
ovavg.anchor=Overlay.ANCHOR_IMAGE_TOP_RIGHT
|
||||
renderer.addOverlays([ovmin, ovmax, ovavg])
|
||||
update_psss_image(renderer)
|
||||
else:
|
||||
ovmin, ovmax, ovavg = None, None, None
|
||||
renderer.setDevice(None)
|
||||
renderer.clearOverlays()
|
||||
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