NaMaster
Macros | Functions
utils.h File Reference

Go to the source code of this file.

Macros

#define HE_NITER_DEFAULT   3
 Default number of iterations used for full-sky spherical harmonic transforms. More...
 

Functions

gsl_rng * init_rng (unsigned int seed)
 Initialize a random number generator. More...
 
double rng_01 (gsl_rng *rng)
 Top-hat random numbers. More...
 
int rng_poisson (double lambda, gsl_rng *rng)
 Poisson random numbers. More...
 
void rng_delta_gauss (double *module, double *phase, gsl_rng *rng, double sigma2)
 Gaussian random numbers (mod-phase). More...
 
void rng_gauss (gsl_rng *rng, double *r1, double *r2)
 Gaussian random numbers. More...
 
void end_rng (gsl_rng *rng)
 Destructor for random number generators. More...
 
int my_linecount (FILE *f)
 Count number of lines in an ASCII file. More...
 
void * my_malloc (size_t size)
 Error-checked malloc. More...
 
void * my_calloc (size_t nmemb, size_t size)
 Error-checked calloc. More...
 
FILE * my_fopen (const char *path, const char *mode)
 Error-checked fopen. More...
 
size_t my_fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream)
 Error-checked fwrite. More...
 
size_t my_fread (void *ptr, size_t size, size_t count, FILE *stream)
 Error-checked fread. More...
 
int drc3jj (int il2, int il3, int im2, int im3, int *l1min_out, int *l1max_out, double *thrcof, int size)
 Wigner 3-j symbols. More...
 
void moore_penrose_pinv (gsl_matrix *M, double threshold)
 Moore-Penrose pseudo-inverse. More...
 
void * dftw_malloc (size_t n)
 Wrapper around fftw_malloc More...
 
void dftw_free (void *p)
 Wrapper around fftw_free More...
 
void fs_mapcpy (nmt_flatsky_info *fs, flouble *destmap, flouble *srcmap)
 Copies a map. More...
 
void fs_map_product (nmt_flatsky_info *fs, flouble *mp1, flouble *mp2, flouble *mp_out)
 Multiplies two flat-sky maps. More...
 
flouble fs_map_dot (nmt_flatsky_info *fs, flouble *mp1, flouble *mp2)
 Dot product of flat-sky maps. More...
 
void fs_map2alm (nmt_flatsky_info *fs, int ntrans, int spin, flouble **map, fcomplex **alm)
 Flat-sky SHT. More...
 
void fs_alm2map (nmt_flatsky_info *fs, int ntrans, int spin, flouble **map, fcomplex **alm)
 Flat-sky inverse SHT. More...
 
nmt_k_functionfs_generate_beam_window (double fwhm_amin)
 Gaussian beam. More...
 
void fs_zero_alm (nmt_flatsky_info *fs, fcomplex *alm)
 Zero SHT coefficients. More...
 
void fs_alter_alm (nmt_flatsky_info *fs, double fwhm_amin, fcomplex *alm_in, fcomplex *alm_out, nmt_k_function *window, int add_to_out)
 Multiply SHT coefficients by beam. More...
 
void fs_alm2cl (nmt_flatsky_info *fs, nmt_binning_scheme_flat *bin, fcomplex **alms_1, fcomplex **alms_2, int spin_1, int spin_2, flouble **cls, flouble lmn_x, flouble lmx_x, flouble lmn_y, flouble lmx_y)
 Computes Flat-sky power spectrum from Fourier coefficients. More...
 
void fs_anafast (nmt_flatsky_info *fs, nmt_binning_scheme_flat *bin, flouble **maps_1, flouble **maps_2, int spin_1, int spin_2, flouble **cls)
 Computes Flat-sky power spectrum from maps. More...
 
fcomplex ** fs_synalm (int nx, int ny, flouble lx, flouble ly, int nmaps, nmt_k_function **cells, nmt_k_function **beam, int seed)
 Gaussian realizations of flat-sky Fourier coefficients. More...
 
floublefs_read_flat_map (char *fname, int *nx, int *ny, flouble *lx, flouble *ly, int nfield)
 Reads flat-sky map. More...
 
long he_nside2npix (long nside)
 HEALPix number of pixels. More...
 
void he_pix2vec_ring (long nside, long ipix, double *vec)
 HEALPix pix2vec. More...
 
