ScreenPanel

This commit is contained in:
voulot_d
2017-06-08 09:02:03 +02:00
parent d2155f810c
commit e0bf701e24
4 changed files with 56 additions and 47 deletions

View File

@@ -1,7 +1,7 @@
#Wed Jun 07 14:45:43 CEST 2017
#Thu Jun 08 08:55:20 CEST 2017
colormap=Flame
colormapAutomatic=false
colormapMax=300.0
colormapMax=6000.0
colormapMin=1.0
flipHorizontally=false
flipVertically=false
@@ -21,9 +21,9 @@ rotation=0.0
rotationCrop=false
scale=1.0
serverURL=localhost\:10000
spatialCalOffsetX=-971.5790174628223
spatialCalOffsetY=-612.4991815322336
spatialCalScaleX=-8.510638533281156
spatialCalScaleY=-8.235816743984502
spatialCalOffsetX=-50.03909304143862
spatialCalOffsetY=-50.048875855327466
spatialCalScaleX=-1.0
spatialCalScaleY=-1.0
spatialCalUnits=mm
transpose=false

View File

@@ -1282,25 +1282,40 @@ public class ScreenPanel extends Panel {
Overlay ov = uo.obj;
//Overlay ov = (Overlay)uo.cls.newInstance();
ov.setCalibration(renderer.getCalibration());
boolean valid = false;
if (ov instanceof Overlays.Polyline) {
double[] x = (uo.channels[0].equals("null")) ? null : getCamtoolDoubleArray(uo.channels[0]);
double[] y = (uo.channels[1].equals("null")) ? null : getCamtoolDoubleArray(uo.channels[1]);
if (x == null) {
x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length);
if ((x != null) || (y !=null)) {
if (x == null) {
x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length);
}
if (y == null) {
y = (renderer.getCalibration() == null) ? Arr.indexesDouble(x.length) : renderer.getCalibration().getAxisY(x.length);
}
((Overlays.Polyline) ov).updateAbsolute(x, y);
valid = true;
}
if (y == null) {
y = (renderer.getCalibration() == null) ? Arr.indexesDouble(x.length) : renderer.getCalibration().getAxisY(x.length);
}
((Overlays.Polyline) ov).updateAbsolute(x, y);
} else {
PointDouble position = new PointDouble(getCamtoolDouble(uo.channels[0]), getCamtoolDouble(uo.channels[1]));
ov.setAbsolutePosition(position);
if (!(ov instanceof Overlays.Crosshairs)) {
DimensionDouble size = new DimensionDouble(getCamtoolDouble(uo.channels[2]) - position.x, getCamtoolDouble(uo.channels[3]) - position.y);
ov.setAbsoluteSize(size);
Double x = getCamtoolDouble(uo.channels[0]); Double y = getCamtoolDouble(uo.channels[1]);
if ((x != null) && (y !=null)) {
PointDouble position = new PointDouble(x,y);
ov.setAbsolutePosition(position);
if (!(ov instanceof Overlays.Crosshairs)) {
Double x2 = getCamtoolDouble(uo.channels[2]); Double y2 = getCamtoolDouble(uo.channels[3]);
if ((x != null) && (y !=null)) {
DimensionDouble size = new DimensionDouble(x2 - position.x, y2 - position.y);
ov.setAbsoluteSize(size);
valid = true;
}
} else {
valid = true;
}
}
}
ret.add(ov);
if (valid){
ret.add(ov);
}
} catch (Exception ex) {
ex.printStackTrace();
}

View File

