Ejemplo n.º 1
0
def FitsImageNTuple( file, resample=2 ):
    #
    # open the image file
    #
    image = pyfits.open(file)
    #
    # The primary header contains the coordinate data
    #
    prihdr = image[0].header
    #
    # build the axis objects and arrays
    #
    xaxis = FitsAxis( "x-axis",
                      keywordVal(prihdr, 'crval1', 0),
                      keywordVal(prihdr, 'cdelt1'),
                      keywordVal(prihdr, 'naxis1'),
                      ctype = keywordVal(prihdr, 'ctype1', 'x'),
                      crpix = keywordVal(prihdr, 'crpix1') )
    yaxis = FitsAxis( "y-axis",
                      keywordVal(prihdr, 'crval2', 0),
                      keywordVal(prihdr, 'cdelt2'),
                      keywordVal(prihdr, 'naxis2'),
                      ctype = keywordVal(prihdr, 'ctype2', 'y'),
                      crpix = keywordVal(prihdr, 'crpix2') )
    xx = xaxis.array()
    yy = yaxis.array()
    #
    # create the image NTuple and register it with HippoDraw
    #
    nt = hippo.NTuple()
    ntc = hippo.NTupleController.instance()
    ntc.registerNTuple(nt)
    #
    x = []
    y = []
    z = []
    for i in range (0, xaxis.naxis, resample):
        for j in range (0, yaxis.naxis, resample):
            x.append(xx[i])
            y.append(yy[j])
            z.append(image[0].data[j][i])
    nt.addColumn(xaxis.ctype, x)
    nt.addColumn(yaxis.ctype, y)
    #
    # use a place-holder name for now
    #
    nt.addColumn("Z values", z)  
    return nt
Ejemplo n.º 2
0
def FitsImageNTuple(file, resample=2):
    #
    # open the image file
    #
    image = pyfits.open(file)
    #
    # The primary header contains the coordinate data
    #
    prihdr = image[0].header
    #
    # build the axis objects and arrays
    #
    xaxis = FitsAxis("x-axis",
                     keywordVal(prihdr, 'crval1', 0),
                     keywordVal(prihdr, 'cdelt1'),
                     keywordVal(prihdr, 'naxis1'),
                     ctype=keywordVal(prihdr, 'ctype1', 'x'),
                     crpix=keywordVal(prihdr, 'crpix1'))
    yaxis = FitsAxis("y-axis",
                     keywordVal(prihdr, 'crval2', 0),
                     keywordVal(prihdr, 'cdelt2'),
                     keywordVal(prihdr, 'naxis2'),
                     ctype=keywordVal(prihdr, 'ctype2', 'y'),
                     crpix=keywordVal(prihdr, 'crpix2'))
    xx = xaxis.array()
    yy = yaxis.array()
    #
    # create the image NTuple and register it with HippoDraw
    #
    nt = hippo.NTuple()
    ntc = hippo.NTupleController.instance()
    ntc.registerNTuple(nt)
    #
    x = []
    y = []
    z = []
    for i in range(0, xaxis.naxis, resample):
        for j in range(0, yaxis.naxis, resample):
            x.append(xx[i])
            y.append(yy[j])
            z.append(image[0].data[j][i])
    nt.addColumn(xaxis.ctype, x)
    nt.addColumn(yaxis.ctype, y)
    #
    # use a place-holder name for now
    #
    nt.addColumn("Z values", z)
    return nt
Ejemplo n.º 3
0
    def setAxis(self, axisObj, naxis):
        axisObj.updateFitsHeader(self.hdu.header, naxis)
        self.axes[naxis] = axisObj

    def writeto(self, filename):
        os.system("rm -f " + filename)
        self.fitsobj = pyfits.HDUList()
        self.fitsobj.append(self.hdu)
        self.fitsobj.writeto(filename)


if __name__ == "__main__":
    print "FitsAxis class tests: "
    fitsobj = pyfits.HDUList()
    hdu = pyfits.PrimaryHDU()
    x = FitsAxis("x-axis", 0., 0.2, 10)
    y = FitsAxis("y-axis", 0., 0.1, 20)
    hdu.data = numarray.zeros((y.naxis, x.naxis))  # note the ordering
    x.updateFitsHeader(hdu.header, 1)
    y.updateFitsHeader(hdu.header, 2)
    fitsobj.append(hdu)
    os.system("rm -f test.fits")
    fitsobj.writeto('test.fits')
    print "FitsAxis class tests completed.\n"

    print "FitsImageArray class tests:"
    x = FitsAxis("x-axis", 0., 0.2, 5)
    y = FitsAxis("y-axis", 0., 0.1, 10)
    array1 = numarray.ones((y.naxis, x.naxis))
    z = {}
    z[1] = FitsImageArray(array1)
Ejemplo n.º 4
0
    def setAxis(self, axisObj, naxis):
        axisObj.updateFitsHeader(self.hdu.header, naxis)
        self.axes[naxis] = axisObj

    def writeto(self, filename):
        os.system("rm -f " + filename)
        self.fitsobj = pyfits.HDUList()
        self.fitsobj.append(self.hdu)
        self.fitsobj.writeto(filename)


if __name__ == "__main__":
    print "FitsAxis class tests: "
    fitsobj = pyfits.HDUList()
    hdu = pyfits.PrimaryHDU()
    x = FitsAxis("x-axis", 0.0, 0.2, 10)
    y = FitsAxis("y-axis", 0.0, 0.1, 20)
    hdu.data = numarray.zeros((y.naxis, x.naxis))  # note the ordering
    x.updateFitsHeader(hdu.header, 1)
    y.updateFitsHeader(hdu.header, 2)
    fitsobj.append(hdu)
    os.system("rm -f test.fits")
    fitsobj.writeto("test.fits")
    print "FitsAxis class tests completed.\n"

    print "FitsImageArray class tests:"
    x = FitsAxis("x-axis", 0.0, 0.2, 5)
    y = FitsAxis("y-axis", 0.0, 0.1, 10)
    array1 = numarray.ones((y.naxis, x.naxis))
    z = {}
    z[1] = FitsImageArray(array1)