Ejemplo n.º 1
0
 def writeAll(self,filename):
    """"Hook function for writing all data"""
    fp = nlclib.nlcopen(filename,'w')
    self.writeHeader(fp)
    for line in all.lines:
       fp.write(line)
    fp.close()
    self.writeFlag = True
Ejemplo n.º 2
0
 def read(self,filename):
    """First steps for reading, calls self.processLine()"""
    fp = nlclib.nlcopen(filename,'r')
    for line in fp:
       if line[0] not in self.comments:
          self.lines.append(line)
          self.num += 1
          tmp = line.split()
          self.processLine(tmp)
    fp.close()
    self.active = [1]*self.num
Ejemplo n.º 3
0
#!/usr/bin/env python

import re,sys
import nlclib

if len(sys.argv) > 1:
   fp = nlclib.nlcopen(sys.argv[1],'r')
   data = fp.readlines()
   fp.close()
else:
   data = sys.stdin.readlines()
   
data.sort(nlclib.smart_sort)

for line in data:
   sys.stdout.write(line)
Ejemplo n.º 4
0
data = fp[ext].data
header = fp[ext].header
fp.close()

shape = data.shape
if len(shape) == 3:
   nrows = shape[1]
   ncols = shape[2]
   data = data[0,:,:].flatten() # only read first plane of cube
elif len(shape) == 2:
   nrows = shape[0]
   ncols = shape[1]
   data = data.flatten()
else:
   nlclib.error("Input file must have 2-D or 3-D data!")

points = meshgrid(arange(ncols),arange(nrows))
x,y = (points[0].flatten() + 1, points[1].flatten() + 1)

fp = nlclib.nlcopen(outFile,'w')

if wcsFlag:
   wcs = pywcs.WCS(header)
   ra,dec = wcs.wcs_pix2sky(x,y,1)
   fp.write("# RA  DEC  data\n")
   savetxt(fp,column_stack((ra,dec,data)),fmt='%lf  %lf  %lf')
else:
   fp.write("#x y data\n")
   savetxt(fp,column_stack((x,y,data)),fmt='%d  %d  %lf')
fp.close()