def dobin(image,offset,bin,unit): """Combine all steps for reading a fits image and binning radially""" junk = nlclib.createtempname() # list of pixel values with distances in arcsecs outdata = nlclib.createtempname() # binned data # read fits header to get crpix and cdelt crpix1 = crpix2 = -1 cdelt1 = cdelt2 = -1 header = iraf.imheader(image,Stdout=1) for line in header: if re.match(r'^CRPIX1',line): crpix1 = float(line.split()[2]) elif re.match(r'^CRPIX2',line): crpix2 = float(line.split()[2]) elif re.match(r'^CDELT1',line): cdelt1 = float(line.split()[2]) elif re.match(r'^CDELT2',line): cdelt2 = float(line.split()[2]) if crpix1 == -1 or crpix2 == -1: nlclib.error("Couldn't read crpix values!") if cdelt1 == -1 or cdelt2 == -1: nlclib.error("Couldn't read cdelt values!") # Add in offsets fac = abs(cdelt1)*3600 # convert pixel distances to arcsecs crpix1 = crpix1 - offset[0]/fac crpix2 = crpix2 + offset[1]/fac # figure out binning if unit == 'step': count = int((bin[1] - bin[0])/bin[2]) elif unit == 'nbin': count = bin[2] if count < 0: nlclib.error('Number of bins is negative!') # get pixel values fp = open(junk,'w') x = iraf.listpixels(image,Stdout=1) for line in x: t = map(float,line.split()) dist = fac*math.sqrt((t[0] - crpix1)**2 + (t[1] - crpix2)**2) fp.write('%f %f\n' %(dist,t[3])) fp.close() # bin data cmd = 'dobin in=%s bin=%f:%f:%d > %s' %(junk,bin[0],bin[1],count,outdata) os.system(cmd) nlclib.remove(junk) return outdata
def apply(self): """Action to take when user clicks on 'Show' button""" global _circsize,_circlecolor _circsize = self.size.get() _circlecolor = self.color.get() os.system('xpaset -p %s regions format ds9' %self.window) blah = nlclib.createtempname() try: fp = open(blah,'w') ds9.makeRegion(fp,_all.ra,_all.dec,self.color.get(),float(self.size.get()), self.number.get()) fp.close() except IOError, value: if "Permission denied" in value: nlclib.error('You do not have write permissions for %s' %os.getcwd()) else: nlclib.error('Unknown problem with opening temp. region file!')
spec = """in = ??? # Input polarization file fits = ??? # FITS image out = ??? # Output file ext = 0 # Extension number cd = False # Set to True to use cd_matrix instead of cdelt""" arg = ReadCmd(spec,__doc__) infile = arg.getstr('in',exist=True) fits = arg.getstr('fits',exist=True) outfile= arg.getstr('out',exist=False) ext = arg.getint('ext') cdFlag = arg.getstr('cd') import nlclib blah = nlclib.createtempname() # new file made by rotatevector.py # get path of this script so we can call rotatevector.py in the same dir path,junk = os.path.split(os.path.abspath(sys.argv[0])) os.system('%s/rotatevector.py in=%s fits=%s out=%s ext=%d cd=%s' %(path, infile,fits,blah,ext,cdFlag)) data1 = nlclib.readdata(infile) data2 = nlclib.readdata(blah,dtype=float) if len(data1) != len(data2): arg.error('Problem rotating vectors!') fp = open(outfile,'w') fp.write('# x y Pol dPol Angle dAngle H dH Filename\n') fp.write('# (pix) (pix) (%) (%) (deg) (deg) (mag) (mag) (string)\n')