various changes 2

This commit is contained in:
2022-03-07 17:14:00 +01:00
parent 998c96518a
commit a2b1a7693e
12 changed files with 95 additions and 46 deletions

View File

@@ -26,6 +26,7 @@ done
-laf=dark \
-d \
-pini=true \
-clog=WARNING \
-sbar \
$@
-clog=WARNING \
-dplt \
-sbar \
$@

View File

@@ -1,7 +1,7 @@
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|||
energy_machine=ch.psi.pshell.epics.ChannelDouble|SARFE10-PBPG050:ENERGY|||true
energy_machine=ch.psi.pshell.epics.ProcessVariable|SARUN03-UIND030:FELPHOTENE|||true
psss_energy=ch.psi.pshell.epics.ChannelDouble|SARFE10-PSSS059:ENERGY|||true
psss_spectrum_x=ch.psi.pshell.epics.ChannelDoubleArray|SARFE10-PSSS059:SPECTRUM_X -1 -3|||true
psss_spectrum_y=ch.psi.pshell.epics.ChannelDoubleArray|SARFE10-PSSS059:SPECTRUM_Y -1 -3|||true

View File

@@ -57,7 +57,7 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="spinnerAverage" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="history" alignment="0" pref="453" max="32767" attributes="0"/>
<Component id="history" alignment="0" pref="461" max="32767" attributes="0"/>
<Component id="plot" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
@@ -97,10 +97,20 @@
<SubComponents>
<Component class="ch.psi.pshell.plot.LinePlotJFree" name="plot">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Dialog" size="14" style="0"/>
</Property>
<Property name="title" type="java.lang.String" value=""/>
</Properties>
</Component>
<Component class="ch.psi.pshell.plot.TimePlotJFree" name="history">
<Properties>
<Property name="durationMillis" type="int" value="1800000"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="tickLabelFont" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="SansSerif" size="14" style="0"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
@@ -141,9 +151,9 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="843" max="32767" attributes="0"/>
<EmptySpace min="0" pref="851" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Component id="renderer" alignment="0" pref="843" max="32767" attributes="0"/>
<Component id="renderer" alignment="0" pref="851" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>

View File

@@ -9,6 +9,7 @@ import ch.psi.utils.Convert;
import ch.psi.utils.State;
import ch.psi.utils.Str;
import java.awt.CardLayout;
import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
@@ -25,12 +26,17 @@ public class PSSS extends Panel {
PipelineServer pipelineServer;
volatile boolean updatingPlot;
volatile boolean updatingImage;
final Color PLOT_BACKGROUND =Color.WHITE;
public PSSS() {
initComponents();
plot.getAxis(Plot.AxisId.X).setLabel(null);
plot.getAxis(Plot.AxisId.Y).setLabel(null);
renderer.setMode(RendererMode.Stretch);
plot.setPlotBackgroundColor(PLOT_BACKGROUND);
history.setPlotBackgroundColor(PLOT_BACKGROUND);
histogramGeneratorPanelCenter.getPlot().setPlotBackgroundColor(PLOT_BACKGROUND);
histogramGeneratorFwhm.getPlot().setPlotBackgroundColor(PLOT_BACKGROUND);
}
//Overridable callbacks
@@ -205,8 +211,13 @@ public class PSSS extends Panel {
}
});
plot.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N
plot.setTitle("");
history.setDurationMillis(1800000);
history.setFocusable(false);
history.setTickLabelFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
jLabel1.setText("Average:");
spinnerAverage.setModel(new javax.swing.SpinnerNumberModel(1, 1, 100, 1));
@@ -231,7 +242,7 @@ public class PSSS extends Panel {
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spinnerAverage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(history, javax.swing.GroupLayout.DEFAULT_SIZE, 453, Short.MAX_VALUE)
.addComponent(history, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE)
.addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -264,9 +275,9 @@ public class PSSS extends Panel {
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 843, Short.MAX_VALUE)
.addGap(0, 851, Short.MAX_VALUE)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 843, Short.MAX_VALUE))
.addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 851, Short.MAX_VALUE))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

View File

@@ -1077,7 +1077,7 @@ def fork(*functions):
*functions(function references)
Returns:
List of callable
List of future objects
"""
callables = []
for m in functions:

View File

@@ -2035,7 +2035,7 @@ def fork(*functions):
*functions(function references)
Returns:
List of callable
List of future objects
"""
raise Exception("Not implemented")

View File

@@ -15,11 +15,9 @@ def fit_energy(e_from, e_to, steps, num_shots, data):
popt,pcov = curve_fit(gaus,energy_range,centre_line_out,p0=[1,energy_range[np.argmax(centre_line_out)],energy_range.mean()*1e-3,1e3*num_shots])
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')
#return None
max_ind = np.argmax(centre_line_out)
max_photon_energy=energy_range[max_ind]
print(max_photon_energy)
#print(max_photon_energy)
return popt, centre_line_out

View File

