def imgseq (inna,incl,indisk,inseq):
    uvdata = AIPSUVData (inna,incl,indisk,inseq)
    for i in AIPSCat()[1]:
        if i['name']==inna and i['klass']=='IMGSEQ':
            AIPSImage(inna,'IMGSEQ',indisk,i['seq']).zap()
        if i['name']==inna and i['klass']=='ICL001':
            AIPSImage(inna,'ICL001',indisk,i['seq']).zap()
    imagr=AIPSTask('imagr')
    imagr.indata = uvdata
    imagr.cellsize[1:] = [0.2,0.2]
    imagr.imsize[1:] = [1024,1024]
    imagr.uvwtfn = 'NA'
    imagr.uvrange[1:] = [5.0,100000.0]
    imagr.source[1] = 'BEAM_1'
    imagr.outname = inna
    imagr.niter = 200
    imagr.nchav = 54
    uvtap = [400.0,200.0,100.0,50.0]
    beam  = [0.5,0.9,1.8,5.0]
    for i in range(4):
        imagr.uvtaper[1:] = [uvtap[i],uvtap[i]]
        imagr.bmaj,imagr.bmin = beam[i],beam[i]
        imagr.go()
        AIPSImage(inna,'IBM001',indisk,1).zap()
        AIPSImage(inna,'ICL001',indisk,1).rename(inna,'IMGSEQ',indisk,0)
Exemple #2
0
def zapexisting(inna, incl, indisk=1):
    for i in AIPSCat()[indisk]:
        if i['name'] == inna and i['klass'] == incl:
            if i['type'] == 'MA':
                AIPSImage(inna, incl, indisk, i['seq']).clrstat()
                AIPSImage(inna, incl, indisk, i['seq']).zap()
            else:
                AIPSUVData(inna, incl, indisk, i['seq']).clrstat()
                AIPSUVData(inna, incl, indisk, i['seq']).zap()
def get_fits(no):
    seq = 1
    if no<1000:
        n = str(no)
        n = n.zfill(3)
        imtype = 'IIM'+n
    else:
        imtype = 'II'+str(no)
    dat = AIPSImage('J0528+2200',imtype,1,seq)
    if not dat.exists():
        print imtype+' failed!!!!'
    fittp = AIPSTask('FITTP')
    fittp.indata = dat
    fittp.dataout = '/jop87_2/scratch/huang/rp024c/grid_trial/p0beam/beam'+str(no)+'.fits'
    fittp.go()
def self_calibration(uvdata, source_no, RA_shift, Dec_shift, solints, sc_type, pols, imsize, niter,refant):
	nchan = uvdata.header.naxis[2]
	sutable = uvdata.table('SU',1)
	sourceID = str(sutable[0].source)
	for i in range(len(solints)):
		print('Self calibration iteration %d' % i)
		for j in range(len(pols)):
			print('Iteration %d: Imaging source number %d' % (i,source_no))
			imagr = AIPSTask('IMAGR')
			pol_data = AIPSUVData(uvdata.name,pols[j],indisk,uvdata.seq)
			print pol_data.klass
			print pols[j]
			imagr.indata = pol_data
			imagr.sources[1] = sourceID
			#imagr.cellsize = AIPSList([findmaxb(uvdata)[0],findmaxb(uvdata)[1]])
			imagr.cellsize = AIPSList([0.2,0.2])
			imagr.imsize = AIPSList(imsize)
			imagr.docalib = 2
			imagr.gainuse = i+1
			imagr.stokes = pols[j]
			imagr.rashift[1] = RA_shift
			imagr.decshift[1] = Dec_shift
			imagr.niter = niter
			imagr.nchav = nchan
			imagr.outname = 'S%s_SC%s' % (source_no,str(i+1))
			imagr.outdisk = indisk
			imagr.go()

			image = AIPSImage('S%s_SC%s' % (source_no,str(i+1)),'%sCL001'%pols[j][0],indisk,1)

			print('Iteration %d: Making calibrations soln w/ solint=%.1f min and %s type' % (i,solints[i],sc_type[i]))
			calib = AIPSTask('CALIB')
			calib.indata = pol_data
			calib.calsour[1] = sourceID
			calib.docalib = 2
			calib.in2data = image
			calib.refant = refant
			calib.solint = solints[i]
			calib.aparm[1:] = 3, 0, 0, 0, 0, 0, 3, 0
			calib.ncomp[1] = -1000000
			calib.soltype = 'L1'
			calib.solmode = sc_type[i]
			calib.snver = i+1
			calib.go()

		print('Iteration %d: Applying SN table %d' % (i,i))
		clcal = AIPSTask('CLCAL')
		clcal.indata = pol_data
		clcal.calsour[1] = sourceID
		clcal.sources[1] = sourceID
		clcal.opcode = 'CALP'
		clcal.interpol = 'AMBG'
		clcal.snver = i+1
		clcal.invers = i+1
		clcal.gainver = i+1
		clcal.gainuse = i+2
		clcal.cutoff = 60
		clcal.dobtween = 0
		clcal.refant = refant
		clcal.go()
