This commit is contained in:
X11MA
2017-02-13 14:58:25 +01:00
parent a1a7da5897
commit fc725ebd1a
7 changed files with 446 additions and 0 deletions
+178
View File
@@ -0,0 +1,178 @@
import os
import traceback
import thread
###############################################################################
# Plotting
###############################################################################
task = None
running = False
def _startPlot(type):
global running
print "Starting plot: type " + str(type)
running = True
p = plot(None,name="Energy")[0]
s = p.getSeries(0)
cur = 0
time.sleep(3.0)
while running:
try:
if otf_start.read() == 0:
break
e = energy.read()
if (abs(e-cur)) > 0.1:
v = abs((keithley_2a.read() / ((keithley_1a if (type==1) else keithley_3a).read() )))
s.appendData(e,v)
cur = e
time.sleep(0.2)
except:
pass
print "Done Plotting"
def startPlot(type = 1):
global task
task = fork((_startPlot,(type,)),)
def stopPlot():
global task, running
running = False
ret = join(task)
###############################################################################
# Parameters
###############################################################################
'''
E1 = 680
E2 = 690
TIME = 0.5 #min
DELAY = 10.0 #s
PREFIX = 'Data'
RUNTYPE = "+/-"
ROUNDS = 1
OFFSETp = 0.0
OFFSETm = 0.0
PLOT_TYPE = 1
'''
print "\nStarting energy scan - Parameters: ",
print E1,E2,TIME,DELAY,RUNTYPE
file_prefix = time.strftime("%y%m%d")
input_path = "/sls/X11MA/Data1/public/X11MA/temp/"+file_prefix+"/"
output_path = input_path #+file_prefix+"/" #"/sls/X11MA/Data1/public/e10989/"+file_prefix+"/"
pol_str = None
mag_str = None
fid = get_next_fid(input_path, "o" + file_prefix)
number_of_scans = 1
###############################################################################
#Prepare scan for PGM+ID2
###############################################################################
caput ("X11PHS-E:OPT","PGM+ID2")
caput(OTF_OFF1,-50) #detune ID1
wait_channel(OTF_DONE, 1, type = 'i')
if RUNTYPE in ["+/-", "+", "-"]:
if RUNTYPE == "+":
caput(OTF_MODE2,1) # circ+ in ID2
caput(OTF_OFF2,OFFSETp)
number_of_scans = ROUNDS
elif RUNTYPE == "-":
caput(OTF_MODE2,2) # circ- in ID2
caput(OTF_OFF2,OFFSETm)
number_of_scans = ROUNDS
elif RUNTYPE == "+/-":
caput(OTF_MODE2,1) # circ+ in ID2
caput(OTF_OFF2,OFFSETp)
number_of_scans = 2 * ROUNDS
wait_channel(OTF_DONE, 1, type = 'i')
elif RUNTYPE in ["LH/LV", "LH", "LV"]:
print "Wrong polarization selected!"
else:
raise Exception("Invalid run type: " + RUNTYPE)
open_vg10()
time.sleep(0.5)
open_vg11()
time.sleep(0.5)
open_vg12()
time.sleep(0.5)
open_vg13()
###############################################################################
#Main scan loop
###############################################################################
for scan_no in range(number_of_scans):
suffix = ("%03d" % fid)
input_file = input_path + "o" + file_prefix + "_" + suffix + ".dat"
caput(OTF_E1, E1)
caput(OTF_E2, E2)
caput(OTF_TIME, TIME)
caput(OTF_FTS,file_prefix)
caput(OTF_FID,fid)
time.sleep(2.0)
caput(OTF_ESET, E1)
wait_channel(OTF_DONE, 1, type = 'i')
time.sleep(DELAY)
time.sleep(2.0)
startPlot(PLOT_TYPE)
otf_start.write(1) #Start the OTF scan
time.sleep(3.0)
print "Running scan " + str(scan_no+1) + " out of " + str(number_of_scans)
try:
#wait_channel(OTF_START, 'STOP', timeout = int(TIME*60), type = 's')
otf_start.waitValue(0, (15 + int(TIME*60)) *1000)
except:
print "******** OTF STOP TIMEOUT **********"
otf_start.write(0)
finally:
stopPlot()
time.sleep(5.0)
#TODO: wait for file instead of sleep
#Convert file
output_file = output_path + "os" + file_prefix + "_" + suffix + ".dat"
if RUNTYPE in ["+/-"]:
pol_str = caget(OTF_MODE2)
if pol_str == "CIRC +":
caput(OTF_MODE2,2) # circ- in ID2
caput(OTF_OFF2,OFFSETm)
elif pol_str == "CIRC -":
caput(OTF_MODE2,1) # circ+ in ID2
caput(OTF_OFF2,OFFSETp)
else: print "Check pol. change"
wait_channel(OTF_DONE, 1, type = 'i')
else:
print "running in one polarization mode, no switching"
pol_str = caget(OTF_MODE2)
print("Converting data file: " + output_file);
mag_str = caget(MAG)
convert_file(input_file, output_file, mag_str, pol_str)
plot_file(output_file, file_prefix+"_" + suffix) #"Scan " + str(scan_no+1))
print "Finished scan " + str(scan_no+1) + " out of " + str(number_of_scans)
time.sleep(3.0)
fid = fid + 1
caput(OTF_ESET, E1)
close_vg13()
print "Finished Energy scan"
print("Success")
+87
View File
@@ -0,0 +1,87 @@
#Parameters
'''
B1 = 20 # starting mag. field in Amps
B2 = -20 # final mag. field in Amps
BSTEP = 0.5 # step size mag. field in Amps
ENERGIES = (707.35, 722.35) #list of energies in eV
MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2)
OFFSET1 = -9 #ID1 offset
OFFSET2 = -9.50 #ID2 offset
FIELD_PRECISION = 0.05 # in Amps
ENERGY_CHANGE_SLEEP = 0.0 # put the Enerrgy settling time if needed
FIELD_CHANGE_SLEEP = 0.0 # put the Field settling time if needed
'''
# List of scans. Each scan is defined as: (start,stop, step)
# to make a whole loop two scans are needed: [(B1, B2, BSTEP),(B2,B1,-BSTEP)]
# to make half of a loop one scan is needed: [(B1, B2, BSTEP),] <- don't forget to put comma before ]
RANGES = [(B1, B2, -BSTEP),(B2,B1,BSTEP)]
#Pre-actions
# Here polarization and offsets are set
caput ("X11PHS-E:OPT","PGM+ID1")
caput(OTF_OFF1,OFFSET1) #detune ID1
caput(OTF_OFF2,OFFSET2)
wait_channel(OTF_DONE, 1, type = 'i')
if MODE is 1 or 2:
caput(OTF_MODE2,MODE)
else:
raise Exception("Invalid polarization type: " + MODE)
wait_channel(OTF_DONE, 1, type = 'i')
# Generating a list of mag. fields (setpoints) needed for the loop
setpoints = []
for r in RANGES:
setpoints = setpoints + frange(r[0], r[1], r[2], True)
# plot properties
set_preference(Preference.ENABLED_PLOTS, ['field', 'tey_norm'])
set_preference(Preference.PLOT_TYPES, {'tey_norm':1})
scan = ManualScan(['field', 'Energy'], ['TEY', 'I0', 'polarization', 'temperature', 'RingCurrent', 'tey_norm'] , [min(setpoints), min(ENERGIES)], [max(setpoints), max(ENERGIES)], [len(setpoints)-1, len(ENERGIES)-1])
scan.start()
# Main loop
for B in setpoints:
print "Setting field = ", B
caput("X11MA-XMCD:I-SETraw",B)
time.sleep( FIELD_CHANGE_SLEEP ) # Settling time
readback1 = caget("X11MA-XMCD:Ireadout")
while abs(readback1-B) > FIELD_PRECISION:
readback1 = caget("X11MA-XMCD:Ireadout")
time.sleep(0.5)
for E in ENERGIES:
print "Setting energy = ", E
caput(OTF_ESET, E)
wait_channel(OTF_DONE, 1, type = 'i')
readback2 = energy.read()
if abs(readback2 - E) > 0.1 : # TODO: Check accuracy
raise Exception('Energy could not be set to the value ' + str(E))
sleep( ENERGY_CHANGE_SLEEP ) # Settling time
detector1 = keithley_1a.read() #Keithley1
detector2 = keithley_2a.read() #Keithley2
#detector3 = keithley_3a.read() #Keithley3
detector4 = caget(OTF_MODE1) #polarization in ID1
#detector5 = caget("X11MA-ID1:ALPHA-READ") # polAngle in ID1
detector6 = caget('X11MA-ES3-LSCI:TEMP_RBV') #temperature.get()
detector7 = caget("ARIDI-PCT:CURRENT")
#detector8 = signal_field_analog_x.read() # fieldAnalogX.get()
tey_norm = detector1/detector2
#trans_norm = detector3/detector2
#converting polarization strings to integer numbers: C+ -> 1 and C- -> 2
if detector4 == 'CIRC +': detector4 = 1
elif detector4 == 'CIRC -': detector4 = 2
else: detector4 = 0
scan.append ([B, E], [readback1, readback2], [detector1, detector2, detector4, detector6, detector7, tey_norm])
scan.end()
+26
View File
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" numberOfExecution="1" failOnSensorError="true">
<data format="txt" fileName="harmonic"/>
<scan>
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X11MA-ID1:ENERGY" value="720"/>
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X11MA-ID1:DONE" value="DONE" operation="wait"/>
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X11PHS-E:OPT" value="PGM" operation="put" type="String"/>
<dimension zigzag="false" dataGroup="false">
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RegionPositioner" name="X11MA-PHS:E_SP" readback="X11MA-PGM:rbkenergy" settlingTime="0.5" asynchronous="false" id="PGMenergy">
<region>
<start>710.0</start>
<end>730.0</end>
<stepSize>0.5</stepSize>
</region>
</positioner>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X11MA-ES1:CADC2" id="sample"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X11MA-ES1:CADC1" id="I0"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X11MA-ID1:MODE" id="polarization"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X11MA-ID1:ALPHA" id="polangle"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="X11MA-ID1:ENERGY-OFFS" id="offset"/>
</dimension>
<postAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X11PHS-E:OPT" value="PGM+ID1" operation="put" type="String"/>
</scan>
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="PGMenergy" y="I0" title="I0"/>
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="PGMenergy" y="sample" title="sample"/>
</configuration>
+26
View File
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" numberOfExecution="1" failOnSensorError="true">
<data format="txt" fileName="harmonic"/>
<scan>
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X11MA-ID2:ENERGY" value="720"/>
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X11MA-ID2:DONE" value="DONE" operation="wait"/>
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X11PHS-E:OPT" value="PGM" operation="put" type="String"/>
<dimension zigzag="false" dataGroup="false">
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RegionPositioner" name="X11MA-PHS:E_SP" readback="X11MA-PGM:rbkenergy" settlingTime="0.5" asynchronous="false" id="PGMenergy">
<region>
<start>710.0</start>
<end>730.0</end>
<stepSize>0.5</stepSize>
</region>
</positioner>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X11MA-ES1:CADC2" id="sample"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X11MA-ES1:CADC1" id="I0"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X11MA-ID2:MODE" id="polarization"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X11MA-ID2:ALPHA" id="polangle"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="X11MA-ID2:ENERGY-OFFS" id="offset"/>
</dimension>
<postAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X11PHS-E:OPT" value="PGM+ID2" operation="put" type="String"/>
</scan>
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="PGMenergy" y="I0" title="I0"/>
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="PGMenergy" y="sample" title="sample"/>
</configuration>
+71
View File
@@ -0,0 +1,71 @@
E1 = 690
E2 = 760
TIME = 3 #min
DELAY = 10.0 #s
PREFIX = 'Data'
OFFSETp = -9
OFFSETm = -8
PLOT_TYPE = 1
RUNTYPE = "+"
ROUNDS = 1
run("Sridhar/EnergyScanID1only")
RUNTYPE = "-"
ROUNDS = 1
run("Sridhar/EnergyScanID2only")
RUNTYPE = "-"
ROUNDS = 1
run("Sridhar/EnergyScanID2only")
RUNTYPE = "+"
ROUNDS = 1
run("Sridhar/EnergyScanID1only")
'''
RUNTYPE = "-"
ROUNDS = 1
run("EnergyScanID2only")
RUNTYPE = "+"
ROUNDS = 1
run("EnergyScanID2only")
RUNTYPE = "+"
ROUNDS = 1
run("EnergyScanID2only")
RUNTYPE = "-"
ROUNDS = 1
run("EnergyScanID2only")
RUNTYPE = "-"
ROUNDS = 1
run("EnergyScanID2only")
RUNTYPE = "+"
ROUNDS = 1
run("EnergyScanID2only")
'''
'''
E1 = 690
E2 = 700
TIME = 0.5 #min
DELAY = 10.0 #s
OFFSET1 = -9.7 #eV
OFFSET2 = -12 #eV
PREFIX = 'Sample2_ID1ID2'
RUNTYPE = "+/-"
ROUNDS = 1
PLOT_TYPE = 1
SET_OFFSETS=0
ID1=0
ID2=0
run("EnergyScan")
'''
+26
View File
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" numberOfExecution="1" failOnSensorError="true">
<data format="txt" fileName="harmonic"/>
<scan>
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X11MA-ID2:ENERGY" value="720"/>
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X11MA-ID2:DONE" value="DONE" operation="wait"/>
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X11PHS-E:OPT" value="PGM" operation="put" type="String"/>
<dimension zigzag="false" dataGroup="false">
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RegionPositioner" name="X11MA-PHS:E_SP" readback="X11MA-PGM:rbkenergy" settlingTime="0.5" asynchronous="false" id="PGMenergy">
<region>
<start>710.0</start>
<end>730.0</end>
<stepSize>0.5</stepSize>
</region>
</positioner>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X11MA-ES1:CADC2" id="sample"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X11MA-ES1:CADC1" id="I0"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X11MA-ID2:MODE" id="polarization"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X11MA-ID2:ALPHA" id="polangle"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="X11MA-ID2:ENERGY-OFFS" id="offset"/>
</dimension>
<postAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-PHS-E:OPT" value="PGM+ID" operation="put" type="String"/>
</scan>
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="PGMenergy" y="I0" title="I0"/>
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="PGMenergy" y="sample" title="sample"/>
</configuration>
+32
View File
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" numberOfExecution="1" failOnSensorError="true">
<data format="txt" fileName="harmonic"/>
<scan>
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-ID:ENERGY" value="580"/>
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-ID:DONE" value="DONE" operation="wait"/>
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-PHS-E:OPT" value="PGM" operation="put" type="String"/>
<dimension zigzag="false" dataGroup="false">
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RegionPositioner" name="X07MA-PHS-E:GO.A" readback="X07MA-PGM:CERBK" settlingTime="0.5" asynchronous="false" id="PGMenergy">
<region>
<start>570.0</start>
<end>590.0</end>
<stepSize>0.5</stepSize>
</region>
</positioner>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MA-ES1-AI:SIGNAL0" id="sample"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MA-ES1-AI:SIGNAL1" id="I0"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MA-ID:MODE" id="polarization"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MA-ID:ALPHA" id="polangle"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MA-PC-TC:STS:T1" id="temperature"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="ARIDI-PCT:CURRENT" id="ringCurrent"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MA-PHS-E:GO.A" id="SetEnergy"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MA-PC-PS2:STS:PMCURRENT" id="field"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="X07MA-ES1-AI:SIGNAL2" id="transmission"/>
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="X07MA-ID:ENERGY-OFFS" id="offset"/>
</dimension>
<postAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-PHS-E:OPT" value="PGM+ID" operation="put" type="String"/>
</scan>
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="PGMenergy" y="I0" title="I0"/>
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="PGMenergy" y="sample" title="sample"/>
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="PGMenergy" y="transmission" title=" transmission"/>
</configuration>