コード例 #1
0
ファイル: findav.py プロジェクト: nlchap0/nlctools
   intrinsic['hk']  = arg.getlistfloat("hk")
   intrinsic['cov'] = arg.getfloat("cov")
   intrinsic['method'] =  arg.getstr("method",option=['jh','hk','nicer','rjce'])

   from numpy import loadtxt,savetxt,sqrt

   data = loadtxt(infile,dtype=str)
   d    = data[:,2:8].astype(float)
   if intrinsic['method'] == 'jh' or intrinsic['method'] == 'hk':
      Av,dAv = nice(intrinsic, d[:,0],d[:,1],d[:,2],d[:,3],d[:,4],d[:,5])
   elif intrinsic['method'] == 'nicer':
      Av,dAv = nicer(intrinsic,d[:,0],d[:,1],d[:,2],d[:,3],d[:,4],d[:,5])
   elif intrinsic['method'] == 'rjce':
      Av,dAv = rjce(intrinsic, d[:,0],d[:,1],d[:,2],d[:,3],d[:,4],d[:,5])
   else:
      arg.error('Invalid extinction method: %s' %intrinsic['method'])

   fp = open(outfile,'w')
   fp.write("#  ra         dec       J     dJ     H     dH     Ks    ")
   fp.write("dKs    Av          dAv\n")
   for i in xrange(data.shape[0]):
      fp.write("%10s " %data[i,0])
      fp.write("%10s " %data[i,1])
      fp.write("%6s "  %data[i,2])
      fp.write("%5s "  %data[i,3])
      fp.write("%6s "  %data[i,4])
      fp.write("%5s "  %data[i,5])
      fp.write("%6s "  %data[i,6])
      fp.write("%5s "  %data[i,7])
      fp.write("%11.4e" %Av[i])
      fp.write("%11.4e\n" %dAv[i])
コード例 #2
0
ファイル: imrotate.py プロジェクト: nlchap0/nlctools
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

# add history
for h in hist:
   header.add_history(h)
コード例 #3
0
ファイル: imsub.py プロジェクト: nlchap0/nlctools
import pyfits,pywcs
from numpy import where,nan
   
# open FITS image and read header
if inFile == '-':
   fp = sys.stdin
else:
   fp = pyfits.open(inFile)

header = fp[0].header

# read and interpret region keyword
tmp1 = region[0].split(':')
tmp2 = region[1].split(':')
if len(tmp1) != 2 or len(tmp2) != 2:
   arg.error('Specify region keyword as xmin:xmax,ymin:ymax')
try:
   xmin = int(tmp1[0])
except ValueError:
   if tmp1[0] == 'xmin':
      xmin = 1
try:
   xmax = int(tmp1[1])
except ValueError:
   if tmp1[1] == 'xmax':
      xmax = int(header['naxis1'])
   else:
      arg.error('Specify region keyword as xmin:xmax,ymin:ymax')
   
try:
   ymin = int(tmp2[0])
コード例 #4
0
ファイル: tabbin.py プロジェクト: nlchap0/nlctools
          xmin  = None # Min value for bins (defaults to data min)
          xmax  = None # Max value for bins (defaults to data max)
          nbin  = 10   # Number of bins"""
   
arg = ReadCmd(spec)
infile = arg.getstr("in",exist=True)
xcol   = arg.getint("xcol",min=1)
ycol   = arg.getint("ycol",min=1)
dxcol  = arg.getint("dxcol",min=1)
dycol  = arg.getint("dycol",min=1)
xmin   = arg.getfloat("xmin")
xmax   = arg.getfloat("xmax")
nbin   = arg.getint("nbin",min=1)

if xcol is None:
   arg.error("You must specify a column number for x!")
   
cols = []
for i in [xcol,ycol,dxcol,dycol]:
   if i is not None:
      cols.append(i-1)

errxFlag = True # set to false if no x errors
erryFlag = True # set to false if no y errors

# load data
data = loadtxt(infile,usecols=cols)
xcol = data[:,0]
n = data.shape[0]
if dycol is None or ycol is None:
   dycol = ones(n)
コード例 #5
0
ファイル: cphead.py プロジェクト: nlchap0/nlctools
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

   if keylist[0] != 'all':
      for key in keylist:
         head2.update(key,head1[key])
   else:
      for key in junk:
         head2.update(key,head1[key])
コード例 #6
0
ファイル: imextract.py プロジェクト: nlchap0/nlctools
   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
      tmp = zeros(tuple([nfiles] + list(s1)))
      tmp[0] = d
      data.append(tmp)

for i in xrange(1,nfiles):
   idx = nlcastro.findExt(infiles[i],ext)
   for j in xrange(next): # loop over extension indexes
      d2 = pyfits.getdata(infiles[i],idx[j])
      s2 = d2.shape
      if s1 != s2:
         arg.error('shape mis-match among input arrays!')
      data[j][i] = d2

tmphdu = []
tmphdu.append(pyfits.PrimaryHDU(data[0]))
tmphdu[0].header.extend(header[0].cards,update=True)

for i in xrange(1,next):
   tmphdu.append(pyfits.ImageHDU(data[i]))
   tmphdu[i].header.extend(header[i].cards,update=True)

if next == 1:
   hdu = tmphdu[0]
   if 'EXTEND' in hdu.header.keys():
      hdu.header.update('EXTEND',False)
   if 'XTENSION' in hdu.header.keys():
コード例 #7
0
ファイル: sky2xy.py プロジェクト: nlchap0/nlctools
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')

for l1,l2 in zip(data1,data2):
   fp.write('%8.3f  %8.3f  ' %(l2[0],l2[1])) # x,y from data2
   fp.write('%6s  %6s  ' %(l1[2],l1[3])) # pol,dpol from data1
   try:
      fp.write('%7.3f  %7s  ' %(l2[3],l1[5])) # angle from data2,dangle from data1
   except IndexError:
      fp.close()
      arg.error('Missing angle or delta angle for input file')
   try:
      fp.write('%7s  %7s  ' %(l1[6],l1[7])) # Hmag,dHmag from data1