anafast_cxx_module.cc

00001 /*
00002  *  This file is part of Healpix_cxx.
00003  *
00004  *  Healpix_cxx is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  Healpix_cxx is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with Healpix_cxx; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *  For more information about HEALPix, see http://healpix.sourceforge.net
00019  */
00020 
00021 /*
00022  *  Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
00023  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00024  *  (DLR).
00025  */
00026 
00027 /*
00028  *  Copyright (C) 2003-2015 Max-Planck-Society
00029  *  Author: Martin Reinecke
00030  */
00031 
00032 #include "xcomplex.h"
00033 #include "paramfile.h"
00034 #include "healpix_data_io.h"
00035 #include "alm.h"
00036 #include "alm_fitsio.h"
00037 #include "healpix_map.h"
00038 #include "healpix_map_fitsio.h"
00039 #include "powspec.h"
00040 #include "powspec_fitsio.h"
00041 #include "alm_healpix_tools.h"
00042 #include "alm_powspec_tools.h"
00043 #include "fitshandle.h"
00044 #include "levels_facilities.h"
00045 #include "lsconstants.h"
00046 #include "announce.h"
00047 
00048 using namespace std;
00049 
00050 namespace {
00051 
00052 template<typename T> void anafast_cxx (paramfile &params)
00053   {
00054   int nlmax = params.template find<int>("nlmax");
00055   int nmmax = params.template find<int>("nmmax",nlmax);
00056   string infile = params.template find<string>("infile");
00057   string outfile = params.template find<string>("outfile","");
00058   string outfile_alms = params.template find<string>("outfile_alms","");
00059   planck_assert ((outfile!="") || (outfile_alms!=""),
00060     "no output specified, nothing done");
00061   bool polarisation = params.template find<bool>("polarisation");
00062   int num_iter = params.template find<int>("iter_order",0);
00063   bool remove_mono = params.template find<bool>("remove_monopole",false);
00064 
00065   if (!polarisation)
00066     {
00067     Healpix_Map<T> map;
00068     read_Healpix_map_from_fits(infile,map,1,2);
00069 
00070     tsize nmod = map.replaceUndefWith0();
00071     if (nmod!=0)
00072       cout << "WARNING: replaced " << nmod <<
00073               " undefined map pixels with a value of 0" << endl;
00074 
00075     double avg=0.;
00076     if (remove_mono)
00077       {
00078       avg=map.average();
00079       map.Add(T(-avg));
00080       }
00081 
00082     arr<double> weight;
00083     get_ring_weights (params,map.Nside(),weight);
00084 
00085     Alm<xcomplex<T> > alm(nlmax,nmmax);
00086     if (map.Scheme()==NEST) map.swap_scheme();
00087     map2alm_iter(map,alm,num_iter,weight);
00088 
00089     alm(0,0) += T(avg*sqrt(fourpi));
00090 
00091     if (outfile!="")
00092       {
00093       PowSpec powspec;
00094       extract_powspec (alm,powspec);
00095       write_powspec_to_fits (outfile,powspec,1);
00096       }
00097     if (outfile_alms!="")
00098       write_Alm_to_fits(outfile_alms,alm,nlmax,nmmax,planckType<T>());
00099     }
00100   else
00101     {
00102     Healpix_Map<T> mapT, mapQ, mapU;
00103     read_Healpix_map_from_fits(infile,mapT,mapQ,mapU,2);
00104 
00105     tsize nmod = mapT.replaceUndefWith0()+mapQ.replaceUndefWith0()
00106                 +mapU.replaceUndefWith0();
00107     if (nmod!=0)
00108       cout << "WARNING: replaced " << nmod <<
00109               " undefined map pixels with a value of 0" << endl;
00110 
00111     double avg=0.;
00112     if (remove_mono)
00113       {
00114       avg=mapT.average();
00115       mapT.Add(T(-avg));
00116       }
00117 
00118     arr<double> weight;
00119     get_ring_weights (params,mapT.Nside(),weight);
00120 
00121     Alm<xcomplex<T> > almT(nlmax,nmmax), almG(nlmax,nmmax), almC(nlmax,nmmax);
00122     if (mapT.Scheme()==NEST) mapT.swap_scheme();
00123     if (mapQ.Scheme()==NEST) mapQ.swap_scheme();
00124     if (mapU.Scheme()==NEST) mapU.swap_scheme();
00125     map2alm_pol_iter
00126       (mapT,mapQ,mapU,almT,almG,almC,num_iter,weight);
00127 
00128     almT(0,0) += T(avg*sqrt(fourpi));
00129 
00130     if (outfile!="")
00131       {
00132       PowSpec powspec;
00133       extract_powspec (almT,almG,almC,powspec);
00134       params.template find<bool>("full_powerspectrum",false) ?
00135         write_powspec_to_fits (outfile,powspec,6) :
00136         write_powspec_to_fits (outfile,powspec,4);
00137       }
00138     if (outfile_alms!="")
00139       write_Alm_to_fits (outfile_alms,almT,almG,almC,nlmax,nmmax,planckType<T>());
00140     }
00141   }
00142 
00143 } // unamed namespace
00144 
00145 int anafast_cxx_module (int argc, const char **argv)
00146   {
00147   module_startup ("anafast_cxx", argc, argv);
00148   paramfile params (getParamsFromCmdline(argc,argv));
00149 
00150   bool dp = params.find<bool> ("double_precision",false);
00151   dp ? anafast_cxx<double>(params) : anafast_cxx<float>(params);
00152   return 0;
00153   }

Generated on Thu Oct 8 14:48:52 2015 for Healpix C++