Esempio n. 1
0
 def vec2xy(self, vx, vy=None, vz=None, direct=False):
     if not direct:
         theta,phi=R.vec2dir(self.rotator(vx,vy,vz))
     else:
         theta,phi=R.vec2dir(vx,vy,vz)
     flip = self._flip
     # set phi in [-pi,pi]
     x = flip*((phi+pi)%(2*pi)-pi)
     x /= dtor # convert in degree
     y = pi/2. - theta
     y /= dtor # convert in degree
     return x,y
Esempio n. 2
0
 def vec2xy(self, vx, vy=None, vz=None, direct=False):
     if not direct:
         theta,phi=R.vec2dir(self.rotator(vx,vy,vz))
     else:
         theta,phi=R.vec2dir(vx,vy,vz)
     flip = self._flip
     # set phi in [-pi,pi]
     x = flip*((phi+pi)%(2*pi)-pi)
     x /= dtor # convert in degree
     y = pi/2. - theta
     y /= dtor # convert in degree
     return x,y
Esempio n. 3
0
 def vec2xy(self, vx, vy=None, vz=None, direct=False):
     if not direct:
         theta,phi=R.vec2dir(self.rotator(vx,vy,vz))
     else:
         theta,phi=R.vec2dir(vx,vy,vz)
     flip = self._flip
     X,Y = MollweideProj.__molldata
     # set phi in [-pi,pi]
     phi = (phi+pi)%(2*pi)-pi
     lat = pi/2. - theta
     A = MollweideProj.__lininterp(X,Y,lat)
     x = flip*2./pi * phi * np.cos(A)
     y = np.sin(A)
     return x,y
Esempio n. 4
0
 def vec2xy(self, vx, vy=None, vz=None, direct=False):
     if not direct:
         theta,phi=R.vec2dir(self.rotator(vx,vy,vz))
     else:
         theta,phi=R.vec2dir(vx,vy,vz)
     flip = self._flip
     X,Y = MollweideProj.__molldata
     # set phi in [-pi,pi]
     phi = (phi+pi)%(2*pi)-pi
     lat = pi/2. - theta
     A = MollweideProj.__lininterp(X,Y,lat)
     x = flip*2./pi * phi * np.cos(A)
     y = np.sin(A)
     return x,y
Esempio n. 5
0
 def vec2xy(self, vx, vy=None, vz=None, direct=False):
     if not direct:
         theta,phi=R.vec2dir(self.rotator(vx,vy,vz))
     else:
         theta,phi=R.vec2dir(vx,vy,vz)
     if self.arrayinfo is None:
         raise TypeError("No projection plane array information defined for"
                         " this projector")
     half_sky = self.arrayinfo['half_sky']
     flip = self._flip
     # set phi in [-pi,pi]
     phi = flip*(phi+pi)%(2*pi)-pi
     lat = pi/2. - theta
     x = np.cos(lat)*np.sin(phi)
     if not half_sky: x -= 1.0
     y = np.sin(lat)
     # unfold back of sphere
     cosc = np.cos(lat)*np.cos(phi)
     if np.any(cosc<0):
         hmask = (cosc<0)
         if hasattr(x,'__len__'):
             if half_sky:
                 x[hmask] = np.nan
             else:
                 x[hmask] *= -1
         elif hmask:
             if half_sky:
                 x = np.nan
             else:
                 x *= 1
     if half_sky:
         mask = (np.asarray(x)**2+np.asarray(y)**2>1.0)
     else:
         mask = ((np.mod(np.asarray(x)+2.0,2.0)-1.0)**2 + \
                 np.asarray(y)**2>1.0)
     if mask.any():
         if not hasattr(x,'__len__'):
             x = np.nan
             y = np.nan
         else:
             x[mask] = np.nan
             y[mask] = np.nan
     return x,y
