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 "alm_healpix_tools.h"
00040 #include "alm_powspec_tools.h"
00041 #include "fitshandle.h"
00042 #include "levels_facilities.h"
00043 #include "lsconstants.h"
00044 #include "announce.h"
00045 #include "planck_rng.h"
00046
00047 using namespace std;
00048
00049 namespace {
00050
00051 template<typename T> void alm2map_cxx (paramfile ¶ms)
00052 {
00053 int nlmax = params.template find<int>("nlmax");
00054 int nmmax = params.template find<int>("nmmax",nlmax);
00055 planck_assert(nmmax<=nlmax,"nmmax must not be larger than nlmax");
00056 string infile = params.template find<string>("infile");
00057 string outfile = params.template find<string>("outfile");
00058 int nside = params.template find<int>("nside");
00059 double fwhm = arcmin2rad*params.template find<double>("fwhm_arcmin",0);
00060 int cw_lmin=-1, cw_lmax=-1;
00061 if (params.param_present("cw_lmin"))
00062 {
00063 cw_lmin = params.template find<int>("cw_lmin");
00064 cw_lmax = params.template find<int>("cw_lmax");
00065 }
00066
00067 arr<double> temp, pol;
00068 get_pixwin (params,nlmax,nside,temp,pol);
00069
00070 bool deriv = params.template find<bool>("derivatives",false);
00071 if (deriv)
00072 {
00073 Alm<xcomplex<T> > alm;
00074 read_Alm_from_fits(infile,alm,nlmax,nmmax,2);
00075 if (fwhm>0) smoothWithGauss (alm, fwhm);
00076 if (cw_lmin>=0) applyCosineWindow(alm, cw_lmin, cw_lmax);
00077 Healpix_Map<T> map(nside,RING,SET_NSIDE),
00078 mapdth(nside,RING,SET_NSIDE),
00079 mapdph(nside,RING,SET_NSIDE);
00080 alm.ScaleL(temp);
00081
00082 double offset = alm(0,0).real()/sqrt(fourpi);
00083 alm(0,0) = 0;
00084 alm2map_der1(alm,map,mapdth,mapdph);
00085 map.Add(T(offset));
00086 write_Healpix_map_to_fits (outfile,map,mapdth,mapdph,planckType<T>());
00087 return;
00088 }
00089
00090 bool polarisation = params.template find<bool>("polarisation");
00091 bool do_regnoise = params.param_present("regnoiseT");
00092 if (!polarisation)
00093 {
00094 Alm<xcomplex<T> > alm;
00095 read_Alm_from_fits(infile,alm,nlmax,nmmax,2);
00096 if (fwhm>0) smoothWithGauss (alm, fwhm);
00097 if (cw_lmin>=0) applyCosineWindow(alm, cw_lmin, cw_lmax);
00098 Healpix_Map<T> map(nside,RING,SET_NSIDE);
00099 alm.ScaleL(temp);
00100
00101 double offset = alm(0,0).real()/sqrt(fourpi);
00102 alm(0,0) = 0;
00103 alm2map(alm,map);
00104 map.Add(T(offset));
00105 if (do_regnoise)
00106 {
00107 planck_rng rng(params.template find<int>("rand_seed",42));
00108 double rms = params.template find<double>("regnoiseT");
00109 for (int i=0; i<map.Npix(); ++i)
00110 map[i] += rms*rng.rand_gauss();
00111 }
00112 write_Healpix_map_to_fits (outfile,map,planckType<T>());
00113 }
00114 else
00115 {
00116 Alm<xcomplex<T> > almT, almG, almC;
00117 read_Alm_from_fits(infile,almT,almG,almC,nlmax,nmmax,2);
00118 if (fwhm>0) smoothWithGauss (almT, almG, almC, fwhm);
00119 if (cw_lmin>=0) applyCosineWindow(almT, almG, almC, cw_lmin, cw_lmax);
00120 Healpix_Map<T> mapT(nside,RING,SET_NSIDE), mapQ(nside,RING,SET_NSIDE),
00121 mapU(nside,RING,SET_NSIDE);
00122 almT.ScaleL(temp);
00123 almG.ScaleL(pol); almC.ScaleL(pol);
00124
00125 double offset = almT(0,0).real()/sqrt(fourpi);
00126 almT(0,0) = 0;
00127 alm2map_pol(almT,almG,almC,mapT,mapQ,mapU);
00128 mapT.Add(T(offset));
00129 if (do_regnoise)
00130 {
00131 planck_rng rng(params.template find<int>("rand_seed",42));
00132 double rmsT = params.template find<double>("regnoiseT"),
00133 rmsQU = params.template find<double>("regnoiseQU");
00134 for (int i=0; i<mapT.Npix(); ++i)
00135 {
00136 mapT[i] += rmsT *rng.rand_gauss();
00137 mapQ[i] += rmsQU*rng.rand_gauss();
00138 mapU[i] += rmsQU*rng.rand_gauss();
00139 }
00140 }
00141 write_Healpix_map_to_fits (outfile,mapT,mapQ,mapU,planckType<T>());
00142 }
00143 }
00144
00145 }
00146
00147 int alm2map_cxx_module (int argc, const char **argv)
00148 {
00149 module_startup ("alm2map_cxx", argc, argv);
00150 paramfile params (getParamsFromCmdline(argc,argv));
00151
00152 bool dp = params.find<bool> ("double_precision",false);
00153 dp ? alm2map_cxx<double>(params) : alm2map_cxx<float>(params);
00154 return 0;
00155 }