示例#1
0
    def _reproject_hpx(self, geom, mode='interp', order=1):
        from reproject import reproject_to_healpix
        from .hpxnd import HpxNDMap

        map_out = HpxNDMap(geom)
        coordsys = 'galactic' if geom.coordsys == 'GAL' else 'icrs'
        axes_eq = np.all(
            [ax0 == ax1 for ax0, ax1 in zip(geom.axes, self.geom.axes)])

        for vals, idx in map_out.iter_by_image():

            if self.geom.ndim == 2 or axes_eq:
                img = self.data[idx[::-1]]
            else:
                coords = axes_pix_to_coord(geom.axes, idx)
                img = self.interp_image(coords, order=order).data

            # TODO: For partial-sky HPX we need to map from full- to
            # partial-sky indices
            if self.geom.projection == 'CAR' and self.geom.is_allsky:
                data, footprint = reproject_car_to_hpx((img, self.geom.wcs),
                                                       coordsys,
                                                       nside=geom.nside,
                                                       nested=geom.nest,
                                                       order=order)
            else:
                data, footprint = reproject_to_healpix((img, self.geom.wcs),
                                                       coordsys,
                                                       nside=geom.nside,
                                                       nested=geom.nest,
                                                       order=order)
            vals[...] = data

        return map_out
示例#2
0
文件: wcsnd.py 项目: pdeiml/gammapy
    def _reproject_hpx(self, geom, mode='interp', order=1):
        from reproject import reproject_to_healpix
        from .hpxnd import HpxNDMap

        map_out = HpxNDMap(geom)
        coordsys = 'galactic' if geom.coordsys == 'GAL' else 'icrs'
        axes_eq = np.all([ax0 == ax1 for ax0, ax1 in
                          zip(geom.axes, self.geom.axes)])

        for vals, idx in map_out.iter_by_image():

            if self.geom.ndim == 2 or axes_eq:
                img = self.data[idx[::-1]]
            else:
                coords = axes_pix_to_coord(geom.axes, idx)
                img = self.interp_image(coords, order=order).data

            # TODO: For partial-sky HPX we need to map from full- to
            # partial-sky indices
            if self.geom.projection == 'CAR' and self.geom.is_allsky:
                data, footprint = reproject_car_to_hpx((img, self.geom.wcs),
                                                       coordsys,
                                                       nside=geom.nside,
                                                       nested=geom.nest,
                                                       order=order)
            else:
                data, footprint = reproject_to_healpix((img, self.geom.wcs),
                                                       coordsys,
                                                       nside=geom.nside,
                                                       nested=geom.nest,
                                                       order=order)
            vals[...] = data

        return map_out
示例#3
0
    def _reproject_to_hpx(self, geom, mode="interp", order=1):
        from reproject import reproject_to_healpix

        data = np.empty(geom.data_shape)
        coordsys = "galactic" if geom.coordsys == "GAL" else "icrs"

        for img, idx in self.iter_by_image():
            # TODO: For partial-sky HPX we need to map from full- to
            # partial-sky indices
            if self.geom.projection == "CAR" and self.geom.is_allsky:
                vals, footprint = reproject_car_to_hpx(
                    (img, self.geom.wcs),
                    coordsys,
                    nside=geom.nside,
                    nested=geom.nest,
                    order=order,
                )
            else:
                vals, footprint = reproject_to_healpix(
                    (img, self.geom.wcs),
                    coordsys,
                    nside=geom.nside,
                    nested=geom.nest,
                    order=order,
                )
            data[idx] = vals

        return self._init_copy(geom=geom, data=data)
示例#4
0
文件: wcsnd.py 项目: gammapy/gammapy
    def _reproject_to_hpx(self, geom, mode="interp", order=1):
        from reproject import reproject_to_healpix

        data = np.empty(geom.data_shape)
        coordsys = "galactic" if geom.coordsys == "GAL" else "icrs"

        for img, idx in self.iter_by_image():
            # TODO: For partial-sky HPX we need to map from full- to
            # partial-sky indices
            if self.geom.projection == "CAR" and self.geom.is_allsky:
                vals, footprint = reproject_car_to_hpx(
                    (img, self.geom.wcs),
                    coordsys,
                    nside=geom.nside,
                    nested=geom.nest,
                    order=order,
                )
            else:
                vals, footprint = reproject_to_healpix(
                    (img, self.geom.wcs),
                    coordsys,
                    nside=geom.nside,
                    nested=geom.nest,
                    order=order,
                )
            data[idx] = vals

        return self._init_copy(geom=geom, data=data)