@@ -15,7 +15,7 @@ nb = caget(station + "-RSYS:SET-NUM-AVERAGE")
disp = caget(bpm_ch + ":DISPERSION")
energy0 = caget(bpm_ch + ":ENERGY")
phase = ControlledVariable("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:SET-VSUM-PHASE")
phase = ControlledVariable("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE")
phase.config.minValue =-180.0
phase.config.maxValue = 360.0
phase.config.resolution = 0.5
@@ -39,30 +39,31 @@ arr_phase,arr_energy = [],[]
def after(rec):
global disp, energy0
arr_phase.append(rec.positions[0])
arr_energy.append(rec.values[0].mean/1000.0/disp*energy0)
arr_energy.append(energy0 * (1 + rec.values[0].mean / 1000.0 / disp))
caput(station + "-RSYS:GET-PHASE-ARRAY", to_array(arr_phase, 'd'))
caput(station + "-RSYS:GET-ENERGY-ARRAY", to_array(arr_energy,'d'))
try:
xb = create_averager(x, nb, 0.100)
r = lscan(phase, xb, start, stop, step, latency=lat, after_read = after)
x_averager = create_averager(x, nb, 0.100)
r = lscan(phase, x_averager, start, stop, step, latency=lat, after_read = after)
rf_phase = r.getPositions(0)
energy = [val.mean/1000.0/disp*energy0 for val in r.getReadable(0)]
energy = [energy0 * (1 + val.mean / 1000.0 / disp) for val in r.getReadable(0)]
caput(station + "-RSYS:GET-ENERGY-ARRAY", to_array(energy, 'd'))
caput(station + "-RSYS: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)
run("CPython/wrapper")
(fit_amplitude, fit_phase_deg, fit_offset, ph_crest, fit_x, fit_y) = hfitoff(energy , rf_phase)
except:
raise Exception("Fit failure")
caput(station + "-RSYS:GET-ONCREST-VSUM-PHASE", phase_fit_max)
caput(station + "-RSYS:GET-ONCREST-E-GAIN", energy_max)
plot([energy, fit_y], ["data", "fit"], [rf_phase, fit_x])
caput(station + "-RSYS:GET-ONCREST-VSUM-PHASE", ph_crest)
caput(station + "-RSYS:GET-ONCREST-E-GAIN", fit_amplitude)
caput(station + "-RSYS:GET-FIT-PHASE-ARRAY", fit_x)
caput(station + "-RSYS: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)
if not (phase_min <= ph_crest <= phase_max):
raise Exception("On-crest phase outside scan range")
phase.write(ph_crest)
time.sleep(lat)
Ampl = V.read()
Power = P.read()
@@ -75,10 +76,7 @@ finally:
P.close()
x.close()
print ("------------------------------------")
print ("Valid fit")
phase_offset = 90 - phase_fit_max
phase_offset = 90 - ph_crest
amplitude_scale = energy_max / Ampl
power_scale = Power / math.pow(Ampl,2)

View File

@@ -15,15 +15,17 @@ nb = caget(station + "-RSYS:SET-NUM-AVERAGE")
disp = caget(bpm_ch + ":DISPERSION")
energy0 = caget(bpm_ch + ":ENERGY")
phase = ControlledVariable("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:SET-VSUM-PHASE")
phase = ControlledVariable("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE")
phase.config.minValue =-180.0
phase.config.maxValue = 360.0
phase.config.resolution = 0.5
phase.initialize()
V = Channel(station + "-RSYS:GET-VSUM-AMPLT", type = 'd', alias='Amplitude Readback')
P = Channel(station + "-RSYS:GET-KLY-POWER", type = 'd', alias='Power Readback')
x = Channel(bpm_ch + ":X1-SIMU", type = 'd', alias='BPM-X')
V = Channel(station + "-RSYS:GET-VSUM-AMPLT", type = 'd', alias='Amplitude Readback')
P = Channel(station + "-RSYS:GET-KLY-POWER", type = 'd', alias='Power Readback')
x = Channel(bpm_ch + ":X1-SIMU", type = 'd', alias='BPM-X')
phase0 = phase.read()
caput(station + "-RSYS:GET-FIT-PHASE-ARRAY", to_array([0.0],'d'))
caput(station + "-RSYS:GET-FIT-ENERGY-ARRAY", to_array([0.0],'d'))
@@ -32,14 +34,12 @@ caput(station + "-RSYS:GET-ONCREST-VSUM-AMPLT", float('nan'))
caput(station + "-RSYS:GET-ONCREST-E-GAIN", float('nan'))
caput(station + "-RSYS:GET-ONCREST-KLY-POWER", float('nan'))
phase0 = phase.read()
#update the plot dynamically
arr_phase,arr_energy = [],[]
def after(rec):
global disp, energy0
arr_phase.append(rec.positions[0])
arr_energy.append(rec.values[0].mean/1000.0/disp*energy0)
arr_energy.append(energy0 * (1 + rec.values[0].mean / 1000.0 / disp))
caput(station + "-RSYS:GET-PHASE-ARRAY", to_array(arr_phase, 'd'))
caput(station + "-RSYS:GET-ENERGY-ARRAY", to_array(arr_energy,'d'))
@@ -47,7 +47,7 @@ try:
x_averager = create_averager(x, nb, 0.100)
r = lscan(phase, x_averager, start, stop, step, latency=lat, after_read = after)
rf_phase = r.getPositions(0)
energy = [val.mean/1000.0/disp*energy0 for val in r.getReadable(0)]
energy = [energy0 * (1 + val.mean / 1000.0 / disp) for val in r.getReadable(0)]
caput(station + "-RSYS:GET-ENERGY-ARRAY", to_array(energy, 'd'))
caput(station + "-RSYS:GET-PHASE-ARRAY", to_array(rf_phase,'d'))
try:
@@ -56,9 +56,8 @@ try:
except:
raise Exception("Fit failure")
plot([energy, fit_y], ["data", "fit"], [rf_phase, fit_x])
energy_max = fit_amplitude - fit_offset
caput(station + "-RSYS:GET-ONCREST-VSUM-PHASE", ph_crest)
caput(station + "-RSYS:GET-ONCREST-E-GAIN", energy_max)
caput(station + "-RSYS:GET-ONCREST-E-GAIN", fit_amplitude)
caput(station + "-RSYS:GET-FIT-PHASE-ARRAY", fit_x)
caput(station + "-RSYS:GET-FIT-ENERGY-ARRAY", fit_y)
phase_min, phase_max = min(rf_phase), max(rf_phase)
@@ -77,9 +76,6 @@ finally:
P.close()
x.close()
print ("------------------------------------")
print ("Valid fit")
phase_offset = 90 - ph_crest
amplitude_scale = energy_max / Ampl
power_scale = Power / math.pow(Ampl,2)