Esempio n. 1
0
arg = ReadCmd(spec)
inFile  = arg.getstr('in',exist=True,type='file')
outFile = arg.getstr('out',exist=False)
expand  = arg.getbool('expand')
tmpext  = arg.getstr('ext')
rot     = arg.getstr('rot')
hist    = arg.getkeys(comment='IMROTATE.PY:',format=72,time=True).strip().split('\n')

import nlcastro
import pyfits
import scipy.interpolate
from numpy import nan,isnan,pi,arctan2,cos,sin,meshgrid,arange,ceil,floor
from numpy import amin,amax,where,isfinite,zeros,around

ext = nlcastro.findExt(inFile,tmpext)

header = pyfits.getheader(inFile,ext=ext)
if header['naxis'] != 2:
   arg.error('Can only rotate 2-d images!')
data   = pyfits.getdata(inFile,ext=ext)

angle = getAngle(rot,header)
data2 = doRotate(data,angle,expand)

if expand is True: # fix header so center is still at center of map
   naxis2,naxis1 = data2.shape
   header['naxis1'] = naxis1
   header['naxis2'] = naxis2
   header['crpix1'] = naxis1/2. + 0.5
   header['crpix2'] = naxis2/2. + 0.5
Esempio n. 2
0
arg = ReadCmd(spec,head=__doc__)
infiles = arg.getliststr('in',exist=True)
ext     = arg.getliststr('ext')
outfile = arg.getstr('out',exist=False)
hist    = arg.getkeys(comment='IMEXTRACT.PY:',format=72,time=True).strip().split('\n')

next = len(ext)
nfiles = len(infiles)

import pyfits
import nlcastro
from numpy import zeros

# do first file, need outside loop in case there is only one file in total
idx = nlcastro.findExt(infiles[0],ext)
header = [pyfits.getheader(infiles[0],idx[i]) for i in xrange(next)]

# compile list with names of extensions.  Read from first file
img = pyfits.open(infiles[0])
extname = [img[idx[i]].name for i in xrange(next)]
img.close()

data = []
for i in xrange(next):
   d = pyfits.getdata(infiles[0],idx[i])
   if i == 0:
      s1 = d.shape
   if nfiles == 1: # one file, so no cube
      data.append(d)
   else: # if multiple files, make a cube.  Each plane of cube is 1 file
Esempio n. 3
0
arg     = ReadCmd(spec)
inFile  = arg.getstr('in',exist=True)
inext   = arg.getstr('inext')
junk    = arg.getliststr('key')
outFile = arg.getstr('out',exist=True)
outext  = arg.getliststr('outext')
hist    = arg.getkeys(comment='CPHEAD.PY:',format=72,time=True).strip().split('\n')

import nlcastro
import pyfits

keylist = [a.lower() for a in junk]


img   = pyfits.open(inFile)
idx   = nlcastro.findExt(img,inext)
head1 = img[idx].header
img.close()

junk = [a.lower() for a in head1.keys()]
if keylist[0] != 'all':
   for key in keylist:
      if key not in junk:
         arg.error("Keyword '%s' not in '%s'" %(key,inFile))

img   = pyfits.open(outFile,'update')
# make sure all output extensions exist first
outidx = [nlcastro.findExt(img,out) for out in outext]

for idx in outidx:
   head2 = img[idx].header
Esempio n. 4
0
junk    = arg.getliststr('key')
value   = arg.getliststr('value',length=[1,len(junk)])
outfile = arg.getliststr('out',exist=False,length=len(infile))
histroot = arg.getkeys(comment='HEDIT.PY:',format=72,time=True).strip().split('\n')

keylist = [a.lower() for a in junk]
if len(value) == 1:
   value = len(junk)*value

import pyfits
import nlcastro

for inname,outname in zip(infile,outfile):
   print "%s -> %s" %(inname,outname)
   img = pyfits.open(inname)
   extnames = [nlcastro.findExt(inname,e) for e in ext]

   for e in extnames:
      head = img[e].header
      hist = histroot[:]

      for k,v in zip(keylist,value):
         if k == 'history':
            hist.append(v)
         elif k == 'comment':
            head.add_comment(v)
         elif k[0] == '-': # delete specified keyword
            del(head[k[1:]])
         else:
            try: # try to convert to float before updating header
               tmp = float(v)