Healpix C++  3.83
smoothing_cxx_module.cc
1 /*
2  * This file is part of Healpix_cxx.
3  *
4  * Healpix_cxx is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Healpix_cxx is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Healpix_cxx; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * For more information about HEALPix, see http://healpix.sourceforge.net
19  */
20 
21 /*
22  * Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
23  * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
24  * (DLR).
25  */
26 
27 /*
28  * Copyright (C) 2005-2017 Max-Planck-Society
29  * Author: Martin Reinecke
30  */
31 
32 #include "xcomplex.h"
33 #include "paramfile.h"
34 #include "healpix_data_io.h"
35 #include "alm.h"
36 #include "healpix_map.h"
37 #include "healpix_map_fitsio.h"
38 #include "alm_healpix_tools.h"
39 #include "alm_powspec_tools.h"
40 #include "weight_utils.h"
41 #include "fitshandle.h"
42 #include "levels_facilities.h"
43 #include "lsconstants.h"
44 #include "announce.h"
45 
46 using namespace std;
47 
48 namespace {
49 
50 template<typename T> void smoothing_cxx (paramfile &params)
51  {
52  int nlmax = params.template find<int>("nlmax");
53  string infile = params.template find<string>("infile");
54  string outfile = params.template find<string>("outfile");
55  bool polarisation = params.template find<bool>("polarisation");
56  int num_iter = params.template find<int>("iter_order",0);
57  double fwhm = arcmin2rad*params.template find<double>("fwhm_arcmin");
58  if (fwhm<0)
59  cout << "NOTE: negative FWHM supplied, doing a deconvolution..." << endl;
60  bool do_pwgt = params.param_present("pixelweights");
61  planck_assert(!(params.param_present("ringweights")&&do_pwgt),
62  "both pixel and ring weights specified");
63  planck_assert((num_iter==0)||(!do_pwgt),
64  "iterative analysis cannot be done in combination with pixel weights");
65 
66  if (!polarisation)
67  {
68  Healpix_Map<T> map;
69  read_Healpix_map_from_fits(infile,map,1,2);
70 
71  tsize nmod = map.replaceUndefWith0();
72  if (nmod!=0)
73  cout << "WARNING: replaced " << nmod <<
74  " undefined map pixels with a value of 0" << endl;
75 
76  double avg=map.average();
77  map.Add(T(-avg));
78 
79  if (do_pwgt)
80  {
81  auto pwgt = read_fullweights_from_fits(
82  params.template find<string>("pixelweights"), map.Nside());
83  apply_fullweights(map,pwgt);
84  }
85 
86  arr<double> weight;
87  get_ring_weights (params,map.Nside(),weight);
88 
89  Alm<xcomplex<T> > alm(nlmax,nlmax);
90  if (map.Scheme()==NEST) map.swap_scheme();
91 
92  map2alm_iter(map,alm,num_iter,weight);
93  smoothWithGauss (alm, fwhm);
94  alm2map(alm,map);
95 
96  map.Add(T(avg));
97  write_Healpix_map_to_fits (outfile,map,planckType<T>());
98  }
99  else
100  {
101  Healpix_Map<T> mapT, mapQ, mapU;
102  read_Healpix_map_from_fits(infile,mapT,mapQ,mapU);
103 
104  tsize nmod = mapT.replaceUndefWith0()+mapQ.replaceUndefWith0()
105  +mapU.replaceUndefWith0();
106  if (nmod!=0)
107  cout << "WARNING: replaced " << nmod <<
108  " undefined map pixels with a value of 0" << endl;
109 
110  double avg=mapT.average();
111  mapT.Add(T(-avg));
112 
113  if (do_pwgt)
114  {
115  auto pwgt = read_fullweights_from_fits(
116  params.template find<string>("pixelweights"), mapT.Nside());
117  apply_fullweights(mapT,pwgt);
118  apply_fullweights(mapQ,pwgt);
119  apply_fullweights(mapU,pwgt);
120  }
121 
122  arr<double> weight;
123  get_ring_weights (params,mapT.Nside(),weight);
124 
125  Alm<xcomplex<T> > almT(nlmax,nlmax), almG(nlmax,nlmax), almC(nlmax,nlmax);
126  if (mapT.Scheme()==NEST) mapT.swap_scheme();
127  if (mapQ.Scheme()==NEST) mapQ.swap_scheme();
128  if (mapU.Scheme()==NEST) mapU.swap_scheme();
129 
131  (mapT,mapQ,mapU,almT,almG,almC,num_iter,weight);
132  smoothWithGauss (almT, almG, almC, fwhm);
133  alm2map_pol(almT,almG,almC,mapT,mapQ,mapU);
134 
135  mapT.Add(T(avg));
136  write_Healpix_map_to_fits (outfile,mapT,mapQ,mapU,planckType<T>());
137  }
138  }
139 
140 } // unnamed namespace
141 
142 int smoothing_cxx_module (int argc, const char **argv)
143  {
144  module_startup ("smoothing_cxx", argc, argv);
145  paramfile params (getParamsFromCmdline(argc,argv));
146 
147  bool dp = params.find<bool> ("double_precision",false);
148  dp ? smoothing_cxx<double>(params) : smoothing_cxx<float>(params);
149 
150  return 0;
151  }
I Nside() const
Definition: healpix_base.h:427
double average() const
Definition: healpix_map.h:244
Definition: alm.h:88
void map2alm_pol_iter(const Healpix_Map< T > &mapT, const Healpix_Map< T > &mapQ, const Healpix_Map< T > &mapU, Alm< xcomplex< T > > &almT, Alm< xcomplex< T > > &almG, Alm< xcomplex< T > > &almC, int num_iter, const arr< double > &weight)
void apply_fullweights(Healpix_Map< T > &map, const std::vector< double > &wgt)
void read_Healpix_map_from_fits(fitshandle &inp, Healpix_Map< T > &map, int colnum)
void alm2map_pol(const Alm< xcomplex< T > > &almT, const Alm< xcomplex< T > > &almG, const Alm< xcomplex< T > > &almC, Healpix_Map< T > &mapT, Healpix_Map< T > &mapQ, Healpix_Map< T > &mapU, bool add_map)
tsize replaceUndefWith0()
Definition: healpix_map.h:306
Healpix_Ordering_Scheme Scheme() const
Definition: healpix_base.h:431
void write_Healpix_map_to_fits(fitshandle &out, const Healpix_Map< T > &map, PDT datatype)
void map2alm_iter(const Healpix_Map< T > &map, Alm< xcomplex< T > > &alm, int num_iter, const arr< double > &weight)
void alm2map(const Alm< xcomplex< T > > &alm, Healpix_Map< T > &map, bool add_map)
void swap_scheme()
Definition: healpix_map.h:179
void Add(T val)
Definition: healpix_map.h:255

Generated on Wed Nov 13 2024 12:18:30 for Healpix C++