(m, nest=False, bad=UNSEEN, gal_cut=0)
return mono, dipole
Fit a dipole and a monopole to the map, excluding bad pixels.

    Parameters
    ----------
    m : float, array-like
      the map to which a dipole is fitted and subtracted, accepts masked maps
    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 [degrees]
      pixels at latitude in [-gal_cut;+gal_cut] degrees are not taken into account

    Returns
    -------
    res : tuple of length 2
      the monopole value in res[0] and the dipole vector (as array) in res[1]

    See Also
    --------
    remove_dipole, fit_monopole, remove_monopole
Fit a dipole and a monopole to the map, excluding bad pixels.
Fit a dipole and a monopole to the map excluding bad pixels .
def fit_dipole(m, nest=False, bad=UNSEEN, gal_cut=0):
    """Fit a dipole and a monopole to the map, excluding bad pixels.

    Parameters
    ----------
    m : float, array-like
      the map to which a dipole is fitted and subtracted, accepts masked maps
    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 [degrees]
      pixels at latitude in [-gal_cut;+gal_cut] degrees are not taken into account

    Returns
    -------
    res : tuple of length 2
      the monopole value in res[0] and the dipole vector (as array) in res[1]

    See Also
    --------
    remove_dipole, fit_monopole, remove_monopole
    """
    m = ma_to_array(m)
    m = np.asarray(m)
    npix = m.size
    nside = npix2nside(npix)
    if nside > 128:
        bunchsize = npix // 24
    else:
        bunchsize = npix
    aa = np.zeros((4, 4), dtype=np.float64)
    v = np.zeros(4, dtype=np.float64)
    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)
        if gal_cut > 0:
            w = np.abs(z) >= np.sin(gal_cut * np.pi / 180)
            ipix = ipix[w]
            x = x[w]
            y = y[w]
            z = z[w]
            del w
        aa[0, 0] += ipix.size
        aa[1, 0] += x.sum()
        aa[2, 0] += y.sum()
        aa[3, 0] += z.sum()
        aa[1, 1] += (x ** 2).sum()
        aa[2, 1] += (x * y).sum()
        aa[3, 1] += (x * z).sum()
        aa[2, 2] += (y ** 2).sum()
        aa[3, 2] += (y * z).sum()
        aa[3, 3] += (z ** 2).sum()
        v[0] += m.flat[ipix].sum()
        v[1] += (m.flat[ipix] * x).sum()
        v[2] += (m.flat[ipix] * y).sum()
        v[3] += (m.flat[ipix] * z).sum()
    aa[0, 1] = aa[1, 0]
    aa[0, 2] = aa[2, 0]
    aa[0, 3] = aa[3, 0]
    aa[1, 2] = aa[2, 1]
    aa[1, 3] = aa[3, 1]
    aa[2, 3] = aa[3, 2]
    res = np.dot(np.linalg.inv(aa), v)
    mono = res[0]
    dipole = res[1:4]
    return mono, dipole
def fit_dipole ( m , nest = False , bad = UNSEEN , gal_cut = 0 ) : m = ma_to_array ( m ) m = np . asarray ( m ) npix = m . size nside = npix2nside ( npix ) if nside > 128 : bunchsize = npix // 24 else : bunchsize = npix aa = np . zeros ( ( 4 , 4 ) , dtype = np . float64 ) v = np . zeros ( 4 , dtype = np . float64 ) 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 ) if gal_cut > 0 : w = np . abs ( z ) >= np . sin ( gal_cut * np . pi / 180 ) ipix = ipix [ w ] x = x [ w ] y = y [ w ] z = z [ w ] del w aa [ 0 , 0 ] += ipix . size aa [ 1 , 0 ] += x . sum ( ) aa [ 2 , 0 ] += y . sum ( ) aa [ 3 , 0 ] += z . sum ( ) aa [ 1 , 1 ] += ( x ** 2 ) . sum ( ) aa [ 2 , 1 ] += ( x * y ) . sum ( ) aa [ 3 , 1 ] += ( x * z ) . sum ( ) aa [ 2 , 2 ] += ( y ** 2 ) . sum ( ) aa [ 3 , 2 ] += ( y * z ) . sum ( ) aa [ 3 , 3 ] += ( z ** 2 ) . sum ( ) v [ 0 ] += m . flat [ ipix ] . sum ( ) v [ 1 ] += ( m . flat [ ipix ] * x ) . sum ( ) v [ 2 ] += ( m . flat [ ipix ] * y ) . sum ( ) v [ 3 ] += ( m . flat [ ipix ] * z ) . sum ( ) aa [ 0 , 1 ] = aa [ 1 , 0 ] aa [ 0 , 2 ] = aa [ 2 , 0 ] aa [ 0 , 3 ] = aa [ 3 , 0 ] aa [ 1 , 2 ] = aa [ 2 , 1 ] aa [ 1 , 3 ] = aa [ 3 , 1 ] aa [ 2 , 3 ] = aa [ 3 , 2 ] res = np . dot ( np . linalg . inv ( aa ) , v ) mono = res [ 0 ] dipole = res [ 1 : 4 ] return mono , dipole