nawrapper package

Submodules

nawrapper.covtools module

Power spectrum objects and utilities.

nawrapper.covtools.compute_covmat(namap1, namap2, bins, mc_11=None, mc_12=None, mc_22=None, signal=None, noise=None, smoothing_window=11, smoothing_polyorder=3, cosmic_variance=True, verbose=True)

Compute all of the relevant covariances between two namap.

This computes all covarainces between two nawrapper.power.abstract_namap for which there is information.

Parameters
  • namap1 (nawrapper.power.namap_hp or) – nawrapper.ps.namap_car. The first map to compute correlations with.

  • namap2 (nawrapper.power.namap_hp or) – nawrapper.ps.namap_car. To be correlated with namap1.

  • bins (NaMaster NmtBin object) – The binning scheme used for this. This must match the mode-coupling objects, if you pass those.

  • mc_11 (nawrapper.power.mode_coupling object (optional)) – This object contains precomputed mode-coupling matrices for the auto-spectrum of namap1.

  • mc_12 (nawrapper.power.mode_coupling object (optional)) – This object contains precomputed mode-coupling matrices for the cross-spectrum between namap1 and namap2.

  • mc_22 (nawrapper.power.mode_coupling object (optional)) – This object contains precomputed mode-coupling matrices for the auto-spectrum of namap2.

  • signal (dictionary) – The unbinned input spectra, must have keys TT, TE, EE, etc. Any unspecified signal spectra will be estimated from the cross- spectrum beteween namap1 and namap2.

  • noise (dictionary) – The unbinned noise power spectra. Must have keys T1T1, T2T2, and others of the form XiYj, where X,Y are in T, E, B, and i,j are 1 or 2. These refer to the noise spectra in various maps. Unspecified noise where i == j will be computed from the auto minus cross-spectra, and i != j will be set to zero.

smoothing_windowint

Savgol filter smoothing window, for smoothing the estimated signal and noise spectra.

smoothing_polyorderint

Savgol filter polynomial order, for smoothing the estimated signal and noise spectra.

Returns

Binned covariances, with the relevant covariances (i.e. TETT) as dictionary keys. This also contains the bin centers as key ‘ell’.

Return type

dictionary

nawrapper.covtools.delta(a, b)
nawrapper.covtools.get_Nl(theta_fwhm=(10.0, 7.0, 5.0), sigma_T=(68.1, 42.6, 65.4), f_sky=0.6, l_min=2, l_max=2509, verbose=False)

Get Knox TT noise curve. Uses the Planck bluebook parameters by default.

Parameters
  • theta_fwhm (list of float:) – beam resolution in arcmin

  • sigma_T (list of float) – temperature resolution in muK

  • sigma_P (list of float) – polarization resolution in muK

  • f_sky (float) – sky fraction covered

  • l_min (int) – minimum ell for CMB power spectrum

  • l_max (int) – maximum ell for CMB power spectrum

  • verbose (bool) – flag for printing out debugging output

class nawrapper.covtools.nacov(namap1, namap2, mc_11, mc_12, mc_22, signal=None, noise=None, noise_smoothing_mode='savgol', smoothing_window=11, smoothing_polyorder=3, cosmic_variance=True)

Bases: object

Wrapper around the NaMaster covariance workspace object.

This object contains the computationally intensive parts of covariance computation – the coupling coefficients.

Create a nacov object.

Parameters
  • namap1 (namap) – We use the mask in this namap to compute the mode-coupling matrices.

  • namap2 (namap) – We use the mask in this namap to compute the mode-coupling matrices.

cl_inputs(s1, s2, m1, m2)
compute(verbose=False)
compute_subcovmat(spins)
get_cov_input_spectra(spins)
get_field(namap_in, field_spin)
get_smooth_noise(cb, signal, smoothing_polyorder)
smooth_and_interpolate(lb, cb, smoothing_window, smoothing_polyorder)
total_spec(XY, m1, m2)

nawrapper.maptools module

Utility functions for preprocessing maps.

nawrapper.maptools.apod_C2(input_mask, radius)

Apodizes an input mask over a radius in degrees.

A sharp mask will cause complicated mode coupling and ringing. One solution is to smooth out the sharp edges. This function applies the C2 apodisation as defined in 0903.2350.

Parameters
  • input_mask (enmap) – The input mask (must have all pixel values be non-negative).

  • radius (float) – Apodization radius in degrees.

Returns

result – The apodized mask.

Return type

enmap

nawrapper.maptools.get_cmb_sim_hp(signal, nside_out)

Generate a healpix realization of the spectra.

Parameters
  • signal (dictionary) – dictionary containing spectra starting from ell = 0 with keys TT, EE, BB, TE.

  • nside_out (int) – output map resolution

