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-2015 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 
00065     tsize nmod = map.replaceUndefWith0();
00066     if (nmod!=0)
00067       cout << "WARNING: replaced " << nmod <<
00068               " undefined map pixels with a value of 0" << endl;
00069 
00070     double avg=map.average();
00071     map.Add(T(-avg));
00072 
00073     arr<double> weight;
00074     get_ring_weights (params,map.Nside(),weight);
00075 
00076     Alm<xcomplex<T> > alm(nlmax,nlmax);
00077     if (map.Scheme()==NEST) map.swap_scheme();
00078 
00079     map2alm_iter(map,alm,num_iter,weight);
00080     smoothWithGauss (alm, fwhm);
00081     alm2map(alm,map);
00082 
00083     map.Add(T(avg));
00084     write_Healpix_map_to_fits (outfile,map,planckType<T>());
00085     }
00086   else
00087     {
00088     Healpix_Map<T> mapT, mapQ, mapU;
00089     read_Healpix_map_from_fits(infile,mapT,mapQ,mapU);
00090 
00091     tsize nmod = mapT.replaceUndefWith0()+mapQ.replaceUndefWith0()
00092                 +mapU.replaceUndefWith0();
00093     if (nmod!=0)
00094       cout << "WARNING: replaced " << nmod <<
00095               " undefined map pixels with a value of 0" << endl;
00096 
00097     double avg=mapT.average();
00098     mapT.Add(T(-avg));
00099 
00100     arr<double> weight;
00101     get_ring_weights (params,mapT.Nside(),weight);
00102 
00103     Alm<xcomplex<T> > almT(nlmax,nlmax), almG(nlmax,nlmax), almC(nlmax,nlmax);
00104     if (mapT.Scheme()==NEST) mapT.swap_scheme();
00105     if (mapQ.Scheme()==NEST) mapQ.swap_scheme();
00106     if (mapU.Scheme()==NEST) mapU.swap_scheme();
00107 
00108     map2alm_pol_iter
00109       (mapT,mapQ,mapU,almT,almG,almC,num_iter,weight);
00110     smoothWithGauss (almT, almG, almC, fwhm);
00111     alm2map_pol(almT,almG,almC,mapT,mapQ,mapU);
00112 
00113     mapT.Add(T(avg));
00114     write_Healpix_map_to_fits (outfile,mapT,mapQ,mapU,planckType<T>());
00115     }
00116   }
00117 
00118 } // unnamed namespace
00119 
00120 int smoothing_cxx_module (int argc, const char **argv)
00121   {
00122   module_startup ("smoothing_cxx", argc, argv);
00123   paramfile params (getParamsFromCmdline(argc,argv));
00124 
00125   bool dp = params.find<bool> ("double_precision",false);
00126   dp ? smoothing_cxx<double>(params) : smoothing_cxx<float>(params);
00127 
00128   return 0;
00129   }

Generated on Thu Oct 8 14:48:52 2015 for Healpix C++