NaMaster: utils.h Source File

NaMaster

- Main Page
- Data Structures
- Files

- File List
- Globals

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
248 flouble fs_map_dot(nmt_flatsky_info *fs,flouble *mp1,flouble *mp2);
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
342 void fs_alm2cl(nmt_flatsky_info *fs,nmt_binning_scheme_flat *bin,
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
361 void fs_anafast(nmt_flatsky_info *fs,nmt_binning_scheme_flat *bin,
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
511 int he_get_largest_possible_lmax(nmt_curvedsky_info *cs);
512
520 int he_get_lmax(nmt_curvedsky_info *cs);
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
708 flouble he_get_pix_area(nmt_curvedsky_info *cs,long i);
709
720 void he_map_product(nmt_curvedsky_info *cs,flouble *mp1,flouble *mp2,flouble *mp_out);
721
735 flouble he_map_dot(nmt_curvedsky_info *cs,flouble *mp1,flouble *mp2);
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_
he_read_map
flouble * he_read_map(char *fname, nmt_curvedsky_info *sky_info, int nfield)
Reads full-sky map from FITS file.
he_ang2pix
long he_ang2pix(long nside, double cth, double phi)
Modified HEALPix ang2pix.
my_fopen
FILE * my_fopen(const char *path, const char *mode)
Error-checked fopen.
he_write_healpix_map
void he_write_healpix_map(flouble **tmap, int nfields, long nside, char *fname)
Writes full-sky maps to FITS file.
he_write_CAR_map
void he_write_CAR_map(flouble **tmap, int nfields, nmt_curvedsky_info *sky_info, char *fname)
Writes CAR maps to FITS file.
he_alter_alm
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.
nmt_k_function
Flat-sky Fourier-space function.
Definition: namaster.h:265
he_nside2npix
long he_nside2npix(long nside)
HEALPix number of pixels.
he_get_pix_area
flouble he_get_pix_area(nmt_curvedsky_info *cs, long i)
Computes pixel area.
he_query_strip
void he_query_strip(long nside, double theta1, double theta2, int *pixlist, long *npix_strip)
Returns pixel indices in a given latitude strip.
he_synalm
fcomplex ** he_synalm(nmt_curvedsky_info *cs, int nmaps, int lmax, flouble **cells, flouble **beam, int seed)
Gaussian realizations of full-sky harmonic coefficients.
my_fread
size_t my_fread(void *ptr, size_t size, size_t count, FILE *stream)
Error-checked fread.
init_rng
gsl_rng * init_rng(unsigned int seed)
Initialize a random number generator.
nmt_binning_scheme_flat
Flat-sky bandpowers.
Definition: namaster.h:71
rng_poisson
int rng_poisson(double lambda, gsl_rng *rng)
Poisson random numbers.
he_zero_alm
void he_zero_alm(int lmax, fcomplex *alm)
Zero SHT coefficients.
he_nalms
long he_nalms(int lmax)
Number of alm coefficients.
fs_map_dot
flouble fs_map_dot(nmt_flatsky_info *fs, flouble *mp1, flouble *mp2)
Dot product of flat-sky maps.
fs_read_flat_map
flouble * fs_read_flat_map(char *fname, int *nx, int *ny, flouble *lx, flouble *ly, int nfield)
Reads flat-sky map.
my_linecount
int my_linecount(FILE *f)
Count number of lines in an ASCII file.
he_pix2vec_ring
void he_pix2vec_ring(long nside, long ipix, double *vec)
HEALPix pix2vec.
my_fwrite
size_t my_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
Error-checked fwrite.
fs_map2alm
void fs_map2alm(nmt_flatsky_info *fs, int ntrans, int spin, flouble **map, fcomplex **alm)
Flat-sky SHT.
fs_alm2map
void fs_alm2map(nmt_flatsky_info *fs, int ntrans, int spin, flouble **map, fcomplex **alm)
Flat-sky inverse SHT.
cov_get_coupling_pair_index
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)
fcomplex
double complex fcomplex
Definition: namaster.h:33
he_get_lmax
int he_get_lmax(nmt_curvedsky_info *cs)
Get maximum multipole allowed by sky geometry configuration.
drc3jj
int drc3jj(int il2, int il3, int im2, int im3, int *l1min_out, int *l1max_out, double *thrcof, int size)
Wigner 3-j symbols.
rng_gauss
void rng_gauss(gsl_rng *rng, double *r1, double *r2)
Gaussian random numbers.
fs_synalm
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.
he_indexlm
long he_indexlm(int l, int m, int lmax)
Harmonic coefficient ordering.
he_get_file_params
nmt_curvedsky_info * he_get_file_params(char *fname, int is_healpix, int *nfields, int *isnest)
Read map parameters from FITS file.
rng_01
double rng_01(gsl_rng *rng)
Top-hat random numbers.
fs_map_product
void fs_map_product(nmt_flatsky_info *fs, flouble *mp1, flouble *mp2, flouble *mp_out)
Multiplies two flat-sky maps.
dftw_free
void dftw_free(void *p)
Wrapper around fftw_free
end_rng
void end_rng(gsl_rng *rng)
Destructor for random number generators.
fs_alm2cl
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.
rng_delta_gauss
void rng_delta_gauss(double *module, double *phase, gsl_rng *rng, double sigma2)
Gaussian random numbers (mod-phase).
fs_zero_alm
void fs_zero_alm(nmt_flatsky_info *fs, fcomplex *alm)
Zero SHT coefficients.
he_map_product
void he_map_product(nmt_curvedsky_info *cs, flouble *mp1, flouble *mp2, flouble *mp_out)
Multiplies two full-sky maps.
flouble
double flouble
Definition: namaster.h:32
he_alm2map
void he_alm2map(nmt_curvedsky_info *cs, int lmax, int ntrans, int spin, flouble **maps, fcomplex **alms)
Full-sky inverse SHT.
fs_generate_beam_window
nmt_k_function * fs_generate_beam_window(double fwhm_amin)
Gaussian beam.
nmt_flatsky_info
Flat-sky information.
Definition: namaster.h:311
dftw_malloc
void * dftw_malloc(size_t n)
Wrapper around fftw_malloc
he_map_dot
flouble he_map_dot(nmt_curvedsky_info *cs, flouble *mp1, flouble *mp2)
Dot product of full-sky maps.
namaster.h
moore_penrose_pinv
void moore_penrose_pinv(gsl_matrix *M, double threshold)
Moore-Penrose pseudo-inverse.
he_alm2cl
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.
my_calloc
void * my_calloc(size_t nmemb, size_t size)
Error-checked calloc.
he_udgrade
void he_udgrade(flouble *map_in, long nside_in, flouble *map_out, long nside_out, int nest)
Up/down grade map resolution.
fs_alter_alm
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.
he_get_largest_possible_lmax
int he_get_largest_possible_lmax(nmt_curvedsky_info *cs)
Gets the multipole approximately corresponding to the Nyquist frequency.
fs_anafast
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.
he_nest2ring_inplace
void he_nest2ring_inplace(flouble *map_in, long nside)
Transform from NEST to RING.
my_malloc
void * my_malloc(size_t size)
Error-checked malloc.
he_query_disc
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.
he_ring_num
int he_ring_num(long nside, double z)
HEALPix ring number.
nmt_curvedsky_info
Curved-sky information.
Definition: namaster.h:470
fs_mapcpy
void fs_mapcpy(nmt_flatsky_info *fs, flouble *destmap, flouble *srcmap)
Copies a map.
he_anafast
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.
he_map2alm
void he_map2alm(nmt_curvedsky_info *cs, int lmax, int ntrans, int spin, flouble **maps, fcomplex **alms, int niter)
Full-sky SHT.
he_generate_beam_window
double * he_generate_beam_window(int lmax, double fwhm_amin)
Gaussian beam.
he_in_ring
void he_in_ring(int nside, int iz, flouble phi0, flouble dphi, int *listir, int *nir)
Returns pixel indices in a given ring.
he_ring2nest_inplace
void he_ring2nest_inplace(flouble *map_in, long nside)
Transform from RING to NEST.