Esempio n. 1
0
 def createFromHDU(hdu):
     
     header = hdu.header
     wcs = pywcs.WCS(header,relax=True)
     axes = copy.deepcopy(FITSAxis.create_axes(header))
     
     return SkyImage(wcs,axes,copy.deepcopy(hdu.data.astype(float).T))
Esempio n. 2
0
    def createFromHDU(hdu):
        
        header = pyfits.Header.fromstring(hdu.header.tostring())
#        header = hdu.header

        wcs = pywcs.WCS(header,naxis=[1,2])#,relax=True)
#        wcs1 = pywcs.WCS(header,naxis=[3])
        axes = copy.deepcopy(FITSAxis.create_axes(header))
        return SkyCube(wcs,axes,copy.deepcopy(hdu.data.astype(float).T))
Esempio n. 3
0
    def createWCS(ra,dec,roi_radius_deg,bin_size_deg=0.2,coordsys='cel'):
        nbin = np.ceil(2.0*roi_radius_deg/bin_size_deg)
        deg_to_pix = bin_size_deg
        wcs = pywcs.WCS(naxis=2)

        wcs.wcs.crpix = [nbin/2.+0.5, nbin/2.+0.5]
        wcs.wcs.cdelt = np.array([-deg_to_pix,deg_to_pix])
        wcs.wcs.crval = [ra, dec]
        
        if coordsys == 'cel': wcs.wcs.ctype = ["RA---AIT", "DEC--AIT"]
        else: wcs.wcs.ctype = ["GLON-AIT", "GLAT-AIT"]            
        wcs.wcs.equinox = 2000.0
        return wcs
Esempio n. 4
0
    def createFromFITS(fitsfile,ihdu=0):
        
        hdulist = pyfits.open(fitsfile)        
        header = hdulist[ihdu].header
        wcs = pywcs.WCS(header,naxis=[1,2],relax=True)

        if hdulist[1].name == 'ENERGIES':
            v = bintable_to_array(hdulist[1].data)
            v = np.log10(v)
            energy_axis = Axis.createFromArray(v)
            axes = copy.deepcopy(FITSAxis.create_axes(header))
            axes[2]._crval = energy_axis.edges[0]
            axes[2]._delta = energy_axis.width[0]
            axes[2]._crpix = 0.0
        else:        
            axes = copy.deepcopy(FITSAxis.create_axes(header))
        return SkyCube(wcs,axes,
                       copy.deepcopy(hdulist[ihdu].data.astype(float).T))
Esempio n. 5
0
    def get_projected_map(self, header):

        map_shape = (header["naxis2"], header["naxis1"])
        iy, ix = np.indices(map_shape)
        wcs = pywcs.WCS(header)
        phi, theta = wcs.wcs_pix2sky(ix, iy, 0)

        if self._coord is not None:
            from pywcsgrid2.wcs_helper import coord_system_guess, sky2sky
            map_coord = coord_system_guess(header["ctype1"],
                                           header["ctype2"],
                                           equinox=header["equinox"])
            if (map_coord is not None) and (map_coord != self._coord):
                warnings.warn(" doing the conversion " + map_coord)
                phi, theta = sky2sky(map_coord, self._coord)(phi, theta)

        if self._flipy:
            theta -= 90
            theta *= -np.pi / 180.
        else:
            theta += 90
            theta *= np.pi / 180.

        phi *= np.pi / 180

        if self._nested:
            ang2pix = healpy._healpy_pixel_lib._ang2pix_nest
        else:
            ang2pix = healpy._healpy_pixel_lib._ang2pix_ring

        # some values could be NaNs. Maske those out before calling
        # ang2pix and recover them.
        mask = np.isfinite(theta) & np.isfinite(theta)

        ipix = ang2pix(self._nside, theta[mask], phi[mask])

        map_data_ = self._data[ipix]
        map_data = np.empty(map_shape, dtype=map_data_.dtype)
        map_data.fill(np.nan)
        map_data.flat[mask] = map_data_

        return map_data
Esempio n. 6
0
    def __getnewargs__(self):

        self._wcs = pywcs.WCS(self._header)
        return ()