From 9e56d92e46ae1831cc09858f98841b8af27fb015 Mon Sep 17 00:00:00 2001 From: sfop Date: Mon, 27 Jun 2016 15:15:24 +0200 Subject: [PATCH] Startup --- script/RFscan/phase_scan_caqtdm_dv.py | 82 +++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 script/RFscan/phase_scan_caqtdm_dv.py diff --git a/script/RFscan/phase_scan_caqtdm_dv.py b/script/RFscan/phase_scan_caqtdm_dv.py new file mode 100644 index 0000000..098c356 --- /dev/null +++ b/script/RFscan/phase_scan_caqtdm_dv.py @@ -0,0 +1,82 @@ +""" +Parameters: +args = [prefix ] +""" + +import ch.psi.pshell.epics.ControlledVariable as ControlledVariable + + +prefix = args[0] +start = caget(prefix + ":SET-SCAN-START") +stop = caget("PSHELL:scanstop") +step = caget("PSHELL:scanstep") +latency = 0.05 + + +print "Prefix = ", prefix +print "Start = ", start +print "Stop = ", stop +print "Step = ", step + + +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 = Channel(prefix + ":GET-VSUM-AMPLT", type = 'd', alias='Amplitude Readback') + +#TODO: update the plot dinamically +def after(rec): + pass + +try: + sim.step = step #TODO: Remove if not simulated + r = lscan(rf_phase_var, [rf_ampl_readback, sim], start, stop, step , latency=latency, after_read = after) + + #Update plot arrays + + + 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") + phase_fit_max = None + try: + (amplitude, angular_frequency, phase, phase_fit_max) = hfit(f , xdata = xdata) + except: + raise Exception("Fit failure") + + start,end = min(xdata), max(xdata) + if not (start <=phase_fit_max <=end): + 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 +finally: + #rf_phase_setpoint.close() + #rf_phase_readback.close() + rf_phase_var.close() + rf_ampl_readback.close() + + + +print ("------------------------------------") +print ("Valid fit") + + + +energy_gain = amplitude +phase_offset = - phase_fit_max +amplitude_scale = energy_gain / a0 +power_scale = power / math.pow(a0,2) + +#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))