long he_ang2pix (long nside, double cth, double phi)
 Modified HEALPix ang2pix. More...
 
long he_nalms (int lmax)
 Number of alm coefficients. More...
 
long he_indexlm (int l, int m, int lmax)
 Harmonic coefficient ordering. More...
 
void he_alm2map (nmt_curvedsky_info *cs, int lmax, int ntrans, int spin, flouble **maps, fcomplex **alms)
 Full-sky inverse SHT. More...
 
void he_map2alm (nmt_curvedsky_info *cs, int lmax, int ntrans, int spin, flouble **maps, fcomplex **alms, int niter)
 Full-sky SHT. More...
 
void he_alm2cl (fcomplex **alms_1, fcomplex **alms_2, int spin_1, int spin_2, flouble **cls, int lmax)
 Computes Full-sky power spectrum from harmonic coefficients. More...
 
int he_get_largest_possible_lmax (nmt_curvedsky_info *cs)
 Gets the multipole approximately corresponding to the Nyquist frequency. More...
 
int he_get_lmax (nmt_curvedsky_info *cs)
 Get maximum multipole allowed by sky geometry configuration. More...
 
void he_anafast (flouble **maps_1, flouble **maps_2, int spin_1, int spin_2, flouble **cls, nmt_curvedsky_info *cs, int lmax, int iter)
 Computes Full-sky power spectrum from maps. More...
 
void he_write_healpix_map (flouble **tmap, int nfields, long nside, char *fname)
 Writes full-sky maps to FITS file. More...
 
void he_write_CAR_map (flouble **tmap, int nfields, nmt_curvedsky_info *sky_info, char *fname)
 Writes CAR maps to FITS file. More...
 
nmt_curvedsky_infohe_get_file_params (char *fname, int is_healpix, int *nfields, int *isnest)
 Read map parameters from FITS file. More...
 
floublehe_read_map (char *fname, nmt_curvedsky_info *sky_info, int nfield)
 Reads full-sky map from FITS file. More...
 
int he_ring_num (long nside, double z)
 HEALPix ring number. More...
 
void he_query_strip (long nside, double theta1, double theta2, int *pixlist, long *npix_strip)
 Returns pixel indices in a given latitude strip. More...
 
void he_ring2nest_inplace (flouble *map_in, long nside)
 Transform from RING to NEST. More...
 
void he_nest2ring_inplace (flouble *map_in, long nside)
 Transform from NEST to RING. More...
 
void he_in_ring (int nside, int iz, flouble phi0, flouble dphi, int *listir, int *nir)
 Returns pixel indices in a given ring. More...
 
void he_query_disc (int nside, double cth0, double phi, flouble radius, int *listtot, int *nlist, int inclusive)
 Returns pixel indices in a given disc. More...
 
void he_udgrade (flouble *map_in, long nside_in, flouble *map_out, long nside_out, int nest)
 Up/down grade map resolution. More...
 
double * he_generate_beam_window (int lmax, double fwhm_amin)
 Gaussian beam. More...
 
void he_zero_alm (int lmax, fcomplex *alm)
 Zero SHT coefficients. More...
 
void he_alter_alm (int lmax, double fwhm_amin, fcomplex *alm_in, fcomplex *alm_out, double *window, int add_to_out)
 Multiply SHT coefficients by beam. More...
 
flouble he_get_pix_area (nmt_curvedsky_info *cs, long i)
 Computes pixel area. More...
 
void he_map_product (nmt_curvedsky_info *cs, flouble *mp1, flouble *mp2, flouble *mp_out)
 Multiplies two full-sky maps. More...
 
flouble he_map_dot (nmt_curvedsky_info *cs, flouble *mp1, flouble *mp2)
 Dot product of full-sky maps. More...
 
fcomplex ** he_synalm (nmt_curvedsky_info *cs, int nmaps, int lmax, flouble **cells, flouble **beam, int seed)
 Gaussian realizations of full-sky harmonic coefficients. More...
 
int cov_get_coupling_pair_index (int na, int nc, int nb, int nd, int ia1, int ia2, int ic1, int ic2, int ib1, int ib2, int id1, int id2)
 

Macro Definition Documentation

#define HE_NITER_DEFAULT   3

Default number of iterations used for full-sky spherical harmonic transforms.

Function Documentation

