def main(argv=None): global simulate global fp global shut_open global current global x3h5capture #parse command line options usage = "usage: %prog [options]\nData files are written to /data/<year>/<month>/<day>/" parser = OptionParser(usage) parser.add_option("--detname", action="store", type="string", dest="detname", help="detector PV base") parser.add_option("--xstart", action="store", type="float", dest="xo", help="starting X position") parser.add_option("--xnumstep", action="store", type="int", dest="Nx", help="number of steps in X") parser.add_option("--xstepsize", action="store", type="float", dest="dx", help="step size in X") parser.add_option("--ystart", action="store", type="float", dest="yo", help="starting Y position") parser.add_option("--ynumstep", action="store", type="int", dest="Ny", help="number of steps in Y") parser.add_option("--ystepsize", action="store", type="float", dest="dy", help="step size in Y") parser.add_option("--wait", action="store", type="float", dest="stall", help="wait at each step [seconds]") parser.add_option("--simulate", action="store_true", dest="sim", default=False, help="simulate motor moves") parser.add_option("--checkbeam", action="store_true", dest="checkbeam", default=False, help="only acquire when beam is on") parser.add_option("--acqtime", action="store", type="float", dest="acqt", default=1, help="image integration time [sec]") parser.add_option("--acqnum", action="store", type="int", dest="acqn", default=1, help="frames per scan point") (options, args) = parser.parse_args() #open log file D0 = time.localtime()[0] D1 = time.localtime()[1] D2 = time.localtime()[2] D3 = time.localtime()[3] D4 = time.localtime()[4] cd = os.getcwd() filedir = '/nfs/xf05id1/data/' if sys.argv[0][0] == '.': out_filename=filedir+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'log_'+repr(D3)+'_'+repr(D4)+'_'+\ string.split(string.strip(sys.argv[0],'./'),'/')[0]+'.txt' else: out_filename=filedir+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'log_'+repr(D3)+'_'+repr(D4)+'_'+\ string.split(string.strip(sys.argv[0],'./'),'/')[5]+'.txt' try: os.chdir(filedir + repr(D0)) except OSError: try: os.mkdir(filedir + repr(D0)) except Exception: print 'cannot create directory: ' + '/data/' + repr(D0) sys.exit() try: os.chdir(filedir + repr(D0) + '/' + repr(D1)) except OSError: try: os.mkdir(filedir + repr(D0) + '/' + repr(D1)) except Exception: print 'cannot create directory: ' + '/data/' + repr( D0) + '/' + repr(D1) sys.exit() try: os.chdir(filedir + repr(D0) + '/' + repr(D1) + '/' + repr(D2)) except OSError: try: os.mkdir(filedir + repr(D0) + '/' + repr(D1) + '/' + repr(D2)) except Exception: print 'cannot create directory: ' + filedir + repr( D0) + '/' + repr(D1) + '/' + repr(D2) sys.exit() try: fp = open(out_filename, 'a') except Exception: print 'cannot open file: ' + out_filename sys.exit() os.chdir(cd) fp.write('#' + ', '.join(sys.argv)) fp.write('\n') H5path = '/epics/data/201507/300126' #initialize PVs and callbacks if options.detname == None: detstr = '' print "must provide detector pv base, e.g., 'XF:28IDA-BI{URL:01}'" sys.exit() else: detstr = options.detname xmotname = 'XF:05IDD-ES:1{Stg:Smpl1-Ax:X}' ymotname = 'XF:05IDD-ES:1{Stg:Smpl1-Ax:Y}' xmot = PV(xmotname + 'Mtr.VAL') xmot_cur = PV(xmotname + 'Mtr.RBV') ymot = PV(ymotname + 'Mtr.VAL') ymot_cur = PV(ymotname + 'Mtr.RBV') shut_status = PV('SR:C05-EPS{PLC:1}Shutter:Sum-Sts') beam_current = PV('SR:C03-BI{DCCT:1}I:Total-I') bmot_cur = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:P}Mtr.RBV') #transmission #check command line options if options.yo == None: print "must provide a starting point in the vertical" sys.exit() else: yo = options.yo if options.xo == None: print "must provide a starting point in the horizontal" sys.exit() else: xo = options.xo if options.dx == None: dx = 0.00000001 else: dx = options.dx if options.dy == None: dy = 0.00000001 else: dy = options.dy if options.Nx == None: Nx = 0 else: Nx = options.Nx if options.Ny == None: Ny = 0 else: Ny = options.Ny if options.stall == None: twait = 0. else: twait = options.stall diode0 = PV(detstr + 'Cur:I0-I') diode1 = PV(detstr + 'Cur:I1-I') diode2 = PV(detstr + 'Cur:I2-I') diode3 = PV(detstr + 'Cur:I3-I') wb = srxslit.nsls2slit(tb='XF:05IDA-OP:1{Slt:1-Ax:T}', bb='XF:05IDA-OP:1{Slt:1-Ax:B}', ib='XF:05IDA-OP:1{Slt:1-Ax:I}', ob='XF:05IDA-OP:1{Slt:1-Ax:O}') pb = srxslit.nsls2slit(ib='XF:05IDA-OP:1{Slt:2-Ax:I}', ob='XF:05IDA-OP:1{Slt:2-Ax:O}') ssa = srxslit.nsls2slit(tb='XF:05IDB-OP:1{Slt:SSA-Ax:T}', bb='XF:05IDB-OP:1{Slt:SSA-Ax:B}', ob='XF:05IDB-OP:1{Slt:SSA-Ax:O}', ib='XF:05IDB-OP:1{Slt:SSA-Ax:I}') x3acq = PV('XSPRESS3-EXAMPLE:Acquire') x3erase = PV('XSPRESS3-EXAMPLE:ERASE') x3acqtime = PV('XSPRESS3-EXAMPLE:AcquireTime') x3acqnum = PV('XSPRESS3-EXAMPLE:NumImages') x3tmode = PV('XSPRESS3-EXAMPLE:TriggerMode') x3h5path = PV('XSPRESS3-EXAMPLE:HDF5:FilePath') x3h5fname = PV('XSPRESS3-EXAMPLE:HDF5:FileName') x3h5fnum = PV('XSPRESS3-EXAMPLE:HDF5:FileNumber') x3h5vdim = PV('XSPRESS3-EXAMPLE:HDF5:NumExtraDims') x3h5size = PV('XSPRESS3-EXAMPLE:HDF5:ExtraDimSizeN') x3h5d1 = PV('XSPRESS3-EXAMPLE:HDF5:ExtraDimSizeX') x3h5d2 = PV('XSPRESS3-EXAMPLE:HDF5:ExtraDimSizeY') #report ROIs for channels and counts at each point x3ch1roi0min = PV('XSPRESS3-EXAMPLE:C1_MCA_ROI1_LLM') x3ch1roi0max = PV('XSPRESS3-EXAMPLE:C1_MCA_ROI1_HLM') x3ch1roi0ct = PV('XSPRESS3-EXAMPLE:C1_ROI1:Value_RBV') x3ch1roi1min = PV('XSPRESS3-EXAMPLE:C1_MCA_ROI2_LLM') x3ch1roi1max = PV('XSPRESS3-EXAMPLE:C1_MCA_ROI2_HLM') x3ch1roi1ct = PV('XSPRESS3-EXAMPLE:C1_ROI2:Value_RBV') x3ch1roi2min = PV('XSPRESS3-EXAMPLE:C1_MCA_ROI3_LLM') x3ch1roi2max = PV('XSPRESS3-EXAMPLE:C1_MCA_ROI3_HLM') x3ch1roi2ct = PV('XSPRESS3-EXAMPLE:C1_ROI3:Value_RBV') x3ch2roi0min = PV('XSPRESS3-EXAMPLE:C2_MCA_ROI1_LLM') x3ch2roi0max = PV('XSPRESS3-EXAMPLE:C2_MCA_ROI1_HLM') x3ch2roi0ct = PV('XSPRESS3-EXAMPLE:C2_ROI1:Value_RBV') x3ch2roi1min = PV('XSPRESS3-EXAMPLE:C2_MCA_ROI2_LLM') x3ch2roi1max = PV('XSPRESS3-EXAMPLE:C2_MCA_ROI2_HLM') x3ch2roi1ct = PV('XSPRESS3-EXAMPLE:C2_ROI2:Value_RBV') x3ch2roi2min = PV('XSPRESS3-EXAMPLE:C2_MCA_ROI3_LLM') x3ch2roi2max = PV('XSPRESS3-EXAMPLE:C2_MCA_ROI3_HLM') x3ch2roi2ct = PV('XSPRESS3-EXAMPLE:C2_ROI3:Value_RBV') x3ch3roi0min = PV('XSPRESS3-EXAMPLE:C3_MCA_ROI1_LLM') x3ch3roi0max = PV('XSPRESS3-EXAMPLE:C3_MCA_ROI1_HLM') x3ch3roi0ct = PV('XSPRESS3-EXAMPLE:C3_ROI1:Value_RBV') x3ch3roi1min = PV('XSPRESS3-EXAMPLE:C3_MCA_ROI2_LLM') x3ch3roi1max = PV('XSPRESS3-EXAMPLE:C3_MCA_ROI2_HLM') x3ch3roi1ct = PV('XSPRESS3-EXAMPLE:C3_ROI2:Value_RBV') x3ch3roi2min = PV('XSPRESS3-EXAMPLE:C3_MCA_ROI3_LLM') x3ch3roi2max = PV('XSPRESS3-EXAMPLE:C3_MCA_ROI3_HLM') x3ch3roi2ct = PV('XSPRESS3-EXAMPLE:C3_ROI3:Value_RBV') #claim ROI 4 for our own use. we will integrate over all 4096 channels. x3ch1roi3min = PV('XSPRESS3-EXAMPLE:C1_MCA_ROI4_LLM') x3ch1roi3max = PV('XSPRESS3-EXAMPLE:C1_MCA_ROI4_HLM') x3ch1roi3ct = PV('XSPRESS3-EXAMPLE:C1_ROI4:Value_RBV') x3ch2roi3min = PV('XSPRESS3-EXAMPLE:C2_MCA_ROI4_LLM') x3ch2roi3max = PV('XSPRESS3-EXAMPLE:C2_MCA_ROI4_HLM') x3ch2roi3ct = PV('XSPRESS3-EXAMPLE:C2_ROI4:Value_RBV') x3ch3roi3min = PV('XSPRESS3-EXAMPLE:C3_MCA_ROI4_LLM') x3ch3roi3max = PV('XSPRESS3-EXAMPLE:C3_MCA_ROI4_HLM') x3ch3roi3ct = PV('XSPRESS3-EXAMPLE:C3_ROI4:Value_RBV') xmot_cur.get() ymot_cur.get() norm0 = PV('XF:05IDD-BI:1{BPM:01}.S20') norm1 = PV('XF:05IDD-BI:1{BPM:01}.S21') norm2 = PV('XF:05IDD-BI:1{BPM:01}.S22') norm3 = PV('XF:05IDD-BI:1{BPM:01}.S23') xmot_cur.add_callback(cbfx) ymot_cur.add_callback(cbfy) shut_status.add_callback(cbf_shut) beam_current.add_callback(cbf_curr) xmot_cur.run_callbacks() ymot_cur.run_callbacks() shut_status.run_callbacks() beam_current.run_callbacks() x3h5path.put(H5path) x3h5fname.put(repr(D3) + '_' + repr(D4) + '_') x3h5fnum.put(0) x3acqtime.put(options.acqt) x3acqnum.put(options.acqn) x3tmode.put(1) x3ch1roi3min.put(0) x3ch2roi3min.put(0) x3ch3roi3min.put(0) x3ch1roi3max.put(4096) x3ch2roi3max.put(4096) x3ch3roi3max.put(4096) #h5 set up x3h5vdim.put(2) x3h5size.put(options.acqn) x3h5d1.put(options.Nx + 1) x3h5d2.put(options.Ny + 1) str = '#NSLS-II SRX' + time.asctime() fp.write(str) fp.write('\n') str = '#Start time is ' + time.asctime() print str fp.write(str) fp.write('\n') str='# x: %(hs)6.4f ; y: %(vs)6.4f ; ROI1 %(roi1i)d:%(roi1a)d ; ROI2 %(roi2i)d:%(roi2a)d ; ROI3 %(roi3i)d:%(roi3a)d'%\ {"hs":xmot_cur.get(),"vs":ymot_cur.get(), 'roi1i':x3ch1roi0min.get(), 'roi1a':x3ch1roi0max.get(), 'roi2i':x3ch1roi1min.get(), 'roi2a':x3ch1roi1max.get(), 'roi3i':x3ch1roi2min.get(), 'roi3a':x3ch1roi2max.get()} print str fp.write(str) fp.write('\n') roits = x3ch3roi3ct.timestamp str='# SSA HCEN: %(WBHC)f ; SSA HSIZE: %(WBHS)f ; SSA VCEN: %(WBVC)f ; SSA VSIZE: %(WBVS)f'%\ {"WBHC":ssa.hcen(), "WBHS":ssa.hsize(), "WBVC":ssa.vcen(), "WBVS":ssa.vsize()} print str fp.write(str) fp.write('\n') str='# Bragg: %(B)6.4f ; Energy: %(E)6.4f ; WB HCEN: %(WBHC)f ; WB HSIZE: %(WBHS)f ; WB VCEN: %(WBVC)f ; WB VSIZE: %(WBVS)f'%\ {"B":bmot_cur.get(), "E": 12398. / (2 * 3.1355 * math.sin(bmot_cur.get()/180.*3.1416)), "WBHC":wb.hcen(), "WBHS":wb.hsize(), "WBVC":wb.vcen(), "WBVS":wb.vsize()} print str fp.write(str) fp.write('\n') str = "# -------------------------------------------------------------------- " print str fp.write(str) fp.write('\n') str = '#[point #]\tX pos\t\tY pos\tch 1\t\tch 2\t\tch 3\t\tch 4\tdBPM1\t\tdBPM2\t\tdBPM3\t\tdBPM4\t\troi0\t\troi1\t\troi2\t\troi3\t\ttime' print str fp.write(str) fp.write('\n') if options.sim is True: str = " -----simulating motor moves and bursts-----" print str fp.write(str) fp.write('\n') else: time.sleep(2) x3h5capture.put(1) #number of rows and columns completed by scan Ncol = Nrow = 0 LN = 0 #diode readback is now limiting factor for scan speed oldsig = 0. #when the cryocooler kicks in, the beam is unusable for ~3200sec cryo = PV('XF:05IDA-OP:1{Mono:HDCM}T:LN2Out-I') ct = cryo.get() while (ct is None): time.sleep(0.05) ct = cryo.get() t0 = time.time() cryocounter = 0 shut_toggle = False #nested loops for scanning z,x,y for y in np.linspace(yo, yo + ((Ny) * dy), Ny + 1): tar[1][0] = y tar[1][1] = 1 if options.sim is False: ymot.put(tar[1][0]) if indeadband(float(tar[1][0]), float(ymot_cur.get()), dbd) == 1: tar[1][1] = 0 if Nrow % 2 == 0: xs = 0. + xo xe = ((Nx + 1) * dx) + xo - dx xi = dx else: xs = ((Nx) * dx) + xo xe = 0. + xo xi = -dx for x in np.linspace(xs, xe, Nx + 1): tar[0][0] = x tar[0][1] = 1 if indeadband(float(tar[0][0]), float(xmot_cur.get()), dbd) == 1: tar[0][1] = 0 if options.sim is False: xmot.put(tar[0][0]) while ((tar[0][1] == 1) or (tar[1][1] == 1)): time.sleep(0.01) signal0 = signal1 = signal2 = signal3 = 0. nsig0 = nsig1 = nsig2 = nsig3 = 0. sig0 = sig1 = sig2 = sig3 = 0. time.sleep(twait) while (options.checkbeam and (cryo.get() < (ct - 0.1))): print "Stopped. Detected possible cryocooler activation." time.sleep(1) cryocounter = cryocounter + 1 #if the above is true for five cycles, the cryocooler was on, wait another 10min if (options.checkbeam and cryocounter > 300): print "Detected cryocooler activation, waiting 10min" time.sleep(600) cryocounter = 0 while (options.checkbeam and (shut_open == False or beam_current == False)): print "Stopped. Waiting for scan conditions to return to normal." if shut_open == False: shut_toggle = True time.sleep(10.) if shut_toggle == True: print "Entering optics conditioning period. Waiting 5min" time.sleep(300) shut_toggle = False if options.sim is False: x3erase.put(1) while signal0 == 0.: signal0 = diode0.get() while signal1 == 0.: signal1 = float(diode1.get()) while (signal1 == oldsig): time.sleep(0.05) signal1 = diode1.get() oldsig = signal1 while signal2 == 0.: signal2 = diode2.get() while signal3 == 0.: signal3 = diode3.get() while nsig0 == 0.: nsig0 = float(norm0.get()) while nsig1 == 0.: nsig1 = float(norm1.get()) while nsig2 == 0.: nsig2 = float(norm2.get()) while nsig3 == 0.: nsig3 = float(norm3.get()) sig0 = 0 sig1 = 0 sig2 = 0 sig3 = 0 for i in range(0, options.acqn): x3acq.put(1) time.sleep(options.acqt) while (x3ch3roi3ct.get() == 0.0 or x3ch3roi3ct.timestamp == roits): time.sleep(0.02) roits = x3ch3roi3ct.timestamp while (x3ch3roi3ct.timestamp == roits): time.sleep(0.1) sig0 = sig0 + x3ch1roi0ct.get() + x3ch2roi0ct.get( ) + x3ch3roi0ct.get() sig1 = sig1 + x3ch1roi1ct.get() + x3ch2roi1ct.get( ) + x3ch3roi1ct.get() sig2 = sig2 + x3ch1roi2ct.get() + x3ch2roi2ct.get( ) + x3ch3roi2ct.get() sig3 = sig3 + x3ch1roi3ct.get() + x3ch2roi3ct.get( ) + x3ch3roi3ct.get() roits = x3ch3roi3ct.timestamp tn = time.time() - t0 if options.sim is False: str = '%(X)06d %(XC)9.4f %(YC)9.4f %(d1)10.7e %(d2)10.7e %(d3)10.7e %(d4)10.7e %(n0)10.7e %(n1)10.7e %(n2)10.7e %(n3)10.7e %(s0)10.7e %(s1)10.7e %(s2)10.7e %(s3)10.7e %(time)9.2f' % { 'X': Ncol, 'XC': xmot_cur.get(), "YC": ymot_cur.get(), "d1": float(signal0), "d2": float(signal1), "d3": float(signal2), "d4": float(signal3), 'n0': nsig0, 'n1': nsig1, 'n2': nsig2, 'n3': nsig3, "s0": sig0, "s1": sig1, "s2": sig2, "s3": sig3, "time": tn } print str fp.write(str) fp.write('\n') else: str = '%(X)06d %(XC)8.4f %(YC)8.4f %(d1)10.7e %(d2)10.7e %(d3)10.7e %(d4)10.7e' % { "X": int(Ncol), "XC": tar[0][0], "YC": tar[1][0], "d1": float(signal0), "d2": float(signal1), "d3": float(signal2), "d4": float(signal3) } print str fp.write(str) fp.write('\n') Ncol = Ncol + 1 Nrow = Nrow + 1 str = 'End time is ' + time.asctime() print str fp.write(str) fp.write('\n') fp.close() return 0
import sys sys.path.append('/nfs/xf05id1/src/nsls2-xf-utils') import srxslit import srxfe import srxbpm import tempdev import srxm2 wb=srxslit.nsls2slit(tb='XF:05IDA-OP:1{Slt:1-Ax:T}',bb='XF:05IDA-OP:1{Slt:1-Ax:B}',ib='XF:05IDA-OP:1{Slt:1-Ax:I}',ob='XF:05IDA-OP:1{Slt:1-Ax:O}') pb=srxslit.nsls2slit(ib='XF:05IDA-OP:1{Slt:2-Ax:I}',ob='XF:05IDA-OP:1{Slt:2-Ax:O}') ssa=srxslit.nsls2slit(tb='XF:05IDB-OP:1{Slt:SSA-Ax:T}', bb='XF:05IDB-OP:1{Slt:SSA-Ax:B}', ob='XF:05IDB-OP:1{Slt:SSA-Ax:O}',ib='XF:05IDB-OP:1{Slt:SSA-Ax:I}') m2x=srxm2.mottwin(m1='XF:05IDD-OP:1{Mir:2-Ax:XU}Mtr',m2='XF:05IDD-OP:1{Mir:2-Ax:XD}Mtr') bpm1=srxbpm.nsls2bpm(bpm='bpm1') bpm2=srxbpm.nsls2bpm(bpm='bpm2')
def main(argv=None): global dbd global simulate global fp global shut_open global current global T_stop #parse command line options usage = "usage: %prog [options]\nData files are written to /data/<year>/<month>/<day>/" parser = OptionParser(usage) parser.add_option("--wait", action="store", type="float", dest="stall", help="wait at each step [seconds]") usage = "usage: %prog [options]\nData files are written to /data/<year>/<month>/<day>/" parser = OptionParser(usage) parser.add_option("--wait", action="store", type="float", dest="stall", help="wait at each step [seconds]") parser.add_option("--config",action="store", type="string", dest="fname", help="name of config file") parser.add_option("--simulate", action="store_true", dest="sim", default=False, help="simulate motor moves and bursting") parser.add_option("--checkbeam", action="store_true", dest="checkbeam", default=False, help="only acquire when beam is on") parser.add_option("--acqtime", action="store", type="float", dest="acqt", help="image integration time [sec]") parser.add_option("--acqnum", action="store", type="int", dest="acqn", help="images to collect") (options,args) = parser.parse_args() #open log file D0=time.localtime()[0] D1=time.localtime()[1] D2=time.localtime()[2] D3=time.localtime()[3] D4=time.localtime()[4] cd=os.getcwd() fstr='/nfs/xf05id1/data/' if sys.argv[0][0]=='.': out_filename=fstr+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'log_'+repr(D0)+'_'+repr(D1)+'_'+repr(D2)+'_'+repr(D3)+'_'+repr(D4)+'_'+\ string.split(string.strip(sys.argv[0],'./'),'/')[0]+'.txt' else: out_filename=fstr+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'log_'+repr(D0)+'_'+repr(D1)+'_'+repr(D2)+'_'+repr(D3)+'_'+repr(D4)+'_'+\ string.split(string.strip(sys.argv[0],'./'),'/')[5]+'.txt' try: os.chdir(fstr+repr(D0)) except OSError: try: os.mkdir(fstr+repr(D0)) except Exception: print 'cannot create directory: '+fstr+repr(D0) sys.exit() try: os.chdir(fstr+repr(D0)+'/'+repr(D1)) except OSError: try: os.mkdir(fstr+repr(D0)+'/'+repr(D1)) except Exception: print 'cannot create directory: '+fstr+repr(D0)+'/'+repr(D1) sys.exit() try: os.chdir(fstr+repr(D0)+'/'+repr(D1)+'/'+repr(D2)) except OSError: try: os.mkdir(fstr+repr(D0)+'/'+repr(D1)+'/'+repr(D2)) except Exception: print 'cannot create directory: '+fstr+repr(D0)+'/'+repr(D1)+'/'+repr(D2) sys.exit() try: fp=open(out_filename,'a') except Exception: print 'cannot open file: '+out_filename sys.exit() try: os.chdir(fstr+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'HDF5') except OSError: try: os.mkdir(fstr+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'HDF5') except Exception: print 'cannot create directory: '+fstr+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'HDF5' sys.exit() # H5path=fstr+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/HDF5' H5path='/epics/data/2015-3/300198' os.chdir(cd) fp.write('#') fp.write(', '.join(sys.argv)) fp.write('\n') #open list of scan points try: fconfig=open(options.fname) except Exception: print "cannot open file containing scan points. Error opening: "+options.fname sys.exit() fstr='#a default string' pN=0 angle=list() ivu=list() t2gap=list() while fstr.rsplit().__len__() > 0: if (fstr[0] is not '#'): pN=pN+1 angle.append(fstr.rsplit()[0]) ivu.append(fstr.rsplit()[1]) t2gap.append(fstr.rsplit()[2]) fstr=fconfig.readline() fconfig.close() #initialize PVs and callbacks detstr='XF:05IDA{IM:1}' bmot = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:P}Mtr.VAL') bmot_cur = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:P}Mtr.RBV') bmot_stop = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:P}Mtr.STOP') umot = PV('SR:C5-ID:G1{IVU21:1-Mtr:2}Inp:Pos') umot_cur = PV('SR:C5-ID:G1{IVU21:1-LEnc}Gap') umot_go = PV('SR:C5-ID:G1{IVU21:1-Mtr:2}Sw:Go') gmot = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:X2}Mtr.VAL') gmot_cur = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:X2}Mtr.RBV') gmot_stop = PV('XF:05IDA-OP:1{Mono:HDCM-Ax:X2}Mtr.STOP') shut_status=PV('SR:C05-EPS{PLC:1}Shutter:Sum-Sts') beam_current=PV('SR:C03-BI{DCCT:1}I:Total-I') bragg_temp=PV('XF:05IDA-OP:1{Mono:HDCM-Ax:P}T-I') norm0=PV('XF:05IDD-BI:1{BPM:01}.S20') norm1=PV('XF:05IDD-BI:1{BPM:01}.S21') norm2=PV('XF:05IDD-BI:1{BPM:01}.S22') norm3=PV('XF:05IDD-BI:1{BPM:01}.S23') wb=srxslit.nsls2slit(tb='XF:05IDA-OP:1{Slt:1-Ax:T}',bb='XF:05IDA-OP:1{Slt:1-Ax:B}',ib='XF:05IDA-OP:1{Slt:1-Ax:I}',ob='XF:05IDA-OP:1{Slt:1-Ax:O}') pb=srxslit.nsls2slit(ib='XF:05IDA-OP:1{Slt:2-Ax:I}',ob='XF:05IDA-OP:1{Slt:2-Ax:O}') ssa=srxslit.nsls2slit(tb='XF:05IDB-OP:1{Slt:SSA-Ax:T}', bb='XF:05IDB-OP:1{Slt:SSA-Ax:B}', ob='XF:05IDB-OP:1{Slt:SSA-Ax:O}',ib='XF:05IDB-OP:1{Slt:SSA-Ax:I}') x3acq=PV('XSPRESS3-EXAMPLE:Acquire') x3erase=PV('XSPRESS3-EXAMPLE:ERASE') x3acqtime=PV('XSPRESS3-EXAMPLE:AcquireTime') x3acqnum=PV('XSPRESS3-EXAMPLE:NumImages') x3tmode=PV('XSPRESS3-EXAMPLE:TriggerMode') x3h5path=PV('XSPRESS3-EXAMPLE:HDF5:FilePath') x3h5fname=PV('XSPRESS3-EXAMPLE:HDF5:FileName') x3h5fnum=PV('XSPRESS3-EXAMPLE:HDF5:FileNumber') x3h5vdim=PV('XSPRESS3-EXAMPLE:HDF5:NumExtraDims') x3h5size=PV('XSPRESS3-EXAMPLE:HDF5:ExtraDimSizeN') x3h5d1=PV('XSPRESS3-EXAMPLE:HDF5:ExtraDimSizeX') x3h5d2=PV('XSPRESS3-EXAMPLE:HDF5:ExtraDimSizeY') #report ROIs for channels and counts at each point x3ch1roi0min=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI1_LLM') x3ch1roi0max=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI1_HLM') x3ch1roi0ct=PV('XSPRESS3-EXAMPLE:C1_ROI1:Value_RBV') x3ch1roi1min=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI2_LLM') x3ch1roi1max=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI2_HLM') x3ch1roi1ct=PV('XSPRESS3-EXAMPLE:C1_ROI2:Value_RBV') x3ch1roi2min=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI3_LLM') x3ch1roi2max=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI3_HLM') x3ch1roi2ct=PV('XSPRESS3-EXAMPLE:C1_ROI3:Value_RBV') x3ch2roi0min=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI1_LLM') x3ch2roi0max=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI1_HLM') x3ch2roi0ct=PV('XSPRESS3-EXAMPLE:C2_ROI1:Value_RBV') x3ch2roi1min=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI2_LLM') x3ch2roi1max=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI2_HLM') x3ch2roi1ct=PV('XSPRESS3-EXAMPLE:C2_ROI2:Value_RBV') x3ch2roi2min=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI3_LLM') x3ch2roi2max=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI3_HLM') x3ch2roi2ct=PV('XSPRESS3-EXAMPLE:C2_ROI3:Value_RBV') x3ch3roi0min=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI1_LLM') x3ch3roi0max=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI1_HLM') x3ch3roi0ct=PV('XSPRESS3-EXAMPLE:C3_ROI1:Value_RBV') x3ch3roi1min=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI2_LLM') x3ch3roi1max=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI2_HLM') x3ch3roi1ct=PV('XSPRESS3-EXAMPLE:C3_ROI2:Value_RBV') x3ch3roi2min=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI3_LLM') x3ch3roi2max=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI3_HLM') x3ch3roi2ct=PV('XSPRESS3-EXAMPLE:C3_ROI3:Value_RBV') #claim ROI 4 for our own use. we will integrate over all 4096 channels. x3ch1roi3min=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI4_LLM') x3ch1roi3max=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI4_HLM') x3ch1roi3ct=PV('XSPRESS3-EXAMPLE:C1_ROI4:Value_RBV') x3ch2roi3min=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI4_LLM') x3ch2roi3max=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI4_HLM') x3ch2roi3ct=PV('XSPRESS3-EXAMPLE:C2_ROI4:Value_RBV') x3ch3roi3min=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI4_LLM') x3ch3roi3max=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI4_HLM') x3ch3roi3ct=PV('XSPRESS3-EXAMPLE:C3_ROI4:Value_RBV') dett=PV('XF:05IDD-ES:1{EVR:1-Out:FP3}Src:Scale-SP') deti=PV('XF:05IDA{IM:1}Per-SP') detinit=PV('XF:05IDA{IM:1}Cmd:Init') det0 = PV(detstr+'Cur:I0-I') det1 = PV(detstr+'Cur:I1-I') det2 = PV(detstr+'Cur:I2-I') det3 = PV(detstr+'Cur:I3-I') bmot.info bmot_cur.info bmot_stop.info umot.info umot_cur.info umot_go.info gmot.info gmot_cur.info gmot_stop.info det0.info det1.info det2.info det3.info bragg_temp.info bmot_cur.add_callback(cbfx) bmot_cur.run_callbacks() umot_cur.add_callback(cbfy) umot_cur.run_callbacks() gmot_cur.add_callback(cbfz) gmot_cur.run_callbacks() shut_status.add_callback(cbf_shut) beam_current.add_callback(cbf_curr) shut_status.run_callbacks() beam_current.run_callbacks() bragg_temp.add_callback(cbf_temp) bragg_temp.run_callbacks() x3h5path.put(H5path) x3h5fname.put(repr(D0)+'_'+repr(D1)+'_'+repr(D2)+'_'+repr(D3)+'_'+repr(D4)+'_') x3h5fnum.put(0) x3acqtime.put(options.acqt) x3acqnum.put(options.acqn) x3tmode.put(1) x3ch1roi3min.put(0) x3ch2roi3min.put(0) x3ch3roi3min.put(0) x3ch1roi3max.put(4096) x3ch2roi3max.put(4096) x3ch3roi3max.put(4096) #h5 set up x3h5vdim.put(1) x3h5size.put(options.acqn) x3h5d1.put(pN) x3h5d2.put(0) roits=x3ch3roi3ct.timestamp dett.put(3) #overhead on triggering F460 deti.put(float(options.acqn)*options.acqt*.9) detinit.put(1) #check command line options if options.stall == None: twait = 0. else: twait = options.stall str='#NSLS-II SRX'+time.asctime() fp.write(str) fp.write('\n') str='# Start time is '+time.asctime() print str fp.write(str) fp.write('\n') if options.sim is True: str=" -----simulating motor moves and bursts-----" print str fp.write(str) fp.write('\n') else: x3h5capture.put(1) dett.put(4) time.sleep(2) while x3h5capture.get() == 0: time.sleep(0.5) dett.put(3) str='# bragg: %(br)6.4f ; undulator: %(un)6.4f ; gap: %(cg)f ; ROI1 %(roi1i)d:%(roi1a)d ; ROI2 %(roi2i)d:%(roi2a)d ; ROI3 %(roi3i)d:%(roi3a)d'%\ {"br":bmot_cur.get(),"un":umot_cur.get(), "cg":gmot_cur.get(),'roi1i':x3ch1roi0min.get(), 'roi1a':x3ch1roi0max.get(), 'roi2i':x3ch1roi1min.get(), 'roi2a':x3ch1roi1max.get(), 'roi3i':x3ch1roi2min.get(), 'roi3a':x3ch1roi2max.get()} print str fp.write(str) fp.write('\n') str="# --------------------" print str fp.write(str) fp.write('\n') str="# bragg u-gap c-gap energy I0-1 I0-2 I0-3 I0-4 time ROI-1 ROI-2 ROI-3 ROI-4 intensity" print str fp.write(str) fp.write('\n') LN=0 oldsig=det0.get() t0=time.time() sig0=0. sig1=0. sig2=0. sig3=0. nsig0=0. nsig1=0. nsig2=0. nsig3=0. for x in range(0,pN): tar[0][1] = 1 tar[0][0] = float(angle[x]) tar[1][1] = 1 tar[1][0] = float(ivu[x]) tar[2][1] = 1 tar[2][0] = float(t2gap[x]) #if tar[0][0] is the original position, raise "in position" flag if indeadband(float(tar[0][0]),float(bmot_cur.get()),dbd)==1: tar[0][1] = 0 if indeadband(float(tar[1][0]),float(umot_cur.get()),dbd)==1: tar[1][1] = 0 if indeadband(float(tar[2][0]),float(gmot_cur.get()),dbd)==1: tar[2][1] = 0 if options.sim is False: bmot.put(tar[0][0]) umot.put(tar[1][0]) gmot.put(tar[2][0]) time.sleep(1) umot_go.put(0) else: tar[0][1]=0 tar[1][1]=0 tar[2][1]=0 while (tar[0][1] == 1) or (tar[1][1] == 1) or(tar[2][1] == 1): time.sleep(0.05) if LN > 400: umot_go.put(0) LN=0 else: LN=LN+1 if options.sim is False: time.sleep(twait) while ( options.checkbeam and (shut_open == False or beam_current == False)) or T_stop==True: print "Stopped. Waiting for scan conditions to return to normal." if shut_open == False: print "\t->shutter is closed" elif beam_current == False: print "\t->Ring current is below threshold" elif T_stop==True: print "\t->HDCM pitch motor is too hot" else: print "\t->why not have a nice cup of tea or hit ctrl-C?" time.sleep(60.) x3erase.put(1) dett.put(4) nsig0=norm0.get() nsig1=norm1.get() nsig2=norm2.get() nsig3=norm3.get() sig0=sig1=sig2=sig3=3 for i in range(0,options.acqn): x3acq.put(1) while ( x3ch3roi3ct.get()==0.0 or x3ch3roi3ct.timestamp==roits): time.sleep(0.02) sig0=sig0+x3ch1roi0ct.get()+x3ch2roi0ct.get()+x3ch3roi0ct.get() sig1=sig1+x3ch1roi1ct.get()+x3ch2roi1ct.get()+x3ch3roi1ct.get() sig2=sig2+x3ch1roi2ct.get()+x3ch2roi2ct.get()+x3ch3roi2ct.get() sig3=sig3+x3ch1roi3ct.get()+x3ch2roi3ct.get()+x3ch3roi3ct.get() roits=x3ch3roi3ct.timestamp signal0=float(det1.get()) while (signal0==0.0): signal0=float(det1.get()) # while(signal0 == oldsig): # signal0=det0.get() # oldsig=signal0 dett.put(3) else: while ( options.checkbeam and (shut_open == False or beam_current == False)): print "Stopped. Waiting for beam to return." time.sleep(60.) signal0=0. nsig1=0 nsig2=0 nsig3=0 tn=time.time()-t0 if options.sim is False: # str=' %(B)8.4f %(U)8.4f %(G)8.3f %(E)8.2f %(C0)10.7e %(C1)10.7e %(C2)10.7e %(C3)10.7e %(T)d %(ROI1)d %(ROI2)d %(ROI3)d %(ROI4)d %(T1)10.7e'%{"B":float(bmot_cur.get()), "U":float(umot_cur.get()), "G":float(gmot_cur.get()), "C0":nsig0, "C1":nsig1, "C2":nsig2, "C3":nsig3, "ROI1":sig0,'T':tn,"ROI2":sig1,"ROI3":sig2,"ROI4":sig3,"T1":signal0,"E":12398.4 / (2 * 3.13029665951 * math.sin((bmot_cur.get()+0.323658778534)/180.*np.pi))} str=' %(B)8.4f %(U)8.4f %(G)8.3f %(E)8.2f %(C0)10.7e %(C1)10.7e %(C2)10.7e %(C3)10.7e %(T)d %(ROI1)d %(ROI2)d %(ROI3)d %(ROI4)d %(T1)10.7e'%{"B":float(bmot_cur.get()), "U":float(umot_cur.get()), "G":float(gmot_cur.get()), "C0":nsig0, "C1":nsig1, "C2":nsig2, "C3":nsig3, "ROI1":sig0,'T':tn,"ROI2":sig1,"ROI3":sig2,"ROI4":sig3,"T1":signal0,"E":12398.4 / (2 * dSi111 * math.sin((bmot_cur.get()+dbragg)/180.*np.pi))} print str fp.write(str) fp.write('\n') else: str=' B= %(B)8.4f U= %(U)8.4f G= %(G)8.3f : %(C0)10.7e %(C1)10.7e %(C2)10.7e %(C3)10.7e %(ROI)d %(T)d'%{"B":tar[0][0], "U":tar[1][0], "G":tar[2][0], "C0":signal0, "C1":nsig1, "C2":nsig2, "C3":nsig3, "ROI":x3ch1roi0ct.get(),'T':time.time()} print str fp.write(str) fp.write('\n') str='#End time is '+time.asctime() print str fp.write(str) fp.write('\n') fp.close()
def main(argv=None): global simulate global fp global shut_open global current #parse command line options usage = "usage: %prog [options]\nData files are written to /data/<year>/<month>/<day>/" parser = OptionParser(usage) parser.add_option("--slitname", action="store", type="string", dest="motname", help="valid options: wb, pb, ssa") parser.add_option("--detname", action="store", type="string", dest="detname", help="detector PV base") parser.add_option("--xstart", action="store", type="float", dest="xo", help="starting X position") parser.add_option("--xnumstep", action="store", type="int", dest="Nx", help="number of steps in X") parser.add_option("--xstepsize", action="store", type="float", dest="dx", help="step size in X") parser.add_option("--ystart", action="store", type="float", dest="yo", help="starting Y position") parser.add_option("--ynumstep", action="store", type="int", dest="Ny", help="number of steps in Y") parser.add_option("--ystepsize", action="store", type="float", dest="dy", help="step size in Y") parser.add_option("--hsize", action="store", type="float", dest="hs", help="slit size in horizontal") parser.add_option("--vsize", action="store", type="float", dest="vs", help="slit size in vertical") parser.add_option("--wait", action="store", type="float", dest="stall", help="wait at each step [seconds]") parser.add_option("--simulate", action="store_true", dest="sim", default=False, help="simulate motor moves") parser.add_option("--checkbeam", action="store_true", dest="checkbeam", default=False, help="only acquire when beam is on") (options, args) = parser.parse_args() #open log file D0 = time.localtime()[0] D1 = time.localtime()[1] D2 = time.localtime()[2] D3 = time.localtime()[3] D4 = time.localtime()[4] cd = os.getcwd() filedir = '/nfs/xf05id1/data/' if sys.argv[0][0] == '.': out_filename=filedir+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'log_'+repr(D3)+'_'+repr(D4)+'_'+\ string.split(string.strip(sys.argv[0],'./'),'/')[0]+'.txt' else: out_filename=filedir+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'log_'+repr(D3)+'_'+repr(D4)+'_'+\ string.split(string.strip(sys.argv[0],'./'),'/')[5]+'.txt' try: os.chdir(filedir + repr(D0)) except OSError: try: os.mkdir(filedir + repr(D0)) except Exception: print 'cannot create directory: ' + '/data/' + repr(D0) sys.exit() try: os.chdir(filedir + repr(D0) + '/' + repr(D1)) except OSError: try: os.mkdir(filedir + repr(D0) + '/' + repr(D1)) except Exception: print 'cannot create directory: ' + '/data/' + repr( D0) + '/' + repr(D1) sys.exit() try: os.chdir(filedir + repr(D0) + '/' + repr(D1) + '/' + repr(D2)) except OSError: try: os.mkdir(filedir + repr(D0) + '/' + repr(D1) + '/' + repr(D2)) except Exception: print 'cannot create directory: ' + filedir + repr( D0) + '/' + repr(D1) + '/' + repr(D2) sys.exit() try: fp = open(out_filename, 'a') except Exception: print 'cannot open file: ' + out_filename sys.exit() os.chdir(cd) fp.write(', '.join(sys.argv)) fp.write('\n') #initialize PVs and callbacks if options.motname == None: # xmotstr='XF:03IDA-OP{Mon:1-Ax:P}' xmotstr = '' print "must provide slit pv base, e.g., 'XF:28IDA-OP:1{Slt:MB1-Ax:T}'" sys.exit() else: xmotstr = options.motname if options.detname == None: # detstr='XF:03IDA-BI{FS:1-CAM:1}' detstr = '' print "must provide detector pv base, e.g., 'XF:28IDA-BI{URL:01}'" sys.exit() else: detstr = options.detname if options.motname == 'wb': slit=srxslit.nsls2slit(ib='XF:05IDA-OP:1{Slt:1-Ax:I}',\ ob='XF:05IDA-OP:1{Slt:1-Ax:O}',tb='XF:05IDA-OP:1{Slt:1-Ax:T}',\ bb='XF:05IDA-OP:1{Slt:1-Ax:B}') elif options.motname == 'pb': slit = srxslit.nsls2slit(ib='XF:05IDA-OP:1{Slt:2-Ax:I}', ob='XF:05IDA-OP:1{Slt:2-Ax:O}') elif options.motname == 'ssa': # slit=srxslit.nsls2slit(ib='XF:05IDB-OP:1{Slt:SSA-Ax:T}',\ # ob='XF:05IDB-OP:1{Slt:SSA-Ax:B}',tb='XF:05IDB-OP:1{Slt:SSA-Ax:O}',\ # bb='XF:05IDB-OP:1{Slt:SSA-Ax:I}') slit=srxslit.nsls2slit(ib='XF:05IDB-OP:1{Slt:SSA-Ax:I}',\ ob='XF:05IDB-OP:1{Slt:SSA-Ax:O}',tb='XF:05IDB-OP:1{Slt:SSA-Ax:T}',\ bb='XF:05IDB-OP:1{Slt:SSA-Ax:B}') # diode=PV('XF:05IDA{IM:1}Cur:I0-I') diode = PV('XF:05IDD-BI:1{Mscp:1-Cam:1}Stats1:Total_RBV') else: print "no valid slit options found on command line" sys.exit() #transmission #check command line options if options.yo == None: print "must provide a starting point in the vertical" sys.exit() else: yo = options.yo if options.xo == None: print "must provide a starting point in the horizontal" sys.exit() else: xo = options.xo if options.dx == None: dx = 0.00000001 else: dx = options.dx if options.dy == None: dy = 0.00000001 else: dy = options.dy if options.Nx == None: Nx = 0 else: Nx = options.Nx if options.Ny == None: Ny = 0 else: Ny = options.Ny if options.stall == None: twait = 0. else: twait = options.stall if options.hs is not None: if options.sim is False: slit.hsize(options.hs) if options.vs is not None: if options.sim is False: slit.vsize(options.vs) if options.motname == 'pb' or options.motname == 'wb': diode0 = PV(detstr + ':DataRead_Ch1') diode1 = PV(detstr + ':DataRead_Ch2') diode2 = PV(detstr + ':DataRead_Ch3') diode3 = PV(detstr + ':DataRead_Ch4') else: diode0 = PV(detstr + ':Current1:MeanValue_RBV') diode1 = PV(detstr + ':Current2:MeanValue_RBV') diode2 = PV(detstr + ':Current3:MeanValue_RBV') diode3 = PV(detstr + ':Current4:MeanValue_RBV') traj_o_x = PV('SR:C31-{AI}Aie5-2:Offset-x-Cal') traj_o_y = PV('SR:C31-{AI}Aie5-2:Offset-y-Cal') traj_a_x = PV('SR:C31-{AI}Aie5-2:Angle-x-Cal') traj_a_y = PV('SR:C31-{AI}Aie5-2:Angle-y-Cal') shut_status = PV('SR:C05-EPS{PLC:1}Shutter:Sum-Sts') beam_current = PV('SR:C03-BI{DCCT:1}I:Total-I') shut_status.add_callback(cbf_shut) beam_current.add_callback(cbf_curr) shut_status.run_callbacks() beam_current.run_callbacks() str = 'Start time is ' + time.asctime() print str fp.write(str) fp.write('\n') str = '#[point #]\tX pos\tY pos\tch 1\tch 2\tch 3\tch 4\tbpm ox\tbpm oy\tbpm ax\tbpm ay\tdiff h\tdiff v\tib\tob\tbb\ttp' print str fp.write(str) fp.write('\n') str='# h size: %(hs)6.3f ; v size: %(vs)6.3f ; h center: %(hc)6.3f ; v center: %(vc)6.3f'%\ {"hs":slit.hsize(),"vs":slit.vsize(),"hc":slit.hcen(),"vc":slit.vcen()} print str fp.write(str) fp.write('\n') if options.sim is True: str = " -----simulating motor moves and bursts-----" print str fp.write(str) fp.write('\n') time.sleep(2) #number of rows and columns completed by scan Ncol = Nrow = 0 LN = 0 #scan direction for x dir = 1 count = 0 sigarray = list() #nested loops for scanning z,x,y for y in np.linspace(yo, yo + ((Ny) * dy), Ny + 1): sigarry = [] if Nrow % 2 == 0: xs = 0. + xo xe = ((Nx + 1) * dx) + xo - dx xi = dx else: xs = ((Nx) * dx) + xo xe = 0. + xo xi = -dx for x in np.linspace(xs, xe, Nx + 1): if options.sim is False: h = slit.hcen(x) v = slit.vcen(y) time.sleep(twait) while (options.checkbeam and (shut_open == False or beam_current == False)): print "Stopped. Waiting for scan conditions to return to normal." time.sleep(60.) sig = 0. if options.motname == 'ssa': while sig == 0.: sig = diode.get() #sigarray.append([x,sig]) signal0 = signal1 = signal2 = signal3 = 0. while signal0 == 0.: signal0 = diode0.get() while signal1 == 0.: signal1 = diode1.get() while signal2 == 0.: signal2 = diode2.get() while signal3 == 0.: signal3 = diode3.get() if options.sim is False: str = '[%(X)04d] at ( %(XC)8.3f , %(YC)8.3f ): %(d1)10.7e %(d2)10.7e %(d3)10.7e %(d4)10.7e %(ox)6.3f %(oy)6.3f %(ax)6.3f %(ay)6.3f %(in)7.4e %(out)7.4e %(down)7.4e %(IB)7.4e %(OB)7.4e %(TB)7.4e %(BB)7.4e' % { "IB": slit.ibraw(), "OB": slit.obraw(), "BB": slit.bbraw(), "TB": slit.tbraw(), "down": float(sig), "X": Ncol, "XC": float(slit.hcen()), "d1": float(signal0), "d2": float(signal1), "d3": float(signal2), "d4": float(signal3), 'YC': float(slit.vcen()), 'ox': float(traj_o_x.get()), 'oy': float(traj_o_y.get()), 'ax': float(traj_a_x.get()), 'ay': float(traj_a_y.get()), 'in': (float(signal0) - float(signal1)) / float(signal1), 'out': (float(signal2) - float(signal3)) / float(signal3) } print str fp.write(str) fp.write('\n') else: str = '[%(X)04d] at ( %(XC)8.3f , %(YC)8.3f ): %(d1)10.7e %(d2)10.7e %(d3)10.7e %(d4)10.7e %(ox)6.3f %(oy)6.3f %(ax)6.3f %(ay)6.3f %(down)7.4e' % { "down": float(sig), "X": int(Ncol), "XC": float(x), "d1": float(signal0), "d2": float(signal1), "d3": float(signal2), "d4": float(signal3), 'YC': float(y), 'ox': float(traj_o_x.get()), 'oy': float(traj_o_y.get()), 'ax': float(traj_a_x.get()), 'ay': float(traj_a_y.get()) } print str fp.write(str) fp.write('\n') Ncol = Ncol + 1 #M=0. #for m in range(0,len(sigarray)): # if sigarray[m][1]>1.8e-7: # M=M+float(sigarray[m][1]) #MX=0. #for m in range(0,len(sigarray)): # if sigarray[m][1]>1.8e-7: # MX=MX+float(sigarray[m][0])*float(sigarray[m][1]) #str="CoM detected at %6.3e"%(MX/M) #print str #fp.write(str) #fp.write('\n') Nrow = Nrow + 1 str = 'End time is ' + time.asctime() print str fp.write(str) fp.write('\n') fp.close() if options.sim is False: slit.hcen(xo) slit.vcen(yo) return 0
def main(argv=None): global simulate global fp global shut_open global current global x3h5capture global xmot_cur global ymot_cur global shut_status global beam_current #parse command line options usage = "usage: %prog [options]\nData files are written to /data/<year>/<month>/<day>/" parser = OptionParser(usage) parser.add_option("--detname", action="store", type="string", dest="detname", help="detector PV base") parser.add_option("--xstart", action="store", type="float", dest="xo", help="starting X position") parser.add_option("--xnumstep", action="store", type="int", dest="Nx", help="number of steps in X") parser.add_option("--xstepsize", action="store", type="float", dest="dx", help="step size in X") parser.add_option("--ystart", action="store", type="float", dest="yo", help="starting Y position") parser.add_option("--ynumstep", action="store", type="int", dest="Ny", help="number of steps in Y") parser.add_option("--ystepsize", action="store", type="float", dest="dy", help="step size in Y") parser.add_option("--wait", action="store", type="float", dest="stall", help="wait at each step [seconds]") parser.add_option("--simulate", action="store_true", dest="sim", default=False, help="simulate motor moves") parser.add_option("--checkbeam", action="store_true", dest="checkbeam", default=False, help="only acquire when beam is on") parser.add_option("--checkcryo", action="store_true", dest="checkcryo", default=False, help="only acquire when cryo status is ok") parser.add_option("--acqtime", action="store", type="float", dest="acqt", default=1, help="image integration time [sec]") parser.add_option("--acqnum", action="store", type="int", dest="acqn", default=1, help="frames per scan point") (options,args) = parser.parse_args() #open log file D0=time.localtime()[0] D1=time.localtime()[1] D2=time.localtime()[2] D3=time.localtime()[3] D4=time.localtime()[4] cd=os.getcwd() filedir = '/nfs/xf05id1/data/' if sys.argv[0][0]=='.': out_filename=filedir+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'log_'+repr(D1)+'_'+repr(D2)+'_'+repr(D3)+'_'+repr(D4)+'_'+\ string.split(string.strip(sys.argv[0],'./'),'/')[0]+'.txt' else: out_filename=filedir+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'log_'+repr(D1)+'_'+repr(D2)+'_'+repr(D3)+'_'+repr(D4)+'_'+\ string.split(string.strip(sys.argv[0],'./'),'/')[5]+'.txt' try: os.chdir(filedir+repr(D0)) except OSError: try: os.mkdir(filedir+repr(D0)) except Exception: print 'cannot create directory: '+'/data/'+repr(D0) sys.exit() try: os.chdir(filedir+repr(D0)+'/'+repr(D1)) except OSError: try: os.mkdir(filedir+repr(D0)+'/'+repr(D1)) except Exception: print 'cannot create directory: '+'/data/'+repr(D0)+'/'+repr(D1) sys.exit() try: os.chdir(filedir+repr(D0)+'/'+repr(D1)+'/'+repr(D2)) except OSError: try: os.mkdir(filedir+repr(D0)+'/'+repr(D1)+'/'+repr(D2)) except Exception: print 'cannot create directory: '+filedir+repr(D0)+'/'+repr(D1)+'/'+repr(D2) sys.exit() try: fp=open(out_filename,'a') except Exception: print 'cannot open file: '+out_filename sys.exit() os.chdir(cd) fp.write('#'+', '.join(sys.argv)) fp.write('\n') H5path='/epics/data/2015-3/in-house' #H5path='/epics/data/2015-2/testing' #initialize PVs and callbacks if options.detname == None: detstr='' print "must provide detector pv base, e.g., 'XF:28IDA-BI{URL:01}'" sys.exit() else: detstr=options.detname ##### original script for Aerotech stages # xmotname='XF:05IDD-ES:1{Stg:Smpl1-Ax:X}' # ymotname='XF:05IDD-ES:1{Stg:Smpl1-Ax:Y}' # xmot=PV(xmotname+'Mtr.VAL') # xmot_cur=PV(xmotname+'Mtr.RBV') # ymot=PV(ymotname+'Mtr.VAL') # ymot_cur=PV(ymotname+'Mtr.RBV') ###### #####modified for nPoint Stages # xmot=PV('NPOINT:CH1:SET_POSITION.A',connection_timeout=2) # xmot_cur=PV('NPOINT:CH1:GET_POSITION',connection_timeout=2) # ymot=PV('NPOINT:CH2:SET_POSITION.A',connection_timeout=2) # ymot_cur=PV('NPOINT:CH2:GET_POSITION',connection_timeout=2) #####modified for HR coarse Stages; X=Attocube ECS505 X, Y=Attocube ECS505 Z xmot=PV('XF:05IDD-ES:1{Stg:Ecs50}:ACT0:CMD:TARGET',connection_timeout=2) xmot_cur=PV('XF:05IDD-ES:1{Stg:Ecs50}:ACT0:POSITION',connection_timeout=2) ymot=PV('XF:05IDD-ES:1{Stg:Ecs50}:ACT1:CMD:TARGET',connection_timeout=2) ymot_cur=PV('XF:05IDD-ES:1{Stg:Ecs50}:ACT1:POSITION',connection_timeout=2) ##### shut_status=PV('SR:C05-EPS{PLC:1}Shutter:Sum-Sts',connection_timeout=2) beam_current=PV('SR:C03-BI{DCCT:1}I:Total-I',connection_timeout=2) bmot_cur=PV('XF:05IDA-OP:1{Mono:HDCM-Ax:P}Mtr.RBV',connection_timeout=2) #transmission #check command line options if options.yo == None: print "must provide a starting point in the vertical" sys.exit() else: yo = options.yo if options.xo == None: print "must provide a starting point in the horizontal" sys.exit() else: xo = options.xo if options.dx == None: dx = 0.00000001 else: dx = options.dx if options.dy == None: dy = 0.00000001 else: dy = options.dy if options.Nx == None: Nx = 0 else: Nx = options.Nx if options.Ny == None: Ny = 0 else: Ny = options.Ny if options.stall == None: twait = 0. else: twait = options.stall diode0=PV(detstr+'Cur:I0-I',connection_timeout=4) diode1=PV(detstr+'Cur:I1-I',connection_timeout=4) diode2=PV(detstr+'Cur:I2-I',connection_timeout=4) diode3=PV(detstr+'Cur:I3-I',connection_timeout=4) diode0.connect() diode1.connect() diode2.connect() diode3.connect() dett=PV('XF:05IDD-ES:1{EVR:1-Out:FP3}Src:Scale-SP',connection_timeout=2) deti=PV('XF:05IDA{IM:1}Per-SP',connection_timeout=4) detinit=PV('XF:05IDA{IM:1}Cmd:Init',connection_timeout=4) wb=srxslit.nsls2slit(tb='XF:05IDA-OP:1{Slt:1-Ax:T}',bb='XF:05IDA-OP:1{Slt:1-Ax:B}',ib='XF:05IDA-OP:1{Slt:1-Ax:I}',ob='XF:05IDA-OP:1{Slt:1-Ax:O}') pb=srxslit.nsls2slit(ib='XF:05IDA-OP:1{Slt:2-Ax:I}',ob='XF:05IDA-OP:1{Slt:2-Ax:O}') ssa=srxslit.nsls2slit(tb='XF:05IDB-OP:1{Slt:SSA-Ax:T}', bb='XF:05IDB-OP:1{Slt:SSA-Ax:B}', ob='XF:05IDB-OP:1{Slt:SSA-Ax:O}',ib='XF:05IDB-OP:1{Slt:SSA-Ax:I}') x3acq=PV('XSPRESS3-EXAMPLE:Acquire',connection_timeout=2) x3erase=PV('XSPRESS3-EXAMPLE:ERASE',connection_timeout=2) x3acqtime=PV('XSPRESS3-EXAMPLE:AcquireTime',connection_timeout=2) x3acqnum=PV('XSPRESS3-EXAMPLE:NumImages',connection_timeout=2) x3tmode=PV('XSPRESS3-EXAMPLE:TriggerMode',connection_timeout=2) x3h5path=PV('XSPRESS3-EXAMPLE:HDF5:FilePath',connection_timeout=2) x3h5fname=PV('XSPRESS3-EXAMPLE:HDF5:FileName',connection_timeout=2) x3h5fnum=PV('XSPRESS3-EXAMPLE:HDF5:FileNumber',connection_timeout=2) x3h5vdim=PV('XSPRESS3-EXAMPLE:HDF5:NumExtraDims',connection_timeout=2) x3h5size=PV('XSPRESS3-EXAMPLE:HDF5:ExtraDimSizeN',connection_timeout=2) x3h5d1=PV('XSPRESS3-EXAMPLE:HDF5:ExtraDimSizeX',connection_timeout=2) x3h5d2=PV('XSPRESS3-EXAMPLE:HDF5:ExtraDimSizeY',connection_timeout=2) #report ROIs for channels and counts at each point x3ch1roi0min=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI1_LLM',connection_timeout=2) x3ch1roi0max=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI1_HLM',connection_timeout=2) x3ch1roi0ct=PV('XSPRESS3-EXAMPLE:C1_ROI1:Value_RBV',connection_timeout=2) x3ch1roi1min=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI2_LLM',connection_timeout=2) x3ch1roi1max=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI2_HLM',connection_timeout=2) x3ch1roi1ct=PV('XSPRESS3-EXAMPLE:C1_ROI2:Value_RBV',connection_timeout=2) x3ch1roi2min=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI3_LLM',connection_timeout=2) x3ch1roi2max=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI3_HLM',connection_timeout=2) x3ch1roi2ct=PV('XSPRESS3-EXAMPLE:C1_ROI3:Value_RBV',connection_timeout=2) x3ch2roi0min=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI1_LLM',connection_timeout=2) x3ch2roi0max=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI1_HLM',connection_timeout=2) x3ch2roi0ct=PV('XSPRESS3-EXAMPLE:C2_ROI1:Value_RBV',connection_timeout=2) x3ch2roi1min=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI2_LLM',connection_timeout=2) x3ch2roi1max=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI2_HLM',connection_timeout=2) x3ch2roi1ct=PV('XSPRESS3-EXAMPLE:C2_ROI2:Value_RBV',connection_timeout=2) x3ch2roi2min=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI3_LLM',connection_timeout=2) x3ch2roi2max=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI3_HLM',connection_timeout=2) x3ch2roi2ct=PV('XSPRESS3-EXAMPLE:C2_ROI3:Value_RBV',connection_timeout=2) x3ch3roi0min=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI1_LLM',connection_timeout=2) x3ch3roi0max=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI1_HLM',connection_timeout=2) x3ch3roi0ct=PV('XSPRESS3-EXAMPLE:C3_ROI1:Value_RBV',connection_timeout=2) x3ch3roi1min=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI2_LLM',connection_timeout=2) x3ch3roi1max=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI2_HLM',connection_timeout=2) x3ch3roi1ct=PV('XSPRESS3-EXAMPLE:C3_ROI2:Value_RBV',connection_timeout=2) x3ch3roi2min=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI3_LLM',connection_timeout=2) x3ch3roi2max=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI3_HLM',connection_timeout=2) x3ch3roi2ct=PV('XSPRESS3-EXAMPLE:C3_ROI3:Value_RBV',connection_timeout=2) #claim ROI 4 for our own use. we will integrate over all 4096 channels. x3ch1roi3min=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI4_LLM',connection_timeout=2) x3ch1roi3max=PV('XSPRESS3-EXAMPLE:C1_MCA_ROI4_HLM',connection_timeout=2) x3ch1roi3ct=PV('XSPRESS3-EXAMPLE:C1_ROI4:Value_RBV',connection_timeout=2) x3ch2roi3min=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI4_LLM',connection_timeout=2) x3ch2roi3max=PV('XSPRESS3-EXAMPLE:C2_MCA_ROI4_HLM',connection_timeout=2) x3ch2roi3ct=PV('XSPRESS3-EXAMPLE:C2_ROI4:Value_RBV',connection_timeout=2) x3ch3roi3min=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI4_LLM',connection_timeout=2) x3ch3roi3max=PV('XSPRESS3-EXAMPLE:C3_MCA_ROI4_HLM',connection_timeout=2) x3ch3roi3ct=PV('XSPRESS3-EXAMPLE:C3_ROI4:Value_RBV',connection_timeout=2) # xmot_cur.get() xmot_cur.connect() # ymot_cur.get() ymot_cur.connect() norm0=PV('XF:05IDD-BI:1{BPM:01}.S20',connection_timeout=2) norm1=PV('XF:05IDD-BI:1{BPM:01}.S21',connection_timeout=2) norm2=PV('XF:05IDD-BI:1{BPM:01}.S22',connection_timeout=2) norm3=PV('XF:05IDD-BI:1{BPM:01}.S23',connection_timeout=2) xmot_cur.add_callback(cbfx) ymot_cur.add_callback(cbfy) shut_status.add_callback(cbf_shut) beam_current.add_callback(cbf_curr) xmot_cur.run_callbacks() ymot_cur.run_callbacks() shut_status.run_callbacks() beam_current.run_callbacks() x3h5path.put(H5path) x3h5fname.put(repr(D0)+'_'+repr(D1)+'_'+repr(D2)+'_'+repr(D3)+'_'+repr(D4)+'_') x3h5fnum.put(0) x3acqtime.put(options.acqt) x3acqnum.put(options.acqn) x3tmode.put(1) x3ch1roi3min.put(0) x3ch2roi3min.put(0) x3ch3roi3min.put(0) x3ch1roi3max.put(4096) x3ch2roi3max.put(4096) x3ch3roi3max.put(4096) #h5 set up x3h5vdim.put(2) x3h5size.put(options.acqn) x3h5d1.put(options.Nx+1) x3h5d2.put(options.Ny+1) dett.put(3) #overhead on triggering F460 deti.put(float(options.acqn)*options.acqt*1.) detinit.put(1) #ring buffer and PV for tracking ion chamber value ic_hist=collections.deque(maxlen=50) ic_hist.append(0.) v19st=PV('XF:05IDA-UT{Cryo:1-IV:19}Pos-I',connection_timeout=4) v19st.connect() str='#NSLS-II SRX'+time.asctime() fp.write(str) fp.write('\n') str='#Start time is '+time.asctime() print str fp.write(str) fp.write('\n') str='# x: %(hs)6.4f ; y: %(vs)6.4f ; ROI1 %(roi1i)d:%(roi1a)d ; ROI2 %(roi2i)d:%(roi2a)d ; ROI3 %(roi3i)d:%(roi3a)d'%\ {"hs":xmot_cur.get(),"vs":ymot_cur.get(), 'roi1i':x3ch1roi0min.get(), 'roi1a':x3ch1roi0max.get(), 'roi2i':x3ch1roi1min.get(), 'roi2a':x3ch1roi1max.get(), 'roi3i':x3ch1roi2min.get(), 'roi3a':x3ch1roi2max.get()} print str fp.write(str) fp.write('\n') roits=x3ch3roi3ct.timestamp str='# SSA HCEN: %(WBHC)f ; SSA HSIZE: %(WBHS)f ; SSA VCEN: %(WBVC)f ; SSA VSIZE: %(WBVS)f'%\ {"WBHC":ssa.hcen(), "WBHS":ssa.hsize(), "WBVC":ssa.vcen(), "WBVS":ssa.vsize()} print str fp.write(str) fp.write('\n') str='# Bragg: %(B)6.4f ; Energy: %(E)6.4f ; WB HCEN: %(WBHC)f ; WB HSIZE: %(WBHS)f ; WB VCEN: %(WBVC)f ; WB VSIZE: %(WBVS)f'%\ {"B":bmot_cur.get(), "E": 12398. / (2 * 3.12964794061 * math.sin((bmot_cur.get()+0.323341791985)/180.*3.1416)), "WBHC":wb.hcen(), "WBHS":wb.hsize(), "WBVC":wb.vcen(), "WBVS":wb.vsize()} print str fp.write(str) fp.write('\n') str="# -------------------------------------------------------------------- " print str fp.write(str) fp.write('\n') str='#[point #]\tX pos\t\tY pos\tch 1\t\tch 2\t\tch 3\t\tch 4\tdBPM1\t\tdBPM2\t\tdBPM3\t\tdBPM4\t\troi0\t\troi1\t\troi2\t\troi3\t\ttime' print str fp.write(str) fp.write('\n') if options.sim is True: str=" -----simulating motor moves and bursts-----" print str fp.write(str) fp.write('\n') else: x3h5capture.put(1) dett.put(4) time.sleep(2) thisisstupid=0 while x3h5capture.get() == 0: time.sleep(0.5) thisisstupid+=1 if (thisisstupid%20==0): print "waiting for xspress3" dett.put(3) ic_hist.append(diode1.get()) #number of rows and columns completed by scan Ncol=Nrow=0 LN=0 #diode readback is now limiting factor for scan speed oldsig=0. #when the cryocooler kicks in, the beam is unusable for ~3200sec # cryo=PV('XF:05IDA-OP:1{Mono:HDCM}T:LN2Out-I') # ct=cryo.get() # while( ct is None): # time.sleep(0.1) # ct=cryo.get() # print "waiting for cryocooler to respond" t0=time.time() cryocounter=0 shut_toggle=False #nested loops for scanning z,x,y for y in np.linspace(yo,yo+((Ny)*dy),Ny+1): tar[1][0]=y tar[1][1]=1 if options.sim is False: ymot.put(tar[1][0]) if indeadband(float(tar[1][0]),float(ymot_cur.get()),dbd)==1: tar[1][1] = 0 if Nrow%2==0: xs=0.+xo xe=((Nx+1)*dx)+xo-dx xi=dx else: xs=((Nx)*dx)+xo xe=0.+xo xi=-dx for x in np.linspace(xs,xe,Nx+1): tar[0][0]=x tar[0][1]=1 if indeadband(float(tar[0][0]),float(xmot_cur.get()),dbd)==1: tar[0][1]=0 if options.sim is False: xmot.put(tar[0][0]) while ((tar[0][1] == 1) or (tar[1][1] == 1)): time.sleep(0.01) signal0=signal1=signal2=signal3=0. nsig0=nsig1=nsig2=nsig3=0. sig0=sig1=sig2=sig3=0. # while ( options.checkbeam and (cryo.get() < (ct - 0.1)) ): # print "Stopped. Detected possible cryocooler activation." # time.sleep(1) # cryocounter=cryocounter+1 #if the above is true for five cycles, the cryocooler was on, wait another 10min # if ( options.checkbeam and cryocounter > 300 ): # print "Detected cryocooler activation, waiting 10min" # time.sleep(600) # cryocounter=0 #this is my averge IC current tavg=np.asarray(ic_hist).mean() #check the filling valve status and set flag high if it is open while ( options.checkcryo and (v19st.get() > 0.)): print "Stopped. Crycooler valve V19 is open." cryocounter=1 time.sleep(1) #while the ion chamber is reading less than 80% of previous history, sleep while (cryocounter==1): #trigger the 460 and store the ion chamber value dett.put(4) time.sleep(5+options.acqt) oldsig=diode1.get() dett.put(3) #if the reading is less than 80% of historical value or the valve is open, sleep #remember that the reading is negative-going if (oldsig > (-1.*0.8*tavg)) and (v19st.get > 0.): print "Beam current has not returned" time.sleep(30) else: cryocounter=0 while ( options.checkbeam and (shut_open == False or beam_current == False)): print "Stopped. Waiting for scan conditions to return to normal." if shut_open==False: shut_toggle=True time.sleep(10.) if shut_toggle==True: print "Entering optics conditioning period. Waiting 5min" time.sleep(300) shut_toggle=False if options.sim is False: x3erase.put(1) dett.put(4) while nsig0==0.: nsig0=float(norm0.get()) while nsig1==0.: nsig1=float(norm1.get()) while nsig2==0.: nsig2=float(norm2.get()) while nsig3==0.: nsig3=float(norm3.get()) sig0=0 sig1=0 sig2=0 sig3=0 for i in range(0,options.acqn): x3acq.put(1) while ( x3ch3roi3ct.get()==0.0 or x3ch3roi3ct.timestamp==roits): time.sleep(0.02) sig0=sig0+x3ch1roi0ct.get()+x3ch2roi0ct.get()+x3ch3roi0ct.get() sig1=sig1+x3ch1roi1ct.get()+x3ch2roi1ct.get()+x3ch3roi1ct.get() sig2=sig2+x3ch1roi2ct.get()+x3ch2roi2ct.get()+x3ch3roi2ct.get() sig3=sig3+x3ch1roi3ct.get()+x3ch2roi3ct.get()+x3ch3roi3ct.get() roits=x3ch3roi3ct.timestamp signal0=diode0.get() if signal0==oldsig: time.sleep(0.02) signal0=diode0.get() oldsig=signal0 signal1=diode1.get() signal2=diode2.get() signal3=diode3.get() dett.put(3) #populate a ring buffer with every 100th ion chamber reading #we will use the average of this buffer to determine recovery #from a cryocooler activation if(Nx%100 ==0): ic_hist.append(signal1) time.sleep(twait) tn=time.time()-t0 if options.sim is False: str='%(X)06d %(XC)9.4f %(YC)9.4f %(d1)10.7e %(d2)10.7e %(d3)10.7e %(d4)10.7e %(n0)10.7e %(n1)10.7e %(n2)10.7e %(n3)10.7e %(s0)10.7e %(s1)10.7e %(s2)10.7e %(s3)10.7e %(time)9.2f'%{ 'X':Ncol, 'XC':xmot_cur.get(),"YC":ymot_cur.get(), "d1":float(signal0), "d2":float(signal1), "d3":float(signal2),"d4":float(signal3), 'n0':nsig0, 'n1':nsig1, 'n2':nsig2, 'n3':nsig3, "s0":sig0,"s1":sig1,"s2":sig2,"s3":sig3, "time":tn} print str fp.write(str) fp.write('\n') else: str='%(X)06d %(XC)8.4f %(YC)8.4f %(d1)10.7e %(d2)10.7e %(d3)10.7e %(d4)10.7e'%{"X":int(Ncol),"XC":tar[0][0], "YC":tar[1][0], "d1":float(signal0), "d2":float(signal1), "d3":float(signal2),"d4":float(signal3)} print str fp.write(str) fp.write('\n') Ncol=Ncol+1 Nrow=Nrow+1 str='#End time is '+time.asctime() print str fp.write(str) fp.write('\n') fp.close() xmot_cur.clear_callbacks() ymot_cur.clear_callbacks() shut_status.clear_callbacks() beam_current.clear_callbacks() return 0
import sys sys.path.append('/nfs/xf05id1/src/nsls2-xf-utils') import srxslit import srxfe import srxbpm import tempdev import srxm2 wb = srxslit.nsls2slit(tb='XF:05IDA-OP:1{Slt:1-Ax:T}', bb='XF:05IDA-OP:1{Slt:1-Ax:B}', ib='XF:05IDA-OP:1{Slt:1-Ax:I}', ob='XF:05IDA-OP:1{Slt:1-Ax:O}') pb = srxslit.nsls2slit(ib='XF:05IDA-OP:1{Slt:2-Ax:I}', ob='XF:05IDA-OP:1{Slt:2-Ax:O}') ssa = srxslit.nsls2slit(tb='XF:05IDB-OP:1{Slt:SSA-Ax:T}', bb='XF:05IDB-OP:1{Slt:SSA-Ax:B}', ob='XF:05IDB-OP:1{Slt:SSA-Ax:O}', ib='XF:05IDB-OP:1{Slt:SSA-Ax:I}') m2x = srxm2.mottwin(m1='XF:05IDD-OP:1{Mir:2-Ax:XU}Mtr', m2='XF:05IDD-OP:1{Mir:2-Ax:XD}Mtr') bpm1 = srxbpm.nsls2bpm(bpm='bpm1') bpm2 = srxbpm.nsls2bpm(bpm='bpm2')
def main(argv=None): global simulate global fp #parse command line options usage = "usage: %prog [options]\nData files are written to /data/<year>/<month>/<day>/" parser = OptionParser(usage) parser.add_option("--slitname", action="store", type="string", dest="motname", help="valid options: wb, pb") parser.add_option("--detname", action="store", type="string", dest="detname", help="detector PV base") parser.add_option("--xstart", action="store", type="float", dest="xo", help="starting X position") parser.add_option("--xnumstep", action="store", type="int", dest="Nx", help="number of steps in X") parser.add_option("--xstepsize", action="store", type="float", dest="dx", help="step size in X") parser.add_option("--ystart", action="store", type="float", dest="yo", help="starting Y position") parser.add_option("--ynumstep", action="store", type="int", dest="Ny", help="number of steps in Y") parser.add_option("--ystepsize", action="store", type="float", dest="dy", help="step size in Y") parser.add_option("--hsize", action="store", type="float", dest="hs", help="slit size in horizontal") parser.add_option("--vsize", action="store", type="float", dest="vs", help="slit size in vertical") parser.add_option("--wait", action="store", type="float", dest="stall", help="wait at each step [seconds]") parser.add_option("--simulate", action="store_true", dest="sim", default=False, help="simulate motor moves") (options, args) = parser.parse_args() #open log file D0 = time.localtime()[0] D1 = time.localtime()[1] D2 = time.localtime()[2] D3 = time.localtime()[3] D4 = time.localtime()[4] cd = os.getcwd() filedir = '/nfs/xf05id1/data/' if sys.argv[0][0] == '.': out_filename=filedir+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'log_'+repr(D3)+'_'+repr(D4)+'_'+\ string.split(string.strip(sys.argv[0],'./'),'/')[0]+'.txt' else: out_filename=filedir+repr(D0)+'/'+repr(D1)+'/'+repr(D2)+'/'+'log_'+repr(D3)+'_'+repr(D4)+'_'+\ string.split(string.strip(sys.argv[0],'./'),'/')[5]+'.txt' try: os.chdir(filedir + repr(D0)) except OSError: try: os.mkdir(filedir + repr(D0)) except Exception: print 'cannot create directory: ' + '/data/' + repr(D0) sys.exit() try: os.chdir(filedir + repr(D0) + '/' + repr(D1)) except OSError: try: os.mkdir(filedir + repr(D0) + '/' + repr(D1)) except Exception: print 'cannot create directory: ' + '/data/' + repr( D0) + '/' + repr(D1) sys.exit() try: os.chdir(filedir + repr(D0) + '/' + repr(D1) + '/' + repr(D2)) except OSError: try: os.mkdir(filedir + repr(D0) + '/' + repr(D1) + '/' + repr(D2)) except Exception: print 'cannot create directory: ' + filedir + repr( D0) + '/' + repr(D1) + '/' + repr(D2) sys.exit() try: fp = open(out_filename, 'a') except Exception: print 'cannot open file: ' + out_filename sys.exit() os.chdir(cd) fp.write(', '.join(sys.argv)) fp.write('\n') #initialize PVs and callbacks if options.motname == None: # xmotstr='XF:03IDA-OP{Mon:1-Ax:P}' xmotstr = '' print "must provide slit pv base, e.g., 'XF:28IDA-OP:1{Slt:MB1-Ax:T}'" sys.exit() else: xmotstr = options.motname if options.detname == None: # detstr='XF:03IDA-BI{FS:1-CAM:1}' detstr = '' print "must provide detector pv base, e.g., 'XF:28IDA-BI{URL:01}'" sys.exit() else: detstr = options.detname if options.motname == 'wb': slit=srxslit.nsls2slit(ib='XF:05IDA-OP:1{Slt:1-Ax:I}',\ ob='XF:05IDA-OP:1{Slt:1-Ax:O}',tb='XF:05IDA-OP:1{Slt:1-Ax:T}',\ bb='XF:05IDA-OP:1{Slt:1-Ax:B}') elif options.motname == 'pb': slit = srxslit.nsls2slit(ib='XF:05IDA-OP:1{Slt:2-Ax:I}', ob='XF:05IDA-OP:1{Slt:2-Ax:O}') else: print "no valid slit options found on command line" sys.exit() #transmission #check command line options if options.yo == None: print "must provide a starting point in the vertical" sys.exit() else: yo = options.yo if options.xo == None: print "must provide a starting point in the horizontal" sys.exit() else: xo = options.xo if options.dx == None: dx = 0.00000001 else: dx = options.dx if options.dy == None: dy = 0.00000001 else: dy = options.dy if options.Nx == None: Nx = 0 else: Nx = options.Nx if options.Ny == None: Ny = 0 else: Ny = options.Ny if options.stall == None: twait = 0. else: twait = options.stall if options.hs is not None: if options.sim is False: slit.hsize(options.hs) if options.vs is not None: if options.sim is False: slit.vsize(options.vs) diode0 = PV(detstr + ':DataRead_Ch1') diode1 = PV(detstr + ':DataRead_Ch2') diode2 = PV(detstr + ':DataRead_Ch3') diode3 = PV(detstr + ':DataRead_Ch4') traj_o_x = PV('SR:C31-{AI}Aie5-2:Offset-x-Cal') traj_o_y = PV('SR:C31-{AI}Aie5-2:Offset-y-Cal') traj_a_x = PV('SR:C31-{AI}Aie5-2:Angle-x-Cal') traj_a_y = PV('SR:C31-{AI}Aie5-2:Angle-y-Cal') str = 'Start time is ' + time.asctime() print str fp.write(str) fp.write('\n') str = '#[point #]\tX pos\tY pos\tch 1\tch 2\tch 3\tch 4\tbpm ox\tbpm oy\tbpm ax\tbpm ay' print str fp.write(str) fp.write('\n') str='# h size: %(hs)6.3f ; v size: %(vs)6.3f ; h center: %(hc)6.3f ; v center: %(vc)6.3f'%\ {"hs":slit.hsize(),"vs":slit.vsize(),"hc":slit.hcen(),"vc":slit.vcen()} print str fp.write(str) fp.write('\n') if options.sim is True: str = " -----simulating motor moves and bursts-----" print str fp.write(str) fp.write('\n') time.sleep(2) #number of rows and columns completed by scan Ncol = Nrow = 0 LN = 0 #scan direction for x dir = 1 count = 0 #nested loops for scanning z,x,y for y in frange(0, Ny * dy, dy): if Nrow % 2 == 0: xs = 0 xe = Nx * dx xi = dx else: xs = Nx * dx xe = 0 xi = -dx for x in frange(xs, xe, xi): if options.sim is False: slit.hcen(x + xo) slit.vcen(y + yo) signal0 = diode0.get() signal1 = diode1.get() signal2 = diode2.get() signal3 = diode3.get() time.sleep(twait) if options.sim is False: str = '[%(X)04d] at ( %(XC)8.3f , %(YC)8.3f ): %(d1)10.7e %(d2)10.7e %(d3)10.7e %(d4)10.7e %(ox)6.3f %(oy)6.3f %(ax)6.3f %(ay)6.3f %(in)7.4e %(out)7.4e' % { "X": Ncol, "XC": slit.hcen(), "d1": signal0, "d2": signal1, "d3": signal2, "d4": signal3, 'YC': slit.vcen(), 'ox': traj_o_x.get(), 'oy': traj_o_y.get(), 'ax': traj_a_x.get(), 'ay': traj_a_y.get(), 'in': (signal0 - signal1) / signal1, 'out': (signal2 - signal3) / signal3 } print str fp.write(str) fp.write('\n') else: str = '[%(X)04d] at ( %(XC)8.3f , %(YC)8.3f ): %(d1)10.7e %(d2)10.7e %(d3)10.7e %(d4)10.7e %(ox)6.3f %(oy)6.3f %(ax)6.3f %(ay)6.3f' % { "X": Ncol, "XC": x, "d1": signal0, "d2": signal1, "d3": signal2, "d4": signal3, 'YC': y, 'ox': traj_o_x.get(), 'oy': traj_o_y.get(), 'ax': traj_a_x.get(), 'ay': traj_a_y.get() } print str fp.write(str) fp.write('\n') Ncol = Ncol + 1 Nrow = Nrow + 1 str = 'End time is ' + time.asctime() print str fp.write(str) fp.write('\n') fp.close() if options.sim is False: slit.hcen(xo) slit.vcen(yo) return 0