import os import urllib AIPS.userno = 1999 # Download a smallish FITS file from the EVN archive. url = 'http://archive.jive.nl/exp/N05L1_050301/pipe/n05l1_4C39.25_ICLN.FITS' 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('_')[1].upper() image = AIPSImage(name, 'ICLN', 1, 1) if image.exists(): image.zap() pass assert (not image.exists()) fitld = AIPSTask('fitld') fitld.datain = file fitld.outdata = image fitld.go() assert (image.exists()) try: image = WizAIPSImage(image) parangle = image.keywords['PARANGLE']
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))
from AIPS import AIPS from AIPSTask import AIPSTask from AIPSData import AIPSImage AIPS.userno = 1999 image = AIPSImage('MANDELBROT', 'MANDL', 1, 1) if image.exists(): image.zap() mandl = AIPSTask('mandl') mandl.outdata = image mandl.imsize[1:] = [ 512, 512 ] mandl.go() try: header = image.header print 'Dimension: %dx%d' % (header.naxis[0], header.naxis[1]) print image.tables finally: image.zap()
def __init__(self, clVers, **args): self.clVers = clVers self.args = args self.clVers = 3 AIPS.userno=self.args["user"] uvdata = AIPSUVData(self.args["name"], 'UVDATA', 1, self.args["inseq"]) t = [] #files t with [day, hour, min, sec, day, hour, min, sec] with open(self.args["timeList"], 'r') as f: for l in f.readlines(): t.append(map(str,l.split()[1:9])) for j in t: realtime = ''.join([j[i] for i in range(len(j))])[0:7] imgname = realtime[0:5] #need to shorten the names for AIPS imagr = AIPSTask('IMAGR') imagr.indata = uvdata imagr.sources[1] = self.args["source"] imagr.docalib = 1 imagr.gainuse = self.clVers imagr.bchan = self.args["SCbchan"] imagr.echan = self.args["SCechan"] imagr.nchav = (self.args["SCechan"] - self.args["SCbchan"] + 1) #averages over all channels if self.args["doBP"]: imagr.doband = 1 imagr.bpver = 1 if self.args["excludeTelly"]: imagr.antennas[1:] = self.args["excludedTellys"] imagr.outname = imgname imagr.outseq = 1 imagr.cellsize = AIPSList([0.0001,0.0001]) #imagr.imsize = AIPSList([1024,1024]) imagr.imsize = AIPSList([256,256]) imagr.nboxes = 1 imagr.clbox[1] = self.args["fitBox"] imagr.niter = 1000 imagr.timerang[1:] = [int(j[i]) for i in range(len(j))]#AIPSList(j) good = True try: imagr.go() except RuntimeError as e: print("\nSomething went wrong!\n => {0}".format(e)) with open(os.getcwd() + '/images_{0}/badtimes.txt'.format(self.args["date"]), 'a') as out: out.write("{0}\n".format(imgname)) good = False if good: imageClean = AIPSImage(imgname, 'ICL001',1,1) imageDirty = AIPSImage(imgname, 'IBM001',1,1) imageClean.clrstat() #makes sure AIPS does not trip imageDirty.clrstat() jmfit = AIPSTask('JMFIT') jmfit.indata = imageClean jmfit.blc[1] = .80*self.args["fitBox"][1]#fraction to increase box size jmfit.blc[2] = .80*self.args["fitBox"][2] jmfit.trc[1] = 1.20*self.args["fitBox"][3] jmfit.trc[2] = 1.20*self.args["fitBox"][4] jmfit.niter = 1000 jmfit.doprint = 1 #CHANGED TO doprint! address = os.getcwd() + '/images_{0}/'.format(self.args["date"]) + realtime jmfit.fitout = address + '.crd' jmfit.go() RA = [None]*4 #holds locations DEC = [None]*4 with open(address + '.crd', 'r') as f: for l in f.readlines(): temp = l.split() #for j in range(len(temp)): if len(temp)>0: if temp[0] == 'RA': RA[0] = int(temp[1]) RA[1] = int(temp[2]) RA[2] = float(temp[3]) RA[3] = float(temp[5]) elif temp[0] =='DEC': DEC[0] = int(temp[1]) DEC[1] = int(temp[2]) DEC[2] = float(temp[3]) DEC[3] = float(temp[5]) with open(os.getcwd() + '/images_{0}/locations.txt'.format(self.args["date"]), 'a') as out: out.write("{0}\t{1}\t{2}\t{3:^10}\t{4:^6}\t{5}\t{6}\t{7:^7}\t{8}\n". format(realtime, RA[0], RA[1], RA[2], RA[3], \ DEC[0], DEC[1], DEC[2], DEC[3])) #makes contour plot kntr = AIPSTask('KNTR') kntr.indata = imageClean kntr.levs = AIPSList([2,3,4,5,7,10,13,17]) 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 if good: lwmp.outfile = address + '.ps' else: lwmp.outfile = address + '_bad.ps' lwmp.go() imageClean.zap() imageDirty.zap()
print 'CHECKPT b' print '***fringemap error 2***' pickle.dump(obs, open(picdir + aipsname + '.pic', 'wb')) uvdata = AIPSUVData(aipsname, 'FITS', indisk, 1) uvdata.zap() uvdata = AIPSUVData(aipsname, 'SPLIT', indisk, 1) uvdata.zap() pca = AIPSCat() try: for j in pca[indisk]: if j['name'][:len(aipsname )] == aipsname and j['klass'] == 'IMAP': imdata = AIPSImage(j['name'], 'IMAP', indisk, j['seq']) imdata.zap() print 'Removing', j['name'], '.IMAP' except: pass AIPSMessageLog().zap() except: print 'CHECK EXC' print '***exception***' time.sleep(60) aipsname = str(fi.split('/')[-1].split('.')[0])[:12] # special provisions: # delete FR606 if we are between L264200 and L266700 fring_antennas = list(all_antennas) # copy list
import time from parseltest import urlretrieve AIPS.userno = 1999 # Download a smallish FITS file from the EVN archive. url = 'http://archive.jive.nl/exp/N05L1_050301/pipe/n05l1_4C39.25_ICLN.FITS' 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('_')[1].upper() image = AIPSImage(name, 'ICLN', 1, 1) if image.exists(): image.zap() pass assert (not image.exists()) fitld = AIPSTask('fitld') fitld.datain = file fitld.outdata = image fitld.msgkill = 2 fitld() assert (image.exists()) image.zap(force=True) assert (not image.exists())
from AIPS import AIPS from AIPSTask import AIPSTask from AIPSData import AIPSImage AIPS.userno = 1999 image = AIPSImage('MANDELBROT', 'MANDL', 1, 1) if image.exists(): image.zap() image2 = AIPSImage('MANDELBROT', 'MANDL', 1, 1, 2) if image2.exists(): image2.zap() mandl = AIPSTask('mandl') mandl.userno = 2 mandl.outdata = image mandl.imsize[1:] = [ 512, 512 ] mandl.go() try: assert(not image.exists()) assert(image2.exists()) AIPS.userno = 2 image = AIPSImage('MANDELBROT', 'MANDL', 1, 1) assert(image.exists()) finally: image2.zap()
import time import urllib AIPS.userno = 1999 # Download a smallish FITS file from the EVN archive. url = 'http://archive.jive.nl/exp/N05L1_050301/pipe/n05l1_4C39.25_ICLN.FITS' 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('_')[1].upper() image = AIPSImage(name, 'ICLN', 1, 1) if image.exists(): image.zap() pass assert(not image.exists()) fitld = AIPSTask('fitld') fitld.datain = file fitld.outdata = image fitld.msgkill = 2 fitld() assert(image.exists()) image.zap(force=True) assert(not image.exists())
snversion += 1 clversion += 1 # Correct for leakage if needed #leakagedopol = 0 if xpolmodelfile != "": # First the xpoldelays if not options.targetonly: xpolscan = 1 if not os.path.exists(xpolmodelfile): print "Can't find xpol delay model " + xpolmodelfile print "Aborting!!" sys.exit(1) xpolmodel = AIPSImage("LKGSRC", "CLEAN", 1, 1) if xpolmodel.exists(): xpolmodel.zap() vlbatasks.fitld_image(xpolmodelfile, xpolmodel) xpolsolintmins = 1 inttimesecs = 0.5 # Doesn't matter if this is wrong if os.path.exists(xpolsnfilename): os.remove(xpolsnfilename) vlbatasks.xpoldelaycal(caldata, clversion, refant, options.sourcename, xpolscan, xpolmodel, xpolsolintmins, inttimesecs, xpolsnfilename, delaywindow, ratewindow) vlbatasks.loadtable(caldata, xpolsnfilename, snversion) vlbatasks.applysntable(caldata, snversion, '2PT', clversion, refant) if not options.calibrateonly: vlbatasks.loadtable(targetdata, xpolsnfilename, snversion) vlbatasks.applysntable(targetdata, snversion, '2PT', clversion, refant) snversion += 1
def makeslices(imfile, source=False, freq=False, outdisk=1, **kwargs): logger = logging.getLogger('__name__') ''' imfile: location to the image source: source name to use for naming of catalog in aips, if not set the imfile name will be used freq: frequency string to use for naming of catalog in aips, if not set the imfile name will be used ''' args = { 'ang': 0, 'blc': False, 'trc': False, 'nfit': 0, 'gmax': 1, 'gwidth': 9, 'gpos': 0, 'step1': True, #rotate image 'step2': True, #make slices 'step3': True, #fit slices 'step4': True, #plot slices with fit and write output data table 'ang_step': False, 'image_fraction': 1, 'del_imcat': True, # delete image files after program is finished 'plot_slice': False } args.update(kwargs) if not args['blc']: blc, trc = get_blc_trc(imfile, args['image_fraction']) else: blc = args['blc'] trc = args['trc'] nfit = args['nfit'] gmax = args['gmax'] gwidth = args['gwidth'] gpos = args['gpos'] fitdir = 'SLFIT_{}degree'.format(args['ang']) if source: if freq: imname = source + '_' + freq else: imname = source else: imname = imfile.split('/')[-1].split('.')[0] if len(imname) > 12: imname = imname[:12] logger.info('Image name too long, will use \'{}\'\n'.format(imname)) imdata = AIPSImage(*[imname, 'FITS', outdisk, 1]) if imdata.exists() == True: imdata.zap() imcat = AT.imlod(imname, outdisk, imfile, 'FITS') imdata = AIPSImage(*AT.getndata(outdisk, imcat)) if imdata.exists() == True: logger.info('Successfully loaded new image file.\n') logger.info('Data Loaded: (%s, %s, %d, %d)\n', imdata.name, imdata.klass, imdata.disk, imdata.seq) else: logger.info('Image file not loeaded. Check input.\n') return if args['ang_step']: raw_input("Press Enter to continue...") rotname = imname[:10] + '_R' #### if args['step1']: rotdata = AIPSImage(*[rotname, 'FITS', outdisk, 1]) if rotdata.exists() == True: rotdata.zap() rotcat = AT.lgeom(imdata, rotname, outdisk, outseq=1, aparm=[0, 0, args['ang'], 0, 0, 0, 0, 0, 0]) rotdata = AIPSImage(*AT.getndata(outdisk, rotcat)) if rotdata.exists() == True: logger.info('Rotated image exists.\n') else: logger.error('Rotated image not loaded.\n') sys.exit() else: rotdata = AIPSImage(*[rotname, 'FITS', outdisk, 1]) sys.stdout.write('data that will be used {}'.format(rotdata)) ###########3#### if args['step2']: AT.extd(rotdata, 'SL', -1) j = 1 for i in range(blc[0], trc[0]): AT.slices(rotdata, blc=[i, blc[1], 1], trc=[i, trc[1], 1]) if args['plot_slice']: AT.sl2pl(rotdata, inv=j) j += 1 if args['plot_slice']: outfile = '%s_slice.pdf' % rotdata.name AT.lwpla(rotdata, outfile) ############# if args['step3']: if os.path.isdir(fitdir): for f in glob(fitdir + '/*'): os.remove(f) else: os.makedirs(fitdir) if type(gmax) != list: if type(nfit) == int: nn = np.arange(nfit, rotdata.table_highver('SL') + 1) else: nn = np.concatenate([np.arange(n[0], n[1] + 1) for n in nfit]) for ii in nn: gmax1 = gmax gwidth1 = gwidth saveLog = fitdir + '/SLFIT_{}_{}.log'.format(rotdata.name, ii) AT.slfit(rotdata, inv=int(ii), gmax=gmax, gwidth=gwidth, gpos=gpos, savelog=saveLog) lines = [] with open(saveLog, 'r') as f: for line in f: if line.find('LOGFILE') == -1: lines.append(line) # automatically get the fitting results from this slice to use as starting values for the next one jj = 0 for line in lines: if line.find('Results in physical units') != -1: gmax = float(lines[jj + 2].split()[3]) peakunit = lines[jj + 2].split()[5] gwidth = float(lines[jj + 4].split()[3]) gwidthEr = float(lines[jj + 4].split()[4]) if peakunit == 'MicroJy/BEAM': gmax *= 1e-3 #convert everything to MilliJy/beam # elif peakunit == 'MilliJy/BEAM': # gmax *= 1 break jj += 1 if np.logical_or.reduce( (gwidth < gwidthEr, gmax < gmax1 / 5., gmax > 5 * gmax1)): gmax = gmax1 gwidth = gwidth1 else: for gma, gwi, nf in zip(gmax, gwidth, nfit): for ii in range(nf[0], nf[1] + 1): AT.slfit(rotdata, inv=ii, gmax=gma, gwidth=gwi, savelog=fitdir + '/SLFIT_{}_{}.log'.format(rotdata.name, ii)) ########### if args['step4']: AT.extd(rotdata, 'PL', -1) for i in range(0, trc[0] - blc[0]): AT.sl2pl(rotdata, inv=i + 1, domod=1, dores=1) outfile = '{}_fit_{}degree'.format(rotdata.name, args['ang']) AT.lwpla(rotdata, outfile + '.pdf', docol=1, plcolors=[[0, 0, 0], [0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [1, 1, 1]]) AT.slcol(rotdata, outfile + '.txt', inv=1, nfiles=rotdata.table_highver('SL')) ################# if args['del_imcat']: sys.stdout.write('Deleting loaded map catalog and rotated catalog.\n') rotdata.zap() imdata.zap()