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 tsize nmod = map.replaceUndefWith0();
00065 if (nmod!=0)
00066 cout << "WARNING: replaced " << nmod <<
00067 " undefined map pixels with a value of 0" << endl;
00068
00069 arr<double> weight;
00070 get_ring_weights (params,map.Nside(),weight);
00071
00072 Alm<xcomplex<T> > alm(nlmax,nlmax);
00073 double avg=map.average();
00074 map.Add(T(-avg));
00075 if (map.Scheme()==NEST) map.swap_scheme();
00076
00077 map2alm_iter(map,alm,num_iter,weight);
00078 smoothWithGauss (alm, fwhm);
00079 alm2map(alm,map);
00080
00081 map.Add(T(avg));
00082 write_Healpix_map_to_fits (outfile,map,planckType<T>());
00083 }
00084 else
00085 {
00086 Healpix_Map<T> mapT, mapQ, mapU;
00087 read_Healpix_map_from_fits(infile,mapT,mapQ,mapU);
00088 tsize nmod = mapT.replaceUndefWith0()+mapQ.replaceUndefWith0()
00089 +mapU.replaceUndefWith0();
00090 if (nmod!=0)
00091 cout << "WARNING: replaced " << nmod <<
00092 " undefined map pixels with a value of 0" << endl;
00093
00094 arr<double> weight;
00095 get_ring_weights (params,mapT.Nside(),weight);
00096
00097 Alm<xcomplex<T> > almT(nlmax,nlmax), almG(nlmax,nlmax), almC(nlmax,nlmax);
00098 double avg=mapT.average();
00099 mapT.Add(T(-avg));
00100 if (mapT.Scheme()==NEST) mapT.swap_scheme();
00101 if (mapQ.Scheme()==NEST) mapQ.swap_scheme();
00102 if (mapU.Scheme()==NEST) mapU.swap_scheme();
00103
00104 map2alm_pol_iter
00105 (mapT,mapQ,mapU,almT,almG,almC,num_iter,weight);
00106 smoothWithGauss (almT, almG, almC, fwhm);
00107 alm2map_pol(almT,almG,almC,mapT,mapQ,mapU);
00108
00109 mapT.Add(T(avg));
00110 write_Healpix_map_to_fits (outfile,mapT,mapQ,mapU,planckType<T>());
00111 }
00112 }
00113
00114 }
00115
00116 int smoothing_cxx_module (int argc, const char **argv)
00117 {
00118 module_startup ("smoothing_cxx", argc, argv);
00119 paramfile params (getParamsFromCmdline(argc,argv));
00120
00121 bool dp = params.find<bool> ("double_precision",false);
00122 dp ? smoothing_cxx<double>(params) : smoothing_cxx<float>(params);
00123
00124 return 0;
00125 }