@@ -8,6 +8,7 @@ from mathutils import PolynomialFunction, Gaussian, HarmonicOscillator, Gaussian
from plotutils import plot_function, plot_data
import java.awt.Color as Color
from jeputils import import_py
run("psss/psss")
###################################################################################################
@@ -145,6 +146,25 @@ def plot_gauss_fit(xdata, ydata, gauss_pars=None, p=None, title = "Data"):
p.addMarker(mean_value, None, "Mean=" + str(round(mean_value,2)), Color.LIGHT_GRAY)
return p,(amp, mean_value, sigma)
###################################################################################################
# Devices
###################################################################################################
class PSSSEnergySet(RegisterBase):
def doRead(self):
return psss_energy.read()
def doWrite(self, val):
if not is_dry_run():
psss_energy.write(val)
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)
add_device(PSSSEnergySet("psss_energy_set"), True)
psss_energy_set.alias = "energy"
###################################################################################################
# Tools
###################################################################################################

View File

@@ -10,6 +10,9 @@ if get_exec_pars().source == CommandSource.ui:
STEPS = 20
NUM_SHOTS= 10 #100
PLOT=None
import_py("cpython/psss","get_signal_centre")
p = plot(None, title="Data")[0] if (PLOT is None) else PLOT
p.clear()
p.removeMarker(None)
@@ -17,8 +20,6 @@ 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:
@@ -37,7 +38,7 @@ def after_read(record, scan):
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)
signal_centre, projection = get_signal_centre(to_array(samples, 'd') , to_array(cam_range, 'd') )
#Set max position
cam_x.write(signal_centre)

View File

@@ -10,6 +10,9 @@ if get_exec_pars().source == CommandSource.ui:
STEPS = 10 #20
NUM_SHOTS= 10 # 100
PLOT=None
import_py("cpython/psss","fit_crystal_height")
# get current camera ROIs and then set to max for scan
roi_min = psss_roi_min.read()
roi_max = psss_roi_max.read()
@@ -22,8 +25,6 @@ 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
@@ -47,7 +48,8 @@ r = lscan(xstal_height, (av, av_samples), RANGE_FROM, RANGE_TO, STEPS, latency=2
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)
data = to_array(samples, 'd')
[amp, mean_val, sigma, offset], projection = fit_crystal_height(RANGE_FROM, RANGE_TO, STEPS+1, data)
print(mean_val)
if not (RANGE_FROM < mean_val < RANGE_TO or RANGE_TO < mean_val < RANGE_FROM):

View File

@@ -14,6 +14,9 @@ if get_exec_pars().source == CommandSource.ui:
STEPS = 5 #60
NUM_SHOTS= 10 #100
PLOT=None
import_py("cpython/psss","fit_energy")
p = plot(None, title="Data")[0] if (PLOT is None) else PLOT
p.clear()
p.removeMarker(None)
@@ -24,7 +27,6 @@ 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()
@@ -32,20 +34,6 @@ 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"
@@ -53,26 +41,44 @@ 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]))
p.setTitle("Energy = %1.3f" %(record[psss_energy_set]))
r = lscan(en, (av, av_samples), RANGE_FROM, RANGE_TO, STEPS, latency=0.0, after_read = after_read, save=False )
r = lscan(psss_energy_set, (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)
data=to_array(samples, 'd')
intensity= [sum(x) for x in average]
max_index=intensity.index(max(intensity))
max_val = energy_range[max_index]
mean_val=None
print "Maximum value: ", max_val
if not (RANGE_FROM < mean_val < RANGE_TO or RANGE_TO < mean_val < RANGE_FROM):
raise Exception ("Invalid fit mean: " + str(mean_val))
try:
[amp, mv, sigma, offset],centre_line_out = fit_energy(RANGE_FROM, RANGE_TO, STEPS+1, NUM_SHOTS, data)
if not (RANGE_FROM < mean_val < RANGE_TO or RANGE_TO < mean_val < RANGE_FROM):
#raise Exception ("Invalid fit mean: " + str(mean_val))
show_message("Fit error - Using maximum value instead at: " + str(max_val), "Fit Error")
else:
mean_val = mv
except Exception as e:
show_message("Fit error - Using maximum value instead at: " + str(max_val) + "\n" + str(e), "Fit Error")
except:
show_message("Fit error - Using maximum value instead at: " + str(max_val))
print "Fit value: ", mean_val
#If invalid fit uses maximum value
if mean_val is None:
mean_val = max_val
measured_offset = energy_machine.read() - mean_val
#Set fitted energy
print "measured offset", measured_offset
en.write(mean_val)
psss_energy_set.write(mean_val)
p.clear()

View File

@@ -75,8 +75,8 @@ def plot_psss(p, h=None, average = None):
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)
m.alpha=0.4
m.setLabelPaint(Color.BLACK)
else:
m = p.getMarkers()[0]
@@ -110,7 +110,7 @@ def plot_psss(p, h=None, average = None):
center=center.doubleValue()
fwhm=fwhm.doubleValue()
m.startValue, m.endValue = center - fwhm/2, center + fwhm/2
m.label = str(center)
m.label = "%1.3f" % (center,)
if h:
if h.getNumberOfSeries()==0: