smoothing_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) 2005-2011 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 "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 &params)
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 } // unnamed namespace
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   }

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