From b1e640f8563cb507c387d794e298d5cdd631a28b Mon Sep 17 00:00:00 2001 From: follath_r Date: Fri, 1 Sep 2017 16:34:27 +0200 Subject: [PATCH] Startup --- devices/Beam phase.properties | 4 +- devices/CurrentCamera.properties | 26 +++++----- script/test/PBPGMonitor.py | 19 ++++++++ script/test/PBPGMonitor_dv.py | 20 ++++++++ script/test/SchottkyScan_dv.py | 81 ++++++++++++++++---------------- script/test/didier.py | 50 ++++++++++---------- 6 files changed, 119 insertions(+), 81 deletions(-) create mode 100644 script/test/PBPGMonitor.py create mode 100644 script/test/PBPGMonitor_dv.py diff --git a/devices/Beam phase.properties b/devices/Beam phase.properties index 0336756..8ffe649 100644 --- a/devices/Beam phase.properties +++ b/devices/Beam phase.properties @@ -1,9 +1,9 @@ -#Thu Aug 31 15:34:24 CEST 2017 +#Fri Sep 01 09:01:32 CEST 2017 maxValue=360.0 minValue=-360.0 offset=0.0 precision=3 -resolution=0.01 +resolution=0.1 rotation=false scale=1.0 unit=deg diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index 8aef419..2dab3d0 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,16 +1,16 @@ -#Thu Aug 31 16:04:25 CEST 2017 -colormap=Flame -colormapAutomatic=false -colormapMax=100.0 -colormapMin=0.0 +#Fri Sep 01 16:03:41 CEST 2017 +colormap=Grayscale +colormapAutomatic=true +colormapMax=65535.0 +colormapMin=68.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=2160 -imageWidth=2560 +imageHeight=494 +imageWidth=659 invert=false -regionStartX=1 -regionStartY=1 +regionStartX=0 +regionStartY=0 rescaleFactor=1.0 rescaleOffset=0.0 roiHeight=-1 @@ -21,9 +21,9 @@ rotation=0.0 rotationCrop=false scale=1.0 serverURL=localhost\:10000 -spatialCalOffsetX=-494.60613836798643 -spatialCalOffsetY=-127.25760231742446 -spatialCalScaleX=-12.531280555023006 -spatialCalScaleY=-10.582010451001521 +spatialCalOffsetX=-640.5003909304144 +spatialCalOffsetY=-512.5004887585533 +spatialCalScaleX=-8.4375 +spatialCalScaleY=-8.49609375 spatialCalUnits=mm transpose=false diff --git a/script/test/PBPGMonitor.py b/script/test/PBPGMonitor.py new file mode 100644 index 0000000..33f0be2 --- /dev/null +++ b/script/test/PBPGMonitor.py @@ -0,0 +1,19 @@ +#ch1 = Channel("SARFE10-PBPG050:HAMP-INTENSITY",'d',alias="CH1") +ch1 = create_channel_device("SARFE10-PBPG050:HAMP-INTENSITY", type='d', size=None, deviceName="CH1" ) +av1 = create_averager(ch1, count = 30, interval = 1.0, name="AV1") +ch1.monitored = True +av1.monitored = True + +class StDev(ReadonlyRegisterBase): + def doRead(self): + global av1 + return av1.getStdev().read() + + +stdev1 = StDev() +stdev1.initialize() +stdev1.setPolling(0.1) + +add_device(ch1, True) +add_device(av1, True) +add_device(stdev1, True) diff --git a/script/test/PBPGMonitor_dv.py b/script/test/PBPGMonitor_dv.py new file mode 100644 index 0000000..8f23442 --- /dev/null +++ b/script/test/PBPGMonitor_dv.py @@ -0,0 +1,20 @@ +#ch1 = Channel("SARFE10-PBPG050:HAMP-INTENSITY",'d',alias="CH1") +ch1 = create_channel_device("SARFE10-PBPG050:HAMP-INTENSITY", type='d', size=None, deviceName="HAMP-INTENSITY" ) +ch2 = create_channel_device("SARFE10-PBPG050:PHOTON-ENERGY-PER-SECOND-US", type='d', size=None, deviceName="PHOTON-ENERGY-PER-SECOND-US" ) +ch3 = create_channel_device("SARFE10-PBPG050:PHOTON-ENERGY-PER-SECOND-DS", type='d', size=None, deviceName="PHOTON-ENERGY-PER-SECOND-DS" ) +av1 = create_averager(ch1, count = 30, interval = 1.0, name="AV-HAMP-INTENSITY") +av2 = create_averager(ch2, count = 30, interval = 1.0, name="AV-PHOTON-ENERGY-PER-SECOND-US") +av3 = create_averager(ch3, count = 30, interval = 1.0, name="AV-PHOTON-ENERGY-PER-SECOND-DS") +ch1.monitored = True +ch2.monitored = True +ch3.monitored = True +av1.monitored = True +av2.monitored = True +av3.monitored = True + +add_device(ch1, True) +add_device(ch2, True) +add_device(ch3, True) +add_device(av1, True) +add_device(av2, True) +add_device(av3, True) diff --git a/script/test/SchottkyScan_dv.py b/script/test/SchottkyScan_dv.py index 8ce7d52..a83d012 100644 --- a/script/test/SchottkyScan_dv.py +++ b/script/test/SchottkyScan_dv.py @@ -5,8 +5,6 @@ dry_run = True do_elog = False is_panel = get_exec_pars().source != CommandSource.ui #must be check before run -run("CPython/wrapper") - if is_panel: start = args[0] stop = args[1] @@ -17,16 +15,19 @@ if is_panel: else: start = -50.0 stop = 150.0 - step = 2.0 + step = 10.0 nb = 2 lat = 0.120 - plt = None + plt = plot(None, title="Output")[0] -if plt is not None: - plt.clear() - plt.addSeries(LinePlotErrorSeries("Values")) - plt.getAxis(plt.AxisId.X).setLabel("Gun Beam Phase (deg)") - plt.getAxis(plt.AxisId.Y).setLabel("SINEG01-DICT215:B1_CHARGE") +#Plot setup +plt.clear() +plt.removeMarker(None) +plt.setStyle(plt.Style.ErrorY) +plt.addSeries(LinePlotErrorSeries("Charge", Color.red)) +plt.getAxis(plt.AxisId.X).setLabel("Gun Beam Phase (deg)") +plt.getAxis(plt.AxisId.Y).setLabel("SINEG01-DICT215:B1_CHARGE") +plt.setLegendVisible(True) if dry_run: bph = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM") @@ -45,7 +46,6 @@ else: q = ChannelDouble("Charge", "SINEG01-DICT215:B1_CHARGE") q.initialize() q.monitored=True - bph.config.minValue = -360.0 bph.config.maxValue = 360.0 bph.config.precision = 3 @@ -59,49 +59,48 @@ rph.monitored=True bph0 = bph.read() rph0 = rph.read() +#Creating averagers +rph_averager = create_averager(rph, nb, 0.1) +q_averager = create_averager(q, nb, 0.1) +q_averager.monitored=True + #Record callback: uptate of output plot def after_sample(record, scan): - if plt is not None: - plt.getSeries(0).appendData(record.positions[0], record.values[1].mean, record.values[1].stdev) + plt.getSeries(0).appendData(record.positions[0], record.values[1].mean, record.values[1].stdev) +#The scan loop try: - rph_averager = create_averager(rph, nb, 0.1) - q_averager = create_averager(q, nb, 0.1) - q_averager.monitored=True r = lscan(bph, (rph_averager, q_averager), start, stop, step, latency=lat, after_read = after_sample) - beamphase = r.getPositions(0) - rfphase = [val.mean for val in r.getReadable(0)] - rfphaserms = [val.stdev for val in r.getReadable(0)] - charge = [val.mean for val in r.getReadable(1)] - chargerms = [val.stdev for val in r.getReadable(1)] finally: rph.write(rph0) bph.close() rph.close() q.close() #st.close() - + +beamphase = r.getPositions(0) +rfphase = [val.mean for val in r.getReadable(0)] +rfphaserms = [val.stdev for val in r.getReadable(0)] +charge = [val.mean for val in r.getReadable(1)] +chargerms = [val.stdev for val in r.getReadable(1)] + #Fitting and plotting -try: - i_max = charge.index(max(charge)) - min_i = charge.index(max(charge) * 0.10) - max_i = charge.index(min(charge) * 0.60) - readable = charge[min_i:max_i] - positions = beamphase[min_i:max_i] - pars_polynomial = (a0, a1) = fit_polynomial(readable, positions, 1) - fitted_polynomial_function = PolynomialFunction(pars_polynomial) - - plt.addSeries(LinePlotErrorSeries("Momentum Fit", plt.getSeries(0).color)) - plt.addSeries(LinePlotErrorSeries("Momentum Spread Fit", plt.getSeries(1).color, 2)) - plt.getSeries(2).setData(ph_p_fit, p_fit) - plt.getSeries(3).setData(ph_dp_fit, dp_fit) - plt.getSeries(2).setPointsVisible(False) - plt.getSeries(3).setPointsVisible(False) - plt.addMarker(ph_p_max, plt.AxisId.X, "%3.2f" % ph_p_max, plt.getSeries(0).color) - plt.addMarker(ph_dp_min, plt.AxisId.X, "%3.2f" % ph_dp_min, plt.getSeries(1).color) -except: - raise Exception("Fit failure") - +#try: +i, i_min, i_max = 0, 0, 0 +while charge[i] < max(charge) * 0.10 : i_min = i; i = i + 1 +while charge[i] < max(charge) * 0.60 : i_max = i; i = i + 1 +readable = charge[i_min:i_max] +positions = beamphase[i_min:i_max] +pars_polynomial = (a0, a1) = fit_polynomial(readable, positions, 1) +fitted_polynomial_function = PolynomialFunction(pars_polynomial) +charge_fit = [] +for x in beamphase: charge_fit.append(fitted_polynomial_function.value(x)) +plt.addSeries(LinePlotSeries("Fit", plt.getSeries(0).color)) +plt.getSeries(1).setData(beamphase, charge_fit) +plt.getSeries(1).setPointsVisible(False) + #plt.addMarker(ph_p_max, plt.AxisId.X, "%3.2f" % ph_p_max, plt.getSeries(0).color) +#except: +# raise Exception("Fit failure") #Elog entry if do_elog: diff --git a/script/test/didier.py b/script/test/didier.py index 7d0c3b6..a0ea99f 100644 --- a/script/test/didier.py +++ b/script/test/didier.py @@ -1,33 +1,33 @@ import ch.psi.pshell.epics.ChannelDouble as ChannelDouble - -t = ChannelDouble("fine delay (ns)", "SINEG01-DICT215:Pul1-Delay-SP-SIM") -q = ChannelDouble("charge (pC)", "SINEG01-DICT215:AL1-ICT-CHARGE-SIM") -V = ChannelDouble("DC output (V)", "SINEG01-DICT215:AL1-ICT-VOLTAGE-SIM") -t.initialize() -q.initialize() -V.initialize() - -t0 = t.read() - +A1 = ChannelDouble("Actuator1", "SINSB03-RSYS:GET-BEAM-PHASE") +A2 = ChannelDouble("Actuator2", "SINSB04-RSYS:GET-BEAM-PHASE") +S1 = ChannelDouble("Sensor1", "SARFE10-PBPG050:HAMP-INTENSITY") +S2 = ChannelDouble("Sensor2", "SARFE10-PBPG050:PHOTON-ENERGY-PER-SECOND-US") +A1.initialize() +A2.initialize() +S1.initialize() +S2.initialize() +A1_0 = A1.read() +A2_0 = A2.read() start = 0.0 stop = 10.0 step = 0.1 nb = 2 lat = 0.080 - - try: - q_averager = create_averager(q, nb, lat) - V_averager = create_averager(V, nb, lat) - V_averager.monitored=True - r = lscan(t, (q_averager, V_averager), start, stop, step, latency=lat) - delay = r.getPositions(0) - charge = [val.mean for val in r.getReadable(0)] - chargerms = [val.stdev for val in r.getReadable(0)] - volt = [val.mean for val in r.getReadable(1)] - voltrms = [val.stdev for val in r.getReadable(1)] + S1_averager = create_averager(S1, nb, lat) + S2_averager = create_averager(S2, nb, lat) + S2_averager.monitored=True + r = lscan((A1, A2), (S1_averager, S2_averager), start, stop, step, latency=lat) + Act1 = r.getPositions(0) + Act2 = r.getPositions(1) + S1mean = [val.mean for val in r.getReadable(0)] + S1rms = [val.stdev for val in r.getReadable(0)] + S2mean = [val.mean for val in r.getReadable(1)] + S2rmsn = [val.stdev for val in r.getReadable(1)] finally: - t.write(t0) - t.close() - q.close() - V.close() + A1.write(A1_0) + A2.write(A2_0) + A1.close() + S1.close() + S2.close() \ No newline at end of file