nawrapper.maptools.get_distance(input_mask)

Construct a map of the distance to the nearest zero pixel in the input.

Parameters

input_mask (enmap) – The input mask

Returns

dist – This map is the same size as the input_mask. Each pixel of this map contains the distance to the nearest zero pixel at the corresponding location in the input_mask.

Return type

enmap

nawrapper.maptools.kfilter_map(m, apo, kx_cut, ky_cut, unpixwin=True, legacy_steve=False)

Apply a k-space filter on a map.

By default, we do not reproduce the output of Steve’s code. We do offer this functionality: set the optional flag legacy_steve=True to offset the mask and the map by one pixel in each dimension.

You should filter both in temperature and polarization.

Parameters
  • m (enmap) – Input map which this function will filter.

  • apo (enmap) –

    This map is a smooth tapering of the edges of the map, to be multiplied into the map prior to filtering. The filtered map is divided by the nonzero pixels of this map at the end. This is required because maps of actual data are unlikely to be periodic, which will induce ringing when one applies a k-space filter. To solve this, we taper the edges of the map to zero prior to filtering.

    See nawrapper.ps.rectangular_apodization()

  • kx_cut (float) – We cut modes with wavenumber \(|k_x| < k_x^{\mathrm{cut}}\).

  • ky_cut (float) – We cut modes with wavenumber \(|k_y| < k_y^{\mathrm{cut}}\).

  • unpixwin (bool) – Correct for the CAR pixel window if True.

  • legacy_steve (bool) – Use a slightly different filter if True, to reproduce Steve’s pipeline. Steve’s k-space filter as of June 2019 had a bug where two k-space modes (the most positive cut mode in x and most negative cut mode in y) were not cut. This has a very small effect on the spectrum, but for reproducibility purposes we offer this behavior. By default we do not use this. To reproduce Steve’s code behavior you should set legacy_steve=True.

Returns

result – The map with the specified k-space filter applied.

Return type

enmap

nawrapper.maptools.legacy_steve_shift(target_enmap)

Applies a one-pixel shift to the WCS for reproducing Steve spectra.

Parameters

target_enmap – enmap The enmap whose WCS we will modify in place.

nawrapper.maptools.preprocess_fourier(target_enmap, shape=None, wcs=None, unpixwin=True, kx_cut=90, ky_cut=50, apo_width=40, legacy_steve=False)

Correct an enmap for the pixel window and filter in Fourier space.

This function performs the typical map preprocessing that occurs in ACT map analysis. A CAR map has an anisotropic pixel window, which is easily corrected in Fourier space. It is convenient to combine this step with any filtering of Fourier modes that made be necessary while you have the Fourier-transformed maps, such as removing horizontal noise modes.

If you specify map geometry information by passing shape and wcs, the map will be extracted to that geometry before applying the Fourier transform. In order to avoid ringing at the map edges, it’s useful to generate a rectangular taper, which is done in this function according to this specified shape and WCS information. If these are not specified, it is assumed that the full map will be used as the region for power spectrum calculation, and the taper will be constructed at the edges of the full map inwards. The taper width is specified by apo_width.

Parameters
  • target_enmap (enmap) – The enmap to be modified

  • shape ([tuple of ints], optional) – extraction map shape, by default None

  • wcs (astropy.wcs, optional) – extraction map WCS information, by default None

  • unpixwin (bool, optional) – Correct for the CAR pixel window if True, by default True

  • kx_cut (int, optional) – We cut modes with wavenumber: math: | k_x | < k_x ^ {mathrm{cut}}, by default 90

  • ky_cut (int, optional) – We cut modes with wavenumber: math: | k_y | < k_y ^ {mathrm{cut}}, by default 50

  • apo_width (int, optional) – width of the rectangular taper for the apodized mask, by default 40

  • legacy_steve (bool, optional) – Use a slightly different filter if True, to reproduce Steve’s pipeline. Steve’s k-space filter as of June 2019 had a bug where two k-space modes (the most positive cut mode in x and most negative cut mode in y) were not cut. This has a very small effect on the spectrum, but for reproducibility purposes we offer this behavior. By default False

Returns

the final processed map

Return type

enmap

nawrapper.maptools.rectangular_apodization(shape, wcs, width, N_cut=0)

Generate a tapered mask at the edges of the box.

Maps of actual data are unlikely to be periodic, which will induce ringing when one applies a k-space filter. To solve this, we taper the edges of the map to zero prior to filtering. This taper was written to match the output of Steve’s power spectrum pipeline, for reproducibility.

See nawrapper.maptools.kfilter_map().

Parameters
  • shape (tuple of ints) – Shape of the map to be tapered.

  • wcs (astropy wcs object) – WCS information for the map

  • width (float) – width of the taper

  • N_cut (int) – number of pixels to set to zero at the edges of the map

