Example #1
0
    def calculate(self):
        """
        calculate various properties of the gaussian, fnl, gnl maps i.e. compute
        * Ais
        * As
        * Cls
        * dipoles using remove_dipole
        """
        inpCls=self.inputCls[:self.lmax+1]

        if (self.gausmap!=None):
            self.gausCls=hp.alm2cl(self.gausalm)[0:self.lmax+1]
            self.gausA0=get_A0(self.gausCls[1:], inpCls[1:])
            self.gausAi=Ais(self.gausmap, self.lmax); self.gausA=AistoA(self.gausAi)
            self.gausmp=hp.remove_monopole(self.gausmap, fitval=True)[1]
            self.gausdipole=get_dipole(self.gausmap)

        if (self.gnlmaps!=None):
            self.gnlCls=[]; self.gnlA0=[]; self.gnlAi=[]
            self.gnlmp=[]; self.gnldipole=[]; self.gnlA=[]

            for i in range(self.Ngnls):
                self.gnlCls.append(hp.anafast(self.gnlmaps[i], nspec=self.lmax))
                self.gnlA0.append(get_A0(self.gnlCls[i][1:], inpCls[1:]))
                self.gnlAi.append(Ais(self.gnlmaps[i], self.lmax)); self.gnlA.append(AistoA(self.gnlAi[i]))
                self.gnlmp.append(hp.remove_monopole(self.gnlmaps[i], fitval=True)[1])
                self.gnldipole.append(get_dipole(self.gnlmaps[i]))
Example #2
0
 def test_anafast_xspectra(self):
     cl = hp.anafast(hp.remove_monopole(self.map1[0]),
                     hp.remove_monopole(self.map2[0]),
                     lmax=self.lmax)
     self.assertEqual(len(cl), self.lmax + 1)
     clx = hp.read_cl(
         os.path.join(
             self.path, 'data',
             'cl_wmap_band_iqumap_r9_7yr_WVxspec_v4_udgraded32_II_lmax64_rmmono_3iter.fits'
         ))
     np.testing.assert_array_almost_equal(cl, clx, decimal=8)
Example #3
0
 def test_anafast_xspectra(self):
     cl = hp.anafast(
         hp.remove_monopole(self.map1[0]),
         hp.remove_monopole(self.map2[0]),
         lmax=self.lmax,
     )
     self.assertEqual(len(cl), self.lmax + 1)
     clx = hp.read_cl(
         os.path.join(
             self.path,
             "data",
             "cl_wmap_band_iqumap_r9_7yr_WVxspec_v4_udgraded32_II_lmax64_rmmono_3iter.fits",
         )
     )
     np.testing.assert_array_almost_equal(cl, clx, decimal=8)
Example #4
0
 def test_anafast_iqu(self):
     self.map1[0] = hp.remove_monopole(self.map1[0])
     cl = hp.anafast(self.map1, lmax=self.lmax)
     self.assertEqual(len(cl[0]), 65)
     self.assertEqual(len(cl), 6)
     for i in range(6):
         np.testing.assert_array_almost_equal(cl[i], self.cliqu[i], decimal=8)
Example #5
0
 def test_anafast_iqu(self):
     self.map1[0] = hp.remove_monopole(self.map1[0])
     cl = hp.anafast(self.map1, lmax=self.lmax)
     self.assertEqual(len(cl[0]), 65)
     self.assertEqual(len(cl), 6)
     for i in range(6):
         np.testing.assert_array_almost_equal(cl[i], self.cliqu[i], decimal=8)
Example #6
0
def test_k2g2k_rand():
    """Test that transformation of k->g->k recovers the input convergence map."""

    nside = 16
    npix = hp.nside2npix(nside)
    lmax = 32

    k = np.random.standard_normal(npix)
    k = hp.smoothing(k, lmax=lmax, verbose=False)
    k = hp.remove_monopole(k)
    k = hp.remove_dipole(k)

    g1, g2 = transformations.conv2shear(k, lmax)

    k_recov = transformations.shear2conv(g1, g2, lmax)

    np.testing.assert_almost_equal(k, k_recov, decimal=3)
