def __split_and_fittp(self, startTime, endTime, partNumber, scanNumber): # temporary UVData to store the split, destroyed in the end tempDiskNo = 1 tempSeqNo = 3 tempUVData = AIPSUVData('PSRALL', 'SPLIT ', tempDiskNo, tempSeqNo) self.__clear(tempUVData) splitTask = AIPSTask('SPLIT') splitTask.indata = self.allUVData splitTask.timerang = AIPSList([ 0, startTime.hour, startTime.minute, startTime.second, 0, endTime.hour, endTime.minute, endTime.second ]) splitTask.outdisk = tempDiskNo splitTask.outseq = tempSeqNo try: splitTask.go() except RuntimeError: print("!!!!Warning: SPLIT failed at " + startTime.isoformat() + " - " + endTime.isoformat() + " possibly no data") # if SPLIT is successful, start FITTP if tempUVData.exists(): fittpTask = AIPSTask('FITTP') fittpTask.dataout = ( '/jop87_2/scratch/huang/rp024c/grid_trial/pulses/' + self.prefix + '.PART' + str(partNumber) + '.UVFITS') fittpTask.indata = tempUVData fittpTask.go()
import os import urllib AIPS.userno = 1999 # Download a smallish FITS file from the EVN archive. url = 'http://archive.jive.nl/exp/N03L1_030225/fits/n03l1_1_1.IDI1' file = '/tmp/' + os.path.basename(url) if not os.path.isfile(file): urllib.urlretrieve(url, file) assert(os.path.isfile(file)) name = os.path.basename(url).split('_')[0].upper() uvdata = AIPSUVData(name, 'UVDATA', 1, 1) if uvdata.exists(): uvdata.zap() fitld = AIPSTask('fitld') fitld.datain = file fitld.outdata = uvdata fitld.douvcomp = 0 fitld.msgkill = 2 fitld.go() uvdata = WizAIPSUVData(name, 'UVDATA', 1, 1, AIPS.userno) for vis in uvdata: vis.visibility[0][0][0][2] = 1.234 vis.update() continue
import signal import time import urllib AIPS.userno = 1999 # Download a smallish FITS file from the EVN archive. url = 'http://archive.jive.nl/exp/N03L1_030225/fits/n03l1_1_1.IDI1' file = '/tmp/' + os.path.basename(url) if not os.path.isfile(file): urllib.urlretrieve(url, file) assert(os.path.isfile(file)) name = os.path.basename(url).split('_')[0].upper() uvdata = AIPSUVData(name, 'UVDATA', 1, 1) if uvdata.exists(): uvdata.zap() pass assert(not uvdata.exists()) fitld = AIPSTask('fitld') fitld.datain = file fitld.outdata = uvdata fitld.msgkill = 2 fitld() assert(uvdata.exists()) tv = AIPSTV()
def __init__(self, iterNum, **args): self.iterNum = iterNum self.args = args AIPS.userno=self.args["user"]#username snInit = 0 clInit = 1 AIPSTask.msgkill = -5 #makes the output less verbose uvdata = AIPSUVData(self.args["name"], 'UVDATA', 1, self.args["inseq"]) cleaninseq = iterNum imageClean = AIPSImage(self.args["name"], 'ICL001', 1, cleaninseq) imageDirty = AIPSImage(self.args["name"], 'IBM001', 1, cleaninseq) imageCleanSC = AIPSImage(self.args["source"], 'ICL001', 1, 1) imageDirtySC = AIPSImage(self.args["source"], 'IBM001', 1, 1) flag = AIPSUVData(self.args["name"], 'TASAV', 1, 100) if uvdata.exists() and iterNum == 1: print("Data is already present") ans1 = raw_input('\033[33mDo you want to zap the data (yes/no)? \033[0m').upper() if ans1 == 'YES': print("Zapping data and reloading.") uvdata.clrstat() uvdata.zap() fitld = AIPSTask('fitld') fitld.datain = self.args["dataPath"] fitld.outname = self.args["name"] fitld.outseq = self.args["inseq"] fitld.ncount = self.args["fileCount"] fitld.doconcat = 1 #fitldFL = AIPSTask("FITLD") #fitldFL.datain = args["flagPath"] #fitldFL.outname = self.args["name"] #fitldFL.outseq = 100 #fitldFL.ncount = 1 #fitldFL.go() snVers = 0 clVers = 1 fitld.go() else: ans2 = raw_input('\033[33mDo you want to zap the tables and images(yes/no)? \033[0m').upper() if ans2 == 'YES': print("Zapping tables/images.") uvdata.clrstat() uvdata.zap_table('SN', -1) uvdata.zap_table('FL', -1) tablesToDelete = 0 for i in uvdata.tables: if i[1] == 'AIPS CL' and i[0]>tablesToDelete: tablesToDelete = i[0] for k in range(tablesToDelete,1,-1): uvdata.zap_table('CL', k) snVers = 0 clVers = 1 else: print("Going direclty to imaging.") """ snVers = 0 clVers = 0 for i in uvdata.tables: if i[1] == 'AIPS SN' and i[0] > snVers: snVers = i[0] if i[1] == 'AIPS CL' and i[0] > clVers: clVers = i[0] """ clVers = int(raw_input("What cl table would you like to use? ")) loc = location_finder.Location_finder(clVers, **self.args) sys.exit() elif not uvdata.exists(): print("Loading data") fitld = AIPSTask('fitld') fitld.datain = self.args["dataPath"] fitld.outname = self.args["name"] fitld.outseq = self.args["inseq"] fitld.ncount = self.args["fileCount"] fitld.doconcat = 1 fitld.go() #fitldFL = AIPSTask("FITLD") #fitldFL.datain = args["flagPath"] #fitldFL.outname = self.args["name"] #fitldFL.outseq = 100 #fitldFL.ncount = 1 #fitldFL.go() snVers = 0 clVers = 1 else: snVers = 0 clVers = 0 for i in uvdata.tables: if i[1] == 'AIPS SN' and i[0] > snVers: snVers = i[0] if i[1] == 'AIPS CL' and i[0] > clVers: clVers = i[0] print("Deleting tables.") uvdata.zap_table('SN', -1) for k in range(clVers,1,-1): uvdata.zap_table('CL', k) snVers = 0 clVers = 1 if imageClean.exists(): imageClean.clrstat() imageClean.zap() if imageDirty.exists(): imageDirty.clrstat() imageDirty.zap() if flag.exists(): flag.clrstat() flag.zap() fitldFL = AIPSTask("FITLD") fitldFL.datain = args["flagPath"] fitldFL.outname = self.args["name"] fitldFL.outseq = 100 fitldFL.ncount = 1 fitldFL.go() print("Copying flagging") tacop = AIPSTask("TACOP") tacop.indata = flag tacop.invers = 3 tacop.ncount = 1 tacop.outname = self.args["name"] tacop.outseq = self.args["inseq"] tacop.outclass = 'UVDATA' tacop.outdisk = 1 tacop.outver = 0 tacop.inext = 'FG' tacop.go() if self.args["doBP"]: uvdata.zap_table('BP', -1) #create a new bp table for each reftelly print("Running bandpass") bpass = AIPSTask('BPASS') bpass.indata = uvdata bpass.calsour[1] = self.args["bandPassCal"] bpass.timer = self.args["time"] bpass.refant = self.args["refTelly"] if self.args["excludeTelly"]: bpass.antennas[1:] = self.args["excludedTellys"] bpass.go() """ uvdata.zap_table('TY', -1) uvdata.zap_table('GC', -1) print("Running antab") antab = AIPSTask('ANTAB') antab.indata = uvdata antab.calin = self.args["antPath"] antab.go() print("Running apcal") apcal = AIPSTask('APCAL') apcal.indata = uvdata apcal.timer = self.args["time"] apcal.tyver = 1 apcal.gcver = 1 apcal.go() snVers = snVers + 1 print("apcal made snVers {0}".format(snVers)) #applies new SN table to CL print("Running clcal.") clcal = AIPSTask('clcal') clcal.indata = uvdata clcal.calsour[1] = self.args["cal"] clcal.timerang = self.args["time"] clcal.snver = snVers clcal.inver = snVers clcal.gainver = clInit #apply to original cl clcal.timer = self.args["time"] clcal.interpol = "ambg" clcal.opcode = "calp" clcal.refant = self.args["refTelly"] clcal.go() clVers = clVers + 1 print("clcal made cl table {0}".format(clVers)) """ print("Running Fring.") fring = AIPSTask('fring') #finds fringes fring.indata = uvdata fring.docalib = 1 fring.gainuse = clVers if self.args["excludeTelly"]: fring.antennas[1:] = self.args["excludedTellys"] fring.calsour[1] = self.args["cal"] fring.bchan = self.args["bchan"] fring.echan = self.args["echan"] fring.timer = self.args["time"] fring.refant = self.args["refTelly"] if self.args["doBP"]: fring.doband = 1 fring.bpver = 1 fring.go() snVers = snVers + 1 SN = 0 for i in uvdata.tables: if i[1] == 'AIPS SN' and i[0]>SN: SN = i[0] if not SN == snVers: sys.exit("SN table number missmatch") print("Fring created SN table {0}".\ format(snVers)) #applies new SN table to CL print("Running clcal.") clcal = AIPSTask('clcal') clcal.indata = uvdata clcal.calsour[1] = self.args["cal"] clcal.timerang = self.args["time"] if self.args["excludeTelly"]: clcal.antennas[1:] = self.args["excludedTellys"] clcal.snver = snVers clcal.inver = snVers clcal.gainver = clInit #apply to original cl clcal.timer = self.args["time"] clcal.interpol = "ambg" clcal.opcode = "calp" clcal.refant = self.args["refTelly"] clcal.go() """ clcal.snver = snVers clcal.inver = snVers clcal.gainver = clVers clcal.go() """ CL = 0 clVers = clVers + 1 clFring = clVers for i in uvdata.tables: if i[1] == 'AIPS CL' and i[0]>CL: CL = i[0] if not CL == clVers: sys.exit("CL table number missmatch") print("Clcal created CL table {0}".\ format(clVers)) #determines calibration, creates new SN print("Running calib") calib = AIPSTask('calib') calib.indata = uvdata calib.calsour[1] = self.args["cal"] calib.docalib = 1 calib.gainuse = clVers if self.args["excludeTelly"]: calib.antennas[1:] = self.args["excludedTellys"] calib.smodel[1] = 1 calib.solint = 0.2 calib.soltype = 'L1' calib.solmode = 'P' if self.args["doBP"]: calib.doband = 1 calib.bpver = 1 calib.timer = self.args["time"] calib.refant = self.args["refTelly"] calib.go() snVers = snVers + 1 SN = 0 for i in uvdata.tables: if i[1] == 'AIPS SN' and i[0]>SN: SN = i[0] if not SN == snVers: sys.exit("SN table number missmatch") print("Calib created SN table {0}".\ format(snVers)) #takes SN table created by calib and applies to CL print("Running clcal") clcal.sources[1] = self.args["cal"] clcal.snver = snVers clcal.inver = snVers clcal.gainver = clVers clcal.go() #Apply only to cal clVers = clVers + 1 CL = 0 for i in uvdata.tables: if i[1] == 'AIPS CL' and i[0]>CL: CL = i[0] if not CL == clVers: sys.exit("CL table number missmatch") print("Clcal created CL table {0}".format(clVers)) #cleans the image print("Running imagr") imagr = AIPSTask('IMAGR') imagr.indata = uvdata imagr.sources[1] = self.args["cal"] imagr.timerang = self.args["time"] imagr.docalib = 1 imagr.outseq = iterNum #test to force it to make file imagr.gainuse = clVers imagr.bchan = self.args["bchan"] imagr.echan = self.args["echan"] imagr.nchav = (self.args["echan"]-self.args["bchan"] + 1) if self.args["doBP"]: imagr.doband = 1 imagr.bpver = 1 if self.args["excludeTelly"]: imagr.antennas[1:] = self.args["excludedTellys"] imagr.cellsize = AIPSList([0.0001,0.0001]) imagr.imsize = AIPSList([256,256]) imagr.nboxes = len(self.args["CalCleanBox"]) imagr.clbox[1:] = self.args["CalCleanBox"] imagr.niter = 1000 imagr.go() print("Done with imagr") #to get last positive row latestImgTable = 0 for j in imageClean.tables: if j[1] == 'AIPS CC' and j[0]>latestImgTable: latestImgTable = j[0] ccTable = imageClean.table('CC', latestImgTable) for row, i in enumerate(ccTable, start=2): #start @ 2 to get last positive if i['flux']<0: lastPositive = row break print("The last positive component number is: {0}".\ format(lastPositive)) print("Running Calib") calibSelf = AIPSTask('calib') calibSelf.in2data = imageClean calibSelf.indata = uvdata calibSelf.calsour[1] = self.args["cal"] calibSelf.docalib = 1 calibSelf.gainuse = clFring calibSelf.solint = 0.2 calibSelf.soltype = 'L1' calibSelf.solmode = 'A&P' if self.args["excludeTelly"]: calibSelf.antennas[1:] = self.args["excludedTellys"] calibSelf.ncomp[1] = lastPositive calibSelf.timer = self.args["time"] if self.args["doBP"]: calibSelf.doband = 1 calibSelf.bpver = 1 calibSelf.go() snVers = snVers + 1 SN = 0 for i in uvdata.tables: if i[1] == 'AIPS SN' and i[0]>SN: SN = i[0] if not SN == snVers: print("SN = {0} , snVers = {1}".format(SN, snVers)) sys.exit("SN table number missmatch") print("calibSelf created SN table {0}".format(snVers)) #makes contour plot kntr = AIPSTask('KNTR') kntr.indata = imageClean kntr.levs = AIPSList([-1,1,2,3,4,5,7,10]) kntr.dogrey = -1 kntr.dotv = -1 kntr.dovect = - 1 #kntr.blc[1] = .80*self.args["fitBox"][1] #kntr.blc[2] = .80*self.args["fitBox"][2] #kntr.trc[1] = 1.20*self.args["fitBox"][3] #kntr.trc[2] = 1.20*self.args["fitBox"][4] kntr.go() lwmp = AIPSTask('LWPLA') lwmp.indata = imageClean lwmp.plver = 1 lwmp.invers = 1 lwmp.outfile = os.getcwd() + '/images_{0}/{1}_time{2}'.format(self.args["date"],self.args["cal"],self.iterNum) + '.ps' lwmp.go() print("Running clcal") clcal.snver = snVers clcal.inver = snVers clcal.sources[1] = self.args["cal"] clcal.calsour[1] = self.args["cal"] clcal.gainver = clVers print("clVers = {0}".format(clVers)) clcal.go() #Apply only to cal clVers = clVers + 1 CL = 0 for i in uvdata.tables: if i[1] == 'AIPS CL' and i[0]>CL: CL = i[0] if not CL == clVers: sys.exit("CL table number missmatch") print("clcal created CL table {0}".format(clVers)) print("Running clcal.") clcalFinal = AIPSTask('clcal') clcalFinal.indata = uvdata clcalFinal.sources[1] = self.args["source"] clcalFinal.calsour[1] = self.args["cal"] clcalFinal.timerang = self.args["time"] clcalFinal.snver = snVers clcalFinal.inver = snVers clcalFinal.gainver = clFring if self.args["excludeTelly"]: clcalFinal.antennas[1:] = self.args["excludedTellys"] clcalFinal.timer = self.args["time"] clcalFinal.refant = self.args["refTelly"] print("clFring = {0}".format(clFring)) clcalFinal.go() clVers = clVers +1 CL = 0 for i in uvdata.tables: if i[1] == 'AIPS CL' and i[0]>CL: CL = i[0] if not CL == clVers: sys.exit("CL table number missmatch") print("clcalFinal created CL table {0}".format(clVers)) print("Running imagr") imagrSC = AIPSTask('IMAGR') imagrSC.indata = uvdata imagrSC.sources[1] = self.args["source"] imagrSC.timerang = self.args["time"] imagrSC.docalib = 1 imagrSC.outseq = 1 imagrSC.outname = self.args["source"] imagrSC.gainuse = clVers imagrSC.bchan = self.args["SCbchan"] imagrSC.echan = self.args["SCechan"] imagrSC.nchav = (self.args["SCechan"]-self.args["SCbchan"] + 1) if self.args["doBP"]: imagrSC.doband = 1 imagrSC.bpver = 1 if self.args["excludeTelly"]: imagrSC.antennas[1:] = self.args["excludedTellys"] imagrSC.cellsize = AIPSList([0.0001,0.0001]) imagrSC.imsize = AIPSList([256,256]) imagrSC.nboxes = 1 imagrSC.clbox[1] = self.args["fitBox"] imagrSC.niter = 1000 imagrSC.go() print("Done with imagr") #makes contour plot kntrSC = AIPSTask('KNTR') kntrSC.indata = imageCleanSC kntrSC.levs = AIPSList([2,3,4,5,7,10,13,17]) kntrSC.dogrey = -1 kntrSC.dotv = -1 kntrSC.dovect = - 1 #kntr.blc[1] = .80*self.args["fitBox"][1] #kntr.blc[2] = .80*self.args["fitBox"][2] #kntr.trc[1] = 1.20*self.args["fitBox"][3] #kntr.trc[2] = 1.20*self.args["fitBox"][4] kntrSC.go() lwmpSC = AIPSTask('LWPLA') lwmpSC.indata = imageCleanSC lwmpSC.plver = 1 lwmpSC.invers = 1 lwmpSC.outfile = os.getcwd() + '/images_{0}/{1}_time{2}'.format(self.args["date"],self.args["source"],self.iterNum) + '.ps' lwmpSC.go() loc = location_finder.Location_finder(clVers, **self.args) imageClean.zap() imageDirty.zap() imageCleanSC.zap() imageDirtySC.zap() flag.zap() with open(os.getcwd() + '/images_{0}/params{1}.txt'.format(self.args["date"],self.iterNum),'w') as f: for l in self.args: f.write("\n{0}".format(l))
def main(): ''' #################### ### Help section ### #################### ''' if True in [ sys.argv[1] in ['help', '-help', '--help', 'h', '-h', '--h'], len(sys.argv) < 3 ]: #######1234567890123456789012345678901234567891234567 print '#################### HELP ####################' print '# #' print '# Format: parseltongue <script>.py source #' print '# refant #' print '# #' print '################# PARAMETERS #################' print '# #' print '# source: Name of maser in AIPS #' print '# #' print '# refant: AIPS antenna number of station #' print '# which has a good detection of #' print '# maser in POL1 and accurate pre- #' print '# calibration applied #' print '# #' print '################## END HELP ##################' sys.exit() ''' ############################################ ### Tentatively check arguments are okay ### ############################################ ''' ### Get reasonable experiment name ### logfile = open(sys.argv[0].replace('.py', '.log'), 'a') AIPS.userno, exp = get_experiment() indata = AUV(exp, kla, dsk, seq) if not indata.exists(): sys.exit(indata + ' in AIPSID=\ ' + str(AIPS.userno) + ' does not exist') else: print str(indata) + ' does exist' ### Make sure we operate on CL1 ### CL = indata.table_highver('CL') if CL == 1: sys.exit('CL1 !! Need to pre-calibrate!') ### Check if source is valid ### source = sys.argv[1] sources = indata.sources msources = difflib.get_close_matches(source, sources) try: if not msources[0] == source: read = raw_input('Did you mean ' + msources[0] + '? [y|n]\n') if not read in ['Y', 'y']: sys.exit('Unknown source') else: source = msources[0] except IndexError: sys.exit('No suggested sources, unknown source ' + source) ### Check if ref antenna is valid ### reference_antenna = int(sys.argv[2]) antable = indata.table('AN', 1) an = {} for row in antable: an.update({row['nosta']: row['anname'].replace(' ', '')}) if not reference_antenna in an: print 'Antenna table is ' + str(an) reference_antenna = raw_input('Please enter\ antenna number not name\n') ''' ################################### ### Get relevant visbility data ### ################################### ''' if len(source) > 12: sname = source[:12] #AIPS innames can't handle>12 else: sname = source spl_data = AUV(sname, 'TMPL', 1, 69) if spl_data.exists(): spl_data.zap() #sys.exit() _split(indata, source) wdata = WAUV(spl_data.name, spl_data.klass, 1, 69) t = [] for vis in wdata: t += [vis.time] nchans = wdata.header['naxis'][2] npolas = wdata.header['naxis'][1] ncmplx = wdata.header['naxis'][0] data = np.ones(shape=(len(t), nchans, npolas, ncmplx)) # create key dict to map time -> ant antkey = {} for i in range(len(wdata.antennas)): antkey.update({i: []}) i = 0 for vis in wdata: data[i] = vis.visibility antenna = vis.baseline[0] antkey[antenna - 1] += [i] i = i + 1 ''' ####################################### ### Calculate and apply corrections ### ####################################### ''' #find peaks from ACOR spectrum (avg time,ant,pol) #no weighting or scaling applied peaks = find_peaks(data[:, :, :, 0].mean(0).mean(1)) S_peak = {} # calculating peak for each ant/polar (avg time) for i in range(len(indata.antennas)): S_peak.update({i: []}) S_debaselined = np.ones(shape=data[antkey[i], :, :, 0].mean(0).shape) for j in range(data[antkey[i], :, :, 0].mean(0).shape[1]): S_debaselined[:, j] = baselined_spectrum(data[antkey[i], :, j, 0].mean(0)) S_peak[i] = S_debaselined[peaks, :].T S_ref = S_peak[reference_antenna - 1][0] correctionsq = np.zeros(shape=(len(indata.antennas), npolas, len(peaks))) for i in range(len(indata.antennas)): correctionsq[i] = S_ref / S_peak[i] corrections = correctionsq**0.5 polz = {} for p in range(len(indata.polarizations)): polz.update({p: indata.polarizations[p]}) for ant in range(len(indata.antennas)): for pol in range(len(indata.polarizations)): cor = round(median(corrections[ant, pol]), 2) if True in [cor >= 1.0, cor <= 1.0]: '' else: cor = 0.0 print >> logfile, "Correction for " + an[ ant + 1] + ' ' + polz[pol] + ' is ' + str(cor) _clcor(indata, ant + 1, polz[pol], cor, CL) spl_data.zap() print 'CLCOR2: localhos 31DEC16 TST: Cpu= 0.0 Real= 0 IO= 1' print ' ' print '########################################################################' print 'AMPL: Appears to have ended successfully' print '########################################################################' print ' ' print 'If you want please check ' + sys.argv[0].replace( '.py', '.log') + ' for list of applied corrections' print 'And <antenna>_amplitude_tmp.png diagnostic plots (coming soon)' ''' ### DONE ### '''
class Pulsar: def __init__(self): self.scans = [] self.prefix = '' self.dutyCycle = DUTYCYCLE self.allUVData = AIPSUVData('PSRALL', 'UVDATA', 1, 2) self.__clear(self.allUVData) """load the calibrated gated pusar uvdata """ def load_calibrated_obs(self, filename): fitld = AIPSTask('FITLD') fitld.datain = filename fitld.outdata = self.allUVData fitld.go() # sanity check if not self.allUVData.exists(): raise ValueError #TODO get the start and end time using listr #################################### # If using this program for other projects need to modify scans here ###################################### print "WARNING: I can't deal with cross-midnight observations" self.scans.append(Scan(23, 17, 33, 23, 25, 29)) self.scans.append(Scan(23, 28, 33, 23, 36, 29)) print "WARNING: startTime and endTime of each scan is HARDWIRED in the program" # find the prefix for naming output files self.prefix = filename.split('/')[-1] self.prefix = self.prefix[:self.prefix.rfind('.')] """split the loaded data into multiple files, each containing a pulse """ def split_data(self): # adding today is just a trick to get time addition with the datetime package to work today = date.today() partNumber = 0 scanNumber = -1 for scan in self.scans: scanNumber += 1 endDatetime = datetime.combine(today, scan.endTime) sliceStartTime = datetime.combine(today, scan.startTime) dt = timedelta(seconds=DUTYCYCLE) sliceEndtTime = copy.copy(sliceStartTime) + dt while (endDatetime - sliceEndtTime >= timedelta(seconds=DUTYCYCLE)): self.__split_and_fittp(sliceStartTime.time(), sliceEndtTime.time(), partNumber, scanNumber) sliceStartTime = sliceStartTime + dt partNumber += 1 sliceEndtTime = sliceEndtTime + dt """helper function to call SPLIT and FITTP to generate a single-pulse UVDATA file from the original datafile """ def __split_and_fittp(self, startTime, endTime, partNumber, scanNumber): # temporary UVData to store the split, destroyed in the end tempDiskNo = 1 tempSeqNo = 3 tempUVData = AIPSUVData('PSRALL', 'SPLIT ', tempDiskNo, tempSeqNo) self.__clear(tempUVData) splitTask = AIPSTask('SPLIT') splitTask.indata = self.allUVData splitTask.timerang = AIPSList([ 0, startTime.hour, startTime.minute, startTime.second, 0, endTime.hour, endTime.minute, endTime.second ]) splitTask.outdisk = tempDiskNo splitTask.outseq = tempSeqNo try: splitTask.go() except RuntimeError: print("!!!!Warning: SPLIT failed at " + startTime.isoformat() + " - " + endTime.isoformat() + " possibly no data") # if SPLIT is successful, start FITTP if tempUVData.exists(): fittpTask = AIPSTask('FITTP') fittpTask.dataout = ( '/jop87_2/scratch/huang/rp024c/grid_trial/pulses/' + self.prefix + '.PART' + str(partNumber) + '.UVFITS') fittpTask.indata = tempUVData fittpTask.go() """ helper method to make sure that the disk and catalogue number is available for the AIPSData initialization """ def __clear(self, aipsDataObject): if aipsDataObject.exists(): aipsDataObject.clrstat() aipsDataObject.zap()
print 'clean: Removal all AIPS catalog entries' print 'usage: doImage clean.py <aipsNumber>' print 'where <aipsNumber> Your *PIPELINE* AIPS number (should always be the same)' print '' quit() AIPS.userno = int(sys.argv[1]) # retrieve AIPS pipeline user number mydisk = 2 # choose a good default work disk baddisk = 1 # list a disk to avoid (0==no avoidance) catalog = AIPSCat()[mydisk] catalog_size = len(catalog) print 'catalog_size', catalog_size for xx in range(catalog_size): aname = AIPSCat()[mydisk][xx].name aclass = AIPSCat()[mydisk][xx].klass aseq = AIPSCat()[mydisk][xx].seq spectra = AIPSUVData(aname, aclass, mydisk, aseq) image = AIPSImage(aname, aclass, mydisk, aseq) if spectra.exists(): spectra.clrstat() elif image.exists(): image.clrstat() AIPSCat().zap() # empty the catalog
rate = args.rate clip = args.clip p = args.precision scale = args.scale if clip is not None: clip /= 1e9 aipsDisk = 1 aipsfile = args.aipsfile (name, aipsclass, seq) = aipsfile.split('.') uvdata = AIPSUVData(name, aipsclass, aipsDisk, int(seq)) if not uvdata.exists(): print aipsfile, "does not exists! Aborting" sys.exit() # Make a list of antennas maxanid = 0 antable = uvdata.table('AN', 1) for row in antable: if row.nosta > maxanid: maxanid = row.nosta annames = [] for i in range(maxanid): annames.append("") for row in antable: annames[row.nosta - 1] = row.anname.strip()
def split_out_wide_uvdata_0(uvdata_in, current_source, position_filename, scratch_disk = 1, output_object = None, current_ra = None, current_dec = None, split_splat = 'splat', dopol = None, blver = None, flagver = None, doband = None, bpver = None, n_channel_average = None, solint = None, overwrite = 0 ): """splits out 1 or more positions from a file for wide-field imaging uvdata_in I The AIPSUVData object with the original data current_source I The name of the current source to use. position_filename I Full path+filename of the text file to read the positions from. See read_wide_position_list_0 for more info. scratch_disk I Number of the scratch disk to use. This needs to be big enough to hold a copy of uvdata_in output_object I The object to output. If None, do all of the objects found in position_filename. If an integer, then work on the output_object'th object. If a string, then work on the first object whose name matches. current_ra I The current phase center position of uvdata_in in right ascension. In radians. If None, use SU table 1, source current_source. If None, current_dec must also be None. current_dec I The current phase center position of uvdata_in in declination. In radians. If None, use SU table 1, source current_source. If None, current_ra must also be None. split_splat I Which AIPS splitting routine to use? Should be 'splat' for splat 'split' for split else error overwrite I May output files be overwritten? 0 no, else yes. OUTPUT as: uvdata uvdata O list of AIPSUVData objects. """ # First, get the possible objects new_uvdata, ra, dec = read_wide_position_list_0(position_filename) # Figure out how many we are doing start_pos = 0 end_pos = len(new_uvdata) if(output_object is not None): if(type(output_object) == type(5)): assert((output_object>=0) and (output_object<len(new_uvdata))) start_pos = output_object end_pos = output_object + 1 elif(type(output_object) == type("string")): for i in xrange(len(new_uvdata)): if(new_uvdata.name == output_object.upper()): start_pos = i end_pos = i + 1 break else: raise KeyError, "Name '%s' not found"%output_object else: raise TypeError, "output_object has unsupported type "+type(output_object).__str__() # Get the source position source_id = None sources = Albus_Iono.get_source_positions(uvdata_in) for s in xrange(len(sources)): if(sources[s] is None): continue if(sources[s][1] == current_source): source_id = s # Get the current position information if(current_ra is None): assert(current_dec is None) current_ra = sources[s][2] current_dec = sources[s][3] else: raise KeyError, "Source name '%s' not found"%current_source cos_dec = math.cos(current_dec) if(cos_dec <= 0.0): cos_dec = 1.0 uvdata = [] for i in xrange(start_pos,end_pos): # calculate the shift # From AIPS, RA' = RA + SHIFT_RA/COS(DEC) # DEC' = DEC + SHIFT_DEC delta_ra_as = (ra[i] - current_ra) * cos_dec * M_RAD2AS delta_dec_as = (dec[i] - current_dec) * M_RAD2AS # need a scratch file for i in xrange(1,256): temp_uv = AIPSUVData("SP_WIDE_0", "ALBTMP", scratch_disk, i) if(not temp_uv.exists()): break else: raise IndexError, "Cannot find temp slot " run_uvfix(uvdata_in, temp_uv, ra_shift = delta_ra_as, dec_shift = delta_dec_as ) # Ok, fudge the source name temp_wiz = Wizardry.AIPSData.AIPSUVData(temp_uv.name, temp_uv.klass, temp_uv.disk, temp_uv.seq) SU_table = temp_wiz.table('AIPS SU', 1) for row in SU_table: if(row.id__no == source_id): row.source = new_uvdata.name row.update() break # Now split out the data if(split_splat == 'splat'): aparm=[None,1] run_splat(temp_uv,new_uvdata, new_uvdata.name, docalib = docalib, gainuse = CL_out, dopol = dopol, blver = blver, flagver = flagver, doband = doband, bpver = bpver, aparm=aparm, channel = n_channel_average, solint = solint) elif(split_splat == 'split'): if(solint != None): warnings.warn("solint value set, but split does not perform time averaging") aparm=[None,1] out_list = run_split(temp_uv,new_uvdata, new_uvdata.name, docalib = docalib, gainuse = CL_out, dopol = dopol, blver = blver, flagver = flagver, doband = doband, bpver = bpver, aparm=aparm, nchav = n_channel_average, overwrite=overwrite) if(out_list[0] == new_uvdata): pass else: raise RuntimeError, "Split output file not what expected, wanted %s, got %s"%(new_uvdata.__str__(),out_list[0].__str__()) else: raise KeyError, "Unknown split_splat type %s"%split_splat
import os import urllib AIPS.userno = 1999 # Download a smallish FITS file from the EVN archive. url = 'http://archive.jive.nl/exp/N03L1_030225/fits/n03l1_1_1.IDI1' file = '/tmp/' + os.path.basename(url) if not os.path.isfile(file): urllib.urlretrieve(url, file) assert(os.path.isfile(file)) name = os.path.basename(url).split('_')[0].upper() uvdata = AIPSUVData(name, 'UVDATA', 1, 1) assert(uvdata.exists()) try: uvdata = WizAIPSUVData(name, 'UVDATA', 1, 1, AIPS.userno) count = 0 for vis in uvdata: try: assert(vis.visibility[0][0][0][2] > 1.233) assert(vis.visibility[0][0][0][2] < 1.235) except: print count, vis.visibility[0][0][0][2] break count += 1 continue finally:
#read antab #apply antab, apcal #split (and average to one point per IF?) #fittp if whattodo['load_data']: fitld = task('fitld') fitld.default() outdata = UV('TMP', 'TMP', 1, 1) fitld.datain = infits fitld.outdata = outdata fitld.ncount = 1 # one file fitld.digicor = 1 # Do corrections for digitization loss fitld.clint = 1.0/60 # Every second # If outdata exists, remove it (it is TMP file after all) if outdata.exists(): outdata.zap() fitld.go() if whattodo['listr']: listrfile = 'listr.tmp' if os.path.exists(listrfile): os.remove(listrfile) data = UV('TMP', 'TMP', 1, 1) listr = task('listr') listr.default() listr.indata=data listr.optype='SCAN' listr.outprint=listrfile listr.docrt=-1 listr.go()
print 'usage: doImage clean.py <aipsNumber>' print 'where <aipsNumber> Your *PIPELINE* AIPS number (should always be the same)' print '' quit() AIPS.userno=int(sys.argv[1]) # retrieve AIPS pipeline user number mydisk=2 # choose a good default work disk baddisk=1 # list a disk to avoid (0==no avoidance) catalog = AIPSCat()[mydisk] catalog_size = len(catalog) print 'catalog_size',catalog_size for xx in range(catalog_size): aname = AIPSCat()[mydisk][xx].name aclass = AIPSCat()[mydisk][xx].klass aseq = AIPSCat()[mydisk][xx].seq spectra = AIPSUVData( aname, aclass, mydisk, aseq) image = AIPSImage( aname, aclass, mydisk, aseq) if spectra.exists(): spectra.clrstat() elif image.exists(): image.clrstat() AIPSCat().zap() # empty the catalog
"SWPOL data exists. Will set local variable 'uvdata' to point towards swpol data.\n" ) logger.info( 'SWPOL data exists. Will set local variable uvdata to point towards swpol data.\n' ) uvdata = swpoldata else: sys.stdout.write("Something went wrong with Task('SWPOL')") logger.error("Something went wrong with Task('SWPOL')") sys.exit() msortdata = AT.msort(uvdata) if msortdata[3] < uvdata.seq: logger.error('Something went wrong with Task MSORT \n') sys.exit() msortuv = AIPSUVData(*msortdata) if msortuv.exists() == True: logger.info( 'Msort data exists. Assume it is already TB sorted (INDXR has been run). Will set local variable uvdata to point towards msorted data.\n' ) uvdata = msortuv else: logger.error('Something went wrong with Task MSORT \n') sys.exit() AT.indxr(uvdata) else: logger.info('No data Pre Processing (SWPOL,TABED)') msortdata = [OP.outname, 'MSORT', OP.outdisk, OP.outseq] msortuv = AIPSUVData(*msortdata) if msortuv.exists() == True: logger.info(
import os from parseltest import urlretrieve AIPS.userno = 1999 # Download a smallish FITS file from the EVN archive. url = 'http://archive.jive.nl/exp/N03L1_030225/fits/n03l1_1_1.IDI1' file = '/tmp/' + os.path.basename(url) if not os.path.isfile(file): urlretrieve(url, file) assert (os.path.isfile(file)) name = os.path.basename(url).split('_')[0].upper() uvdata = AIPSUVData(name, 'UVDATA', 1, 1) if uvdata.exists(): uvdata.zap() pass assert (not uvdata.exists()) fitld = AIPSTask('fitld') fitld.datain = file fitld.outdata = uvdata fitld.msgkill = 2 fitld.go() assert (uvdata.exists()) try: print('Antennas:', uvdata.antennas)
obsEndTime, cleanup print '\n####################################' print '# Reading Parameters #' print '####################################' fitld, imagr, split, clcor, splat, dbcon, \ properMotion, positionAngle, sourceName, startTime, \ endTime, cleanup = parseInputFile() print '####################################\n' #Load in data from working unix directory fitld.outname = 'calData' fitld.go() uvdata = AIPSUVData('calData','UVDATA',1,1) print 'Callibrated data set loaded: ', uvdata.exists() splat.indata = uvdata #TODO: get tv to work #tv = AIPSTV(host = 'localhost') # creating full image # first run split on full data set, then imagr split.indata = uvdata temp = split.gainuse split.gainuse = splat.gainuse split.go() split.gainuse = temp fulldata = AIPSUVData(sourceName,'SPLIT',1,1)
import os import urllib AIPS.userno = 1999 # Download a smallish FITS file from the EVN archive. url = 'http://archive.jive.nl/exp/N03L1_030225/fits/n03l1_1_1.IDI1' file = '/tmp/' + os.path.basename(url) if not os.path.isfile(file): urllib.urlretrieve(url, file) assert (os.path.isfile(file)) name = os.path.basename(url).split('_')[0].upper() uvdata = AIPSUVData(name, 'UVDATA', 1, 1) if uvdata.exists(): uvdata.zap() fitld = AIPSTask('fitld') fitld.datain = file fitld.outdata = uvdata fitld.douvcomp = 0 fitld.msgkill = 2 fitld.go() uvdata = WizAIPSUVData(name, 'UVDATA', 1, 1, AIPS.userno) for vis in uvdata: vis.visibility[0][0][0][2] = 1.234 vis.update() continue
# Load up the bandpass to the target if not options.calibrateonly: vlbatasks.loadtable(targetdata, bpfilename, bpversion) # Run selfcal outklass = "SPLIT" if not options.targetonly: applybandpasscal = True splitsnversion = 1 doampcal = True dostokesi = False soltype = "L1R" selfcalsnr = 5 splitcaldata = AIPSUVData(options.sourcename, outklass, 1, 1) if splitcaldata.exists(): splitcaldata.zap() vlbatasks.split(caldata, clversion, outklass, options.sourcename) for i in range(1, 300): todeletedata = AIPSUVData(options.sourcename, "CALIB", 1, i) if todeletedata.exists(): todeletedata.zap() vlbatasks.singlesource_calib(splitcaldata, options.flux, splitsnversion, options.refant, doampcal, solintmins, dostokesi, soltype, selfcalsnr, sumifs) # Write SN table to disk if os.path.exists(selfcalsnfilename): os.system("rm -f " + selfcalsnfilename) vlbatasks.writetable(splitcaldata, "SN", 1, selfcalsnfilename)