/* * This file is part of Healpix_cxx. * * Healpix_cxx is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Healpix_cxx is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Healpix_cxx; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * For more information about HEALPix, see http://healpix.jpl.nasa.gov */ /* * Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt * (DLR). */ /* * Copyright (C) 2004, 2005, 2006, 2007, 2008 Max-Planck-Society * Author: Martin Reinecke */ /* Candidates for testing the validity of the Healpix routines: - done: ang2pix(pix2ang(i)) = i for all Healpix_Bases - done: pix2ang(ang2pix(ptg)) dot ptg > 1-delta for all Healpix_Bases - done: ring2nest(nest2ring(i)) = i for all hierarchical Healpix_Bases - done: downgrade(upgrade(map)) = map for all maps - done: map and downgraded map should have same average - done: alm2map(map2alm(map)) approx map (same for pol) - partly done: neighbor tests - powspec -> alm -> powspec (should produce similar powspecs, also for pol) - done: two swap_schemes() should produce original map - done: query_disc tests (dot products etc.) - a_lms: test Set(), Scale(), Add(), alm(l,m) = alm.mstart(m)[l], etc. */ #include #include "healpix_base.h" #include "healpix_base2.h" #include "healpix_map.h" #include "arr.h" #include "planck_rng.h" #include "lsconstants.h" #include "alm.h" #include "alm_healpix_tools.h" #include "alm_powspec_tools.h" #include "geom_utils.h" using namespace std; const int nsamples = 1000000; planck_rng rng; namespace { void random_dir (pointing &ptg) { ptg.theta = acos(rng.rand_uni()*2-1); ptg.phi = rng.rand_uni()*twopi; } void check_ringnestring() { cout << "testing ring2nest(nest2ring(m))==m" << endl; for (int order=0; order<=13; ++order) { cout << "order = " << order << endl; Healpix_Base base (order,RING); for (int m=0; m=0) && (v_angle(base2.pix2ang(nb[n]),pixpt)>maxang)) cout << " PROBLEM2: order = " << order << ", pix = " << pix << endl; } } for (int nside=3; nside<(1<<13); nside+=nside/2+1) { cout << "nside = " << nside << endl; Healpix_Base base (nside,RING,SET_NSIDE); double maxang = 2.01*base.max_pixrad(); for (int m=0; m nb; vec3 pixpt = base.pix2ang(pix); base.neighbors(pix,nb); for (int n=0; n<8; ++n) if ((nb[n]>=0) && (v_angle(base.pix2ang(nb[n]),pixpt)>maxang)) cout << " PROBLEM: nside = " << nside << ", pix = " << pix << endl; } } } void check_neighbors2() { cout << "testing neighbor function" << endl; for (int order=0; order<=29; ++order) { cout << "order = " << order << endl; Healpix_Base2 base (order,NEST), base2(order,RING); double maxang = 2.01*base.max_pixrad(); for (int m=0; m nb; vec3 pixpt = base.pix2ang(pix); base.neighbors(pix,nb); sort(&nb[0],&nb[0]+8); int check=0; for (int n=0; n<8; ++n) { if (nb[n]<0) { ++check; } else { if (v_angle(base.pix2ang(nb[n]),pixpt)>maxang) cout << " PROBLEM: order = " << order << ", pix = " << pix << endl; if ((n>0) && (nb[n]==nb[n-1])) cout << " PROBLEM: order = " << order << ", pix = " << pix << endl; } } planck_assert((check<=1)||((order==0)&&(check<=2)),"too few neighbors"); pixpt = base2.pix2ang(pix); base2.neighbors(pix,nb); for (int n=0; n<8; ++n) if ((nb[n]>=0) && (v_angle(base2.pix2ang(nb[n]),pixpt)>maxang)) cout << " PROBLEM2: order = " << order << ", pix = " << pix << endl; } } for (int nside=3; nside<(1<<29); nside+=nside/2+1) { cout << "nside = " << nside << endl; Healpix_Base2 base (nside,RING,SET_NSIDE); double maxang = 2.01*base.max_pixrad(); for (int m=0; m nb; vec3 pixpt = base.pix2ang(pix); base.neighbors(pix,nb); for (int n=0; n<8; ++n) if ((nb[n]>=0) && (v_angle(base.pix2ang(nb[n]),pixpt)>maxang)) cout << " PROBLEM: nside = " << nside << ", pix = " << pix << endl; } } } void check_swap_scheme() { cout << "testing whether double swap_scheme() returns the original map" << endl << "(for orders 0 to 10)." << endl; for (int order=0; order<=10; ++order) { cout << "order = " << order << endl; Healpix_Map map(order,NEST); for (int m=0; m >&almT, Alm >&almG, Alm >&almC, int lmax, int mmax) { almT.Set(lmax,mmax); almG.Set(lmax,mmax); almC.Set(lmax,mmax); for (int l=0; l<=lmax; ++l) { almT(l,0).re=rng.rand_gauss(); almT(l,0).im=0.; almG(l,0).re=rng.rand_gauss(); almG(l,0).im=0.; almC(l,0).re=rng.rand_gauss(); almC(l,0).im=0.; } for (int m=1; m<=mmax; ++m) for (int l=m; l<=lmax; ++l) { almT(l,m).re=rng.rand_gauss(); almT(l,m).im=rng.rand_gauss(); almG(l,m).re=rng.rand_gauss(); almG(l,m).im=rng.rand_gauss(); almC(l,m).re=rng.rand_gauss(); almC(l,m).im=rng.rand_gauss(); } almG(0,0)=almC(0,0)=almG(1,0)=almC(1,0)=almG(1,1)=almC(1,1)=0; } void random_alm (Alm >&alm, int lmax, int mmax) { alm.Set(lmax,mmax); for (int l=0; l<=lmax; ++l) { alm(l,0).re=rng.rand_gauss(); alm(l,0).im=0.; } for (int m=1; m<=mmax; ++m) for (int l=m; l<=lmax; ++l) { alm(l,m).re=rng.rand_gauss(); alm(l,m).im=rng.rand_gauss(); } } void check_alm (const Alm >&oalm, const Alm >&alm, double epsilon) { for (int m=0; m<=alm.Mmax(); ++m) for (int l=m; l<=alm.Lmax(); ++l) { if (!abs_approx(oalm(l,m).re,alm(l,m).re,epsilon)) cout << "Problemr " << l << " " << m << endl; if (!abs_approx(oalm(l,m).im,alm(l,m).im,epsilon)) cout << "Problemi " << l << " " << m << endl; } } void check_alm2map2alm (int lmax, int mmax, int nside) { cout << "testing whether a_lm->map->a_lm returns original a_lm" << endl; cout << "lmax=" << lmax <<", mmax=" << mmax << ", nside=" << nside << endl; const double epsilon = 1e-8; Alm > oalmT(lmax,mmax),almT(lmax,mmax), oalmG(lmax,mmax),almG(lmax,mmax),oalmC(lmax,mmax),almC(lmax,mmax); Healpix_Map mapT(nside,RING,SET_NSIDE), mapQ(nside,RING,SET_NSIDE), mapU(nside,RING,SET_NSIDE); random_alm(oalmT,oalmG,oalmC,lmax,mmax); alm2map(oalmT,mapT); map2alm_iter2(mapT,almT,1e-12,1e-12); check_alm (oalmT, almT, epsilon); alm2map_spin(oalmG,oalmC,mapQ,mapU,1); map2alm_spin_iter2(mapQ,mapU,almG,almC,1,1e-12,1e-12); check_alm (oalmG, almG, epsilon); check_alm (oalmC, almC, epsilon); alm2map_pol(oalmT,oalmG,oalmC,mapT,mapQ,mapU); map2alm_pol_iter2(mapT,mapQ,mapU,almT,almG,almC,1e-12,1e-12); check_alm (oalmT, almT, epsilon); check_alm (oalmG, almG, epsilon); check_alm (oalmC, almC, epsilon); } void check_smooth_alm () { cout << "testing whether unsmooth(smooth(a_lm)) returns a_lm" << endl; const double epsilon = 1e-14; const double fwhm = 100.*arcmin2rad; const int lmax=300, mmax=300; Alm > oalmT(lmax,mmax),almT(lmax,mmax), oalmG(lmax,mmax),almG(lmax,mmax),oalmC(lmax,mmax),almC(lmax,mmax); random_alm(oalmT,oalmG,oalmC,lmax,mmax); almT=oalmT; almG=oalmG; almC=oalmC; smoothWithGauss (almT, fwhm); smoothWithGauss (almT, -fwhm); check_alm (oalmT, almT, epsilon); almT=oalmT; smoothWithGauss (almT, almG, almC, fwhm); smoothWithGauss (almT, almG, almC, -fwhm); check_alm (oalmT, almT, epsilon); check_alm (oalmG, almG, epsilon); check_alm (oalmC, almC, epsilon); } void check_rot_alm () { cout << "testing whether rot^-1(rot(a_lm)) returns a_lm" << endl; const double epsilon = 2e-13; const int lmax=300; Alm > oalm(lmax,lmax),alm(lmax,lmax); random_alm(oalm,lmax,lmax); alm=oalm; rotate_alm (alm,3,4,5); rotate_alm (alm,-5,-4,-3); check_alm (oalm, alm, epsilon); } } // unnamed namespace int main(int argc, const char **argv) { module_startup ("hpxtest",argc,argv,1,""); check_smooth_alm(); check_rot_alm(); check_alm2map2alm(620,620,256); check_alm2map2alm(620,2,256); check_average(); check_import(); check_neighbors(); check_neighbors2(); check_pixangpix(); check_pixangpix2(); check_pixvecpix(); check_pixvecpix2(); check_angpixang(); check_angpixang2(); check_ringnestring(); check_ringnestring2(); check_nestpeanonest(); check_nestpeanonest2(); check_query_disc(); check_swap_scheme(); }