def read_and_diff_files_fast_hitweight(f1,f2,fh1,fh2,fhfull,nside=256,tmask=None,return_map=False,remove_monopole=True):
    #assume tmask is already degraded, remove_monopole=True: remove from differences before anafast
    #monopole is removed from I,Q U maps after masking
  
    mm1=hp.read_map(f1,[0,1,2],verbose=False)
    mm2=hp.read_map(f2,[0,1,2],verbose=False)
    h1=hp.read_map(fh1,[3],verbose=False)
    h2=hp.read_map(fh2,[3],verbose=False)
    hit_full=hp.read_map(fhfull,[3],verbose=False)
    
    nsh=hp.npix2nside(len(h1))
    if nsh != nside:
        h1=hp.ud_grade(h1,nside_out=nside,power=-2)
        h2=hp.ud_grade(h2,nside_out=nside,power=-2)
        hit_full=hp.ud_grade(hit_full,nside_out=nside,power=-2)
    
    mmm1=[]
    mmm2=[]
    for m1,m2 in zip(mm1,mm2):
        m1=hp.ud_grade(hp.ma(m1),nside_out=nside)
        m2=hp.ud_grade(hp.ma(m2),nside_out=nside)
        tmask=m1.mask | m2.mask | tmask
        mmm1.append(m1)
        mmm2.append(m2)
    whit = np.sqrt(hit_full*(1./h1+1./h2)) # m1[3] and m2[3] are the hit counts of the two maps to be nulled
    diff=[]
    
    for m1,m2 in zip(mmm1,mmm2):
        d=(m1-m2)/whit
        d.mask=tmask
        if remove_monopole:
            d=hp.remove_monopole(d)
        diff.append(d)
    
    skyfrac=1-float(tmask.sum())/len(tmask)
    cldata=hp.anafast(diff)
    cldata_out=[]
    for cl in cldata:
        cldata_out.append(cl/skyfrac)
        
    if return_map is False:
        return cldata_out
    if return_map is True:
        return cldata_out,diff
Example #8
0
    def calculate(self):
        """
        calculate various properties of the gaussian, fnl, gnl maps i.e. compute
        * Ais
        * As
        * Cls
        * dipoles using remove_dipole
        """
        inpCls = self.inputCls[:self.lmax + 1]

        if (self.gausmap0 != None):
            self.gausCls0 = hp.alm2cl(self.gausalm0)[0:self.lmax + 1]
            self.gausCls1 = hp.alm2cl(self.gausalm1)[0:self.lmax + 1]
            self.gausA0 = get_A0(self.gausCls0[1:], inpCls[1:])
            self.gausAi = Ais(self.gausmap1, self.lmax)
            self.gausA = AistoA(self.gausAi)
            self.gausAi2 = Ais(self.gausmap0, self.lmax)
            self.gausA2 = AistoA(self.gausAi2)
            self.gausmp = hp.remove_monopole(self.gausmap0, fitval=True)[1]
            self.gausdipole = get_dipole(self.gausmap1)

        if (self.fnlmaps1 != None):
            self.fnlCls0 = []
            self.fnlCls1 = []
            self.fnlA0 = []
            self.fnlAi = []
            self.fnlAi2 = []
            self.fnlmp = []
            self.fnldipole = []
            self.fnlA = []
            self.fnlA2 = []

            for i in range(self.Nfnls):
                #self.fnlCls0.append(hp.anafast(self.fnlmaps0[i], nspec=self.lmax))
                self.fnlCls1.append(
                    hp.anafast(self.fnlmaps1[i], nspec=self.lmax))
                #self.fnlA0.append(get_A0(self.fnlCls0[i][1:], inpCls[1:]))
                self.fnlAi.append(Ais(self.fnlmaps1[i], self.lmax))
                self.fnlA.append(AistoA(self.fnlAi[i]))
                #self.fnlAi2.append(Ais(self.fnlmaps0[i], self.lmax)); self.fnlA2.append(AistoA(self.fnlAi2[i]))
                #self.fnlmp.append(hp.remove_monopole(self.fnlmaps0[i], fitval=True)[1])
                self.fnldipole.append(get_dipole(self.fnlmaps1[i]))
