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 "healpix_map.h"
00037 #include "healpix_map_fitsio.h"
00038 #include "alm_healpix_tools.h"
00039 #include "alm_powspec_tools.h"
00040 #include "fitshandle.h"
00041 #include "levels_facilities.h"
00042 #include "lsconstants.h"
00043 #include "announce.h"
00044
00045 using namespace std;
00046
00047 namespace {
00048
00049 template<typename T> void smoothing_cxx (paramfile ¶ms)
00050 {
00051 int nlmax = params.template find<int>("nlmax");
00052 string infile = params.template find<string>("infile");
00053 string outfile = params.template find<string>("outfile");
00054 bool polarisation = params.template find<bool>("polarisation");
00055 int num_iter = params.template find<int>("iter_order",0);
00056 double fwhm = arcmin2rad*params.template find<double>("fwhm_arcmin");
00057 if (fwhm<0)
00058 cout << "NOTE: negative FWHM supplied, doing a deconvolution..." << endl;
00059
00060 if (!polarisation)
00061 {
00062 Healpix_Map<T> map;
00063 read_Healpix_map_from_fits(infile,map,1,2);
00064
00065 tsize nmod = map.replaceUndefWith0();
00066 if (nmod!=0)
00067 cout << "WARNING: replaced " << nmod <<
00068 " undefined map pixels with a value of 0" << endl;
00069
00070 double avg=map.average();
00071 map.Add(T(-avg));
00072
00073 arr<double> weight;
00074 get_ring_weights (params,map.Nside(),weight);
00075
00076 Alm<xcomplex<T> > alm(nlmax,nlmax);
00077 if (map.Scheme()==NEST) map.swap_scheme();
00078
00079 map2alm_iter(map,alm,num_iter,weight);
00080 smoothWithGauss (alm, fwhm);
00081 alm2map(alm,map);
00082
00083 map.Add(T(avg));
00084 write_Healpix_map_to_fits (outfile,map,planckType<T>());
00085 }
00086 else
00087 {
00088 Healpix_Map<T> mapT, mapQ, mapU;
00089 read_Healpix_map_from_fits(infile,mapT,mapQ,mapU);
00090
00091 tsize nmod = mapT.replaceUndefWith0()+mapQ.replaceUndefWith0()
00092 +mapU.replaceUndefWith0();
00093 if (nmod!=0)
00094 cout << "WARNING: replaced " << nmod <<
00095 " undefined map pixels with a value of 0" << endl;
00096
00097 double avg=mapT.average();
00098 mapT.Add(T(-avg));
00099
00100 arr<double> weight;
00101 get_ring_weights (params,mapT.Nside(),weight);
00102
00103 Alm<xcomplex<T> > almT(nlmax,nlmax), almG(nlmax,nlmax), almC(nlmax,nlmax);
00104 if (mapT.Scheme()==NEST) mapT.swap_scheme();
00105 if (mapQ.Scheme()==NEST) mapQ.swap_scheme();
00106 if (mapU.Scheme()==NEST) mapU.swap_scheme();
00107
00108 map2alm_pol_iter
00109 (mapT,mapQ,mapU,almT,almG,almC,num_iter,weight);
00110 smoothWithGauss (almT, almG, almC, fwhm);
00111 alm2map_pol(almT,almG,almC,mapT,mapQ,mapU);
00112
00113 mapT.Add(T(avg));
00114 write_Healpix_map_to_fits (outfile,mapT,mapQ,mapU,planckType<T>());
00115 }
00116 }
00117
00118 }
00119
00120 int smoothing_cxx_module (int argc, const char **argv)
00121 {
00122 module_startup ("smoothing_cxx", argc, argv);
00123 paramfile params (getParamsFromCmdline(argc,argv));
00124
00125 bool dp = params.find<bool> ("double_precision",false);
00126 dp ? smoothing_cxx<double>(params) : smoothing_cxx<float>(params);
00127
00128 return 0;
00129 }