Returns

apo – A smooth mask that is one in the center and tapers to zero at the edges.

Return type

enmap

nawrapper.maptools.sub_mono_di(map_in, mask_in, nside, sub_dipole=True, verbose=False)

Subtract monopole and dipole from a healpix map.

nawrapper.planck module

Utility functions for processing Planck maps into spectra.

class nawrapper.planck.PlanckCov(ellspath, covpath='covmat.dat', clpath='data_extracted.dat')

Bases: object

get_spec(spec)
get_subcov(spec1, spec2=None, verbose=True)

spec: {TT, TE, or EE}, {‘100x100’, ‘143x143’, ‘143x217’, ‘217x217’} cross: string, i.e.

returns tuple:

ells, cl, subcovariance matrix

nawrapper.planck.get_half_mission_namap(freq1, freq2, map_dir, mask_dir, beam_dir)
nawrapper.planck.get_planck_total_spectrum(theory_file, foreground_file, lmax)
nawrapper.planck.load_planck_half_missions(map_dir, mask_dir, beam_dir, par=None, freq1='143', freq2='143', split1='1', split2='2')
nawrapper.planck.preprocess_maps(maps, masks, missing_pixel, pol_eff, nside)

nawrapper.power module

Power spectrum objects and utilities.

class nawrapper.power.abstract_namap(maps, masks=None, beams=None, unpixwin=True, verbose=True)

Bases: object

Object for organizing map products.

Generic abstract

Objects which inherit from this will organize the various ingredients that are required for a map to be used in power spectra analysis. Each map has an associated

  1. IQU maps

  2. mask, referring to the product of hits, point source mask, etc.

  3. beam transfer function

Parameters
  • maps (ndarray or tuple) – The maps you want to operate on. This needs to be a tuple of length 3, or an array of length (3,) + map.shape.

  • masks (ndarray or tuple) – The masks you want to operate on.

  • beams (list or tuple) – The beams you want to use.

  • unpixwin (bool) – If true, we account for the pixel window function when computing power spectra. For healpix this is accomplished by modifying the beam in-place.

  • verbose (bool) – Print various information about what is being assumed. You should probably enable this the first time you try to run a particular scenario, but you can set this to false if you find it’s annoying to have it printing so much stuff, like if you are computing many spectra in a loop.

set_beam(apply_healpix_window=False, verbose=False)

Set and extend the object’s beam up to lmax.

nawrapper.power.bin_spec_dict(Cb, binleft, binright, lmax)

Bin an unbinned spectra dictionary with a specified l^2 binning.

nawrapper.power.compute_spectra(namap1, namap2, bins=None, mc=None, lmax=None, verbose=True)

Compute all of the spectra between two maps.

This computes all cross spectra between two nawrapper.power.abstract_namap for which there is information. For example, TE spectra will be computed only if the first map has a temperature map, and the second has a polarization map.

Parameters
  • namap1 (nawrapper.power.namap_hp or) – nawrapper.ps.namap_car. The first map to compute correlations with.

  • namap2 (nawrapper.power.namap_hp or) – nawrapper.ps.namap_car. To be correlated with namap1.

  • bins (NaMaster NmtBin object (optional)) – At least one of bins or mc must be specified. If you specify bins (possibly from the output of nawrapper.power.read_bins()) then a new mode coupling matrix will be computed within this function call. If you have already computed a relevant mode-coupling matrix, then pass mc instead.

  • mc (nawrapper.power.mode_coupling object (optional)) – This object contains precomputed mode-coupling matrices.

Returns

Cb – Binned spectra, with the relevant cross spectra (i.e. ‘TT’, ‘TE’, ‘EE’) as dictionary keys. This also contains the bin centers as key ‘ell’.

Return type

dictionary

nawrapper.power.create_binning(lmax, lmin=2, widths=1, weight_function=None)

Create a nabin object conveniently.

nawrapper.power.mkdir_p(path)

Make a directory and its parents.

class nawrapper.power.mode_coupling(namap1=None, namap2=None, bins=None, mcm_dir=None, overwrite=False, verbose=True, n_iter=None, **kwargs)

Bases: object

Wrapper around the NaMaster workspace object.

This object contains the computationally intensive parts of mode coupling. It stores w00, the (spin-0, spin-0) mode coupling matrix, and optionally w02, w20, and w22, the (spin-0, spin-2), (spin-2, spin-0) and (spin-2, spin-2) mode coupling matrices if both maps have polarization data.

Create a mode_coupling object.

namap1: namap

We use the mask in this namap to compute the mode-coupling matrices.

namap2: namap

We use the mask in this namap to compute the mode-coupling matrices.

