Healpix C++  3.83
alm2map_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) 2003-2014 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 "alm_fitsio.h"
37 #include "healpix_map.h"
38 #include "healpix_map_fitsio.h"
39 #include "alm_healpix_tools.h"
40 #include "alm_powspec_tools.h"
41 #include "fitshandle.h"
42 #include "levels_facilities.h"
43 #include "lsconstants.h"
44 #include "announce.h"
45 #include "planck_rng.h"
46 
47 using namespace std;
48 
49 namespace {
50 
51 template<typename T> void alm2map_cxx (paramfile &params)
52  {
53  int nlmax = params.template find<int>("nlmax");
54  int nmmax = params.template find<int>("nmmax",nlmax);
55  planck_assert(nmmax<=nlmax,"nmmax must not be larger than nlmax");
56  string infile = params.template find<string>("infile");
57  string outfile = params.template find<string>("outfile");
58  int nside = params.template find<int>("nside");
59  double fwhm = arcmin2rad*params.template find<double>("fwhm_arcmin",0);
60  int cw_lmin=-1, cw_lmax=-1;
61  if (params.param_present("cw_lmin"))
62  {
63  cw_lmin = params.template find<int>("cw_lmin");
64  cw_lmax = params.template find<int>("cw_lmax");
65  }
66 
67  arr<double> temp, pol;
68  get_pixwin (params,nlmax,temp,pol);
69 
70  bool deriv = params.template find<bool>("derivatives",false);
71  if (deriv)
72  {
73  Alm<xcomplex<T> > alm;
74  read_Alm_from_fits(infile,alm,nlmax,nmmax,2);
75  if (fwhm>0) smoothWithGauss (alm, fwhm);
76  if (cw_lmin>=0) applyCosineWindow(alm, cw_lmin, cw_lmax);
77  Healpix_Map<T> map(nside,RING,SET_NSIDE),
78  mapdth(nside,RING,SET_NSIDE),
79  mapdph(nside,RING,SET_NSIDE);
80  alm.ScaleL(temp);
81 
82  double offset = alm(0,0).real()/sqrt(fourpi);
83  alm(0,0) = 0;
84  alm2map_der1(alm,map,mapdth,mapdph);
85  map.Add(T(offset));
86  write_Healpix_map_to_fits (outfile,map,mapdth,mapdph,planckType<T>());
87  return;
88  }
89 
90  bool polarisation = params.template find<bool>("polarisation");
91  bool do_regnoise = params.param_present("regnoiseT");
92  if (!polarisation)
93  {
94  Alm<xcomplex<T> > alm;
95  read_Alm_from_fits(infile,alm,nlmax,nmmax,2);
96  if (fwhm>0) smoothWithGauss (alm, fwhm);
97  if (cw_lmin>=0) applyCosineWindow(alm, cw_lmin, cw_lmax);
98  Healpix_Map<T> map(nside,RING,SET_NSIDE);
99  alm.ScaleL(temp);
100 
101  double offset = alm(0,0).real()/sqrt(fourpi);
102  alm(0,0) = 0;
103  alm2map(alm,map);
104  map.Add(T(offset));
105  if (do_regnoise)
106  {
107  planck_rng rng(params.template find<int>("rand_seed",42));
108  double rms = params.template find<double>("regnoiseT");
109  for (int i=0; i<map.Npix(); ++i)
110  map[i] += rms*rng.rand_gauss();
111  }
112  write_Healpix_map_to_fits (outfile,map,planckType<T>());
113  }
114  else
115  {
116  Alm<xcomplex<T> > almT, almG, almC;
117  read_Alm_from_fits(infile,almT,almG,almC,nlmax,nmmax,2);
118  if (fwhm>0) smoothWithGauss (almT, almG, almC, fwhm);
119  if (cw_lmin>=0) applyCosineWindow(almT, almG, almC, cw_lmin, cw_lmax);
120  Healpix_Map<T> mapT(nside,RING,SET_NSIDE), mapQ(nside,RING,SET_NSIDE),
121  mapU(nside,RING,SET_NSIDE);
122  almT.ScaleL(temp);
123  almG.ScaleL(pol); almC.ScaleL(pol);
124 
125  double offset = almT(0,0).real()/sqrt(fourpi);
126  almT(0,0) = 0;
127  alm2map_pol(almT,almG,almC,mapT,mapQ,mapU);
128  mapT.Add(T(offset));
129  if (do_regnoise)
130  {
131  planck_rng rng(params.template find<int>("rand_seed",42));
132  double rmsT = params.template find<double>("regnoiseT"),
133  rmsQU = params.template find<double>("regnoiseQU");
134  for (int i=0; i<mapT.Npix(); ++i)
135  {
136  mapT[i] += rmsT *rng.rand_gauss();
137  mapQ[i] += rmsQU*rng.rand_gauss();
138  mapU[i] += rmsQU*rng.rand_gauss();
139  }
140  }
141  write_Healpix_map_to_fits (outfile,mapT,mapQ,mapU,planckType<T>());
142  }
143  }
144 
145 } // unnamed namespace
146 
147 int alm2map_cxx_module (int argc, const char **argv)
148  {
149  module_startup ("alm2map_cxx", argc, argv);
150  paramfile params (getParamsFromCmdline(argc,argv));
151 
152  bool dp = params.find<bool> ("double_precision",false);
153  dp ? alm2map_cxx<double>(params) : alm2map_cxx<float>(params);
154  return 0;
155  }
void alm2map_der1(const Alm< xcomplex< T > > &alm, Healpix_Map< T > &map, Healpix_Map< T > &mapdth, Healpix_Map< T > &mapdph)
void ScaleL(const arr< T2 > &factor)
Definition: alm.h:123
void read_Alm_from_fits(fitshandle &inp, Alm< xcomplex< T > > &alms, int lmax, int mmax)
Definition: alm_fitsio.cc:95
Definition: alm.h:88
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)
void write_Healpix_map_to_fits(fitshandle &out, const Healpix_Map< T > &map, PDT datatype)
void alm2map(const Alm< xcomplex< T > > &alm, Healpix_Map< T > &map, bool add_map)

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