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 "alm_fitsio.h"
00039 #include "healpix_map.h"
00040 #include "healpix_map_fitsio.h"
00041 #include "alm_healpix_tools.h"
00042 #include "alm_powspec_tools.h"
00043 #include "fitshandle.h"
00044
00045 using namespace std;
00046
00047 template<typename T> void alm2map_cxx (paramfile ¶ms, simparams &par)
00048 {
00049 par.add_comment("-----------------------");
00050 par.add_comment(" ** alm2map_cxx 1.0 **");
00051 par.add_comment("-----------------------");
00052
00053 int nlmax = params.template find<int>("nlmax");
00054 par.add("nlmax","NLMAX",nlmax,"maximum l of the alms");
00055 int nmmax = params.template find<int>("nmmax",nlmax);
00056 par.add("nmmax","NMMAX",nmmax,"maximum m of the alms");
00057 planck_assert(nmmax<=nlmax,"nmmax must not be larger than nlmax");
00058 string infile = params.template find<string>("infile");
00059 par.add_source_file (infile, 2);
00060 string outfile = params.template find<string>("outfile");
00061 int nside = params.template find<int>("nside");
00062 double fwhm_arcmin = params.template find<double>("fwhm_arcmin",0);
00063
00064 arr<double> temp, pol;
00065 get_pixwin (params,par,nlmax,nside,temp,pol);
00066
00067 bool deriv = params.template find<bool>("derivatives",false);
00068 if (deriv)
00069 {
00070 Alm<xcomplex<T> > alm;
00071 read_Alm_from_fits(infile,alm,nlmax,nmmax,2);
00072 if (fwhm_arcmin>0) smooth_with_Gauss (alm, fwhm_arcmin);
00073 Healpix_Map<T> map(nside,RING,SET_NSIDE),
00074 mapdth(nside,RING,SET_NSIDE),
00075 mapdph(nside,RING,SET_NSIDE);
00076 alm.ScaleL(temp);
00077
00078 double offset = alm(0,0).real()/sqrt(fourpi);
00079 alm(0,0) = 0;
00080 alm2map_der1(alm,map,mapdth,mapdph);
00081 for (int m=0; m<map.Npix(); ++m) map[m]+=offset;
00082 fitshandle out;
00083 out.create (outfile);
00084 write_Healpix_map_to_fits (out,map,mapdth,mapdph,FITSUTIL<T>::DTYPE);
00085 par.add_keys(out);
00086 return;
00087 }
00088
00089 bool polarisation = params.template find<bool>("polarisation");
00090 if (!polarisation)
00091 {
00092 Alm<xcomplex<T> > alm;
00093 read_Alm_from_fits(infile,alm,nlmax,nmmax,2);
00094 if (fwhm_arcmin>0) smooth_with_Gauss (alm, fwhm_arcmin);
00095 Healpix_Map<T> map(nside,RING,SET_NSIDE);
00096 alm.ScaleL(temp);
00097
00098 double offset = alm(0,0).real()/sqrt(fourpi);
00099 alm(0,0) = 0;
00100 alm2map(alm,map);
00101 map.add(offset);
00102 fitshandle out;
00103 out.create (outfile);
00104 write_Healpix_map_to_fits (out,map,FITSUTIL<T>::DTYPE);
00105 par.add_keys(out);
00106 }
00107 else
00108 {
00109 Alm<xcomplex<T> > almT, almG, almC;
00110 read_Alm_from_fits(infile,almT,nlmax,nmmax,2);
00111 read_Alm_from_fits(infile,almG,nlmax,nmmax,3);
00112 read_Alm_from_fits(infile,almC,nlmax,nmmax,4);
00113 if (fwhm_arcmin>0) smooth_with_Gauss (almT, almG, almC, fwhm_arcmin);
00114 Healpix_Map<T> mapT(nside,RING,SET_NSIDE), mapQ(nside,RING,SET_NSIDE),
00115 mapU(nside,RING,SET_NSIDE);
00116 almT.ScaleL(temp);
00117 almG.ScaleL(pol); almC.ScaleL(pol);
00118
00119 double offset = almT(0,0).real()/sqrt(fourpi);
00120 almT(0,0) = 0;
00121 alm2map_pol(almT,almG,almC,mapT,mapQ,mapU);
00122 mapT.add(offset);
00123 fitshandle out;
00124 out.create (outfile);
00125 write_Healpix_map_to_fits (out,mapT,mapQ,mapU,FITSUTIL<T>::DTYPE);
00126 par.add_keys(out);
00127 }
00128 }
00129
00130 int main (int argc, const char **argv)
00131 {
00132 PLANCK_DIAGNOSIS_BEGIN
00133 module_startup ("alm2map_cxx", argc, argv, 2, "<parameter file>");
00134 paramfile params (argv[1]);
00135 simparams par;
00136
00137 bool dp = params.find<bool> ("double_precision",false);
00138 dp ? alm2map_cxx<double>(params,par) : alm2map_cxx<float>(params,par);
00139 PLANCK_DIAGNOSIS_END
00140 }