Esempio n. 6
0
def remove_dipole(m,
                  nest=False,
                  bad=pixlib.UNSEEN,
                  gal_cut=0,
                  fitval=False,
                  copy=True,
                  verbose=False):
    """Fit and subtract the dipole and the monopole from the given map m.
    Input:
      - m: the map from which a dipole is fitted and subtracted
      - nest: False if m is in RING scheme, True if it is NESTED
      - bad: bad values of pixel, default to UNSEEN.
      - gal_cut: latitude below which pixel are not taken into account
      - fitval: whether to return or not the fitted values of monopole and dipole
    Return:
      if fitval is False:
      - the map with monopole and dipole subtracted
      if fitval is True:
      - the map, the monopole value  and the dipole vector
    """
    m = npy.array(m, copy=copy)
    npix = m.size
    nside = npix2nside(npix)
    if nside > 128:
        bunchsize = npix / 24
    else:
        bunchsize = npix
    mono, dipole = fit_dipole(m, nest=nest, bad=bad, gal_cut=gal_cut)
    for ibunch in range(npix / bunchsize):
        ipix = npy.arange(ibunch * bunchsize, (ibunch + 1) * bunchsize)
        ipix = ipix[(m.flat[ipix] != bad) & (npy.isfinite(m.flat[ipix]))]
        x, y, z = pix2vec(nside, ipix, nest)
        m.flat[ipix] -= (dipole[0] * x)
        m.flat[ipix] -= dipole[1] * y
        m.flat[ipix] -= dipole[2] * z
        m.flat[ipix] -= mono
    if verbose:
        import rotator as R
        lon, lat = R.vec2dir(dipole, lonlat=True)
        amp = npy.sqrt((dipole**2).sum())
        print 'monopole: %g  dipole: lon: %g, lat: %g, amp: %g' % (mono, lon,
                                                                   lat, amp)
    if fitval:
        return m, mono, dipole
    else:
        return m
Esempio n. 7
0
def remove_dipole(m,nest=False,bad=pixlib.UNSEEN,gal_cut=0,fitval=False,
                  copy=True,verbose=False):
    """Fit and subtract the dipole and the monopole from the given map m.
    Input:
      - m: the map from which a dipole is fitted and subtracted
      - nest: False if m is in RING scheme, True if it is NESTED
      - bad: bad values of pixel, default to UNSEEN.
      - gal_cut: latitude below which pixel are not taken into account
      - fitval: whether to return or not the fitted values of monopole and dipole
    Return:
      if fitval is False:
      - the map with monopole and dipole subtracted
      if fitval is True:
      - the map, the monopole value  and the dipole vector
    """
    m=npy.array(m,copy=copy)
    npix = m.size
    nside = npix2nside(npix)
    if nside>128:
        bunchsize = npix/24
    else:
        bunchsize = npix
    mono,dipole = fit_dipole(m,nest=nest,bad=bad,gal_cut=gal_cut)
    for ibunch in range(npix/bunchsize):
        ipix = npy.arange(ibunch*bunchsize,
                          (ibunch+1)*bunchsize)
        ipix = ipix[(m.flat[ipix]!=bad) & (npy.isfinite(m.flat[ipix]))]
        x,y,z = pix2vec(nside, ipix, nest)
        m.flat[ipix] -= (dipole[0]*x)
        m.flat[ipix] -= dipole[1]*y
        m.flat[ipix] -= dipole[2]*z
        m.flat[ipix] -= mono
    if verbose:
        import rotator as R
        lon,lat = R.vec2dir(dipole,lonlat=True)
        amp = npy.sqrt((dipole**2).sum())
        print 'monopole: %g  dipole: lon: %g, lat: %g, amp: %g'%(mono,
                                                                 lon,
                                                                 lat,
                                                                 amp)
    if fitval:
        return m,mono,dipole
    else:
        return m
