def time_sort_data(): """Time-sort data in AIPS with the UVSRT task.""" print_header("Time-sorting data") uvsrt = AIPSTask('uvsrt') uvsrt.userno = AIPS.userno # ------------------------------------------------------------------------- # UVSRT the data # ------------------------------------------------------------------------- # sort data to prevent down stream problems uvsrt.indisk = uvsrt.outdisk = DISK_ID uvsrt.baddisk[1] = BADDISK uvsrt.outcl = 'UVSRT' uvsrt.sort = 'TB' last = cat.last_entry() uvsrt.inname = last.name uvsrt.inclass = last.klass uvsrt.inseq = last.seq # will write to entry 1 because input sdf/uv files were removed uvsrt.go() nfiles = len(cat) for dbcon_entry in range(nfiles-1): cat.zap_entry(-1) # remove the DBCON entries
def runuvconfrompoint(antenna_file, outname, start_freq, start_wavelength, dec, min_ha, max_ha, t_int, channel_inc, n_chan, blockage, w_term=0): uvcon = AIPSTask('UVCON') uvcon.infile = antenna_file #uvcon.in2name = fitsfil.name #uvcon.in2class = fitsfil.klass #uvcon.in2seq = fitsfil.seq #uvcon.in2disk = 1 uvcon.outname = outname #uvcon.nmaps = 1 #uvcon.cmethod = 'DFT' #uvcon.cmodel = 'COMP' uvcon.smodel[1:] = 1, 0, 0, 0, 0, 0, 0 uvcon.aparm[1:] = start_freq, start_wavelength, \ dec, min_ha, max_ha, 0,\ t_int, channel_inc, n_chan, \ blockage uvcon.bparm[1:] = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 uvcon.do3dimag = w_term #uvcon.inp() uvcon.go()
def prtan(uvdata): outprint = aips_out+uvdata.name+'_prtan.txt' HF.delete_file(outprint) prtan = AIPSTask('prtan') prtan.indata = uvdata prtan.docrt = -1 prtan.outprint = outprint prtan()
def runuvfix(datafile, inname, indisk, thisdir): uvfix = AIPSTask('UVFIX') klass = datafile.klass uvfix.indata = datafile uvfix.outdata = AIPSUVData(datafile.name,'UVFIX',indisk,thisdir) uvfix.go() datafile.zap() datafile = AIPSUVData(inname,'UVFIX',indisk,thisdir) datafile.rename(inname, klass, thisdir)
def rungetjy(indata, sources, calsour, bif, eif, snver): getjy = AIPSTask('GETJY') getjy.indata = indata getjy.sources[1:] = sources getjy.calsour[1:] = calsour getjy.bif = bif getjy.eif = eif getjy.snver = snver getjy.go()
def runtabedCopy(indata, inext, invers, outdata, outvers): tabed = AIPSTask('TABED') tabed.indata = indata tabed.inext = inext tabed.invers = invers tabed.outdata = outdata tabed.outvers = outvers tabed.optype = 'COPY' tabed.go()
def msort(uvdata): sys.stdout.write('Sorting data by runing MSORT.') msort = AIPSTask('msort') msort.outdata = uvdata msort.outclass = 'MSORT' msort.indata = uvdata HF.print_inp_to_log(msort,'MSORT') msort() return AIPSUVData(uvdata.name,'MSORT',uvdata.disk,uvdata.seq)
def runsnplt(indata, inext, invers, sources, nplots, optype, dotv): snplt = AIPSTask('SNPLT') snplt.indata = indata snplt.inext= inext snplt.invers = invers snplt.sources[1:] = sources snplt.nplots = nplots snplt.optype = optype snplt.dotv = dotv snplt.go()
def runquickpossm(indata, source): possm = AIPSTask('POSSM') possm.indata = indata possm.source[1:] = source possm.aparm[9] = 1 possm.nplots = 6 possm.solint = 30 # plot every 30min possm.stokes = 'HALF' possm.flagver = 0 possm.go()
def _prtuv(split_data, channel): prtuv = AIPSTask('prtuv') prtuv.default prtuv.channel = channel prtuv.indata = split_data prtuv.dparm[7] = 1 prtuv.cparm[10] = 0.01 prtuv.docrt = -1 removefile('/tmp/prtuv.tmp') prtuv.outprint = '/tmp/prtuv.tmp' prtuv.go()
def ptacop(name1, class1, name2, class2, ttype, innum, outnum, disk): tacop = AIPSTask('TACOP') tacop.indata = AIPSUVData(name1, class1, disk, 1) tacop.outdata = AIPSUVData(name2, class2, disk, 1) tacop.inext = ttype tacop.invers = innum tacop.outvers = outnum tacop.go()
def runlistr(indata, sources, optype, docrt, outprint): listr = AIPSTask('LISTR') listr.indata = indata listr.sources[1:] = sources listr.optype = optype listr.docrt = docrt listr.outprint = outprint listr.go()
def tget(taskname): ''' get AIPSTask() object Args: taskname (str): the name of AIPS Task to be called Returns: AIPSTask object ''' task = AIPSTask(taskname) task.defaults() return task
def tabed(uvdata,ine='an',optype='repl',keyvalue=[5,0],aparm=[5,0,0,4,4,14,0],inv=1,outv=1): tabed = AIPSTask('tabed') tabed.indata = uvdata tabed.outdata = uvdata tabed.inext = ine tabed.invers = inv tabed.outvers = outv tabed.aparm[1:]=aparm tabed.keyvalue[1:]=keyvalue tabed.optype = optype HF.print_inp_to_log(tabed,'TABED') tabed()
def slcol(imdata,outfile,inv=1,nfiles=0,pixxy=[0,0],opc='MODL', aparm=[1,1,0]): slcol = AIPSTask('slcol') slcol.indata = imdata slcol.outtext = outfile slcol.nfiles = nfiles slcol.invers = inv slcol.zinc = 0 slcol.pixxy[1:] = pixxy slcol.opcode = opc slcol.aparm[1:] = aparm HF.print_inp_to_log(slcol,'SLCOL') slcol()
def pwtmod (aipsname, refant, antennas, supweight=50.0, indisk=1): uvdata = AIPSUVData (aipsname, 'FITS', indisk, 1) wtmod = AIPSTask ('WTMOD') wtmod.indata = uvdata wtmod.outdata = uvdata wtmod.antwt[1:] = [1]*len(antennas) wtmod.antwt[antennas.index(refant)+1] = supweight wtmod.inp() wtmod.go()
def initial_flag(uvdata, tasav, disk, refant): tacop = AIPSTask('TACOP') tacop.indata = tasav tacop.inext = 'FG' tacop.invers = 1 tacop.ncount = 1 tacop.outdata = uvdata tacop.go() print 'copied EVN flag file to data, now go manually flag please'
def runsetjy(indata, sources, bif, eif, zerosp, optype): setjy = AIPSTask('SETJY') setjy.indata = indata setjy.sources[1:] = sources setjy.bif = bif setjy.eif = eif setjy.zerosp[1:] = zerosp, 0, 0, 0 setjy.optype = optype setjy.go()
def runfittp(uvdata, fittpdir, fittpfile): fittp = AIPSTask('FITTP') fittp.indata = uvdata fittp.doall = -1 fittp.intype = '' fittp.outtape = 1 srcname = re.sub(r"\s+", '-', fittpfile) fittp.dataout = os.path.join(fittpdir, srcname) print "Saving to disk: ", uvdata.name, uvdata.klass, uvdata.seq fittp.go()
def douvcon_casa(): AIPS.userno = AIPSUSER cc = np.array([[0., 0., 1.]]) np.save('cc', cc) os.system('python douvcon_casa.py') #load data into AIPS fitld = AIPSTask('fitld') fitld.datain = './temp.fits' fitld.outname = 'UVSIM' fitld.outclass = 'FITS' fitld.outdisk = indisk fitld.inp() fitld.go()
def runsousp(indata, sources): sousp = AIPSTask('SOUSP') sousp.indata = indata sousp.sources[1:] = sources sousp.order = 1 sousp.dotv = -1 sousp.go() return sousp.specindx
def greys (aipsname, incl, indisk, pmin, pmax, stfac, stvers, logfiledir='./'): greys = AIPSTask('greys') greys.inname = aipsname greys.inclass = incl greys.indisk = indisk greys.pixrange[1:] = [float(pmin),float(pmax)] greys.dotv = -1 greys.stfac = stfac try: greys.stvers = stvers # does not exist in some aips versions except: pass stdout = sys.stdout; sys.stdout = open(logfiledir+aipsname+'.log','a') greys.go() sys.stdout.close(); sys.stdout = stdout
def index(inname, inclass, inseq, indisk): indxr = AIPSTask('indxr') indxr.default indxr.inname = inname indxr.inclass = inclass indxr.inseq = inseq indxr.indisk = indisk indxr.go()
def pclcal (aipsname,indisk,inver,aipsclass='FITS',logdir='./',\ snver=-1,gainver=0,gainuse=0): uvdata = AIPSUVData (aipsname,aipsclass,indisk,1) clcal = AIPSTask ('clcal') clcal.indata = uvdata clcal.inver = inver clcal.snver = inver if snver==-1 else snver clcal.gainver = gainver clcal.gainuse = gainuse stdout = sys.stdout; sys.stdout = open(logdir+aipsname+'.log','a') clcal.go() sys.stdout.close(); sys.stdout = stdout
def psnsmo(aipsname,aipsclass,indisk,smotype,boxcar=2,delaycut=50,smooth=1): snsmo = AIPSTask('snsmo') snsmo.inname = aipsname snsmo.inclass = aipsclass snsmo.indisk = indisk snsmo.smotype = smotype if smotype=='DELA' or smotype=='VLBI': snsmo.bparm[4] = snsmo.bparm[5] = snsmo.bparm[9] = snsmo.bparm[10] = smooth snsmo.cparm[4] = snsmo.cparm[5] = boxcar snsmo.cparm[9] = snsmo.cparm[10] = delaycut snsmo.doblank = -1 snsmo.go()
def make_average_map(restfreq, uniqueid): print_header("Making average map") sqash = AIPSTask('sqash') # squash the frequency axis to make a continuum image sqash.indisk = DISK_ID sqash.outdisk = DISK_ID last = cat.last_entry() sqash.inname = last.name sqash.inclass = last.klass sqash.inseq = last.seq sqash.bdrop = 3 # squash frequency axis sqash.go() outcont = write_average_map(restfreq, uniqueid) return outcont
def __init__(self, name): """ Create Obit task object Creates task object and calls server function to parse TDF file to obtain task specific parametrs and documentation. Following is a list of class members: _default_dict = Dictionary with default values of parameters _input_list = List of input parameters in order _output_list = List of output parameters in order _min_dict = Parameter minimum values as a List _max_dict = Parameter maximum values as a List _hlp_dict = Parameter descriptions (list of strings) as a dictionary _strlen_dict = String parameter lengths as dictionary _help_string = Task Help documentation as list of strings _explain_string = Task Explain documentation as list of strings _short_help = One line description of task _message_list = list of execution messages retCode = Task return code, 0=Finished OK debug = If true save task parameter file logFile = if given, the name of the file in which to write messages doWait = True if synchronous operation wished Current parameter values are given as class members. """ self._task_type = 'OBIT' AIPSTask.__init__(self, name) self._remainder = "" # Partial message buffer if self.userno == 0: self.userno = 1 # Set disk directory names #print "DEBUG ObitTask._init__ before ",FITS.disks dirs = [] for x in FITS.disks: if x != None: #print "DEBUG ObitTask._init__ ",x.dirname dirs.append(x.dirname) #print "DEBUG ObitTask._init__ before ",FITS.disks self.__dict__["FITSdirs"] = dirs #print "DEBUG ObitTask._init__ after ",self.__dict__["FITSdirs"] dirs = [] for x in AIPS.disks: if x != None: #print "DEBUG ObitTask._init__ ",x.dirname dirs.append(x.dirname) self.__dict__["AIPSdirs"] = dirs
def runprtmsg(prtask, outprint): prtmsg = AIPSTask('PRTMSG') clrmsg = AIPSTask('CLRMSG') prtmsg.prtask = prtask prtmsg.docrt = -1 prtmsg.outprint = outprint # RUN VERB prtmsg.go() clrmsg()
def sl2pl(imdata,inv=0,domod=0,dores=0): sl2pl = AIPSTask('sl2pl') sl2pl.indata = imdata sl2pl.invers = inv sl2pl.domodel = domod sl2pl.doslice = 1 sl2pl.doresid = dores sl2pl.dotv = -1 #HF.print_inp_to_log(sl2pl,'SL2PL') sl2pl()
def pang(uvdata,suba=0): clcor = AIPSTask('clcor') clcor.indata = uvdata clcor.opcode = 'PANG' clcor.subarray = suba clcor.gainv = uvdata.table_highver('CL') clcor.gainu = uvdata.table_highver('CL')+1 clcor.clcorprm[1] = 1 HF.print_inp_to_log(clcor,'CLCOR PANG') clcor()
def runmsort(indata): print 'Running MSORT.' msort = AIPSTask('MSORT') msort.indata = indata msort.outdata = indata msort.sort = 'TB' msort.go()
def write_fits(outname): fittp = AIPSTask('fittp') # Write the last Entry in the catalog to disk fittp.indisk = DISK_ID last = cat.last_entry() fittp.inname = last.name fittp.inclass = last.klass fittp.inseq = last.seq if os.path.exists(outname): os.remove(outname) print 'Removed existing file to make room for new one :', outname fittp.dataout = 'PWD:' + outname fittp.go()
def help(obj): if isinstance(obj, AIPSTask): obj.help() elif type(obj) == type(""): AIPSTask(obj).help() else: _help(obj) pass return
def swpol(uvdata,antennas): swpol = AIPSTask('swpol') swpol.indata = uvdata swpol.antennas[1:] = antennas swpol.outname = uvdata.name swpol.outclass = 'SWPOL' swpol.outseq = uvdata.seq swpol.outdisk = uvdata.disk HF.print_inp_to_log(swpol,'SWPOL') swpol() return AIPSUVData(uvdata.name,'SWPOL',uvdata.disk,uvdata.seq)
def acscl(uvdata,gainu=0,bpv=1,doband=1): acscl = AIPSTask('acscl') acscl.indata = uvdata #acscl.timer[1:] = [0] acscl.solint = 0 acscl.docalib = 1 acscl.gainuse =gainu acscl.bpver=bpv acscl.doband=doband HF.print_inp_to_log(acscl,'ACSCL') acscl()
def lwpla(aipsname, incl, indisk, outfile, logfiledir='./'): lwpla = AIPSTask('lwpla') lwpla.inname = aipsname lwpla.inclass = incl lwpla.indisk = indisk lwpla.outfile = outfile stdout = sys.stdout sys.stdout = open(logfiledir + aipsname + '.log', 'a') lwpla.go() sys.stdout.close() sys.stdout = stdout
def make_average_map(restfreq, uniqueid): print_header("Making average map") sqash = AIPSTask("sqash") # squash the frequency axis to make a continuum image sqash.indisk = DISK_ID sqash.outdisk = DISK_ID last = cat.last_entry() sqash.inname = last.name sqash.inclass = last.klass sqash.inseq = last.seq sqash.bdrop = 3 # squash frequency axis sqash.go() outcont = write_average_map(restfreq, uniqueid) return outcont
def lwpla (aipsname,incl,indisk,outfile,logfiledir='./'): lwpla = AIPSTask('lwpla') lwpla.inname = aipsname lwpla.inclass = incl lwpla.indisk = indisk lwpla.outfile = outfile stdout = sys.stdout; sys.stdout = open(logfiledir+aipsname+'.log','a') lwpla.go() sys.stdout.close(); sys.stdout = stdout
def stars (aipsname, incl, indisk, intext='./starsfile',logfiledir='./'): stars = AIPSTask('stars') stars.inname = aipsname stars.inclass = incl stars.indisk = indisk try: stars.stvers = 0 # does not exist in some AIPS versions except: pass stars.intext = './starsfile' stdout = sys.stdout; sys.stdout = open(logfiledir+aipsname+'.log','a') stars.go() sys.stdout.close(); sys.stdout = stdout
def write_fits(outname): fittp = AIPSTask("fittp") # Write the last Entry in the catalog to disk fittp.indisk = DISK_ID last = cat.last_entry() fittp.inname = last.name fittp.inclass = last.klass fittp.inseq = last.seq if os.path.exists(outname): os.remove(outname) print "Removed existing file to make room for new one :", outname fittp.dataout = "PWD:" + outname fittp.go()
def load_into_aips(myfiles): """Load files into AIPS with UVLOD task.""" uvlod = AIPSTask('uvlod') uvlod.outdisk = DISK_ID # write all input data to a select disk uvlod.userno = AIPS.userno first_file = True # to help determine center freq to use for this_file in myfiles: # input all AIPS single dish FITS files print 'Adding {0} to AIPS.'.format(this_file) uvlod.datain = 'PWD:' + this_file uvlod.go() # get the center frequency of the sdf file that was just loaded last = cat.last_entry() spectra = cat.get_uv(last) center_freq = spectra.header.crval[2] # if this is the first file loaded, look for # the same frequency in the next ones if first_file: expected_freq = center_freq first_file = False # if frequency of sdf file just loaded and 1st file differ by # more than 100 kHz, do not use the current file if abs(expected_freq - center_freq) > 1e5: print 'Frequencies differ: {0} != {1}'.format(center_freq, expected_freq) print ' Rejecting {0}'.format(this_file) spectra.zap()
def pclcal (aipsname,indisk,inver,logfiledir='./'): uvdata = AIPSUVData (aipsname,'FITS',indisk,1) clcal = AIPSTask ('clcal') clcal.indata = uvdata clcal.inver = inver clcal.snver = inver stdout = sys.stdout; sys.stdout = open(logfiledir+aipsname+'.log','a') clcal.go() sys.stdout.close(); sys.stdout = stdout
def runlwpla(indata, outfile): plver=0 outfile = re.sub(r"\s+", '-', outfile) for tab in indata.tables : if 'PL' in tab[1] : plver = plver + 1 if os.path.exists(outfile) : os.remove(outfile) lwpla = AIPSTask('LWPLA') lwpla.indata = indata lwpla.plver = 1 lwpla.inver = plver lwpla.outfile = outfile lwpla.msgkill = -10 lwpla.go() # Remove PL tables indata.zap_table('PL', -1)
def runuvsrt(datafile, inname, indisk, thisdir): uvsrt = AIPSTask('UVSRT') klass = datafile.klass uvsrt.indata = datafile uvsrt.outdata = AIPSUVData(datafile.name,'UVSRT',indisk,datafile.seq) uvsrt.sort = 'TB' uvsrt.go() datafile.zap() datafile = AIPSUVData(inname,'UVSRT',indisk,thisdir) datafile.rename(inname,klass,thisdir)
def runtasav(uvdata, fittpdir, fittpfile, indisk): # Backup the FG tables after flagging tasav = AIPSTask('TASAV') tasavfil = AIPSUVData(uvdata.name, 'TASAV', indisk, uvdata.seq) tasav.indata = uvdata tasav.outdata = tasavfil tasav.outseq = uvdata.seq print "Saving tables for ", uvdata.name, uvdata.klass, uvdata.seq tasav.go() runfittp(tasavfil, fittpdir, fittpfile) tasavfil.zap()
def psplit (aipsname,source,indisk,logfiledir='./'): uvdata = AIPSUVData (aipsname,'FITS',indisk,1) split = AIPSTask ('split') split.indata = uvdata split.outclass = 'SPLIT' split.docalib = 1 stdout = sys.stdout; sys.stdout = open(logfiledir+aipsname+'.log','a') split.go() sys.stdout.close(); sys.stdout = stdout uvdata = AIPSUVData(source,'SPLIT',indisk,1) uvdata.rename(aipsname,'SPLIT',1)
def load_into_aips(myfiles): """Load files into AIPS with UVLOD task.""" # mandl = AIPSTask('mandl') # mandl.outdisk = DISK_ID # mandl.go() print_header("Loading data into AIPS") uvlod = AIPSTask('uvlod') uvlod.outdisk = DISK_ID # write all input data to a select disk uvlod.userno = AIPS.userno first_file = True # to help determine center freq to use for this_file in myfiles: # input all AIPS single dish FITS files if not os.path.exists(this_file): print 'WARNING: can not find file: {0}'.format(this_file) continue print 'Adding {0} to AIPS.'.format(this_file) # AIPS has problems with long filenames so we create a symlink to a short filename if os.path.exists(tmpfn): os.unlink(tmpfn) os.symlink(this_file, tmpfn) uvlod.datain = 'PWD:' + tmpfn uvlod.go() os.unlink(tmpfn) # remove the temporary symlink # get the center frequency of the sdf file that was just loaded last = cat.last_entry() spectra = cat.get_uv(last) center_freq = spectra.header.crval[2] # if this is the first file loaded, look for # the same frequency in the next ones if first_file: expected_freq = center_freq first_file = False # if frequency of sdf file just loaded and 1st file differ by # more than 100 kHz, do not use the current file if abs(expected_freq - center_freq) > 1e5: print 'Frequencies differ: {0} != {1}'.format(center_freq, expected_freq) print ' Rejecting {0}'.format(this_file) spectra.zap()
def run_dbcon(entryA, entryB): """Combine the data in AIPS with the DBCON task""" dbcon = AIPSTask('dbcon') # always do firs dbcon.indisk = dbcon.outdisk = dbcon.in2disk = DISK_ID dbcon.userno = AIPS.userno file1 = cat.get_entry(entryA) dbcon.inname = file1.name dbcon.inclass = file1.klass dbcon.inseq = file1.seq file2 = cat.get_entry(entryB) dbcon.in2name = file2.name dbcon.in2class = file2.klass dbcon.in2seq = file2.seq dbcon.reweight[1] = 0 dbcon.reweight[2] = 0 print 'combining 1: ', dbcon.inname, dbcon.inclass, dbcon.inseq print 'combining 2: ', dbcon.in2name, dbcon.in2class, dbcon.in2seq dbcon.go()
# 'Flags_1021+6803.fits', # 'Flags_1022+6806.fits', # 'Flags_1331+305.fits', # 'Flags_1020+6806.fits', # 'Flags_1021+6809.fits', # 'Flags_1022+6812.fits', # 'Flags_1407+284.fits'] filelist = ['Flags_1022+6749.fits'] # 'Flags_1331+305.fits', # 'Flags_1407+284.fits'] flag_dir = '/scratch/nas_mberc2/SuperCLASS/Data/eMERLIN/2C_20150720/flags/' fitld = AIPSTask('FITLD') fitld.outdisk = dsk tacop = AIPSTask('TACOP') uvcop = AIPSTask('UVCOP') clip = AIPSTask('CLIP') #move = AIPSTask('MOVE') for f in filelist: src = f.split('_')[-1].split('.')[0] # fitld.datain = flag_dir+f # outdata = AIPSUVData(src,'FG_TAB',dsk,1)
from AIPSTask import AIPSTask, AIPSList from AIPSData import * from AIPSData import AIPSUVData, AIPSImage from Wizardry.AIPSData import AIPSUVData as WizAIPSUVData from Wizardry.AIPSData import AIPSImage as WizAIPSImage import sys import os import math AIPS.userno=int(sys.argv[1]) # retrieve AIPS pipeline user number myfiles = sys.argv[2:] # make a list of input files mydisk=2 # choose a good default work disk AIPSCat().zap() # empty the catalog uvlod=AIPSTask('uvlod') # Create structures for AIPS tasks sdgrd=AIPSTask('sdgrd') fittp=AIPSTask('fittp') dbcon=AIPSTask('dbcon') trans=AIPSTask('trans') imlin=AIPSTask('imlin') avspc=AIPSTask('avspc') subim=AIPSTask('subim') sqash=AIPSTask('sqash') for thisFile in myfiles: # input all AIPS single dish FITS files print thisFile uvlod.datain='PWD:'+thisFile print uvlod.datain uvlod.outdisk=mydisk uvlod.go()
restFreqMHz = float(sys.argv[3]) # rest Frequency (MHz) velocityKmS = float(sys.argv[4]) # velocity (km/s) velWidthKmS = float(sys.argv[5]) # velocity Full Width (km/s) mydisk=2 defaultName = 'Pipeline' #Enforce name > 5 characters if len(outName) < 6: outName = defaultName[0:(6-len(outName))] + outName print 'Outname : ',outName print 'RestFreq: ',restFreqMHz, ' (MHz)' print 'Velocity: ',velocityKmS,' (km/s)' print 'VelWidth: ',velWidthKmS,' (km/s)' fittp=AIPSTask('fittp') momnt=AIPSTask('momnt') subim=AIPSTask('subim') image = AIPSImage(AIPSCat()[mydisk][-1].name, 'IMLIN', mydisk, 1) # now read parameters passed inside the data header nChan = round(image.header.naxis[0]) refChan = image.header.crpix[0] nuRef = image.header.crval[0] dNu = image.header.cdelt[0] print nChan, refChan, nuRef, dNu #set rest frequency to select out the line restFreq = restFreqMHz * 1.e6
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
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()
# 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() # Wait a bit to make sure the address used by the AIPS TV can be # reused again. time.sleep(30) try: tv.start()
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))