def pbcorr(inimagedata, outimagedata, pbparm, inverse=0): pbaipsparm = AIPSList(pbparm) inimage = makeaipsimage(inimagedata) outimage = makeaipsimage(outimagedata) pbcor = AIPSTask('pbcor') pbcor.outdata = outimage pbcor.indata = inimage pbcor.doinvers = inverse pbcor.pbparm = pbaipsparm pbcor.go() return (outimage)
def immath(inimagedata, outimagedata, opcode, cparm): inimage = makeaipsimage(inimagedata) outimage = makeaipsimage(outimagedata) aipsmaths = AIPSTask('maths') aipsmaths.indata = inimage aipsmaths.outdata = outimage aipsmaths.opcode = opcode aipsmaths.cparm = AIPSList(cparm) aipsmaths.go() return outimage
def getplane(imagedata, plane=1): imagedata2 = imagedata[:] imagedata2[3] = imagedata2[3] + 1 image = makeaipsimage(imagedata) image2 = makeaipsimage(imagedata2) subim = AIPSTask('subim') subim.indata = image subim.outdata = image2 subim.blc = AIPSList([0, 0, plane]) subim.trc = AIPSList([0, 0, plane]) subim.go() image.zap() return imagedata2
def imcombine(in1imagedata, in2imagedata, outimagedata, opcode, aparm, align=1, bparm=[0, 0, 0, 0, 0, 0]): in1image = makeaipsimage(in1imagedata) in2image = makeaipsimage(in2imagedata) outimage = makeaipsimage(outimagedata) comb = AIPSTask('comb') comb.indata = in1image comb.in2data = in2image comb.outdata = outimage comb.doalign = align comb.blc = AIPSList([0, 0]) comb.trc = AIPSList([0, 0]) comb.opcode = opcode comb.aparm = AIPSList(aparm) comb.bparm = AIPSList(bparm) comb.go() return (outimage)
def rmsd(inimagedata, outimagedata, boxsize, opcode, xinc, yinc, scalr1=0, scalr2=0, scalr3=0, flux=0): inimage = makeaipsimage(inimagedata) outimage = makeaipsimage(outimagedata) rmsd = AIPSTask('rmsd') rmsd.indata = inimage rmsd.outdata = outimage rmsd.blc = AIPSList([0, 0]) rmsd.trc = AIPSList([0, 0]) rmsd.imsize = AIPSList(boxsize) rmsd.opcode = opcode rmsd.optype = '' rmsd.scalr1 = scalr1 rmsd.scalr2 = scalr2 rmsd.scalr3 = scalr3 rmsd.flux = flux rmsd.xinc = int(xinc) rmsd.yinc = int(yinc) rmsd.go() return outimage
def copyimage(imagedata1, imagedata2): image1 = makeaipsimage(imagedata1) image2 = makeaipsimage(imagedata2) copy = AIPSTask('subim') copy.indata = image1 copy.outdata = image2 copy.blc = AIPSList([0.0]) copy.trc = AIPSList([0, 0]) copy.xinc = 1 copy.yinc = 1 copy.opcode = '' copy.go()
def imsadrms(indata, inrmsimage, cutoff, outname='', uppercut=[], blc=[0, 0], trc=[0, 0], gain=0.3, icut=0.1, dowidth=1, maxwidth=5, resid=0, residdata=[]): task = AIPSTask('sad') inimage = makeaipsimage(indata) in2image = makeaipsimage(inrmsimage) task.indata = inimage task.in2data = in2image task.blc = AIPSList(blc) task.trc = AIPSList(trc) if len(uppercut) > 0: task.cparm = AIPSList(uppercut + [cutoff, 0]) else: task.cparm = AIPSList([cutoff, 0]) task.doresid = resid if resid > 0: residimage = makeaipsimage(residdata) task.outdata = residimage task.ngauss = 40000 task.icut = icut task.sort = 'RA' if outname == '': task.docrt = 0 task.fitout = '' else: task.docrt = 132 task.fitout = outname task.outvers = 0 task.doall = 1 if dowidth == 1: width = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]] else: width = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] task.dowidth = AIPSList(width) task.gain = gain task.dparm = AIPSList([cutoff, 0, 0.0, maxwidth, -1, 0, cutoff, 0, 2, 0]) task.prtlev = 0 task.pbparm = AIPSList([0, 0, 0, 0, 0, 0, 0]) task.go()
def getmean(inimagedata, blc, trc, tolerance=0.0001, maxiter=50): inimage = makeaipsimage(inimagedata) imean = AIPSTask('imean') imean.indata = inimage imean.blc = AIPSList(blc) imean.trc = AIPSList(trc) imean.doinvers = -1 imean.nboxes = 0 imean.pixrange = AIPSList([0, 0]) imean.functype = '' imean.pixavg = 0 imean.pixstd = 0 imean.docat = 0 imean.dotv = -1 imean.grchan = 0 imean.go() #Set the tolerance to be a fraction of current measured average. tolerance = fabs(imean.pixavg * tolerance) diff = tolerance + 1.0 count = 0 while diff > tolerance and count < maxiter: prevmean = imean.pixavg imean.go() diff = fabs(imean.pixavg - prevmean) count += 1 if count == maxiter: print 'No convergence in IMEAN after ' + str(maxiter) + ' iterations!' return fabs(imean.pixavg)
def addsource(xpix, ypix, amp, width, imagedata, zap=0): newimagedata = imagedata[:] newimagedata[3] += 1 image = makeaipsimage(imagedata) newimage = makeaipsimage(newimagedata) immod = AIPSTask('immod') immod.indata = image immod.outdata = newimage immod.opcode = 'GAUS' immod.ngaus = 1 immod.fmax = AIPSList([float(amp), 0]) immod.fpos = AIPSList([[float(xpix), float(ypix)]]) immod.fwidth = AIPSList([width]) immod.flux = 0 immod.factor = 1 immod.go() if zap == 1: image.zap() return (newimagedata)
def getknownflux(imagedata, maj, min, pa, x, y): image = makeaipsimage(imagedata) imhead = image.header() incrx = imhead['cdelt'][0] * 3600.0 incry = imhead['cdelt'][1] * 3600.0 if (abs(incrx) != abs(incry)): print "WARNING: incrx not = incry -> undefined behaviour of getflux!!!!!" majpix = abs(maj / incrx) minpix = abs(min / incrx) boxhalfsize = abs((maj / incrx) / 2.) + 3. imfit = AIPSTask('jmfit') imfit.indata = image imfit.blc = AIPSList([ int(numpy.floor(abs(x - (boxhalfsize + 1)))), int(numpy.floor(abs(y - (boxhalfsize + 1)))) ]) imfit.trc = AIPSList([ int(numpy.ceil(abs(x + (boxhalfsize + 1)))), int(numpy.ceil(abs(y + (boxhalfsize + 1)))) ]) imfit.ngauss = 1 imfit.ctype = AIPSList([1]) imfit.gmax = AIPSList([pixinterp(x, y, imagedata)]) imfit.gpos = AIPSList([[x, y]]) imfit.gwidth = AIPSList([[majpix, minpix, pa]]) imfit.domax = AIPSList([1]) imfit.dopos = AIPSList([[1, 1]]) # JMFIT always fails if the PA is held fixed- so allow it to vary. imfit.dowidth = AIPSList([[1, 1, 1]]) imfit.bwsmear = 0 imfit.radius = boxhalfsize * 100 imfit.niter = 2000 #imfit.docrt=1 imfit.fitout = '' imfit.dooutput = -1 imfit.offset = 0 imfit.domodel = -1 imfit.outvers = -1 imfit.pbparm = AIPSList([0]) try: imfit.go() flux = imfit.fmax[1] sizehi = imfit.fwidth[1][1] sizelo = imfit.fwidth[1][2] sizepa = imfit.fwidth[1][3] return flux, -1. * sizehi * incrx, sizelo * incry, sizepa except: print "JMFIT failed- try IMFIT!" imfit2 = AIPSTask('imfit') imfit2.indata = image imfit2.blc = AIPSList([ int(numpy.floor(abs(x - (boxhalfsize + 1)))), int(numpy.floor(abs(y - (boxhalfsize + 1)))) ]) imfit2.trc = AIPSList([ int(numpy.ceil(abs(x + (boxhalfsize + 1)))), int(numpy.ceil(abs(y + (boxhalfsize + 1)))) ]) imfit2.ngauss = 1 imfit2.ctype = AIPSList([1]) imfit2.gmax = AIPSList([0]) imfit2.gpos = AIPSList([[x, y]]) imfit2.gwidth = AIPSList([[majpix, minpix, pa]]) imfit2.domax = AIPSList([1]) imfit2.dopos = AIPSList([[0, 0]]) imfit2.dowidth = AIPSList([[0, 0, 1]]) imfit2.bwsmear = 0 imfit2.radius = boxhalfsize * 100 imfit2.niter = 2000 #imfit2.docrt=1 imfit2.fitout = '' imfit2.dooutput = -1 imfit2.offset = 0 imfit2.domodel = -1 imfit2.outvers = -1 imfit2.pbparm = AIPSList([0]) try: imfit2.go() flux = imfit2.fmax[1] except: print "IMFIT has failed as well!!!!! Returning Flux=0.0" flux = 0.0 return flux