Esempio n. 8
0
def remove_dipole(m, nest=False, bad=UNSEEN, gal_cut=0, fitval=False, copy=True, verbose=True):
    """Fit and subtract the dipole and the monopole from the given map m.

    Parameters
    ----------
    m : float, array-like
      the map to which a dipole is fitted and subtracted, accepts masked arrays
    nest : bool
      if ``False`` m is assumed in RING scheme, otherwise map is NESTED
    bad : float
      bad values of pixel, default to :const:`UNSEEN`.
    gal_cut : float
      pixels at latitude in [-gal_cut;+gal_cut] are not taken into account
    fitval : bool
      whether to return or not the fitted values of monopole and dipole
    copy : bool
      whether to modify input map or not (by default, make a copy)
    verbose : bool
      print values of monopole and dipole

    Returns
    -------
    res : array or tuple of length 3
      if fitval is False, returns map with monopole and dipole subtracted,
      otherwise, returns map (array, in res[0]), monopole (float, in res[1]), 
      dipole_vector (array, in res[2])

    See Also
    --------
    fit_dipole, fit_monopole, remove_monopole
    """
    input_ma = is_ma(m)
    m = ma_to_array(m)
    m = np.array(m, copy=copy)
    npix = m.size
    nside = npix2nside(npix)
    if nside > 128:
        bunchsize = npix / 24
    else:
        bunchsize = npix
    mono, dipole = fit_dipole(m, nest=nest, bad=bad, gal_cut=gal_cut)
    for ibunch in range(npix / bunchsize):
        ipix = np.arange(ibunch * bunchsize, (ibunch + 1) * bunchsize)
        ipix = ipix[(m.flat[ipix] != bad) & (np.isfinite(m.flat[ipix]))]
        x, y, z = pix2vec(nside, ipix, nest)
        m.flat[ipix] -= dipole[0] * x
        m.flat[ipix] -= dipole[1] * y
        m.flat[ipix] -= dipole[2] * z
        m.flat[ipix] -= mono
    if verbose:
        import rotator as R

        lon, lat = R.vec2dir(dipole, lonlat=True)
        amp = np.sqrt((dipole ** 2).sum())
        print "monopole: %g  dipole: lon: %g, lat: %g, amp: %g" % (mono, lon, lat, amp)
    if is_ma:
        m = ma(m)
    if fitval:
        return m, mono, dipole
    else:
        return m
Esempio n. 9
0
 def xy2ang(self, x, y=None, lonlat=False, direct=False):
     vec = self.xy2vec(x,y,direct=direct)
     return R.vec2dir(vec,lonlat=lonlat)
Esempio n. 10
0
def remove_dipole(m,nest=False,bad=UNSEEN,gal_cut=0,fitval=False,
                  copy=True,verbose=False):
    """Fit and subtract the dipole and the monopole from the given map m.

    Parameters
    ----------
    m : float, array-like
      the map to which a dipole is fitted and subtracted
    nest : bool
      if ``False`` m is assumed in RING scheme, otherwise map is NESTED
    bad : float
      bad values of pixel, default to :const:`UNSEEN`.
    gal_cut : float
      pixels at latitude in [-gal_cut;+gal_cut] are not taken into account
    fitval : bool
      whether to return or not the fitted values of monopole and dipole
    copy : bool
      whether to modify input map or not (by default, make a copy)
    verbose : bool
      print values of monopole and dipole

    Returns
    -------
    res : array or tuple of length 3
      if fitval is False, returns map with monopole and dipole subtracted,
      otherwise, returns map (array, in res[0]), monopole (float, in res[1]), 
      dipole_vector (array, in res[2])

    See Also
    --------
    fit_dipole, fit_monopole, remove_monopole
    """
    m=npy.array(m,copy=copy)
    npix = m.size
    nside = npix2nside(npix)
    if nside>128:
        bunchsize = npix/24
    else:
        bunchsize = npix
    mono,dipole = fit_dipole(m,nest=nest,bad=bad,gal_cut=gal_cut)
    for ibunch in range(npix/bunchsize):
        ipix = npy.arange(ibunch*bunchsize,
                          (ibunch+1)*bunchsize)
        ipix = ipix[(m.flat[ipix]!=bad) & (npy.isfinite(m.flat[ipix]))]
        x,y,z = pix2vec(nside, ipix, nest)
        m.flat[ipix] -= (dipole[0]*x)
        m.flat[ipix] -= dipole[1]*y
        m.flat[ipix] -= dipole[2]*z
        m.flat[ipix] -= mono
    if verbose:
        import rotator as R
        lon,lat = R.vec2dir(dipole,lonlat=True)
        amp = npy.sqrt((dipole**2).sum())
        print 'monopole: %g  dipole: lon: %g, lat: %g, amp: %g'%(mono,
                                                                 lon,
                                                                 lat,
                                                                 amp)
    if fitval:
        return m,mono,dipole
    else:
        return m
Esempio n. 11
0
 def xy2ang(self, x, y=None, lonlat=False, direct=False):
     vec = self.xy2vec(x,y,direct=direct)
     return R.vec2dir(vec,lonlat=lonlat)