int cov_get_coupling_pair_index ( int  na,
int  nc,
int  nb,
int  nd,
int  ia1,
int  ia2,
int  ic1,
int  ic2,
int  ib1,
int  ib2,
int  id1,
int  id2 
)
void dftw_free ( void *  p)

Wrapper around fftw_free

Wrapping function to support simultaneously single and double precision FFTW memory freeing.

Parameters
pPointer to free.
void* dftw_malloc ( size_t  n)

Wrapper around fftw_malloc

Wrapping function to support simultaneously single and double precision FFTW memory allocation.

Parameters
nNumber of bytes to allocate
Returns
Allocated pointer.
int drc3jj ( int  il2,
int  il3,
int  im2,
int  im3,
int *  l1min_out,
int *  l1max_out,
double *  thrcof,
int  size 
)

Wigner 3-j symbols.

Returns all non-zero wigner-3j symbols

\[ \left( \begin{array}{ccc} \ell_1 & \ell_2 & \ell_3 \\ m_1 & m_2 & m_3 \end{array} \right), \]

for

Parameters
il2= $\ell_2$
im2= $m_2$
il3= $\ell_3$
im3= $m_3$
l1min_outMinimum value of $\ell_1$ allowed by selection rules (output).
l1max_outMaximum value of $\ell_1$ allowed by selection rules (output).
thrcofOutput array that will contain the values of the wigner-3j symbols for l1min_out $\leq\ell_1\leq$ l1max_out.
sizeNumber of elements allocated for thrcof.

Note that the selection rule $m_1+m_2+m_3=0$ completely fix $m_3$.

void end_rng ( gsl_rng *  rng)

Destructor for random number generators.

void fs_alm2cl ( nmt_flatsky_info fs,
nmt_binning_scheme_flat bin,
fcomplex **  alms_1,
fcomplex **  alms_2,
int  spin_1,
int  spin_2,
flouble **  cls,
flouble  lmn_x,
flouble  lmx_x,
flouble  lmn_y,
flouble  lmx_y 
)

Computes Flat-sky power spectrum from Fourier coefficients.

Bins the product of two sets of Fourier coefficients into bandpowers.

Parameters
fsnmt_flatsky_info structure describing the flat-sky patch.
binnmt_binning_scheme_flat structure defining the bandpowers to use.
alms_1First set of Fourier coefficients to correlate.
alms_2Second set of Fourier coefficients to correlate.
spin_1alms_1 spin.
spin_2alms_2 spin.
clsWill hold the output power spectra. Should have shape [ncls][nbands], where ncls is the appropriate number of power spectra given the spins of the input fields (e.g. ncls = 2*2 = 4 if both fields have spin=2) and nbpw is the number of bandpowers defined by bin.
lmn_xLower end of the range of multipoles in the x direction that should be masked.
lmx_xUpper end of the range of multipoles in the x direction that should be masked. if lmx_x < lmn_x, no Fourier-space masked is performed.
lmn_ySame as lmn_x for the y direction.
lmx_ySame as lmx_x for the y direction.
void fs_alm2map ( nmt_flatsky_info fs,
int  ntrans,
int  spin,
flouble **  map,
fcomplex **  alm 
)

Flat-sky inverse SHT.

Computes the inverse SHT of a set of spin-s flat-sky fields. See scientific documentation and companion paper for further details.

Parameters
fsnmt_flatsky_info structure describing the flat-sky patch.
ntransNumber of transfoms to carry out.
spinSpin of the fields to transform (0 or 2).
mapWill hold the output maps. Must have shape [ntrans * nmap][nx * ny], where nmap is 1 or 2 for spin-0 and spin-2 respectively, and (nx,ny) are the dimensions of the patch in the (x,y) directions as defined by fs.
almSHT coefficients to inverse-transform. Must have shape [ntrans * nmap][ny * (nx /2+1)], where nmap, nx and ny have been defined above.
void fs_alter_alm ( nmt_flatsky_info fs,
double  fwhm_amin,
fcomplex alm_in,
fcomplex alm_out,
nmt_k_function window,
int  add_to_out 
)

Multiply SHT coefficients by beam.

Multiplies a given set of flat-sky Fourier coefficients by a circularly-symmetric function.