bins: pymaster NmtBin object

We generate binned mode coupling matrices with this NaMaster binning object.

mcm_dir: string

Specify a directory which contains the workspace files for this mode-coupling object.

compute_master(f_a, f_b, wsp)

Compute mode-coupling-corrected spectra.

Parameters
  • f_a (NmtField) – First field to correlate.

  • f_b (NmtField) – Second field to correlate.

  • wsp (NmtWorkspace) – Workspace containing the mode coupling matrix and binning.

Returns

Contains the TT spectrum if correlating two spin-0 maps, or the TE/TB or EE/EB spectra if working with (spin-0, spin-2) and (spin-2, spin-2) maps respectively.

Return type

numpy array

load_from_dir(mcm_dir)

Read information from a nawrapper mode coupling directory.

write_to_dir(mcm_dir)
class nawrapper.power.nabin(lmax, bpws=None, ells=None, weights=None, nlb=None, is_Dell=False, f_ell=None)

Bases: pymaster.bins.NmtBin

class nawrapper.power.namap_car(maps, masks=None, beams=None, verbose=True, sub_shape=None, sub_wcs=None, purify_e=False, purify_b=False, n_iter=0, lmax_sht=- 1, **kwargs)

Bases: nawrapper.power.abstract_namap

Map container for CAR pixellization

Generate a CAR map container

This bundles CAR pixelization map products, in particular

  1. IQU maps

  2. mask, referring to the product of hits, point source mask, etc.

  3. beam transfer function

Parameters
  • maps (ndarray or tuple) – The maps you want to operate on. This needs to be a tuple of length 3, or an array of length (3,) + map.shape.

  • masks (ndarray or tuple) – The masks you want to operate on.

  • beams (list or tuple) – The beams you want to use.

  • verbose (bool) – Print various information about what is being assumed. You should probably enable this the first time you try to run a particular scenario, but you can set this to false if you find it’s annoying to have it printing so much stuff, like if you are computing many spectra in a loop.

class nawrapper.power.namap_hp(maps, masks=None, beams=None, unpixwin=True, verbose=True, n_iter=3, purify_e=False, purify_b=False, **kwargs)

Bases: nawrapper.power.abstract_namap

Generate a healpix map container

This bundles healpix pixelization map products, in particular

  1. IQU maps

  2. mask, referring to the product of hits, point source mask, etc.

  3. beam transfer function

Parameters
  • maps (ndarray or tuple) – The maps you want to operate on. This needs to be a tuple of length 3, or an array of length (3,) + map.shape.

  • masks (ndarray or tuple) – The masks you want to operate on.

  • beams (list or tuple) – The beams you want to use.

  • unpixwin (bool) – If true, we account for the pixel window function when computing power spectra. For healpix this is accomplished by modifying the beam in-place.

  • n_iter (int) – Number of spherical harmonic iterations, because healpix is not a very good pixellization.

  • verbose (bool) – Print various information about what is being assumed. You should probably enable this the first time you try to run a particular scenario, but you can set this to false if you find it’s annoying to have it printing so much stuff, like if you are computing many spectra in a loop.

nawrapper.power.read_beam(beam_file)

Read a beam file from disk.

This function will interpolate a beam file with columns \(\ell, B_{\ell}\) to a 1D array where index corresponds to \(\ell\).

Parameters
  • beam_file (str) – The filename of the beam

  • multiply_healpix_window (bool) –

Returns

Contains the beam \(B_{\ell}\) where index i corresponds to multipole i (i.e. this array starts at ell = 0).

Return type

numpy array (float)

nawrapper.power.read_bins(file, lmax=7925, is_Dell=False)

Read bins from an ASCII file and create a NmtBin object.

This is a utility function to read ACT binning files and create a NaMaster NmtBin object. The file format consists of three columns: the left bin edge (int), the right bin edge (int), and the bin center (float).

Parameters
  • file (str) – Filename of the binning to read.

  • lmax (int) – Maximum ell to create bins to.

  • is_Dell (bool) – Will generate \(D_{\ell} = \ell (\ell + 1) C_{\ell} / (2 \pi)\) if True, instead of \(C_{\ell}\). This may cause order 1% effects due to weighting inside bins.

Returns

b – Returns a NaMaster binning object.

Return type

pymaster.NmtBin

nawrapper.power.util_bin_FFT_CAR(map1, map2, mask, beam1, beam2, lmax=8000)

Compute the FFTs, multiply, bin

Beams are multiplied at bin centers. This is the worst job you could do for calculating power spectra.

nawrapper.power.util_bin_FFTspec_CAR(data, modlmap, bin_edges)

Module contents

Package init file.

We want the user to get everything right away upon import nawrapper as nw.