Exemple #5
0
def addwenss(aipsname,
             indisk,
             ra,
             dec,
             maxoff,
             pmin,
             pmax,
             w_max=1000.,
             incl='IMAP'):
    if have_astLib:
        wenss = np.load('wenss2000.npy')
        wenss = wenss[wenss[:, 2] < 2]  # only single or centre of multiple
        wenss = wenss[wenss[:, 3] > w_max]  # only sources >w_max mJy
        a = correlate(np.array([[ra, dec]]), 0, 1, wenss, 0, 1, maxoff)
        fo = open('starsfile', 'w')
        for i in a:
            idx = int(i[1])
            sra = astCoords.decimal2hms(wenss[idx, 0], ' ')
            sdec = astCoords.decimal2dms(wenss[idx, 1], ' ')
            fo.write('%s %s\n' % (sra, sdec))
        fo.close()
        stars(aipsname,
              incl,
              indisk,
              intext='./starsfile',
              logfiledir=logfiledir)
    greys(aipsname, incl, indisk, pmin, pmax, 5, 1, logfiledir=logfiledir)
    lwpla(aipsname,
          incl,
          indisk,
          './' + aipsname + '_plot.ps',
          logfiledir=logfiledir)
    AIPSImage(aipsname, incl, indisk, 1).zap()
    os.system('rm starsfile')
Exemple #6
0
def fring_global(uvdata,cals=[],fgv=0,suba=0,refant=0,antennas=[],timer=[0,0,0,1],solint=4,solsub=0,solmin=0,aparm=[1,0,0,0,1,2,4.5,0,1,0],dparm=[1,400,400,0],snv=0,gainu=0,docal=1,search=[],echan=0,bchan=1,bpv=-1,doband=-1,dofit=[0],get2n=False,flux=0):
	fring = AIPSTask('fring')
	fring.indata = uvdata
	fring.flagver = fgv
	fring.calsour[1:] = cals
	fring.timerang[1:] = timer
	fring.solint = solint
	fring.solsub = solsub
	fring.solmin = solmin
	fring.subarray = suba
	fring.antennas[1:] = antennas
	fring.dofit[1:] = dofit
	fring.refant = refant
	fring.gainuse = gainu
	fring.snver = snv
	fring.aparm[1:] = aparm
	fring.dparm[1:] = dparm
	fring.docalib = docal
	fring.doband = doband
	fring.bpver = bpv
	fring.search[1:] = search
	fring.bchan = bchan
	fring.echan = echan
	if get2n:
	#	in2data=getndata(get2n[0],get2n[1])
		fring.in2data=AIPSImage(*get2n)
		fring.flux=flux
	fring.inputs()
	HF.print_inp_to_log(fring,'FRING')
	fring()
Exemple #7
0
def aipszap(aipsname, aipsclass, indisk=1):
    pca = AIPSCat()
    for j in pca[indisk]:
        if j['name'] == aipsname and j['klass'] == aipsclass:
            if j['type'] == 'UV':
                data = AIPSUVData(aipsname, aipsclass, indisk, j['seq'])
            else:
                data = AIPSImage(aipsname, aipsclass, indisk, j['seq'])
            data.zap()
