From 82306b88b4c9f37dfcb877cc08b253b4d60e3114 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 25 Jun 2018 15:18:33 +0200 Subject: [PATCH] --- devices/CurrentCamera.properties | 20 ++--- devices/WireScanner motor.properties | 4 +- plugins/ScreenPanel3.form | 1 + plugins/ScreenPanel3.java | 3 +- script/Diagnostics/WireScan.py | 17 ++++- script/Diagnostics/WireScanCalibration.py | 92 +++++++++++++++-------- script/Scan4.py | 35 +++++++++ 7 files changed, 127 insertions(+), 45 deletions(-) create mode 100644 script/Scan4.py diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index acb3c33..7a4d527 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,16 +1,16 @@ -#Mon Jun 18 16:41:56 CEST 2018 +#Mon Jun 25 12:57:35 CEST 2018 colormap=Flame colormapAutomatic=true -colormapMax=2000.0 +colormapMax=4000.0 colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=1200 -imageWidth=1246 +imageHeight=2160 +imageWidth=2560 invert=false -regionStartX=304 -regionStartY=8 +regionStartX=1 +regionStartY=1 rescaleFactor=1.0 rescaleOffset=0.0 roiHeight=-1 @@ -21,10 +21,10 @@ rotation=0.0 rotationCrop=false scale=1.0 serverURL=null -spatialCalOffsetX=-861.4939970777481 -spatialCalOffsetY=-820.4883730911062 -spatialCalScaleX=-18.90359092620482 -spatialCalScaleY=-19.37984500632817 +spatialCalOffsetX=-938.4756464214289 +spatialCalOffsetY=-887.658980452227 +spatialCalScaleX=-8.510638192507606 +spatialCalScaleY=-8.235816808193258 spatialCalUnits=null t= transpose=false diff --git a/devices/WireScanner motor.properties b/devices/WireScanner motor.properties index c63e09f..be6a1ef 100644 --- a/devices/WireScanner motor.properties +++ b/devices/WireScanner motor.properties @@ -1,5 +1,5 @@ -#Mon Jun 18 12:03:16 CEST 2018 -defaultSpeed=6000.0 +#Mon Jun 25 14:59:33 CEST 2018 +defaultSpeed=707.1067811865476 estbilizationDelay=0 hasEnable=false homingType=None diff --git a/plugins/ScreenPanel3.form b/plugins/ScreenPanel3.form index bc4a4f3..8f0edfa 100644 --- a/plugins/ScreenPanel3.form +++ b/plugins/ScreenPanel3.form @@ -1058,6 +1058,7 @@ + diff --git a/plugins/ScreenPanel3.java b/plugins/ScreenPanel3.java index 14cbbf4..03a3caa 100644 --- a/plugins/ScreenPanel3.java +++ b/plugins/ScreenPanel3.java @@ -2142,7 +2142,7 @@ public class ScreenPanel3 extends Panel { synchronized (imageBuffer) { saveFrames("camera_stack", imageBuffer); } - SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath(), 5000); + SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath()); } public static String getCameraType(String name) { @@ -3250,6 +3250,7 @@ public class ScreenPanel3 extends Panel { toolBar.add(buttonReticle); buttonTitle.setIcon(getIcon("Title")); + buttonTitle.setSelected(true); buttonTitle.setText(" "); buttonTitle.setToolTipText("Show Camera Name"); buttonTitle.setFocusable(false); diff --git a/script/Diagnostics/WireScan.py b/script/Diagnostics/WireScan.py index a5c10c6..e95cf88 100644 --- a/script/Diagnostics/WireScan.py +++ b/script/Diagnostics/WireScan.py @@ -136,11 +136,12 @@ def check_end_scan(record, scan): for i in range (len(blms)): plt.getSeries(i).appendData(position, record[5 + i]) +scanner.park(wait=True) #Process background def do_background(): #Store Background if bkgrd>0: - scanner.park(wait=True) + #scanner.park(wait=True) set_exec_pars(group = "background") r = mscan (st, st.getReadables()[4:], bkgrd) for i in range(len(r.getReadables())): @@ -152,6 +153,16 @@ def do_background(): except: pass +def set_blm_gain(scan_type): + if SET_BLM_WS_MODE and len(blms)>0: + cfg_gain = get_setting(blms[0] + "GainWs" + scan_type) + print "cfg_gain = " , cfg_gain + if cfg_gain is not None: + set_blm_ws_gain(blms[0],cfg_gain) + print "Set = " , blms[0] + + + #Scan def do_scan(index): global scan_complete, cur_cycle, wire @@ -163,6 +174,10 @@ def do_scan(index): plt.getAxis(plt.AxisId.X).setRange(scan_range[0], scan_range[1]) else: plt.getAxis(plt.AxisId.X).setRange(scan_range[2], scan_range[3]) + + + set_blm_gain(scan_type) + scanner.init(wait=True) scanner.curr_cycl.write(0) scan_complete=False diff --git a/script/Diagnostics/WireScanCalibration.py b/script/Diagnostics/WireScanCalibration.py index 6d8f52b..7c0bcdb 100644 --- a/script/Diagnostics/WireScanCalibration.py +++ b/script/Diagnostics/WireScanCalibration.py @@ -7,10 +7,13 @@ run("Devices/WireScanner") run("Diagnostics/sig_process_wrapper") +################################################################################################### +# Arguments and constants +################################################################################################### -ws_prefix = args[0] if is_panel else "S10DI01-DWSC010" #"S10CB07-DWSC440" #"SINDI01-DWSC090" \\ +ws_prefix = args[0] if is_panel else "SINDI01-DWSC090" #"S10DI01-DWSC010" #"S10CB07-DWSC440" #"SINDI01-DWSC090" \\ plt = args[1] if is_panel else plot(None, title = "Wire Scan Calibration")[0] -ws_wire = args[2] if is_panel else WireScanner.WireY2 +ws_wire = args[2] if is_panel else WireScanner.WireX1 cal_range = args[3] if is_panel else True cal_gain = args[4] if is_panel else True @@ -22,21 +25,43 @@ MIN_GAIN, MAX_GAIN = 0.5, 1.1 OPT_STEP = 0.02 SCAN_RANGE_FACTOR = 6.0 +DEFAULT_RANGE = [-2000.0, 2000.0] +################################################################################################### +# Utilities +################################################################################################### def write_ws_gain(val): set_setting(ws_blm + "GainWs" + ws_wire, val) def read_ws_gain(): return get_setting(ws_blm + "GainWs" + ws_wire) +def get_gain(): + return get_blm_ws_gain(ws_blm) + +def set_gain(val): + set_blm_ws_gain(ws_blm,val) + +def set_wire_scan_range(wire, start, end): + sel = {'X1':"W1X" , 'Y1': "W1Y", 'X2':"W2X", 'Y2' : "W2Y"} + start = min (max(start, -2000), 2000.0) + end = min (max(end, -2000), 2000.0) + caput((ws_prefix + ":" + sel[wire] +"_START_SP"), start) + caput((ws_prefix + ":" + sel[wire] +"_END_SP"), end) + + + +################################################################################################### +# Find COM +################################################################################################### +print "--------------- Find COM --------------- " #2) Set the number of RF shots (N_shot) to be acquired during a single cycle WSC measurement (e.g.,N_shot=50) n_shot = 200 #3) Set a test scanning range (e.g.,Xmin=-1000,Xmax=+1000um) -x_min, x_max = -1000.0, 1000.0 - +x_min, x_max = DEFAULT_RANGE[0], DEFAULT_RANGE[1] #4) For a given machine repetition-rate (RR), the scan speed is automatically set to WSC_speed=(Xmax- Xmin)*RR/N_shot rr = get_repetition_rate() @@ -48,6 +73,14 @@ ret = run("Diagnostics/WireScan", args) [rms_com, rms_sigma, com, sigma, pos_path, path] = ret + + +################################################################################################### +# Optimize gain +################################################################################################### +print "--------------- Optimize gain --------------- " + + #1) Select a BLM to be used in the WSC measurement and enable the WS_START so that it can be extracted out of the MPS and PMT-Gain and attenuation can be adjusted start_blm_ws(ws_blm, 600.0) @@ -60,6 +93,8 @@ start_blm_ws(ws_blm, 600.0) #motor_pos=offset - com * math.sqrt(2) ws_info = WireScanInfo("ws_info", ws_prefix ) + +#self.wire_velocity = Channel(self.prefix + ":SCAN_VELO_SP") motor_pos= ws_info.get_motor_pos(com, ws_wire) caput(ws_prefix+":MOTOR_1.VAL", motor_pos) #DVAL? #LOPR:0.5 HOPR:1.1 @@ -74,13 +109,6 @@ st.addScalar("blm1_ws_mode", ws_blm + ":WS_RUNNING", int(100.0 / get_repetition_ st.initialize() st.start() st.waitCacheChange(10000) #Wait stream be running before starting scan - - -def get_gain(): - return get_blm_ws_gain(ws_blm) - -def set_gain(val): - set_blm_ws_gain(ws_blm,val) def get_loss(): @@ -111,14 +139,17 @@ def change_blm_ws_gain(gain): time.sleep(0.1) -#Search loop -for pos in frange(MIN_GAIN, MAX_GAIN, OPT_STEP, True): - change_blm_ws_gain(pos) - loss = get_loss() - print "Pos = ", pos, " Loss = ", loss - if loss>=target: - break - stop_blm_ws(ws_blm) +try: + #Search loop + for pos in frange(MIN_GAIN, MAX_GAIN, OPT_STEP, True): + change_blm_ws_gain(pos) + loss = get_loss() + print "Pos = ", pos, " Loss = ", loss + if loss>=target: + break + stop_blm_ws(ws_blm) +finally: + stop_blm_ws(ws_blm) """ if start_val>target: @@ -147,27 +178,25 @@ print get_loss() #set_gain(0.6) #set_gain(0.5) - - write_ws_gain(pos) -#UPDATE X1 range -#WIRE = 1X, 2X, 1Y, 2Y -def set_wire_scan_range(wire, start, end): - sel = {'X1':"W1X" , 'Y1': "W1Y", 'X2':"W2X", 'Y2' : "W2Y"} - start = min (max(start, -2000), 2000.0) - end = min (max(end, -2000), 2000.0) - caput((ws_prefix + ":" + sel[wire] +"_START_SP"), x_range_min) - caput((ws_prefix + ":" + sel[wire] +"_END_SP"), x_range_max) +time.sleep(1.0) +################################################################################################### +# Optimize scan range +################################################################################################### +set_exec_pars(reset=True, defaults=True) + +print "--------------- Optimize scan range --------------- " #caget(ws_blm+":SAT_RAW_SUM") -args = [ ws_prefix , WireScanner.WireX1, [x_min, x_max, x_min, x_max], 1, ws_speed, [], [ws_blm], 10, plt, False,1] +args = [ ws_prefix , ws_wire, [x_min, x_max, x_min, x_max], 1, ws_speed, [], [ws_blm], 10, plt, False,1] ret = run("Diagnostics/WireScan", args) [rms_com, rms_sigma, com, sigma, pos_path, path] = ret x_range_min, x_range_max = com - SCAN_RANGE_FACTOR * sigma, com + SCAN_RANGE_FACTOR * sigma +print "Optimized range = ", x_range_min , " to " , x_range_max set_wire_scan_range(ws_wire, x_range_min, x_range_max) @@ -182,4 +211,5 @@ set_wire_scan_range(ws_wire, x_range_min, x_range_max) #10)Once condition 9) is reached, the flag: VALID_SCAN should be enabled and a WSC measurement can be performed according to the number of Cycles set in the control-panel and the optimized values of the scan interval and scan speed. -st.close() \ No newline at end of file +st.close() + diff --git a/script/Scan4.py b/script/Scan4.py new file mode 100644 index 0000000..2780fb8 --- /dev/null +++ b/script/Scan4.py @@ -0,0 +1,35 @@ +import ch.psi.pshell.epics.ChannelDouble as ChannelDouble +A1 = ChannelDouble("Offset", "SARUN11-DBPM070:Y-REF-FB") +S1 = ChannelDouble("Intensity", "SARFE10-PBPG050:HAMP-INTENSITY") +S2 = ChannelDouble("Intensity", "SARFE10-PBPG050:HAMP-INTENSITY") +A1.initialize() +S1.initialize() +S2.initialize() +A1_init = A1.read() +A1i = A1_init - 0.100 +A1f = A1_init + 0.100 +nstep = 21 +lat = 0.2 +nav = 10 +plt = plot(None, title="Output")[0] +plt.clear() +plt.setStyle(plt.Style.ErrorY) +plt.addSeries(LinePlotErrorSeries("Sensor1", Color.red)) +def after_sample(record, scan): + plt.getSeries(0).appendData(record.positions[0], record.values[0].mean, record.values[0].stdev) +try: + S1_averager = create_averager(S1, nav, lat) + S2_averager = create_averager(S2, nav, lat) + S2_averager.monitored=True + time.sleep(1.0) + r = lscan(A1, (S1_averager, S2_averager), A1i, A1f, nstep, latency=lat, after_read = after_sample) + Act1 = r.getPositions(0) + 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: + A1.write(A1_init) + A1.close() + S1.close() + S2.close() \ No newline at end of file