alm2map_cxx_module.cc

00001 /*
00002  *  This file is part of Healpix_cxx.
00003  *
00004  *  Healpix_cxx is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  Healpix_cxx is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with Healpix_cxx; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *  For more information about HEALPix, see http://healpix.sourceforge.net
00019  */
00020 
00021 /*
00022  *  Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
00023  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00024  *  (DLR).
00025  */
00026 
00027 /*
00028  *  Copyright (C) 2003-2010 Max-Planck-Society
00029  *  Author: Martin Reinecke
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 
00046 using namespace std;
00047 
00048 namespace {
00049 
00050 template<typename T> void alm2map_cxx (paramfile &params)
00051   {
00052   int nlmax = params.template find<int>("nlmax");
00053   int nmmax = params.template find<int>("nmmax",nlmax);
00054   planck_assert(nmmax<=nlmax,"nmmax must not be larger than nlmax");
00055   string infile = params.template find<string>("infile");
00056   string outfile = params.template find<string>("outfile");
00057   int nside = params.template find<int>("nside");
00058   double fwhm = arcmin2rad*params.template find<double>("fwhm_arcmin",0);
00059 
00060   arr<double> temp, pol;
00061   get_pixwin (params,nlmax,nside,temp,pol);
00062 
00063   bool deriv = params.template find<bool>("derivatives",false);
00064   if (deriv)
00065     {
00066     Alm<xcomplex<T> > alm;
00067     read_Alm_from_fits(infile,alm,nlmax,nmmax,2);
00068     if (fwhm>0) smoothWithGauss (alm, fwhm);
00069     Healpix_Map<T> map(nside,RING,SET_NSIDE),
00070                    mapdth(nside,RING,SET_NSIDE),
00071                    mapdph(nside,RING,SET_NSIDE);
00072     alm.ScaleL(temp);
00073 
00074     double offset = alm(0,0).real()/sqrt(fourpi);
00075     alm(0,0) = 0;
00076     alm2map_der1(alm,map,mapdth,mapdph);
00077     map.Add(T(offset));
00078     write_Healpix_map_to_fits (outfile,map,mapdth,mapdph,planckType<T>());
00079     return;
00080     }
00081 
00082   bool polarisation = params.template find<bool>("polarisation");
00083   if (!polarisation)
00084     {
00085     Alm<xcomplex<T> > alm;
00086     read_Alm_from_fits(infile,alm,nlmax,nmmax,2);
00087     if (fwhm>0) smoothWithGauss (alm, fwhm);
00088     Healpix_Map<T> map(nside,RING,SET_NSIDE);
00089     alm.ScaleL(temp);
00090 
00091     double offset = alm(0,0).real()/sqrt(fourpi);
00092     alm(0,0) = 0;
00093     alm2map(alm,map);
00094     map.Add(T(offset));
00095     write_Healpix_map_to_fits (outfile,map,planckType<T>());
00096     }
00097   else
00098     {
00099     Alm<xcomplex<T> > almT, almG, almC;
00100     read_Alm_from_fits(infile,almT,almG,almC,nlmax,nmmax,2);
00101     if (fwhm>0) smoothWithGauss (almT, almG, almC, fwhm);
00102     Healpix_Map<T> mapT(nside,RING,SET_NSIDE), mapQ(nside,RING,SET_NSIDE),
00103                    mapU(nside,RING,SET_NSIDE);
00104     almT.ScaleL(temp);
00105     almG.ScaleL(pol); almC.ScaleL(pol);
00106 
00107     double offset = almT(0,0).real()/sqrt(fourpi);
00108     almT(0,0) = 0;
00109     alm2map_pol(almT,almG,almC,mapT,mapQ,mapU);
00110     mapT.Add(T(offset));
00111     write_Healpix_map_to_fits (outfile,mapT,mapQ,mapU,planckType<T>());
00112     }
00113   }
00114 
00115 } // unnamed namespace
00116 
00117 int alm2map_cxx_module (int argc, const char **argv)
00118   {
00119   module_startup ("alm2map_cxx", argc, argv);
00120   paramfile params (getParamsFromCmdline(argc,argv));
00121 
00122   bool dp = params.find<bool> ("double_precision",false);
00123   dp ? alm2map_cxx<double>(params) : alm2map_cxx<float>(params);
00124   return 0;
00125   }

Generated on Wed Apr 24 11:31:18 2013 for Healpix C++