Exemple #8
0
def douvcon (antfile,freq,dec,hastart,haend,tint,chwid,nchan,outname,\
             in2name='ZEROS',in2class='FITS',indisk=1,cmodel='CC',phserr=0.0,\
             amperr=0.0,cboth=1.0,noisemult=0.0):
    uvcon = AIPSTask('uvcon')
    uvcon.infile = antfile if antfile[0] in './' else './' + antfile
    uvcon.in2name = in2name
    uvcon.in2class = in2class
    uvcon.in2disk = indisk
    uvcon.cmodel = cmodel
    uvcon.outname = outname
    uvcon.aparm[1:] = [
        freq, 0.0, dec, hastart, haend, 0.0, tint, chwid, nchan, 0.0
    ]
    uvcon.bparm[1:] = [
        noisemult, 0.0, -1.0 * phserr, amperr, cboth, 0.0, 0.0, 0.0, 0.0, 0.0
    ]
    save_stdout = sys.stdout
    sys.stdout = open('uvcon.log', 'a')
    uvcon.inp()
    sys.stdout = save_stdout
    uvcon.go()
    multi = AIPSTask('multi')
    multi.inname = outname
    multi.inclass = 'UVCON'
    multi.indisk = indisk
    multi.outclass = 'MULTI'
    multi.outname = outname
    multi.outdisk = indisk
    multi.go()
    # find the seqno of the file we just created
    uvcon_file_seq = findexisting(outname, 'MULTI')
    is_sutable = findexisting('sutable', 'fits')
    # load the source table if it's not on disk
    if not is_sutable:
        fitld = AIPSTask('fitld')
        fitld.datain = './sutable.fits'
        fitld.outdisk = indisk
        fitld.outname = 'sutable'
        fitld.outclass = 'fits'
        fitld.go()
    # and copy it to the uv data file we just created
    tacop = AIPSTask('tacop')
    tacop.inname = 'sutable'
    tacop.inclass = 'fits'
    tacop.indisk = indisk
    tacop.outname = outname
    tacop.outclass = 'MULTI'
    tacop.outseq = uvcon_file_seq
    tacop.outdisk = indisk
    tacop.inext = 'SU'
    tacop.go()
    # get a list of the antennas from the uv data file
    ants = np.array([])
    f = open(antfile)
    flines = 0
    for line in f:
        flines += 1
        if '#' in line:
            thisant = line.split('#')[1].lstrip().rstrip()
            ants = np.append(ants, thisant.split()[0])
    f.close()
    AIPSImage(in2name, in2class, indisk, 1).clrstat()
    if len(
            ants
    ) == flines - 3:  # if we have antennas for all lines except the first 3 header lines
        insertants(outname, ants, inclass='MULTI')
Exemple #9
0
from AIPS import AIPS
from AIPSTask import AIPSTask
from AIPSData import AIPSImage
from ObitTask import ObitTask

AIPS.userno = 3601

image = AIPSImage('MANDELBROT', 'MANDL', 1, 1)

mandl = AIPSTask('mandl')
mandl.outdata = image
mandl.imsize[1:] = [512, 512]
mandl.go()

try:
    template = ObitTask('Template')
    template.DataType = 'AIPS'
    template.inName = image.name
    template.inClass = image.klass
    template.inDisk = image.disk
    template.inSeq = image.seq
    template.go()
finally:
    image.zap()
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()
Exemple #11
0
if not options.calibrateonly:
    vlbatasks.applysntable(targetdata, snversion, "SELN", clversion, refant)
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)
Exemple #12
0
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:] = [64, 64]
mandl.go()

try:
    jmfit = AIPSTask('jmfit')
    jmfit.indata = image
    jmfit.ngauss = 4
    jmfit.domax[1:] = [1, 0, 0, 0]
    jmfit.go()
    print 'Peak values:', jmfit.fmax[1:]
    for fmax in jmfit.fmax[1:]:
        assert (fmax)
finally:
    image.zap()
            except:
                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
Exemple #14
0
    fitld.go()

    fitld = AIPSTask('FITLD')
    fitld.datain = (directory + str(i + 2) + '/S2_model.fits')
    fitld.ncount = 1
    fitld.doconcat = 0
    fitld.clint = 0
    fitld.wtthresh = 0
    fitld.outname = 'S2'
    fitld.outclass = 'IM'
    fitld.outdisk = indisk
    fitld.digicor = -1
    fitld.go()

    uvdata = AIPSUVData(AIPSuvdataname, 'UV', indisk, 1)
    image = AIPSImage('S1', 'IM', indisk, 1)
    uvsub = AIPSTask('UVSUB')
    uvsub.indata = uvdata
    uvsub.outdata = uvdata
    uvsub.in2data = image
    uvsub.ncomp[1] = -1000000
    uvsub.factor = 1.0
    uvsub.opcode = ''
    uvsub.go()

    uvdata = AIPSUVData(AIPSuvdataname, 'UV', indisk, 1)
    image = AIPSImage('S2', 'IM', indisk, 1)
    uvsub = AIPSTask('UVSUB')
    uvsub.indata = uvdata
    uvsub.in2data = image
    uvsub.ncomp[1] = -1000000
