NaMaster
utils.h
Go to the documentation of this file.
1 #ifndef _NM_UTILS_
2 #define _NM_UTILS_
3 
4 #ifndef NO_DOXY
5 #include "namaster.h"
6 
7 #include <setjmp.h>
8 
9 #define EXIT_ON_ERROR 0
10 #define THROW_ON_ERROR 1
11 extern jmp_buf nmt_exception_buffer;
12 extern int nmt_exception_status;
13 extern int nmt_error_policy;
14 extern char nmt_error_message[256];
15 
16 #define try if ((nmt_exception_status = setjmp(nmt_exception_buffer)) == 0)
17 #define catch(val) else if (nmt_exception_status == val)
18 #define throw(val) longjmp(nmt_exception_buffer,val)
19 #define finally else
20 
21 #define NMT_ERROR_MEMORY 1001
22 #define NMT_ERROR_FOPEN 1002
23 #define NMT_ERROR_WRITE 1003
24 #define NMT_ERROR_READ 1004
25 #define NMT_ERROR_WIG3J 1005
26 #define NMT_ERROR_PINV 1006
27 #define NMT_ERROR_BWEIGHT 1007
28 #define NMT_ERROR_COVAR 1008
29 #define NMT_ERROR_CONSISTENT_RESO 1009
30 #define NMT_ERROR_BADNO 1010
31 #define NMT_ERROR_APO 1011
32 #define NMT_ERROR_HPX 1012
33 #define NMT_ERROR_INCONSISTENT 1013
34 #define NMT_ERROR_VALUE 1014
35 #define NMT_ERROR_NOT_IMPLEMENTED 1015
36 #define NMT_ERROR_LITE 1016
37 #endif //NO_DOXY
38 
45 gsl_rng *init_rng(unsigned int seed);
46 
54 double rng_01(gsl_rng *rng);
55 
64 int rng_poisson(double lambda,gsl_rng *rng);
65 
79 void rng_delta_gauss(double *module,double *phase,
80  gsl_rng *rng,double sigma2);
89 void rng_gauss(gsl_rng *rng,double *r1,double *r2);
90 
94 void end_rng(gsl_rng *rng);
95 
102 int my_linecount(FILE *f);
103 
104 #ifndef NO_DOXY
105 void set_error_policy(int i);
106 void report_error(int level,char *fmt,...);
107 #endif //NO_DOXY
108 
115 void *my_malloc(size_t size);
116 
124 void *my_calloc(size_t nmemb,size_t size);
125 
133 FILE *my_fopen(const char *path,const char *mode);
134 
144 size_t my_fwrite(const void *ptr, size_t size, size_t nmemb,FILE *stream);
145 
155 size_t my_fread(void *ptr,size_t size,size_t count,FILE *stream);
156 
181 int drc3jj(int il2,int il3,int im2, int im3,int *l1min_out,
182  int *l1max_out,double *thrcof,int size);
183 
194 void moore_penrose_pinv(gsl_matrix *M,double threshold);
195 
203 void *dftw_malloc(size_t n);
204 
211 void dftw_free(void *p);
212 
220 void fs_mapcpy(nmt_flatsky_info *fs,flouble *destmap,flouble *srcmap);
221 
232 void fs_map_product(nmt_flatsky_info *fs,flouble *mp1,flouble *mp2,flouble *mp_out);
233 
249 
265 void fs_map2alm(nmt_flatsky_info *fs,int ntrans,int spin,flouble **map,fcomplex **alm);
266 
282 void fs_alm2map(nmt_flatsky_info *fs,int ntrans,int spin,flouble **map,fcomplex **alm);
283 
292 nmt_k_function *fs_generate_beam_window(double fwhm_amin);
293 
302 void fs_zero_alm(nmt_flatsky_info *fs,fcomplex *alm);
303 
319 void fs_alter_alm(nmt_flatsky_info *fs,double fwhm_amin,fcomplex *alm_in,fcomplex *alm_out,
320  nmt_k_function *window,int add_to_out);
321 
343  fcomplex **alms_1,fcomplex **alms_2,int spin_1,int spin_2,flouble **cls,
344  flouble lmn_x,flouble lmx_x,flouble lmn_y,flouble lmx_y);
345 
362  flouble **maps_1,flouble **maps_2,int spin_1,int spin_2,flouble **cls);
363 
381 fcomplex **fs_synalm(int nx,int ny,flouble lx,flouble ly,int nmaps,
382  nmt_k_function **cells,nmt_k_function **beam,int seed);
383 
397 flouble *fs_read_flat_map(char *fname,int *nx,int *ny,flouble *lx,flouble *ly,int nfield);
398 
399 
400 #define HE_NITER_DEFAULT 3
401 
402 
408 long he_nside2npix(long nside);
409 
418 void he_pix2vec_ring(long nside, long ipix, double *vec);
419 
429 long he_ang2pix(long nside,double cth,double phi);
430 
438 long he_nalms(int lmax);
439 
449 long he_indexlm(int l,int m,int lmax);
450 
467 void he_alm2map(nmt_curvedsky_info *cs,int lmax,int ntrans,int spin,flouble **maps,fcomplex **alms);
468 
486 void he_map2alm(nmt_curvedsky_info *cs,int lmax,int ntrans,int spin,flouble **maps,
487  fcomplex **alms,int niter);
488 
502 void he_alm2cl(fcomplex **alms_1,fcomplex **alms_2,int spin_1,int spin_2,flouble **cls,int lmax);
503 
512 
521 
537 void he_anafast(flouble **maps_1,flouble **maps_2,int spin_1,int spin_2,flouble **cls,
538  nmt_curvedsky_info *cs,int lmax,int iter);
539 
548 void he_write_healpix_map(flouble **tmap,int nfields,long nside,char *fname);
549 
558 void he_write_CAR_map(flouble **tmap,int nfields,nmt_curvedsky_info *sky_info,char *fname);
559 
569 nmt_curvedsky_info *he_get_file_params(char *fname,int is_healpix,int *nfields,int *isnest);
570 
579 flouble *he_read_map(char *fname,nmt_curvedsky_info *sky_info,int nfield);
580 
588 int he_ring_num(long nside,double z);
589 
601 void he_query_strip(long nside,double theta1,double theta2,int *pixlist,long *npix_strip);
602 
610 void he_ring2nest_inplace(flouble *map_in,long nside);
611 
619 void he_nest2ring_inplace(flouble *map_in,long nside);
620 
633 void he_in_ring(int nside,int iz,flouble phi0,flouble dphi,int *listir,int *nir);
634 
650 void he_query_disc(int nside,double cth0,double phi,flouble radius,int *listtot,int *nlist,
651  int inclusive);
652 
662 void he_udgrade(flouble *map_in,long nside_in,flouble *map_out,long nside_out,int nest);
663 
672 double *he_generate_beam_window(int lmax,double fwhm_amin);
673 
681 void he_zero_alm(int lmax,fcomplex *alm);
682 
698 void he_alter_alm(int lmax,double fwhm_amin,fcomplex *alm_in,fcomplex *alm_out,
699  double *window,int add_to_out);
700 
709 
720 void he_map_product(nmt_curvedsky_info *cs,flouble *mp1,flouble *mp2,flouble *mp_out);
721 
736 
753 fcomplex **he_synalm(nmt_curvedsky_info *cs,int nmaps,int lmax,flouble **cells,flouble **beam,int seed);
754 
755 int cov_get_coupling_pair_index(int na,int nc,int nb,int nd,
756  int ia1,int ia2,int ic1,int ic2,
757  int ib1,int ib2,int id1,int id2);
758 
759 #endif //_NM_UTILS_
flouble * he_read_map(char *fname, nmt_curvedsky_info *sky_info, int nfield)
Reads full-sky map from FITS file.
long he_ang2pix(long nside, double cth, double phi)
Modified HEALPix ang2pix.
FILE * my_fopen(const char *path, const char *mode)
Error-checked fopen.
void he_write_healpix_map(flouble **tmap, int nfields, long nside, char *fname)
Writes full-sky maps to FITS file.
void he_write_CAR_map(flouble **tmap, int nfields, nmt_curvedsky_info *sky_info, char *fname)
Writes CAR maps to FITS file.
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.
Flat-sky Fourier-space function.
Definition: namaster.h:265
long he_nside2npix(long nside)
HEALPix number of pixels.
flouble he_get_pix_area(nmt_curvedsky_info *cs, long i)
Computes pixel area.
void he_query_strip(long nside, double theta1, double theta2, int *pixlist, long *npix_strip)
Returns pixel indices in a given latitude strip.
fcomplex ** he_synalm(nmt_curvedsky_info *cs, int nmaps, int lmax, flouble **cells, flouble **beam, int seed)
Gaussian realizations of full-sky harmonic coefficients.
size_t my_fread(void *ptr, size_t size, size_t count, FILE *stream)
Error-checked fread.
gsl_rng * init_rng(unsigned int seed)
Initialize a random number generator.
Flat-sky bandpowers.
Definition: namaster.h:71
int rng_poisson(double lambda, gsl_rng *rng)
Poisson random numbers.
void he_zero_alm(int lmax, fcomplex *alm)
Zero SHT coefficients.
long he_nalms(int lmax)
Number of alm coefficients.
flouble fs_map_dot(nmt_flatsky_info *fs, flouble *mp1, flouble *mp2)
Dot product of flat-sky maps.
flouble * fs_read_flat_map(char *fname, int *nx, int *ny, flouble *lx, flouble *ly, int nfield)
Reads flat-sky map.
int my_linecount(FILE *f)
Count number of lines in an ASCII file.
void he_pix2vec_ring(long nside, long ipix, double *vec)
HEALPix pix2vec.
size_t my_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
Error-checked fwrite.
void fs_map2alm(nmt_flatsky_info *fs, int ntrans, int spin, flouble **map, fcomplex **alm)
Flat-sky SHT.
void fs_alm2map(nmt_flatsky_info *fs, int ntrans, int spin, flouble **map, fcomplex **alm)
Flat-sky inverse SHT.
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)
double complex fcomplex
Definition: namaster.h:33
int he_get_lmax(nmt_curvedsky_info *cs)
Get maximum multipole allowed by sky geometry configuration.
int drc3jj(int il2, int il3, int im2, int im3, int *l1min_out, int *l1max_out, double *thrcof, int size)
Wigner 3-j symbols.
void rng_gauss(gsl_rng *rng, double *r1, double *r2)
Gaussian random numbers.
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.
long he_indexlm(int l, int m, int lmax)
Harmonic coefficient ordering.
nmt_curvedsky_info * he_get_file_params(char *fname, int is_healpix, int *nfields, int *isnest)
Read map parameters from FITS file.
double rng_01(gsl_rng *rng)
Top-hat random numbers.
void fs_map_product(nmt_flatsky_info *fs, flouble *mp1, flouble *mp2, flouble *mp_out)
Multiplies two flat-sky maps.
void dftw_free(void *p)
Wrapper around fftw_free
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.
void rng_delta_gauss(double *module, double *phase, gsl_rng *rng, double sigma2)
Gaussian random numbers (mod-phase).
void fs_zero_alm(nmt_flatsky_info *fs, fcomplex *alm)
Zero SHT coefficients.
void he_map_product(nmt_curvedsky_info *cs, flouble *mp1, flouble *mp2, flouble *mp_out)
Multiplies two full-sky maps.
double flouble
Definition: namaster.h:32
void he_alm2map(nmt_curvedsky_info *cs, int lmax, int ntrans, int spin, flouble **maps, fcomplex **alms)
Full-sky inverse SHT.
nmt_k_function * fs_generate_beam_window(double fwhm_amin)
Gaussian beam.
Flat-sky information.
Definition: namaster.h:311
void * dftw_malloc(size_t n)
Wrapper around fftw_malloc
flouble he_map_dot(nmt_curvedsky_info *cs, flouble *mp1, flouble *mp2)
Dot product of full-sky maps.
void moore_penrose_pinv(gsl_matrix *M, double threshold)
Moore-Penrose pseudo-inverse.
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.
void * my_calloc(size_t nmemb, size_t size)
Error-checked calloc.
void he_udgrade(flouble *map_in, long nside_in, flouble *map_out, long nside_out, int nest)
Up/down grade map resolution.
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.
int he_get_largest_possible_lmax(nmt_curvedsky_info *cs)
Gets the multipole approximately corresponding to the Nyquist frequency.
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.
void he_nest2ring_inplace(flouble *map_in, long nside)
Transform from NEST to RING.
void * my_malloc(size_t size)
Error-checked malloc.
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.
int he_ring_num(long nside, double z)
HEALPix ring number.
Curved-sky information.
Definition: namaster.h:470
void fs_mapcpy(nmt_flatsky_info *fs, flouble *destmap, flouble *srcmap)
Copies a map.
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.
void he_map2alm(nmt_curvedsky_info *cs, int lmax, int ntrans, int spin, flouble **maps, fcomplex **alms, int niter)
Full-sky SHT.
double * he_generate_beam_window(int lmax, double fwhm_amin)
Gaussian beam.
void he_in_ring(int nside, int iz, flouble phi0, flouble dphi, int *listir, int *nir)
Returns pixel indices in a given ring.
void he_ring2nest_inplace(flouble *map_in, long nside)
Transform from RING to NEST.