Parameters
fsnmt_flatsky_info structure describing the flat-sky patch.
fwhm_aminFull-width at half-maximum of the Gaussian beam in arcminutes. Only used if window is a NULL pointer.
alm_inInput Fourier coefficients.
alm_outOutput Fourier coefficients.
windownmt_k_function defining the function to multiply the coefficients by. Pass a NULL pointer if you want a Gaussian beam with a FWHM defined by fwhm_amin.
add_to_outIf >0, the result of multiplying alm_in with the window function will be added to the current contents of alm_out. Otherwise, alm_out is overwritten with the product.
void fs_anafast ( nmt_flatsky_info fs,
nmt_binning_scheme_flat bin,
flouble **  maps_1,
flouble **  maps_2,
int  spin_1,
int  spin_2,
flouble **  cls 
)

Computes Flat-sky power spectrum from maps.

Similar to fs_alm2cl() but starting from maps.

Parameters
fsnmt_flatsky_info structure describing the flat-sky patch.
binnmt_binning_scheme_flat structure defining the bandpowers to use.
maps_1First set of maps to correlate.
maps_2Second set of maps to correlate.
spin_1maps_1 spin.
spin_2maps_2 spin.
clsWill hold the output power spectra. Should have shape [ncls][nbands], where ncls is the appropriate number of power spectra given the spins of the input fields (e.g. ncls = 2*2 = 4 if both fields have spin=2). and nbpw is the number of bandpowers defined by bin.
nmt_k_function* fs_generate_beam_window ( double  fwhm_amin)

Gaussian beam.

Generates an nmt_k_function structure defining a circularly symmetric Gaussian beam for flat-sky fields.

Parameters
fwhm_aminFull-width at half-maximum of the beam in arcminutes.
Returns
nmt_k_function defining the beam.
void fs_map2alm ( nmt_flatsky_info fs,
int  ntrans,
int  spin,
flouble **  map,
fcomplex **  alm 
)

Flat-sky SHT.

Computes the direct SHT of a set of spin-s flat-sky fields. See scientific documentation and companion paper for further details.

Parameters
fsnmt_flatsky_info structure describing the flat-sky patch.
ntransNumber of transfoms to carry out.
spinSpin of the fields to transform (0 or 2).
mapMaps to transform. Must have shape [ntrans * nmap][nx * ny], where nmap is 1 or 2 for spin-0 and spin-2 respectively, and (nx,ny) are the dimensions of the patch in the (x,y) directions as defined by fs.
almWill hold the output SHT coefficients. Must have shape [ntrans * nmap][ny * (nx /2+1)], where nmap, nx and ny have been defined above.
flouble fs_map_dot ( nmt_flatsky_info fs,
flouble mp1,
flouble mp2 
)

Dot product of flat-sky maps.

Computes the integral over the patch of the product of two maps:

\[ \int_\Omega d\Omega\, m_1(\hat{\bf n})\,m_2(\hat{\bf n}), \]

where $\Omega$ is the flat-sky patch defined by fs. The integral is computed as a Riemann sum over all pixels in the map.

Parameters
fsnmt_flatsky_info structure describing the flat-sky patch.
mp1First map to multiply.
mp2Second map to multiply.
Returns
Dot product.
void fs_map_product ( nmt_flatsky_info fs,
flouble mp1,
flouble mp2,
flouble mp_out 
)

Multiplies two flat-sky maps.

Parameters
fsnmt_flatsky_info structure describing the flat-sky patch.
mp1First map to multiply
mp2Second map to multiply.
mp_outOutput map containing the product of mp1 and mp2. It is safe to pass either of the input maps as mp_out, in which case that map will be overwritten with the product.
void fs_mapcpy ( nmt_flatsky_info fs,
flouble destmap,
flouble srcmap 
)

Copies a map.

Parameters
fsnmt_flatsky_info structure describing the flat-sky patch.
destmapMap to copy into.
destmapMap to copy from.
flouble* fs_read_flat_map ( char *  fname,
int *  nx,
int *  ny,
flouble lx,
flouble ly,
int  nfield 
)

Reads flat-sky map.

Reads a flat-sky map from a FITS file. The flat map should be in an image HDU with WCS header keywords defining the sky patch (read from file).

Parameters
fnamePath to input file.
nxNumber of grid points in the x dimension (read from file).
nyNumber of grid points in the y dimension (read from file).
lxLength of the x dimension (in steradians) (read from file).
lyLength of the y dimension (in steradians) (read from file).
nfieldWhich field to read (i.e. HDU number to read the map from, starting from 0).
Returns
Read map (with size ny * nx).
fcomplex** fs_synalm ( int  nx,
int  ny,
flouble  lx,
flouble  ly,
int  nmaps,
nmt_k_function **  cells,
nmt_k_function **  beam,
int  seed 
)