from AIPS import AIPS
from AIPSTask import AIPSTask
from AIPSData import AIPSImage
from ObitTask import ObitTask

AIPS.userno = 3601

image = AIPSImage('MANDELBROT', 'MANDL', 1, 1)

mandl = AIPSTask('mandl')
mandl.outdata = image
mandl.imsize[1:] = [ 512, 512 ]
mandl.go()

try:
    template = ObitTask('Template')
    template.DataType = 'AIPS'
    template.inName = image.name
    template.inClass = image.klass
    template.inDisk = image.disk
    template.inSeq = image.seq
    template.go()
finally:
    image.zap()
Exemple #16
0
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()
    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

Exemple #18
0
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:
    image.rename('APPLE')
    assert (image.exists())
    assert (AIPSImage('APPLE', 'MANDL', 1, 1).exists())
    assert (not AIPSImage('MANDELBROT', 'MANDL', 1, 1).exists())
    image.rename(seq=8)
    assert (image.exists())
    assert (image.seq == 8)
    image.rename(klass='APPLE', seq=99)
    assert (image.exists())
    image.rename(klass='PEAR', seq=0)
    assert (image.exists())
    assert (image.seq != 0)
    image.rename('MANDLEBROT', seq=1)
    assert (image.exists())
    try:
Exemple #19
0
def makeaipsimage(data):

    image = AIPSImage(data[0], data[1], data[2], data[3])
    return image
Exemple #20
0
                         timer=AF.scantime(uvdata, OP.st_scan[i]),
                         refant=OP.st_refant[i],
                         gainu=cl_hv,
                         plotname=OP.st_plotname[i])

if OP.global_fring:
    for clv in range(40, uvdata.table_highver('CL')):
        uvdata.zap_table('CL', clv)
    for snv in range(45, uvdata.table_highver('SN')):
        uvdata.zap_table('SN', snv)
    if OP.gf_scan:
        OP.gf_timer = []
        for i in OP.gf_scan:
            OP.gf_timer = AF.scantime(uvdata, i)
    if OP.get2n:
        imfile = AIPSImage(OP.cmap_name, 'CMAP', uvdata.disk, 1)
        if imfile.exists():
            image = [OP.cmap_name, 'CMAP', uvdata.disk, 1]
            logger.info('Using clean image')
    if OP.use_bp:
        cl_hv_af = AF.do_global_fring(uvdata,
                                      cals=OP.gf_cals,
                                      sources=OP.gf_sources,
                                      bpv=1,
                                      doband=2,
                                      timer=OP.gf_timer,
                                      dofit=OP.gf_dofit,
                                      antennas=OP.gf_antennas,
                                      aparm=OP.gf_aparm,
                                      dparm=OP.gf_dparm,
                                      refant=OP.gf_refant,
from Wizardry.AIPSData import AIPSImage as WizAIPSImage

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)
            fitld.datain = ('PWD:' + uvdataname)
            fitld.ncount = 1
            fitld.doconcat = 1
            fitld.clint = 0
            fitld.wtthresh = 0
            fitld.outdisk = 2
            fitld.digicor = -1
            fitld.go()
        if file.endswith(fileend):
            uvname.append(uvdataname[0:8])
    # makes a list of file prefixes to be used in multi self cal, all data is loaded.

    for i in range(len(uvname)):
        uvdata = AIPSUVData(uvname[i], 'SPLAT', 2,
                            1)  #name the uv file in AIPS
        imagedata = AIPSImage(uvname[i], 'IIM001', 2, 1)

        nchan = uvdata.header.naxis[2]
        imagr = AIPSTask('IMAGR')
        imagr.nchav = nchan  #use imagr to get a clean model!
        imagr.indata = uvdata
        imagr.outname = uvdata.name
        imagr.cellsize[1:] = findmaxb(uvdata)
        imagr.imsize[1:] = imsize
        imagr.nboxes = 1
        imagr.nfield = 1
        imagr.outdisk = 2
        imagr.uvwtfn = ''
        imagr.niter = niter
        imagr.go()