Example #9
0
def spice(map1,
          map2=None,
          window=None,
          mask=None,
          window2=None,
          mask2=None,
          apodizesigma=0.0,
          apodizetype=0,
          thetamax=180.0,
          decouple=False,
          returnxi=False,
          remove_monopole=False,
          remove_dipole=False):
    '''This is an implementation of the PolSpice algorithm in Python.

    Parameters
    ----------
    map1 : str or list
        Input filename to load or list of 3 Healpix maps (I, Q, U)

    map2 : str or list, optional
        Input filename to load or list of 3 Healpix maps (I, Q, U)

    window : str or numpy.ndarray, optional
        Filename or array giving the weighted window to use.

    mask : str or numpy.ndarray, optional
        Filename or array giving the mask to use

    window2 : str or numpy.ndarray, optional
        Filename or array giving the weighted window to use for
        the second map. If not input, the same window is used as
        for the first map.

    mask2 : str or numpy.ndarray, optional
        Filename or array giving the mask to use for the second
        map. If not input, the same window is used as for the
        first map.

    apodizesigma : float
        Scale factor of the correlation function apodization (degrees)

    apodizetype : int
        Type of apodization. 0 is a Gaussian window. 1 is a cosine window

    thetamax : float
        maximum value of theta used in the integrals to calculate the
        power spectra from the correlation functions.

    decouple : bool
        whether to compute the decoupled correlation functions

    returnxi : bool
        whether or not to return the correlation functions as an additional
        output of the function

    remove_monopole : bool
        whether or not to remove the monopole from the maps before analyzing
        them

    remove_dipole : bool
        whether or not to remove the dipole from the maps before analyzing
        them

    Returns
    -------
    cls : numpy.ndarray
        An array containing the power spectra of the maps. TT, EE, BB, TE, EB, TB

    xi : numpy.ndarray, optional
        An array containing the real space correlation functions.

    Notes
    -----
    If neither a window nor a mask are input, the functionality will
    be similar to anafast.
    '''

    #If input is a string assume it is a filename
    if isinstance(map1, str):
        try:
            map1 = H.read_map(map1, field=(0, 1, 2))
        except:
            raise ValueError('Input map should have I, Q, and U')

    have_map2 = False
    if isinstance(map2, str):
        try:
            map2 = H.read_map(map2, field=(0, 1, 2))
        except:
            raise ValueError('Input map should have I, Q, and U')
        have_map2 = True

    if isinstance(window, str):
        window = H.read_map(window)
    elif window is None:
        window = np.ones_like(map1[0])

    if mask is None:
        mask = np.ones_like(map1[0])

    #Merge masks/windows
    window = window * mask

    map1 = (map1[0] * window, map1[1] * window, map1[2] * window)

    if have_map2:
        if isinstance(window2, str):
            window2 = H.read_map(window2)
        elif window2 is None:
            window2 = window

        if isinstance(mask2, str):
            mask2 = H.read_map(mask2)
        elif mask2 is None:
            mask2 = mask

        window2 = window2 * mask2

        map2 = (map2[0] * window2, map2[1] * window2, map2[2] * window2)

    #Remove the monopole and dipole. Points outside the mask/window are set
    #to the UNSEEN value so they are ignored when calculating the monopole/
    #dipole
    if remove_monopole:
        idx = window == 0
        map1[0][idx] = H.UNSEEN
        map1[1][idx] = H.UNSEEN
        map1[2][idx] = H.UNSEEN
        map1[0][:] = H.remove_monopole(map1[0], verbose=False)
        map1[1][:] = H.remove_monopole(map1[1], verbose=False)
        map1[2][:] = H.remove_monopole(map1[2], verbose=False)
        map1[0][idx] = 0.0
        map1[1][idx] = 0.0
        map1[2][idx] = 0.0
        if have_map2:
            idx = window2 == 0
            map2[0][idx] = H.UNSEEN
            map2[1][idx] = H.UNSEEN
            map2[2][idx] = H.UNSEEN
            map2[0][:] = H.remove_monopole(map2[0], verbose=False)
            map2[1][:] = H.remove_monopole(map2[1], verbose=False)
            map2[2][:] = H.remove_monopole(map2[2], verbose=False)
            map2[0][idx] = 0.0
            map2[1][idx] = 0.0
            map2[2][idx] = 0.0

    if remove_dipole:
        idx = window == 0
        map1[0][idx] = H.UNSEEN
        map1[1][idx] = H.UNSEEN
        map1[2][idx] = H.UNSEEN
        map1[0][:] = H.remove_dipole(map1[0], verbose=False)
        map1[1][:] = H.remove_dipole(map1[1], verbose=False)
        map1[2][:] = H.remove_dipole(map1[2], verbose=False)
        map1[0][idx] = 0.0
        map1[1][idx] = 0.0
        map1[2][idx] = 0.0
        if have_map2:
            idx = window2 == 0
            map2[0][idx] = H.UNSEEN
            map2[1][idx] = H.UNSEEN
            map2[2][idx] = H.UNSEEN
            map2[0][:] = H.remove_dipole(map2[0], verbose=False)
            map2[1][:] = H.remove_dipole(map2[1], verbose=False)
            map2[2][:] = H.remove_dipole(map2[2], verbose=False)
            map2[0][idx] = 0.0
            map2[1][idx] = 0.0
            map2[2][idx] = 0.0

    #Construction of the cls of the maps and masks/weights
    cls = H.anafast(map1, map2=map2)
    thetas, xi, w, x = get_xi_from_cl(cls,
                                      return_leggauss=True,
                                      thetamax=thetamax)

    if window is None:
        wls = None
    else:
        wls = H.anafast(window, map2=window2)
        #Compute xi from the cls of the map and masks
        thetas, xi_mask = get_xi_from_cl(wls, thetas=thetas)

        xi_final = _correct_xi_from_mask(xi, xi_mask)

    if decouple:
        xi_final = _update_xi(xi_final, x, thetamax, cls, cl_mask=wls)

    ncor = len(xi_final)

    #apodize the correlation function
    if apodizesigma > 0.0:
        apfunction = _apodizefunction(x, apodizesigma, thetamax, apodizetype)
        for i in range(ncor):
            xi_final[i, :] *= apfunction

    #compute the cls from xi
    cls_out = do_cl_from_xi(xi_final,
                            w,
                            x,
                            decouple=decouple,
                            apodizesigma=apodizesigma,
                            apodizetype=apodizetype,
                            thetamax=thetamax)

    #Correct cl for beam, pixel, transfer function???

    if returnxi:
        return cls_out, xi_final
    else:
        return cls_out
