Healpix C++  3.83
mult_alm_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-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 "powspec.h"
36 #include "powspec_fitsio.h"
37 #include "alm.h"
38 #include "alm_fitsio.h"
39 #include "alm_powspec_tools.h"
40 #include "fitshandle.h"
41 #include "levels_facilities.h"
42 #include "lsconstants.h"
43 #include "announce.h"
44 
45 using namespace std;
46 
47 namespace {
48 
49 template<typename T> void mult_alm (paramfile &params)
50  {
51  string infile = params.template find<string>("infile");
52  string outfile = params.template find<string>("outfile");
53  string pixwin_in = params.template find<string>("pixwin_in","");
54  string pixwin_out = params.template find<string>("pixwin_out","");
55  string cl_in = params.template find<string>("cl_in","");
56  string cl_out = params.template find<string>("cl_out","");
57  double fwhm_in = arcmin2rad*params.template find<double>("fwhm_arcmin_in",0);
58  planck_assert (fwhm_in>=0,"fwhm_arcmin_in must be >= 0");
59  double fwhm_out = arcmin2rad*params.template find<double>("fwhm_arcmin_out",0);
60  planck_assert (fwhm_out>=0,"fwhm_arcmin_out must be >= 0");
61  int cw_lmin=-1, cw_lmax=-1;
62  if (params.param_present("cw_lmin"))
63  {
64  cw_lmin = params.template find<int>("cw_lmin");
65  cw_lmax = params.template find<int>("cw_lmax");
66  }
67 
68  bool polarisation = params.template find<bool>("polarisation");
69  if (!polarisation)
70  {
71  int nlmax, nmmax;
72  get_almsize(infile, nlmax, nmmax, 2);
73  Alm<xcomplex<T> > alm;
74  read_Alm_from_fits(infile,alm,nlmax,nmmax,2);
75  if (fwhm_in>0) smoothWithGauss (alm, -fwhm_in);
76  arr<double> temp(nlmax+1);
77  PowSpec tps;
78  if (pixwin_in!="")
79  {
80  read_pixwin(pixwin_in,temp);
81  for (int l=0; l<=nlmax; ++l)
82  temp[l] = 1/temp[l];
83  alm.ScaleL (temp);
84  }
85  if (cl_in!="")
86  {
87  read_powspec_from_fits (cl_in,tps,1,alm.Lmax());
88  for (int l=0; l<=nlmax; ++l)
89  temp[l] = 1./sqrt(tps.tt(l));
90  alm.ScaleL (temp);
91  }
92  if (pixwin_out!="")
93  {
94  read_pixwin(pixwin_out,temp);
95  alm.ScaleL (temp);
96  }
97  if (cl_out!="")
98  {
99  read_powspec_from_fits (cl_out,tps,1,alm.Lmax());
100  for (int l=0; l<=nlmax; ++l)
101  temp[l] = sqrt(tps.tt(l));
102  alm.ScaleL (temp);
103  }
104  if (fwhm_out>0) smoothWithGauss (alm, fwhm_out);
105  if (cw_lmin>=0) applyCosineWindow(alm, cw_lmin, cw_lmax);
106  write_Alm_to_fits (outfile,alm,nlmax,nmmax,planckType<T>());
107  }
108  else
109  {
110  int nlmax, nmmax;
111  get_almsize_pol(infile, nlmax, nmmax);
112  Alm<xcomplex<T> > almT, almG, almC;
113  read_Alm_from_fits(infile,almT,almG,almC,nlmax,nmmax,2);
114  if (fwhm_in>0) smoothWithGauss (almT, almG, almC, -fwhm_in);
115  arr<double> temp(nlmax+1), pol(nlmax+1);
116  if (pixwin_in!="")
117  {
118  read_pixwin(pixwin_in,temp,pol);
119  for (int l=0; l<=nlmax; ++l)
120  { temp[l] = 1/temp[l]; if (pol[l]!=0.) pol[l] = 1/pol[l]; }
121  almT.ScaleL(temp); almG.ScaleL(pol); almC.ScaleL(pol);
122  }
123  if (cl_in!="")
124  planck_fail ("power spectra not (yet) supported with polarisation");
125  if (pixwin_out!="")
126  {
127  read_pixwin(pixwin_out,temp,pol);
128  almT.ScaleL(temp); almG.ScaleL(pol); almC.ScaleL(pol);
129  }
130  if (cl_out!="")
131  planck_fail ("power spectra not (yet) supported with polarisation");
132  if (fwhm_out>0) smoothWithGauss (almT, almG, almC, fwhm_out);
133  if (cw_lmin>=0) applyCosineWindow(almT, almG, almC, cw_lmin, cw_lmax);
134  write_Alm_to_fits (outfile,almT,almG,almC,nlmax,nmmax,planckType<T>());
135  }
136  }
137 
138 } // unnamed namespace
139 
140 int mult_alm_module (int argc, const char **argv)
141  {
142  module_startup ("mult_alm", argc, argv);
143  paramfile params (getParamsFromCmdline(argc,argv));
144 
145  bool dp = params.find<bool> ("double_precision",false);
146  dp ? mult_alm<double>(params) : mult_alm<float>(params);
147 
148  return 0;
149  }
void write_Alm_to_fits(fitshandle &out, const Alm< xcomplex< T > > &alms, int lmax, int mmax, PDT datatype)
Definition: alm_fitsio.cc:151
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
const arr< double > & tt() const
Definition: powspec.h:69
void get_almsize_pol(const std::string &filename, int &lmax, int &mmax)
int Lmax() const
Definition: alm.h:65
void read_powspec_from_fits(fitshandle &inp, PowSpec &powspec, int nspecs, int lmax)
void get_almsize(fitshandle &inp, int &lmax, int &mmax)
Definition: alm_fitsio.cc:42

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