Exemple #23
0
for i in range(5):

	imagr = AIPSTask('IMAGR')
	imagr.indata = uvdata
	imagr.sources[1] = sourceID
	imagr.cellsize[1:] = findmaxb(uvdata)
	imagr.imsize[1:] = sourceimsize
	imagr.docalib = 2
	imagr.gainuse = i+1
	imagr.niter = 1000
	imagr.nchav = 64
	imagr.outname = 'SC'+str(i+1)
	imagr.outdisk = indisk
	imagr.go()

	image = AIPSImage('SC'+str(i+1),'ICL001',indisk,1)

	calib = AIPSTask('CALIB')
	calib.indata = uvdata
	calib.calsour[1] = sourceID
	calib.docalib = 2
	calib.in2data = image
	calib.refant = 15
	if i+1 == 1:
		calib.solint = 5
	if i+1 == 2:
		calib.solint = 2
	if i+1 == 3:
		calib.solint = 2
	if i+1 == 4:
		calib.solint = 1
Exemple #24
0
from Wizardry.AIPSData import AIPSImage as WizAIPSImage

import os
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.go()

assert (image.exists())

try:
    image = WizAIPSImage(image)
Exemple #25
0
def zapim(inna, incl, indisk, top, bottom):
    for i in range(top, bottom - 1, -1):
        try:
            im = AIPSImage(inna, incl, indisk, i).zap()
        except:
            pass
Exemple #26
0
from AIPSData import AIPSImage

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.msgkill = 2
fitld.go()

assert (image.exists())

try:
Exemple #27
0
import os
import signal
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)
from Wizardry.AIPSData import AIPSImage as WizAIPSImage

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)
Exemple #29
0
    # now image all the uvfiles, base the imaging size larger than each square
    pca = AIPSCat(indisk)
    print 'run widemaps'
    for fitsfil in pca[indisk]:
        if (target in fitsfil.name) and ('UV' in fitsfil.klass):  #
            uvdata = AIPSUVData(fitsfil.name, fitsfil.klass, indisk,
                                fitsfil.seq)
            #widemaps(uvdata,indisk,fovradius,target,noiter)
            widebandmaps(uvdata, indisk, fovradius, target, noiter)

    #'''
    #now use APCLN  added nwrigley 20141106
    pca = AIPSCat(indisk)
    for fitsfil in pca[indisk]:
        if (target in fitsfil.name) and ('IIM' in fitsfil.klass):
            imdata = AIPSImage(fitsfil.name, fitsfil.klass, indisk,
                               fitsfil.seq)
            apclean(imdata, target)
    #'''

    print 'run trimmer'
    # trim and flatten the images
    pca = AIPSCat(indisk)
    for fitsfil in pca[indisk]:
        if (target in fitsfil.name) and ('ICL' in fitsfil.klass):  #
            imdata = AIPSImage(fitsfil.name, fitsfil.klass, indisk,
                               fitsfil.seq)
            #flat(imdata,fovradius,target)
            trimmer(imdata, fovradius, target)

    print 'run flatn'
    runflatn(imdata, fovradius, target)
Exemple #30
0
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['inaxes'][0], header['inaxes'][1])
    tables = image.tables()
    print tables
finally:
    image.zap()
Exemple #31
0
    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))
    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
		nchan = uvdata.header.naxis[2]
		imagr = AIPSTask('IMAGR')
		imagr.nchav = nchan #use imagr to get a clean model!
		imagr.indata = uvdata
		imagr.outname = uvdata.name
		imagr.cellsize[1:] = findmaxb(uvdata)
		imagr.imsize[1:] = imsize,imsize
		imagr.uvwtfn='NA'
		imagr.nboxes = 1
		imagr.nfield = 1
		imagr.outdisk = indisk
		imagr.niter = niter
		imagr.go()

		imagedatacl = AIPSImage('A%s' % i,'ICL001',indisk,1)

		imean = AIPSTask('IMEAN')
		imean.indata = imagedatacl
		imean.indisk = indisk
		imean.doprint = 1
		imean.outtext = 'PWD:IMEAN_%s.txt' % UV_files[i]
		imean()

		uvsub = AIPSTask('UVSUB') #Divide visibilites by clean model!
		uvsub.indata = uvdata
		uvsub.nmaps = 1
		uvsub.in2data = imagedatacl
		uvsub.inver = 1
		uvsub.outdisk = indisk
		uvsub.ncomp[1] = -1000000
Exemple #34
0
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

cLightKmSec = 299792.458  # speed of light in Km/Sec

#These constants are particular to each source
Exemple #35
0
from AIPSData import AIPSImage, AIPSUVData

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()

fitld = AIPSTask('fitld')
fitld.datain = file
fitld.outdata = image
fitld.go()

try:
    print 'Stokes:', image.stokes
    assert (len(image.stokes) == 1)

    # Download a second 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)
Exemple #36
0
    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()
Exemple #37
0
import math
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)
import math
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)