00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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 ¶ms)
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
00064 if (!polarisation)
00065 {
00066 Healpix_Map<T> map;
00067 read_Healpix_map_from_fits(infile,map,1,2);
00068 tsize nmod = map.replaceUndefWith0();
00069 if (nmod!=0)
00070 cout << "WARNING: replaced " << nmod <<
00071 " undefined map pixels with a value of 0" << endl;
00072
00073 arr<double> weight;
00074 get_ring_weights (params,map.Nside(),weight);
00075
00076 Alm<xcomplex<T> > alm(nlmax,nmmax);
00077 double avg=map.average();
00078 map.Add(T(-avg));
00079 if (map.Scheme()==NEST) map.swap_scheme();
00080 map2alm_iter(map,alm,num_iter,weight);
00081
00082 alm(0,0) += T(avg*sqrt(fourpi));
00083
00084 if (outfile!="")
00085 {
00086 PowSpec powspec;
00087 extract_powspec (alm,powspec);
00088 write_powspec_to_fits (outfile,powspec,1);
00089 }
00090 if (outfile_alms!="")
00091 write_Alm_to_fits(outfile_alms,alm,nlmax,nmmax,planckType<T>());
00092 }
00093 else
00094 {
00095 Healpix_Map<T> mapT, mapQ, mapU;
00096 read_Healpix_map_from_fits(infile,mapT,mapQ,mapU,2);
00097 tsize nmod = mapT.replaceUndefWith0()+mapT.replaceUndefWith0()
00098 +mapU.replaceUndefWith0();
00099 if (nmod!=0)
00100 cout << "WARNING: replaced " << nmod <<
00101 " undefined map pixels with a value of 0" << endl;
00102
00103 arr<double> weight;
00104 get_ring_weights (params,mapT.Nside(),weight);
00105
00106 Alm<xcomplex<T> > almT(nlmax,nmmax), almG(nlmax,nmmax), almC(nlmax,nmmax);
00107 double avg=mapT.average();
00108 mapT.Add(T(-avg));
00109 if (mapT.Scheme()==NEST) mapT.swap_scheme();
00110 if (mapQ.Scheme()==NEST) mapQ.swap_scheme();
00111 if (mapU.Scheme()==NEST) mapU.swap_scheme();
00112 map2alm_pol_iter
00113 (mapT,mapQ,mapU,almT,almG,almC,num_iter,weight);
00114
00115 almT(0,0) += T(avg*sqrt(fourpi));
00116
00117 if (outfile!="")
00118 {
00119 PowSpec powspec;
00120 extract_powspec (almT,almG,almC,powspec);
00121 params.template find<bool>("full_powerspectrum",false) ?
00122 write_powspec_to_fits (outfile,powspec,6) :
00123 write_powspec_to_fits (outfile,powspec,4);
00124 }
00125 if (outfile_alms!="")
00126 write_Alm_to_fits (outfile_alms,almT,almG,almC,nlmax,nmmax,planckType<T>());
00127 }
00128 }
00129
00130 }
00131
00132 int anafast_cxx_module (int argc, const char **argv)
00133 {
00134 module_startup ("anafast_cxx", argc, argv);
00135 paramfile params (getParamsFromCmdline(argc,argv));
00136
00137 bool dp = params.find<bool> ("double_precision",false);
00138 dp ? anafast_cxx<double>(params) : anafast_cxx<float>(params);
00139 return 0;
00140 }