示例#5
0
文件: utils.py 项目: sopXx/picasso
def f2h(flat, target_header, nside, coord_in='C'):
    #project flatsky->healpix
    pr, footprint = reproject.reproject_to_healpix((flat, target_header),
                                                   coord_system_out='C',
                                                   nside=nside,
                                                   order='nearest-neighbor',
                                                   nested=False)
    return pr
示例#6
0
def image_reproject_to_healpix_to_file(array, target_image_hdu_header, coordsys='galactic', filepath=None):
    """reproject image array to healpix image and write file

    :param array:                   image data
    :param target_image_hdu_header: the HDU object of
    :param coordsys:                target coordinate system --> {'galactic', 'equatorial'}
    :param filepath:                the output file path
    :return:                        array, footprint (only if filepath=None)
    """
    array, footprint = reproject_to_healpix((array, target_image_hdu_header), coordsys)
    if filepath is not None:
        # write file
        write_map(filepath, array)
    else:
        # return array & footprint
        return array, footprint
示例#7
0
def image_reproject_to_healpix_to_file(array,
                                       target_image_hdu_header,
                                       coordsys='galactic',
                                       filepath=None):
    """reproject image array to healpix image and write file

    :param array:                   image data
    :param target_image_hdu_header: the HDU object of
    :param coordsys:                target coordinate system --> {'galactic', 'equatorial'}
    :param filepath:                the output file path
    :return:                        array, footprint (only if filepath=None)
    """
    array, footprint = reproject_to_healpix((array, target_image_hdu_header),
                                            coordsys)
    if filepath is not None:
        # write file
        write_map(filepath, array)
    else:
        # return array & footprint
        return array, footprint
示例#8
0
文件: sky.py 项目: sjtuzyk/fg21sim
    def reproject_from(self, data, wcs, squeeze=False):
        """
        Reproject the given image/data together with WCS information
        onto the grid of this sky.

        Parameters
        ----------
        data : 2D float `~numpy.ndarray`
            The input data/image to be reprojected
        wcs : `~astropy.wcs.WCS`
            The WCS information of the input data/image (naxis=2)
        squeeze : bool, optional
            Whether to squeeze the reprojected data to only keep
            the positive pixels.

        Returns
        -------
        If ``squeeze=True``, then returns tuple of ``(indexes, values)``,
        otherwise, returns the reprojected image/data array.

        indexes : 1D int `~numpy.ndarray`
            The indexes of the pixels with positive values.
        values : 1D float `~numpy.ndarray`
            The values of the above pixels.

        reprojected : 1D `~numpy.ndarray`
            The reprojected data/image with same shape of this sky,
            i.e., ``self.data.shape``.
        """
        eps = 1e-5
        reprojected, __ = reproject_to_healpix(input_data=(data, wcs),
                                               coord_system_out="galactic",
                                               nested=False,
                                               nside=self.nside)
        if squeeze:
            with np.errstate(invalid="ignore"):
                indexes = reprojected > eps
            values = reprojected[indexes]
            return (indexes, values)
        else:
            return reprojected
示例#9
0
文件: utils.py 项目: giuspugl/picasso
def f2h(flat, target_header, nside, coord_in='C'):
    """
    Returns a  HEALPIX map projected  and the footprint of a flat one , given a WCS header,
    using :py:mod:`reproject` package

    **Parameters**

    - ``flat`` : {2D array}
        flat  map
    - ``target_header``:
        header defined from :func:`set_header`
    - ``nside``:{int}
        nside of output healpix map


    """

    pr, footprint = reproject.reproject_to_healpix((flat, target_header),
                                                   coord_system_out='C',
                                                   nside=nside,
                                                   order='nearest-neighbor',
                                                   nested=False)
    return pr, footprint
示例#10
0
rbins = np.linspace(0, 90, 26)
r = (rbins[1:] + rbins[:-1]) / 2
f = np.zeros(len(rbins) - 1)
R = np.sqrt(X**2 + Y**2)
for i in range(len(rbins) - 1):
    inds = (R > rbins[i]) & (R <= rbins[i + 1])
    f[i] = Gmap[inds].mean()
plt.figure()
plt.plot(r, f)
plt.xlabel(r'$\theta$')
plt.ylabel(r'$b(\theta)$')
plt.yscale('log')

beam, footprint = reproject_to_healpix((Gmap, wcs.WCS(header)),
                                       'C',
                                       nside=nside)

beam[~np.isfinite(beam)] = 0
beam[beam == hp.UNSEEN] = 0
hp.orthview(np.log10(beam))
#plt.show()

d1 = np.loadtxt('horizon_hwt.txt')
az, el = d1.T

pickup = np.zeros(hp.nside2npix(nside))
lon, lat = hp.pix2ang(nside, np.arange(len(pickup)), lonlat=True)
f = interp1d(az,
             el,
             fill_value=(el[0], el[-1]),