Exemple #1
0
def cel2gal(ra, dec, inverse=False):
    _r, _d = ra * np.pi / 180., (np.pi / 2. - dec * np.pi / 180.)
    if inverse:
        r = hp.Rotator(coord=['G', 'C'])
    else:
        r = hp.Rotator(coord=['C', 'G'])
    _d, _r = r(_d, _r)

    return _r * 180. / np.pi, (np.pi / 2. - _d) * 180. / np.pi
Exemple #2
0
def map_rotation(x, theta=22.5, phi=22.5, inv=None, PutToZero=False):

    nside = gnside(x)
    npix = hpy.nside2npix(nside)
    pix = np.arange(npix)

    t, p = hpy.pix2ang(nside, pix)  #theta, phi

    r = hpy.Rotator(deg=True, rot=[theta, phi], inv=inv)

    map_rot = -1e10 * np.ones(npix)

    trot, prot = r(t, p)
    u = hpy.ang2pix(nside=nside, phi=prot, theta=trot)
    map_rot[u] = x

    ind = np.where(map_rot > -1e9)[0]
    jnd = np.where(map_rot < -1e9)[0]

    if PutToZero:

        map_rot[jnd] = np.mean(map_rot)

    else:

        for i in jnd:
            d = np.sqrt((t[ind] - t[i])**2 + (p[ind] - p[i])**2)
            I = np.argsort(d)
            map_rot[i] = np.mean(map_rot[ind[I[0:10]]])

    return map_rot
Exemple #3
0
def get_theta_phi(ra, dec):
    '''Get theta, phi [radians] used in Healpy from RA, DEC [degree].'''
    rot = hp.Rotator(coord=['C', 'G'])
    theta_equ, phi_equ = np.deg2rad(90.-dec), np.deg2rad(ra)
    theta_gal, phi_gal = rot(theta_equ, phi_equ)

    return theta_gal, phi_gal
Exemple #4
0
def get_nhits(nside_out=64):
    """ Generates an Nhits map in Galactic coordinates.

    Parameters
    ----------
    nside_out : int
        Output resolution.

    Returns
    -------
    ndarray
        Hits map.
    """
    try:
        # Read in a hits map that has already been calculated
        # in galactic coordinates
        mp_G = hp.read_map(_SO_HIT_MAP, verbose=False)
    except FileNotFoundError:
        # if reading in galactic map fails, read in
        # celestial coordinates map and rotate it.
        mp_C = hp.read_map(_SO_HIT_MAP, verbose=False)
        nside_l = hp.get_nside(mp_C)
        nside_h = 512
        ipixG = np.arange(hp.nside2npix(nside_h))
        thG, phiG = hp.pix2ang(nside_h, ipixG)
        r = hp.Rotator(coord=['G', 'C'])
        thC, phiC = r(thG, phiG)
        ipixC = hp.ang2pix(nside_l, thC, phiC)
        mp_G = hp.ud_grade(mp_C[ipixC], nside_out=nside_l)
    return hp.ud_grade(mp_G, nside_out=nside_out)
Exemple #5
0
 def rotate(self, *a, **kw):
     kw['inv'] = kw.get('inv', True)
     rot = healpy.Rotator(*a, **kw)
     thetas0, phis0 = self._thetas_phis
     thetas, phis = rot(thetas0, phis0)
     rmap = healpy.get_interp_val(self.map, thetas, phis)
     return HealHist(rmap)
Exemple #6
0
def change_coord(m, coord):
    """
    Define the new binning.

    Parameters
	----------
    m : array
       map to be converted
    coord: list
       list of two strings choosen among 'G', 'C', 'E'. E.g.: to go from galactic to 
       celestial coordinates: coord = ['G', 'C'] 
	Returns
	-------
	array
	   the array with the new map
    """
    # Basic HEALPix parameters
    npix = m.shape[-1]
    nside = hp.npix2nside(npix)
    ang = hp.pix2ang(nside, np.arange(npix))

    # Select the coordinate transformation
    rot = hp.Rotator(coord=reversed(coord))

    # Convert the coordinates
    new_ang = rot(*ang)
    new_pix = hp.ang2pix(nside, *new_ang)

    return m[..., new_pix]