Example #10
0
def solar_dipole_fit(s, gal_cut=30):
    import healpy as hp
    dipmap = solar_system_dipole_map(nside=hp.npix2nside(len(s)))
    return np.sum(hp.remove_monopole(s.filled(), gal_cut=gal_cut) * np.logical_not(s.mask) * dipmap)/np.sum(dipmap ** 2 * np.logical_not(s.mask))
def remove_monopole(data):
    "DEPRECATED"
    return hp.remove_monopole(data, fitval=False)
Example #12
0
 def test_anafast_nomask(self):
     cl = hp.anafast(hp.remove_monopole(self.map1[0].data), lmax=self.lmax)
     self.assertEqual(len(cl), 65)
     np.testing.assert_array_almost_equal(cl,
                                          self.cl_fortran_nomask,
                                          decimal=8)
ell = np.arange(len(cl))
plt.plot(ell, ell*(ell+1)*cl)
plt.xlabel('$l$')
plt.ylabel('$l(l+1) C_l$')


plt.show()


clGal = hp.anafast(galMap, lmax=LMAX)
ellGal = np.arange(len(clGal))
plt.plot(ellGal, clGal)
plt.yscale('log')
plt.xscale('log')
plt.xlabel('$l$')
plt.ylabel('$C_l$')
plt.ylim([10**-7, 10**-3])
plt.title('CMASS North dr12 auto-power spectrum')
plt.show()


