This commit is contained in:
voulot_d
2017-01-13 15:58:33 +01:00
parent 67e6862dca
commit 818a0d6bc9
5 changed files with 84 additions and 276 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
#Fri Jan 13 15:53:19 CET 2017
#Fri Jan 13 15:57:44 CET 2017
colormap=Temperature
colormapAutomatic=true
colormapMax=0.0
+13 -2
View File
@@ -468,6 +468,9 @@ public class ScreenPanel extends Panel {
return (Integer) state.get("run");
}
}
Thread tcomboScreen;
Thread tcomboFilter;
void setCamera(String cameraName) throws IOException, InterruptedException {
System.out.println("Setting camera: " + cameraName + " [" + (buttonCamtool.isSelected() ? "camtool" : "direct") + "]");
@@ -493,6 +496,14 @@ public class ScreenPanel extends Panel {
renderer.removeOverlays(userOv);
renderer.clear();
renderer.resetZoom();
if ((tcomboScreen!=null) && (tcomboScreen.isAlive())){
tcomboScreen.interrupt();
}
if ((tcomboFilter!=null) && (tcomboFilter.isAlive())){
tcomboFilter.interrupt();
}
if (screen != null) {
screen.close();
@@ -504,7 +515,7 @@ public class ScreenPanel extends Panel {
}
//Parallelizing initialization
Thread tcomboScreen = new Thread(() -> {
tcomboScreen = new Thread(() -> {
try {
screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS");
screen.initialize();
@@ -525,7 +536,7 @@ public class ScreenPanel extends Panel {
});
tcomboScreen.start();
Thread tcomboFilter = new Thread(() -> {
tcomboFilter = new Thread(() -> {
try {
filter = new DiscretePositioner("CurrentFilter", cameraName + ":SET_FILTER", cameraName + ":GET_FILTER");
filter.initialize();
+70 -88
View File
@@ -1,113 +1,95 @@
"""
Parameters:
args = [prefix ]
"""
import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
latency = 0.05
if get_exec_pars().source == CommandSource.ui:
prefix = "MINSB03-RSYS"
start = -170.0
stop = 180.0
step = 10.0
prefix = "SINSB04-RSYS"
else:
prefix = args[0]
start = caget("PSHELL:scanstart")
stop = caget("PSHELL:scanstop")
step = caget("PSHELL:scanstep")
prefix = args[0] + "-RSYS"
start = caget(prefix + ":SET-SCAN-START")
stop = caget(prefix + ":SET-SCAN-STOP")
step = caget(prefix + ":SET-SCAN-STEP")
lat = caget(prefix + ":SET-SCAN-WAIT-TIME")
nb = caget(prefix + ":SET-NUM-AVERAGE")
bpm_ch = caget(prefix + ":DBPM")
disp = caget(bpm_ch + ":DISPERSION")
energy0 = caget(bpm_ch + ":ENERGY")
print "Prefix = ", prefix
print "Start = ", start
print "Stop = ", stop
print "Step = ", step
phase = ControlledVariable("Phase", prefix + ":SET-VSUM-PHASE-SIM", prefix + ":GET-VSUM-PHASE-SIM")
phase.config.minValue =-45.0
phase.config.maxValue = 360.0
phase.config.resolution = 0.5
phase.initialize()
#rf_phase_setpoint = Channel(prefix + ":SET-VSUM-PHASE")
#rf_phase_readback = Channel(prefix + ":GET-VSUM-PHASE")
#rf_ampl_readback = Channel(prefix + ":GET-VSUM-AMPLT")
#rf_phase_setpoint = create_channel_device(prefix + ":SET-VSUM-PHASE", type = 'd', deviceName='Phase Setpoint')
#rf_phase_readback = create_channel_device(prefix + ":GET-VSUM-PHASE", type = 'd', deviceName='Phase Readback')
V = Channel(prefix + ":GET-VSUM-AMPLT-SIM", type = 'd', alias='Amplitude Readback')
P = Channel(prefix + ":GET-KLY-POWER-SIM", type = 'd', alias='Power Readback')
x = Channel(bpm_ch + ":X1-SIMU", type = 'd', alias='BPM-X')
rf_phase_var = ControlledVariable("Phase", prefix + ":SET-VSUM-PHASE", prefix + ":GET-VSUM-PHASE")
(rf_phase_var.config.minValue, rf_phase_var.config.maxValue)= (-180.0, 180.0)
rf_phase_var.config.resolution = 0.001
rf_phase_var.initialize()
rf_ampl_readback = create_channel_device(prefix + ":GET-VSUM-AMPLT", type = 'd', deviceName='Amplitude Readback')
caput(prefix + ":GET-FIT-PHASE-ARRAY", to_array([0.0],'d'))
caput(prefix + ":GET-FIT-ENERGY-ARRAY", to_array([0.0],'d'))
caput(prefix + ":GET-ONCREST-VSUM-PHASE", float('nan'))
caput(prefix + ":GET-ONCREST-VSUM-AMPLT", float('nan'))
caput(prefix + ":GET-ONCREST-E-GAIN", float('nan'))
caput(prefix + ":GET-ONCREST-KLY-POWER", float('nan'))
caput(prefix + ":CALC-VSUM-PHASE-OFFSET", float('nan'))
caput(prefix + ":CALC-VSUM-AMPLT-SCALE" , float('nan'))
caput(prefix + ":CALC-VOLT-POWER-SCALE" , float('nan'))
#add_device (rf_phase_var, True)
#add_device (rf_ampl_readback, True)
"""
scan_pos.set([])
scan_val.set([])
#update the plot dynamically
arr_phase,arr_energy = [],[]
def after(rec):
scan_val.append(rec.values[0])
scan_pos.append(rec.positions[0])
"""
#TODO: this is workaround to CAS not supporting dynamic arrays
def after(rec):
global arrpos,arrval
#print rec.index
arrval = scan_val.take().tolist()
arrpos = scan_pos.take().tolist()
arrval[rec.index] = rec.values[0]
arrpos[rec.index] = rec.positions[0]
arrval[rec.index:] = [rec.values[0]] * (len(arrval) -rec.index)
arrpos[rec.index:] = [rec.positions[0]] * (len(arrpos) -rec.index)
scan_val.set(arrval)
scan_pos.set(arrpos)
global arrpos, arrval, disp, energy0
arr_phase.append(rec.positions[0])
arr_energy.append(rec.values[1]/1000.0/disp*energy0)
caput(prefix + ":GET-ENERGY-ARRAY", to_array(arr_energy,'d'))
caput(prefix + ":GET-PHASE-ARRAY", to_array(arr_phase,'d'))
try:
#r = lscan(pos, [rf_phase_readback, rf_ampl_readback, sim], start, stop, step , latency=0.2, after_read = after)
#r = lscan(rf_phase_setpoint, [rf_phase_readback, rf_ampl_readback, sim], start, stop, step , latency=0.5, after_read = after)
sim.step = step
r = lscan(rf_phase_var, [rf_ampl_readback, bpm_q], start, stop, step , latency=latency, after_read = after)
#To sample a0
Vb = create_averager(V, nb, lat)
xb = create_averager(x, nb, lat)
f = r.getReadable(1) # r.getReadable(2)
f_ampl = r.getReadable(0) # r.getReadable(1)
xdata = r.getPositions(0) # r.getReadable(0)
#plot(r.getReadable(1), xdata = r.getPositions(0), title = "data")
r = lscan(phase, [V, x], start, stop, step , latency=lat, after_read = after)
rf_phase = r.getPositions(0)
energy = [val/1000.0/disp*energy0 for val in r.getReadable(1)]
caput(prefix + ":GET-ENERGY-ARRAY", to_array(energy,'d'))
caput(prefix + ":GET-PHASE-ARRAY", to_array(rf_phase,'d'))
phase_fit_max = None
try:
(amplitude, angular_frequency, phase, phase_fit_max, fit_x, fit_y) = hfit(f , xdata = xdata)
(energy_max, angular_frequency, phase0, in_range, phase_fit_max, fit_x, fit_y) = hfit(energy , xdata = rf_phase)
except:
raise Exception("Fit failure")
start,end = min(xdata), max(xdata)
if not (start <=phase_fit_max <=end):
raise Exception("Fit failure")
caput(prefix + ":GET-ONCREST-VSUM-PHASE", phase_fit_max)
caput(prefix + ":GET-ONCREST-E-GAIN", energy_max)
caput(prefix + ":GET-FIT-PHASE-ARRAY", fit_x)
caput(prefix + ":GET-FIT-ENERGY-ARRAY", fit_y)
phase_min, phase_max = min(rf_phase), max(rf_phase)
if not (phase_min <= phase_fit_max <= phase_max):
raise Exception("Fit maximum outside scan range")
rf_phase_var.write(phase_fit_max)
time.sleep(latency)
a0 = rf_ampl_readback.read()
power = 1.0 #TODO
phase.write(phase_fit_max)
time.sleep(lat)
Ampl = V.read()
Power = P.read()
caput(prefix + ":GET-ONCREST-VSUM-AMPLT", Ampl)
caput(prefix + ":GET-ONCREST-KLY-POWER", Power)
finally:
#rf_phase_setpoint.close()
#rf_phase_readback.close()
rf_phase_var.close()
rf_ampl_readback.close()
phase.close()
V.close()
P.close()
x.close()
print ("------------------------------------")
print ("Valid fit")
energy_gain = energy_max
phase_offset = 90 - phase_fit_max
amplitude_scale = energy_gain / Ampl
power_scale = Power / math.pow(Ampl,2)
caput(prefix + ":CALC-VSUM-PHASE-OFFSET", phase_offset)
caput(prefix + ":CALC-VSUM-AMPLT-SCALE" , amplitude_scale)
caput(prefix + ":CALC-VOLT-POWER-SCALE" , power_scale)
energy_gain = amplitude
phase_offset = - phase_fit_max
amplitude_scale = energy_gain / a0
power_scale = power / math.pow(a0,2)
set_return("\nEnergy Gain: " + str(energy_gain) + "\n" +
"Phase Offset: " + str(phase_offset) + "\n" +
"Amplitude Scale: " + str(amplitude_scale) + "\n" +
"Power Scale: " + str(power_scale))
#caput(prefix + ":SET-VSUM-PHASE-OFFSET", phase_offset)
#caput(prefix + ":SET-VSUM-AMPLT-SCALE", amplitude_scale)
#caput(prefix + ":SET-VOLT-POWER-SCALE", power_scale)
#set_return(r.print())
set_return("Energy Gain: " + str(energy_gain) + "\nPhase Offset: " + str(phase_offset) + "\nAmplitude Scale: " + str(amplitude_scale) + "\nPower Scale: "+ str(power_scale))
-90
View File
@@ -1,90 +0,0 @@
import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
if get_exec_pars().source != CommandSource.ui:
prefix = args[0] + "-RSYS"
start = caget(prefix + ":SET-SCAN-START")
stop = caget(prefix + ":SET-SCAN-STOP")
step = caget(prefix + ":SET-SCAN-STEP")
lat = caget(prefix + ":SET-SCAN-WAIT-TIME")
nb = caget(prefix + ":SET-NUM-AVERAGE")
bpm_ch = caget(prefix + ":DBPM")
disp = caget(bpm_ch + ":DISPERSION")
energy0 = caget(bpm_ch + ":ENERGY")
rf_phase_var = ControlledVariable("Phase", prefix + ":SET-VSUM-PHASE-SIM", prefix + ":SET-VSUM-PHASE-SIM") #TODO: CHANGE TO GET
rf_phase_var.config.minValue =-180.0
rf_phase_var.config.maxValue = 180.0
rf_phase_var.config.resolution = 0.001
rf_phase_var.initialize()
rf_ampl_rbk = Channel(prefix + ":GET-VSUM-AMPLT-SIM", type = 'd', alias='Amplitude Readback')
rf_ampl_rbk.write(1.0)
rf_power_rbk = Channel(prefix + ":GET-KLY-POWER-SIM", type = 'd', alias='Power Readback')
bpm_x = Channel(bpm_ch + ":X1-SIM", type = 'd', alias='BPM-X')
caput(prefix + ":GET-FIT-PHASE-ARRAY", to_array([0.0],'d'))
caput(prefix + ":GET-FIT-ENERGY-ARRAY", to_array([0.0],'d'))
caput(prefix + ":CALC-VSUM-PHASE-OFFSET", float('nan'))
caput(prefix + ":CALC-VSUM-AMPLT-SCALE" , float('nan'))
caput(prefix + ":CALC-VOLT-POWER-SCALE" , float('nan'))
#update the plot dynamically
arr_phase,arr_energy = [],[]
def after(rec):
global arrpos,arrval, disp, energy0
arr_phase.append(rec.positions[0])
arr_energy.append(rec.values[1]/1000.0/disp*energy0)
caput(prefix + ":GET-ENERGY-ARRAY", to_array(arr_energy,'d'))
caput(prefix + ":GET-PHASE-ARRAY", to_array(arr_phase,'d'))
try:
r = lscan(rf_phase_var, [rf_ampl_rbk, bpm_q], start, stop, step , latency=lat, after_read = after)
rf_phase = r.getPositions(0)
energy = [x/1000.0/disp*energy0 for x in r.getReadable(1)]
caput(prefix + ":GET-ENERGY-ARRAY", to_array(energy,'d'))
caput(prefix + ":GET-PHASE-ARRAY", to_array(rf_phase,'d'))
phase_fit_max = None
try:
(energy_max, angular_frequency, phase0, in_range, phase_fit_max, fit_x, fit_y) = hfit(energy , xdata = rf_phase)
except:
raise Exception("Fit failure")
caput(prefix + ":GET-FIT-PHASE-ARRAY", fit_x)
caput(prefix + ":GET-FIT-ENERGY-ARRAY", fit_y)
phase_min, phase_max = min(rf_phase), max(rf_phase)
if not (phase_min <= phase_fit_max <= phase_max):
raise Exception("Fit maximum outside scan range")
rf_phase_var.write(phase_fit_max)
time.sleep(lat)
ampl = rf_ampl_rbk.read()
power = rf_power_rbk.read()
finally:
rf_phase_var.close()
rf_ampl_rbk.close()
rf_power_rbk.close()
bpm_x.close()
print ("------------------------------------")
print ("Valid fit")
energy_gain = energy_max
phase_offset = - phase_fit_max
amplitude_scale = energy_gain / ampl
power_scale = power / math.pow(ampl,2)
caput(prefix + ":CALC-VSUM-PHASE-OFFSET", phase_offset)
caput(prefix + ":CALC-VSUM-AMPLT-SCALE" , amplitude_scale)
caput(prefix + ":CALC-VOLT-POWER-SCALE" , power_scale)
set_return("\nEnergy Gain: " + str(energy_gain) + "\n" +
"Phase Offset: " + str(phase_offset) + "\n" +
"Amplitude Scale: " + str(amplitude_scale) + "\n" +
"Power Scale: " + str(power_scale))
-95
View File
@@ -1,95 +0,0 @@
import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
if get_exec_pars().source == CommandSource.ui:
prefix = "SINSB04-RSYS"
else:
prefix = args[0] + "-RSYS"
start = caget(prefix + ":SET-SCAN-START")
stop = caget(prefix + ":SET-SCAN-STOP")
step = caget(prefix + ":SET-SCAN-STEP")
lat = caget(prefix + ":SET-SCAN-WAIT-TIME")
nb = caget(prefix + ":SET-NUM-AVERAGE")
bpm_ch = caget(prefix + ":DBPM")
disp = caget(bpm_ch + ":DISPERSION")
energy0 = caget(bpm_ch + ":ENERGY")
phase = ControlledVariable("Phase", prefix + ":SET-VSUM-PHASE-SIM", prefix + ":GET-VSUM-PHASE-SIM")
phase.config.minValue =-45.0
phase.config.maxValue = 360.0
phase.config.resolution = 0.5
phase.initialize()
V = Channel(prefix + ":GET-VSUM-AMPLT-SIM", type = 'd', alias='Amplitude Readback')
P = Channel(prefix + ":GET-KLY-POWER-SIM", type = 'd', alias='Power Readback')
x = Channel(bpm_ch + ":X1-SIMU", type = 'd', alias='BPM-X')
caput(prefix + ":GET-FIT-PHASE-ARRAY", to_array([0.0],'d'))
caput(prefix + ":GET-FIT-ENERGY-ARRAY", to_array([0.0],'d'))
caput(prefix + ":GET-ONCREST-VSUM-PHASE", float('nan'))
caput(prefix + ":GET-ONCREST-VSUM-AMPLT", float('nan'))
caput(prefix + ":GET-ONCREST-E-GAIN", float('nan'))
caput(prefix + ":GET-ONCREST-KLY-POWER", float('nan'))
caput(prefix + ":CALC-VSUM-PHASE-OFFSET", float('nan'))
caput(prefix + ":CALC-VSUM-AMPLT-SCALE" , float('nan'))
caput(prefix + ":CALC-VOLT-POWER-SCALE" , float('nan'))
#update the plot dynamically
arr_phase,arr_energy = [],[]
def after(rec):
global arrpos, arrval, disp, energy0
arr_phase.append(rec.positions[0])
arr_energy.append(rec.values[1]/1000.0/disp*energy0)
caput(prefix + ":GET-ENERGY-ARRAY", to_array(arr_energy,'d'))
caput(prefix + ":GET-PHASE-ARRAY", to_array(arr_phase,'d'))
try:
Vb = create_averager(V, nb, lat)
xb = create_averager(x, nb, lat)
r = lscan(phase, [V, x], start, stop, step , latency=lat, after_read = after)
rf_phase = r.getPositions(0)
energy = [val/1000.0/disp*energy0 for val in r.getReadable(1)]
caput(prefix + ":GET-ENERGY-ARRAY", to_array(energy,'d'))
caput(prefix + ":GET-PHASE-ARRAY", to_array(rf_phase,'d'))
phase_fit_max = None
try:
(energy_max, angular_frequency, phase0, in_range, phase_fit_max, fit_x, fit_y) = hfit(energy , xdata = rf_phase)
except:
raise Exception("Fit failure")
caput(prefix + ":GET-ONCREST-VSUM-PHASE", phase_fit_max)
caput(prefix + ":GET-ONCREST-E-GAIN", energy_max)
caput(prefix + ":GET-FIT-PHASE-ARRAY", fit_x)
caput(prefix + ":GET-FIT-ENERGY-ARRAY", fit_y)
phase_min, phase_max = min(rf_phase), max(rf_phase)
if not (phase_min <= phase_fit_max <= phase_max):
raise Exception("Fit maximum outside scan range")
phase.write(phase_fit_max)
time.sleep(lat)
Ampl = V.read()
Power = P.read()
caput(prefix + ":GET-ONCREST-VSUM-AMPLT", Ampl)
caput(prefix + ":GET-ONCREST-KLY-POWER", Power)
finally:
phase.close()
V.close()
P.close()
x.close()
print ("------------------------------------")
print ("Valid fit")
energy_gain = energy_max
phase_offset = 90 - phase_fit_max
amplitude_scale = energy_gain / Ampl
power_scale = Power / math.pow(Ampl,2)
caput(prefix + ":CALC-VSUM-PHASE-OFFSET", phase_offset)
caput(prefix + ":CALC-VSUM-AMPLT-SCALE" , amplitude_scale)
caput(prefix + ":CALC-VOLT-POWER-SCALE" , power_scale)
set_return("\nEnergy Gain: " + str(energy_gain) + "\n" +
"Phase Offset: " + str(phase_offset) + "\n" +
"Amplitude Scale: " + str(amplitude_scale) + "\n" +
"Power Scale: " + str(power_scale))