Gaussian realizations of flat-sky Fourier coefficients.

Generates a Gaussian realization of a set of Fourier coefficients given an input power spectrum.

Parameters
nxNumber of grid points in the x dimension.
nyNumber of grid points in the y dimension.
lxLength of the x dimension (in steradians).
lyLength of the y dimension (in steradians).
nmapsNumber of fields to generate.
cellsSet of nmaps * (nmaps + 1) / 2 nmt_k_function structures defining each of the power spectra needed to generate the Fourier coefficients. It must contain only the the upper-triangular part in row-major order (e.g. if nmaps is 3, there will be 6 power spectra ordered as [1-1,1-2,1-3,2-2,2-3,3-3].
beamSet of nmaps nmt_k_function structures defining the beam of each field.
seedSeed for this particular realization.
Returns
Gaussian realization with shape [nmaps][ny * (nx /2 +1)].
void fs_zero_alm ( nmt_flatsky_info fs,
fcomplex alm 
)

Zero SHT coefficients.

Sets all elements of a set of flat-sky Fourier coefficients to zero.

Parameters
fsnmt_flatsky_info structure describing the flat-sky patch.
almSet of Fourier coefficients to zero. See fs_map2alm() for the expected shape of flat-sky Fourier coefficients.
void he_alm2cl ( fcomplex **  alms_1,
fcomplex **  alms_2,
int  spin_1,
int  spin_2,
flouble **  cls,
int  lmax 
)

Computes Full-sky power spectrum from harmonic coefficients.

Computes the angular power spectrum of two sets of harmonic coefficients

Parameters
alms_1First set of harmonic coefficients to correlate.
alms_2Second set of harmonic coefficients to correlate.
spin_1alms_1 spin.
spin_2alms_2 spin.
clsWill hold the output power spectra. Should have shape [ncls][lmax + 1], where ncls is the appropriate number of power spectra given the spins of the input fields (e.g. ncls = 2*2 = 4 if both fields have spin=2).
lmaxmaximum multipole order.
void he_alm2map ( nmt_curvedsky_info cs,
int  lmax,
int  ntrans,
int  spin,
flouble **  maps,
fcomplex **  alms 
)

Full-sky inverse SHT.

Computes the inverse SHT of a set of spin-s full-sky fields. See scientific documentation and companion paper for further details.

Parameters
cscurved sky geometry information.
lmaxmaximum multipole order.
ntransNumber of transfoms to carry out.
spinSpin of the fields to transform (0 or 2).
mapsWill hold the output maps. Must have shape [ntrans * nmap][npix], where nmap is 1 or 2 for spin-0 and spin-2 respectively, and npix is the number of pixels associated with nside.
almsSHT coefficients to inverse-transform. Must have shape [ntrans * nmap][nalm], where nmap is defined above and nalm can be computed with he_nalm().
void he_alter_alm ( int  lmax,
double  fwhm_amin,
fcomplex alm_in,
fcomplex alm_out,
double *  window,
int  add_to_out 
)

Multiply SHT coefficients by beam.

Multiplies a given set of harmonic coefficients by a circularly-symmetric function.

Parameters
lmaxMaximum multipole order.
fwhm_aminFull-width at half-maximum of the Gaussian beam in arcminutes. Only used if window is a NULL pointer.
alm_inInput harmonic coefficients.
alm_outOutput harmonic coefficients.
windowArray of size lmax + 1 containing the function to multiply by. Pass a NULL pointer if you want a Gaussian beam with a FWHM defined by fwhm_amin.
add_to_outIf >0, the result of multiplying alm_in with the window function will be added to the current contents of alm_out. Otherwise, alm_out is overwritten with the product.
void he_anafast ( flouble **  maps_1,
flouble **  maps_2,
int  spin_1,
int  spin_2,
flouble **  cls,
nmt_curvedsky_info cs,
int  lmax,
int  iter 
)

Computes Full-sky power spectrum from maps.

Computes the angular power spectrum of two sets of maps.

Parameters
maps_1First set of maps to correlate.
maps_2Second set of maps to correlate.
spin_1maps_1 spin.
spin_2maps_2 spin.
clsWill hold the output power spectra. Should have shape [ncls][lmax + 1], where ncls is the appropriate number of power spectra given the spins of the input fields (e.g. ncls = 2*2 = 4 if both fields have spin=2).
cscurved sky geometry information.
lmaxmaximum multipole order.
iterNumber of iterations to use when computing the spherical harmonic transforms.
long he_ang2pix ( long  nside,
double  cth,
double  phi 
)

Modified HEALPix ang2pix.

Returns pixel containing a given point in the sphere.

Parameters
nsideHEALPix resolution parameter
phiAzimuth spherical coordinate $\varphi$ (in radians).
cthCosine of inclination spherical coordinate $\theta$.
Returns
Pixel index.
double* he_generate_beam_window ( int  lmax,
double  fwhm_amin 
)

Gaussian beam.

Generates an array defining the harmonic coefficients of a Gaussian beam.

Parameters
lmaxMaximum multipole order.
fwhm_aminFWHM of the beam in arcminutes.
Returns
List of harmonic coefficients from 0 to lmax (inclusive).
nmt_curvedsky_info* he_get_file_params ( char *  fname,
int  is_healpix,
int *  nfields,
int *  isnest 
)

Read map parameters from FITS file.

Parameters
fnamePath to input FITS file.
is_healpixWhether pixelization should be HEALPix.
nfieldsnumber of fields in file.
isnest>0 if maps are in NESTED ordering.
Returns
curved sky geometry information.
int he_get_largest_possible_lmax ( nmt_curvedsky_info cs)

Gets the multipole approximately corresponding to the Nyquist frequency.

Computes the maximum multipole probed by a map.

Parameters
cscurved sky geometry info.
Returns
maximum multipole.
int he_get_lmax ( nmt_curvedsky_info cs)

Get maximum multipole allowed by sky geometry configuration.

Returns the maximum multipole for a nmt_curvedsky_info.

Parameters
cscurved sky geometry info.
Returns
maximum multipole.
flouble he_get_pix_area ( nmt_curvedsky_info cs,
long  i 
)

Computes pixel area.

Parameters
cscurved sky geometry info.
iring number.
Returns
pixel area in sterad.
void he_in_ring ( int  nside,
int  iz,
flouble  phi0,
flouble  dphi,
int *  listir,
int *  nir 
)

Returns pixel indices in a given ring.

Parameters
nsideHEALPix resolution parameter
izRing index.
phi0Center of azimuth range.
dphiWidth of azimuth range.
listirOutput list of pixels
nirOn input, it should hold the number of elements allocated in listir. On output, it contains the number of pixels in the ring.
long he_indexlm ( int  l,
int  m,
int  lmax 
)

Harmonic coefficient ordering.

Returns the position of a given harmonic coefficient.

Parameters
l$\ell$ index
m$m$ index
lmaxmaximum multipole order.
Returns
Index holding the value of $a_{\ell m}$.
void he_map2alm ( nmt_curvedsky_info cs,
int  lmax,
int  ntrans,
int  spin,
flouble **  maps,
fcomplex **  alms,
int  niter 
)

Full-sky SHT.

Computes the direct SHT of a set of spin-s full-sky fields. See scientific documentation and companion paper for further details.

Parameters
cscurved sky geometry information.
lmaxmaximum multipole order.
ntransNumber of transfoms to carry out.
spinSpin of the fields to transform (0 or 2).
mapsMaps to transform. Must have shape [ntrans * nmap][npix], where nmap is 1 or 2 for spin-0 and spin-2 respectively, and npix is the number of pixels associated with nside.
almsWill hold the output SHT coefficients. Must have shape [ntrans * nmap][nalm], where nmap is defined above and nalm can be computed with he_nalm().
niterNumber of iterations to use when computing the spherical harmonic transforms.
flouble he_map_dot ( nmt_curvedsky_info cs,
flouble mp1,
flouble mp2 
)

Dot product of full-sky maps.

Computes the integral over the full sphere of the product of two maps:

\[ \int d\Omega\, m_1(\hat{\bf n})\,m_2(\hat{\bf n}), \]

The integral is computed as a Riemann sum over all pixels in the map.

Parameters
cscurved sky geometry information.
mp1First map to multiply.
mp2Second map to multiply.
Returns
Dot product.
void he_map_product ( nmt_curvedsky_info cs,
flouble mp1,
flouble mp2,
flouble mp_out 
)

Multiplies two full-sky maps.

Parameters
cscurved sky geometry information.
mp1First map to multiply
mp2Second map to multiply.
mp_outOutput map containing the product of mp1 and mp2. It is safe to pass either of the input maps as mp_out, in which case that map will be overwritten with the product.
long he_nalms ( int  lmax)

Number of alm coefficients.

Returns number of harmonic coefficients up to a given multipole order.

Parameters
lmaxMaximum multipole order.
Returns
Number of harmonic coefficients.
void he_nest2ring_inplace ( flouble map_in,
long  nside 
)

Transform from NEST to RING.

Transforms a HEALPix map from NEST to RING ordering in place.

Parameters
map_inMap to transform.
nsideHEALPix resolution parameter
long he_nside2npix ( long  nside)

HEALPix number of pixels.

Parameters
nsideHEALPix resolution parameter
Returns
12 * nside * nside.
void he_pix2vec_ring ( long  nside,
long  ipix,
double *  vec 
)

HEALPix pix2vec.

Returns normal vector pointing in the direction of a given pixel.

Parameters
nsideHEALPix resolution parameter.
ipixPixel index in RING ordering.
vecOutput vector.
void he_query_disc ( int  nside,
double  cth0,
double  phi,
flouble  radius,
int *  listtot,
int *  nlist,
int  inclusive 
)

Returns pixel indices in a given disc.

Parameters
nsideHEALPix resolution parameter
cth0$\cos(\theta)$ for the disc centre.
phiAzimuth for the disc centre.
radiusDisc radius in radians.
listtotOutput list of pixels
nlistOn input, it should hold the number of elements allocated in listtot. On output, it contains the number of pixels in the disc.
inclusiveIf >0, include all pixels that are partially insie the disc. Otherwise include only pixels whose centres are inside the disc.
void he_query_strip ( long  nside,
double  theta1,
double  theta2,
int *  pixlist,
long *  npix_strip 
)

Returns pixel indices in a given latitude strip.

Parameters
nsideHEALPix resolution parameter
theta1Lower edge of latitude range.
theta2Upper edge of latitude range.
pixlistOutput list of pixels
npix_stripOn input, it should hold the number of elements allocated in pixlist. On output, it contains the number of pixels in the strip.
flouble* he_read_map ( char *  fname,
nmt_curvedsky_info sky_info,
int  nfield 
)

Reads full-sky map from FITS file.

Parameters
fnamePath to input FITS file.
sky_infocurved sky geometry information.
nfieldWhich field to read (i.e. HDU number to read the map from, starting from 0).
Returns
Read map.
void he_ring2nest_inplace ( flouble map_in,
long  nside 
)

Transform from RING to NEST.

Transforms a HEALPix map from RING to NEST ordering in place.

Parameters
map_inMap to transform.
nsideHEALPix resolution parameter
int he_ring_num ( long  nside,
double  z 
)

HEALPix ring number.

Parameters
nsideHEALPix resolution parameter.
zz (cos(theta)) coordinate.
Returns
ring number
fcomplex** he_synalm ( nmt_curvedsky_info cs,
int  nmaps,
int  lmax,
flouble **  cells,
flouble **  beam,
int  seed 
)

Gaussian realizations of full-sky harmonic coefficients.

Generates a Gaussian realization of a set of harmonic coefficients given an input power spectrum.

Parameters
cscurved sky geometry information.
nmapsNumber of fields to generate.
lmaxMaximum multipole order
cellsSet of nmaps * (nmaps + 1) / 2 arrays of length lmax + 1 defining each of the power spectra needed to generate the Fourier coefficients. It must contain only the the upper-triangular part in row-major order (e.g. if nmaps is 3, there will be 6 power spectra ordered as [1-1,1-2,1-3,2-2,2-3,3-3].
beamSet of nmaps arrays of length lmax + 1 defining the beam of each field.
seedSeed for this particular realization.
Returns
Gaussian realization with shape [nmaps][nalm], where nalm can be computed with he_nalms().
void he_udgrade ( flouble map_in,
long  nside_in,
flouble map_out,
long  nside_out,
int  nest 
)

Up/down grade map resolution.

Parameters
map_inInput map.
nside_inInput HEALPix resolution parameter.
map_outOutput map.
nside_outOutput HEALPix resolution parameter.
nestIf >0, intput and output maps are in NESTED ordering.
void he_write_CAR_map ( flouble **  tmap,
int  nfields,
nmt_curvedsky_info sky_info,
char *  fname 
)

Writes CAR maps to FITS file.

Parameters
tmapArray of maps to write.
nfieldsNumber of maps to write.
sky_infocurved sky geometry information
fnamePath to output FITS file.
void he_write_healpix_map ( flouble **  tmap,
int  nfields,
long  nside,
char *  fname 
)

Writes full-sky maps to FITS file.

Parameters
tmapArray of maps to write.
nfieldsNumber of maps to write.
nsideHEALPix resolution parameter.
fnamePath to output FITS file.
void he_zero_alm ( int  lmax,
fcomplex alm 
)

Zero SHT coefficients.

Sets all elements of a set of harmonic coefficients to zero.

Parameters
lmaxMaximum multipole order
almCoefficients to zero. Must have a length given by he_nalms().
gsl_rng* init_rng ( unsigned int  seed)

Initialize a random number generator.

Parameters
seedSeed.
Returns
A GSL random number generator object.
void moore_penrose_pinv ( gsl_matrix *  M,
double  threshold 
)

Moore-Penrose pseudo-inverse.

Returns the Moore-Penrose pseudo-inverse.

Parameters
MInput matrix to invert. Will be overwritten with inverse.
thresholdWhen inverting, all eigenvalues smaller than threshold times the largest eigenvalue will be discarded (i.e. the corresponding eigenvalue of the pseudo-inverse will be set to zero).
void* my_calloc ( size_t  nmemb,
size_t  size 
)

Error-checked calloc.

Parameters
nmembNumber of elements in pointer to initialize.
sizeSize in bytes of each element in pointer to initialize.
Returns
Allocated pointer.
FILE* my_fopen ( const char *  path,
const char *  mode 
)

Error-checked fopen.

Parameters
pathPath to file.
modeOpening mode ("w", "r" etc.).
Returns
Opened file.
size_t my_fread ( void *  ptr,
size_t  size,
size_t  count,
FILE *  stream 
)

Error-checked fread.

Parameters
ptrPointer to data to input data.
sizeSize of each element of input data in bytes.
countNumber of elements in input data.
streamOpen file to read from.
Returns
count.
size_t my_fwrite ( const void *  ptr,
size_t  size,
size_t  nmemb,
FILE *  stream 
)

Error-checked fwrite.

Parameters
ptrPointer to data to output data.
sizeSize of each element of output data in bytes.
nmembNumber of elements in output data.
streamOpen file to write into.
Returns
nmbemb.
int my_linecount ( FILE *  f)

Count number of lines in an ASCII file.

Parameters
fAn open file.
Returns
Number of lines in file.
void* my_malloc ( size_t  size)

Error-checked malloc.

Parameters
sizeSize in bytes of pointer to initialize.
Returns
Allocated pointer.
double rng_01 ( gsl_rng *  rng)

Top-hat random numbers.

Draw a random number from 0 to 1 with a top-hat distribution.

Parameters
rngA random number generator.
Returns
Random number.
void rng_delta_gauss ( double *  module,
double *  phase,
gsl_rng *  rng,
double  sigma2 
)

Gaussian random numbers (mod-phase).

Draw modulus and phase of a complex Gaussian random numbers with variance sigma.

Parameters
moduleOutput random modulus.
phaseOutput random phase.
rngA random number generator.
sigma2Input variance.
Warning
From module and phase you could build a complex number with real and imaginary parts re and im. The input sigma2 parameter is the mean modulus squared, i.e. sigma2 = < re^2 + im^2 >. Therefore the variance of either re or im on their own is sigma2 / 2.
void rng_gauss ( gsl_rng *  rng,
double *  r1,
double *  r2 
)

Gaussian random numbers.

Draw a pair of Gaussian random numbers with zero mean and unit variance.

Parameters
rngA random number generator.
r1First output random number.
r2Second output random number.
int rng_poisson ( double  lambda,
gsl_rng *  rng 
)

Poisson random numbers.

Draw a random integer from a Poisson distribution with mean and variance given by lambda.

Parameters
lambdaMean and variance of the distribution.
rngA random number generator.
Returns
Random integer.