clCross = hp.anafast(galMap, hp.remove_monopole(planckmapMasked), lmax = LMAX)
ellCross = np.arange(len(clCross))
plt.plot(ellCross, ellCross*(ellCross+1)*clCross)
#plt.xscale('log')
#plt.yscale('log')
plt.xlabel('$l$')
plt.ylabel('$l(l+1)C_l$')
plt.title('CMASS North dr12 and Planck %i GHz cross-power spectrum'%(mapFreq))
plt.show()
import numpy as np

ft = hp.read_map('ftsumner.fits')
al = hp.read_map('alicesprings.fits')

ft[ft<0]=0
al[al<0]=0

NSIDE = 32
hit = hp.ud_grade(ft + al, NSIDE, power=-2)

noise = {8:308, 10:307, 15:163} #microK rt Sec
fsamp = 30. #Hz

#for freq, no in zip([8, 10, 15], noise):
freq = 8 
key = 'map'
if freq == 8:
    key = 'brian'
signal = gal2eq(hp.remove_monopole(hp.ud_grade(
hp.read_map('/smbmount/data1/COFE/Simulations/COFE_simulationPSMv163/cofe1/frequency_maps/coadded%s_%dGhz.fits' % (key,freq)), NSIDE),gal_cut=50))
if freq == 8:
    signal *= 1.e3

noise_map = noise[freq] / np.sqrt(hit * 1/fsamp) / 1e3

signoise = hp.ma(np.absolute(signal)/noise_map)
signoise.mask = hit == 0
hp.mollview(signoise, min=1,max=10.,coord='CG',title='Signal to noise at %d GHz' % freq,xsize=2000, norm='log')
plt.savefig('sigtonoise_%d.png' % freq)
Example #15
0
                            range(3),
                            verbose=False), nside)
                else:
                    m = hp.ud_grade(
                        hp.read_map(
                            '/Users/reijo/data/PR2/frequencymaps/'
                            'HFI_SkyMap_{:03}_2048_R2.02_full.fits'.format(
                                freq),
                            range(3),
                            verbose=False), nside)
                m = hp.smoothing(m,
                                 fwhm=4 * np.pi / 180,
                                 lmax=512,
                                 verbose=False)
                m = np.array(m)
                m[0] = hp.remove_monopole(m[0], gal_cut=80)
                hp.mollview(m[0] * norm,
                            min=-amp,
                            max=amp,
                            sub=[nrow, ncol, ifreq + 1],
                            title='PR2 {}GHz'.format(freq))
                hp.mollview(np.sqrt(m[1]**2 + m[2]**2) * norm,
                            min=0,
                            max=pol_amp,
                            sub=[nrow, ncol, ifreq + ncol + 1],
                            title='PR2 {}GHz P'.format(freq))
            except Exception:
                m = None
                pass

        t1 = MPI.Wtime()
OPTIONS, ARGS = parse_command_line()
validate_args(OPTIONS, ARGS)

Map = create_namedtuple_for_map(OPTIONS)

########################################
# Read the input maps in memory

