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 "cxxutils.h"
00034 #include "paramfile.h"
00035 #include "simparams.h"
00036 #include "healpix_data_io.h"
00037 #include "alm.h"
00038 #include "healpix_map.h"
00039 #include "healpix_map_fitsio.h"
00040 #include "alm_healpix_tools.h"
00041 #include "alm_powspec_tools.h"
00042 #include "fitshandle.h"
00043
00044 using namespace std;
00045
00046 template<typename T> void smoothing_cxx (paramfile ¶ms, simparams &par)
00047 {
00048 int nlmax = params.template find<int>("nlmax");
00049 string infile = params.template find<string>("infile");
00050 string outfile = params.template find<string>("outfile");
00051 bool polarisation = params.template find<bool>("polarisation");
00052 int num_iter = params.template find<int>("iter_order",0);
00053 double fwhm_arcmin = params.template find<double>("fwhm_arcmin");
00054
00055 if (!polarisation)
00056 {
00057 Healpix_Map<T> map;
00058 read_Healpix_map_from_fits(infile,map,1,2);
00059 arr<double> weight_T;
00060 get_ring_weights (params,par,map.Nside(),weight_T);
00061
00062 Alm<xcomplex<T> > alm(nlmax,nlmax);
00063 double avg=map.average();
00064 map.add(-avg);
00065 if (map.Scheme()==NEST) map.swap_scheme();
00066
00067 map2alm_iter(map,alm,num_iter,weight_T);
00068 if (fwhm_arcmin>0) smooth_with_Gauss (alm, fwhm_arcmin);
00069 alm2map(alm,map);
00070
00071 map.add(avg);
00072 fitshandle out;
00073 out.create (outfile);
00074 write_Healpix_map_to_fits (out,map,FITSUTIL<T>::DTYPE);
00075 par.add_keys(out);
00076 }
00077 else
00078 {
00079 Healpix_Map<T> mapT, mapQ, mapU;
00080 read_Healpix_map_from_fits(infile,mapT,1,2);
00081 read_Healpix_map_from_fits(infile,mapQ,2,2);
00082 read_Healpix_map_from_fits(infile,mapU,3,2);
00083 arr<double> weight;
00084 get_ring_weights (params,par,mapT.Nside(),weight);
00085
00086 Alm<xcomplex<T> > almT(nlmax,nlmax), almG(nlmax,nlmax), almC(nlmax,nlmax);
00087 double avg=mapT.average();
00088 mapT.add(-avg);
00089 if (mapT.Scheme()==NEST) mapT.swap_scheme();
00090 if (mapQ.Scheme()==NEST) mapQ.swap_scheme();
00091 if (mapU.Scheme()==NEST) mapU.swap_scheme();
00092
00093 map2alm_pol_iter
00094 (mapT,mapQ,mapU,almT,almG,almC,num_iter,weight);
00095 if (fwhm_arcmin>0) smooth_with_Gauss (almT, almG, almC, fwhm_arcmin);
00096 alm2map_pol(almT,almG,almC,mapT,mapQ,mapU);
00097
00098 mapT.add(avg);
00099 fitshandle out;
00100 out.create (outfile);
00101 write_Healpix_map_to_fits (out,mapT,mapQ,mapU,FITSUTIL<T>::DTYPE);
00102 par.add_keys(out);
00103 }
00104 }
00105
00106 int main (int argc, const char **argv)
00107 {
00108 PLANCK_DIAGNOSIS_BEGIN
00109 module_startup ("smoothing_cxx", argc, argv, 2, "<parameter file>");
00110 paramfile params (argv[1]);
00111 simparams par;
00112
00113 bool dp = params.find<bool> ("double_precision",false);
00114 dp ? smoothing_cxx<double>(params,par) : smoothing_cxx<float>(params,par);
00115 PLANCK_DIAGNOSIS_END
00116 }