def MakeMtrDefaults(fil=None, out=None): ''' Creates an initialization file from a spreadsheet describing the 1-ID beamline motor assignments :param str fil: input file to read. By default opens file ../1ID/1ID_stages.csv relative to the location of the current file. :param str out: output file to write. By default writes file ../1ID/mtrsetup.py.new Note that if the default file name is used, the output file must be renamed before use to mtrsetup.py ''' import csv # DEFINE INPUT & OUTPUT FILES if fil is None: fil = os.path.join( os.path.split(os.path.split(os.path.abspath(__file__))[0])[0], '1ID', '1ID_stages.csv') print('reading file: '+str(fil)) if out is None: out = os.path.join( os.path.split(os.path.split(os.path.abspath(__file__))[0])[0], '1ID', 'mtrsetup.py.new') print('writing file: '+str(out)) fo = open(out,'w') fo.write("# created " + mac.specdate() + "\n") fo.write("import sys\n") fo.write('sys.path.append("'+os.path.split(os.path.abspath(__file__))[0]+'")\n') fo.write("import APSpy.spec as spec\n") fo.write("spec.EnableEPICS()\n") fo.write("spec.DefineScaler('1id:scaler1',16)\n") # define column number symbols (N.B. numbering starts with 0) crate = 0 mnum = 1 msym = 2 comments = 3 with open(fil, 'rUb') as fp: reader = csv.reader(fp) i = 0 for row in reader: i += 1 if i==1: continue # skip 1st row if row[crate].strip() == "": continue fo.write("spec.DefineMtr(" + "'" + row[msym].strip() + "', " + "'" + row[crate].strip() + ':m' + row[mnum].strip() + "', " + "'" + row[comments].strip() + "') \t # " + str(i) + "\n") fp.close() fo.close() return
def EnergyMonitor(pfname=None, elename=None): ''' Energy monitoring macro Foil configuration needs to be checked to make sure that it is up to date. :param str pfname: output file for energy monitoring result. if nonthing is provided, results is written in the default file. :param int/str elename: element name or number for energy monitor. if nothing is provided, user gets to choose before the function spins the wheel. ''' # DEFINE INPUT & OUTPUT FILES if pfname is None: # pfname = os.path.join( # os.path.split(os.path.split(os.path.abspath(__file__))[0])[0], # '1ID', # 'EnergyMonitor.data') pfname = './exp_setup/energymonitortest.data' print('writing energy monitor results to file: '+str(pfname)) if elename is None: print '65: Tb, 51.996 keV' print '70: Yb, 61.332 keV' print '72: Hf, 65.351 keV' print '79: Au, 80.723 keV' print '83: Bi, 90.527 keV' elename = raw_input('enter appropriate element number to start energy monitor: ') elename = int(elename) # MOVE FOIL IN if elename == 65 or elename is 'Tb': spec.umv(spec.foilB, 135) elif elename == 70 or elename is 'Yb': spec.umv(spec.foilB, 90) elif elename == 72 or elename is 'Hf': spec.umv(spec.foilB, -135) elif elename == 83 or elename is 'Bi': spec.umv(spec.foilB, 45) else: raise NameError('foil not on the wheel.') spec.sleep(0.25) # COUNT / CALCULATE spec.count_em(5); spec.wait_count() print (mac.specdate() + ', ' + str(ep.caget('1id:userCalc9.VAL')) + ', ' + str(ep.caget('1id:scaler1.S3')) + ', ' + str(ep.caget('1id:scaler1.S5')) + ', ' + str(ep.caget('1id:scaler1.T'))) fo = open(pfname, 'a') fo.write(mac.specdate() + ', ' + str(ep.caget('1id:userCalc9.VAL')) + ', ' + str(ep.caget('1id:scaler1.S3')) + ', ' + str(ep.caget('1id:scaler1.S5')) + ', ' + str(ep.caget('1id:scaler1.T')) + '\n') fo.close() # MOVE FOIL OUT spec.umv('foilB', 0) return