INPUT_MAPS = []
for cur_title, cur_map_file in zip(*[iter(ARGS)] * 2):
    try:
        log.info('reading map `%s\'...', cur_map_file)
        cur_map = healpy.read_map(cur_map_file, field=OPTIONS.stokes_component)

        if OPTIONS.no_monopole:
            result = healpy.remove_monopole(cur_map, fitval=True, copy=False)
            log.info('monopole has been removed (%s)', str(result))
        if OPTIONS.no_dipole:
            result = healpy.remove_dipole(cur_map, fitval=True, copy=False)
            log.info('dipole has been removed (amplitude: %s)', str(result))

        cur_map[cur_map < -1.6e+30] = np.NaN

        if type(OPTIONS.mask) is not None:
            cur_map[OPTIONS.mask == 0] = np.NaN

        cur_entry = dict(title=cur_title,
                         pixels=cur_map,
                         input_file=cur_map_file)
        if OPTIONS.plot_distributions:
            cur_entry['histogram'] = np.histogram(cur_map[~np.isnan(cur_map)],
Example #17
0
 def test_anafast(self):
     cl = hp.anafast(hp.remove_monopole(self.map1[0].filled()), lmax=self.lmax)
     self.assertEqual(len(cl), 65)
     np.testing.assert_array_almost_equal(cl, self.cla, decimal=8)
Example #18
0
 def test_anafast_nomask(self):
     cl = hp.anafast(hp.remove_monopole(self.map1[0].data), lmax=self.lmax)
     self.assertEqual(len(cl), 65)
     np.testing.assert_array_almost_equal(cl, self.cl_fortran_nomask, decimal=8)
Example #19
0
def powspec(nside,
            theta,
            phi,
            res,
            Conf=0.68,
            remove_monopole=True,
            remove=[],
            shift=False):
    #Generating a map of the residuals
    residuals = pixres(nside, theta, phi, res)
    numresiduals = pixarr(nside, theta, phi)

    residuals[remove] = hp.UNSEEN
    numresiduals[remove] = 0.
    for i in range(len(numresiduals)):
        if numresiduals[i] == hp.UNSEEN:
            numresiduals[i] = 0.

    print 'Number of SN Used:', sum(numresiduals)
    blockPrint()
    if remove_monopole == True:
        residuals = hp.remove_monopole(residuals)
    enablePrint()

    #Finding Norm Factor
    dA = hp.nside2pixarea(nside)
    omg_sky = 4 * pi - dA * np.count_nonzero(residuals == hp.UNSEEN)
    norz = (4 * pi / omg_sky)

    #Generating Data Spectrum
    cl_dat = hp.anafast(residuals)
    ell_dat = np.arange(len(cl_dat))

    #Running the Simulations and Finding Normal Spectrum + Error Bars
    x = []
    y = []

    mres = np.copy(res)
    for i in range(1001):
        np.random.shuffle(mres)
        mresiduals = pixres(nside, theta, phi, mres)

        blockPrint()
        if remove_monopole == True:
            mresiduals = hp.remove_monopole(mresiduals)
        enablePrint()

        cls = hp.anafast(mresiduals)
        ell = np.arange(len(cls))

        x.extend(ell)
        y.extend(cls)

    x = np.array(x)
    y = np.array(y)

    CI = CIL(Conf, x, y)

    ell_sim = CI[:, 0]
    cl_sim = CI[:, 1]
    err_sim = [CI[:, 2], CI[:, 3]]
    print "done"
    return ell_dat, cl_dat, ell_sim, cl_sim, err_sim, norz
Example #20
0
    # file names for the input high resolution FITS map and an optional
    # downgraded and smoothed version of the same map (when save_lowres is
    # enabled)

    fn_hires \
        = '/project/projectdirs/planck/data/ffp8/mc_noise/{:03}/{:03}_{:02}/ffp8_noise_{:03}_full_map_mc_{:05}.fits'.format( \
           freq, freq, real_batch, freq, current_step )

    fn_lowres \
        = 'maps/mc_noise/{:03}/{:03}_{:02}/ffp8_noise_{:03}_full_map_mc_{:05}.fits'.format( \
          freq, freq, real_batch, freq, current_step )

    # Read the map from the appropriate Monte Carlo directory.
    maps[ifreq] = hp.read_map( fn_hires )
    # Remove a global offset from the map (ignores unobserved pixels)
    maps[ifreq] = hp.remove_monopole( maps[ifreq] )
    # Reduce the resolution first, makes the smoothing faster
    maps[ifreq] = hp.ud_grade( maps[ifreq], nside )
    # Apply the smoothing kernel
    maps[ifreq] = hp.smoothing( maps[ifreq], fwhm=fwhm, lmax=lmax )

    if freq < 545:
        maps[ifreq][ maps[ifreq] != hp.UNSEEN ] *= 1e6

dpi = 96
layouts = \
    { '1080p' : {'res':[1920, 1080], 'label_font_size':12, 'title_font_size':14, 'cbar_fraction':0.1, 'margins':None},
      '720p' : {'res':[1280, 720], 'label_font_size':10, 'title_font_size':12, 'cbar_fraction':0.15, 'margins':None},
      '480p' : {'res':[720, 480], 'label_font_size':8, 'title_font_size':10, 'cbar_fraction':0.1, 'margins':None} }

for layout in layouts.itervalues():
m30rh2=hp.ma(hp.read_map(f30rh2,[0,1,2]))
m30ss1=hp.ma(hp.read_map(f30ss1,[0,1,2])) 
m30ss2=hp.ma(hp.read_map(f30ss2,[0,1,2]))

m30ss1rh1=hp.ma(hp.read_map(f30ss1rh1,[0,1,2])) 
m30ss1rh2=hp.ma(hp.read_map(f30ss1rh2,[0,1,2]))
m30ss2rh1=hp.ma(hp.read_map(f30ss2rh1,[0,1,2])) 
m30ss2rh2=hp.ma(hp.read_map(f30ss2rh2,[0,1,2]))

m30rhdiff=[]
m30ssdiff=[]
m30ssrhdiff=[]
for m1,m2 in zip(m30rh1,m30rh2):
    m1.mask=tmask30|m1.mask|m2.mask
    m2.mask=tmask30|m1.mask|m2.mask
    m30rhdiff.append(hp.remove_monopole(m1-m2)/2.)
    frac30rh =(1-float(m1.mask.sum())/len(m1.mask))     
for m1,m2 in zip (m30ss1,m30ss2):
    m1.mask=tmask30|m1.mask|m2.mask
    m2.mask=tmask30|m1.mask|m2.mask
    m30ssdiff.append(hp.remove_monopole(m1-m2)/2.)
    frac30ss=(1-float(m1.mask.sum())/len(m1.mask))     
for m1a,m1b,m2a,m2b in zip (m30ss1rh1,m30ss1rh2,m30ss2rh1,m30ss2rh2):
    m1a.mask=tmask30|m1a.mask|m2a.mask|m1b.mask|m2b.mask
    m1b.mask=m1a.mask
    m2a.mask=m1a.mask
    m2b.mask=m1a.mask
    m30ssrhdiff.append(hp.remove_monopole(m1a+m2a-m1b-m2b)/4.)
    frac30ssrh=(1-float(m1a.mask.sum())/len(m1a.mask)) 

# <codecell>
Example #22
0
 def test_anafast(self):
     cl = hp.anafast(hp.remove_monopole(self.map1[0].filled()),
                     lmax=self.lmax)
     self.assertEqual(len(cl), 65)
     np.testing.assert_array_almost_equal(cl, self.cla, decimal=8)
Example #23
0
NSIDE = 32
hit = hp.ud_grade(ft + al, NSIDE, power=-2)

noise = {8: 308, 10: 307, 15: 163}  #microK rt Sec
fsamp = 30.  #Hz

#for freq, no in zip([8, 10, 15], noise):
freq = 8
key = 'map'
if freq == 8:
    key = 'brian'
signal = gal2eq(
    hp.remove_monopole(hp.ud_grade(
        hp.read_map(
            '/smbmount/data1/COFE/Simulations/COFE_simulationPSMv163/cofe1/frequency_maps/coadded%s_%dGhz.fits'
            % (key, freq)), NSIDE),
                       gal_cut=50))
if freq == 8:
    signal *= 1.e3

noise_map = noise[freq] / np.sqrt(hit * 1 / fsamp) / 1e3

signoise = hp.ma(np.absolute(signal) / noise_map)
signoise.mask = hit == 0
hp.mollview(signoise,
            min=1,
            max=10.,
            coord='CG',
            title='Signal to noise at %d GHz' % freq,
            xsize=2000,
OPTIONS, ARGS = parse_command_line()
validate_args(OPTIONS, ARGS)

Map = create_namedtuple_for_map(OPTIONS)

########################################
# Read the input maps in memory

INPUT_MAPS = []
for cur_title, cur_map_file in zip(*[iter(ARGS)] * 2):
    try:
        log.info('reading map `%s\'...', cur_map_file)
        cur_map = healpy.read_map(cur_map_file, field=OPTIONS.stokes_component)

        if OPTIONS.no_monopole:
            result = healpy.remove_monopole(cur_map, fitval=True, copy=False)
            log.info('monopole has been removed (%s)', str(result))
        if OPTIONS.no_dipole:
            result = healpy.remove_dipole(cur_map, fitval=True, copy=False)
            log.info('dipole has been removed (amplitude: %s)',
                     str(result))
            
        cur_map[cur_map < -1.6e+30] = np.NaN

        if type(OPTIONS.mask) is not None:
            cur_map[OPTIONS.mask == 0] = np.NaN

        cur_entry = dict(title=cur_title,
                         pixels=cur_map,
                         input_file=cur_map_file)
        if OPTIONS.plot_distributions:
Example #25
0
"""
STEP 5: Removing monopole and dipole
"""

mapa = hp.read_map('LFI_CompMap_Foregrounds-smica_1024_R2.00.fits')

hp.mollview(mapa, norm='hist', title='all multipoles')
#pyplot.savefig('foreg_all_multipoles.png')

print('<mapa> =', np.mean(mapa))

####################
# Removing DIPOLE:::

mapa2 = hp.remove_monopole(mapa)

print('<mapa2> =', np.mean(mapa2))

hp.mollview(mapa2, norm='hist', title='l >= 1')
#pyplot.savefig('foreg_lge1.png')

mapa_mono = mapa - mapa2
print(mapa_mono)

hp.mollview(mapa_mono, norm='hist', title='l = 0 (monopole)')
pyplot.savefig('foreg_l1.png')

# with and without gal_cut ... 
# Compare:::
        nside = 1024
    else:
        nside = 2048

    print(freq)
    cmb = hp.ud_grade(cmb_hires, nside)
    psmask = hp.ud_grade(
        hp.read_map(hfi_pipe + 'psmask_{:03}.fits'.format(freq)), nside) < .9
    fname = '/global/cscratch1/sd/keskital/npipe_maps/' \
            '{}/{}_{:03}_map.fits'.format(ver, ver, freq)
    if not os.path.isfile(fname):
        fname = '/global/cscratch1/sd/keskital/npipe_maps/' \
                '{}/{}_{:03}-1_map.fits'.format(ver, ver, freq)
    freqmap = hp.ud_grade(hp.read_map(fname), nside)
    freqmap -= cmb
    freqmap = hp.remove_monopole(freqmap, gal_cut=70)
    low, high = threshhold
    mask_low = np.ones(freqmap.size, dtype=np.float32)
    mask_high = np.ones(freqmap.size, dtype=np.float32)
    weighted_low = freqmap > low
    weighted_high = freqmap > high
    mask_low[weighted_low] = (low / freqmap[weighted_low])
    mask_high[weighted_high] = (high / freqmap[weighted_high])
    mask_low[psmask] *= 1e-10
    mask_high[psmask] *= 1e-10
    mask_madam = mask_high > 0.9
    plt.figure(1)
    hp.mollview(mask_low,
                xsize=1200,
                title='{}GHz'.format(freq),
                sub=[nrow, ncol, iplot + 1])
l = [70,143,217,353,545,857]
freqs = [100] + l
fs = ["/scratch/r/rbond/msyriac/data/sims/websky/new_cib/cib_ns4096_nu%s.fits" % str(x).zfill(4) for x in  freqs]
f0 = 100.

acls = []

anis = []
monos = []



for i,f in enumerate(fs):

    freq = freqs[i]
    print(freq)
    imap = hp.read_map(f)
    _,mono = hp.remove_monopole(imap,fitval=True)

    ialm = hp.map2alm(imap)
    cls = hp.alm2cl(ialm)
    ells = np.arange(len(cls))
    acls.append(cls)

    anis.append(cls[np.logical_and(ells>4000,ells<6000)].mean())
    monos.append(mono)

    

io.save_cols(os.environ['WORK'] + "/new_cib.txt",(freqs,monos,anis))