mult_alm_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) 2003-2014 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 "powspec.h"
00036 #include "powspec_fitsio.h"
00037 #include "alm.h"
00038 #include "alm_fitsio.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 mult_alm (paramfile &params)
00050   {
00051   string infile = params.template find<string>("infile");
00052   string outfile = params.template find<string>("outfile");
00053   int nside_pixwin_in = params.template find<int>("nside_pixwin_in",0);
00054   planck_assert (nside_pixwin_in>=0,"nside_pixwin_in must be >= 0");
00055   int nside_pixwin_out = params.template find<int>("nside_pixwin_out",0);
00056   planck_assert (nside_pixwin_out>=0,"nside_pixwin_out must be >= 0");
00057   string cl_in = params.template find<string>("cl_in","");
00058   string cl_out = params.template find<string>("cl_out","");
00059   double fwhm_in = arcmin2rad*params.template find<double>("fwhm_arcmin_in",0);
00060   planck_assert (fwhm_in>=0,"fwhm_arcmin_in must be >= 0");
00061   double fwhm_out = arcmin2rad*params.template find<double>("fwhm_arcmin_out",0);
00062   planck_assert (fwhm_out>=0,"fwhm_arcmin_out must be >= 0");
00063   int cw_lmin=-1, cw_lmax=-1;
00064   if (params.param_present("cw_lmin"))
00065     {
00066     cw_lmin = params.template find<int>("cw_lmin");
00067     cw_lmax = params.template find<int>("cw_lmax");
00068     }
00069 
00070   string datadir;
00071   if ((nside_pixwin_in>0) || (nside_pixwin_out>0))
00072     datadir = params.template find<string>("healpix_data");
00073 
00074   bool polarisation = params.template find<bool>("polarisation");
00075   if (!polarisation)
00076     {
00077     int nlmax, nmmax;
00078     get_almsize(infile, nlmax, nmmax, 2);
00079     Alm<xcomplex<T> > alm;
00080     read_Alm_from_fits(infile,alm,nlmax,nmmax,2);
00081     if (fwhm_in>0) smoothWithGauss (alm, -fwhm_in);
00082     arr<double> temp(nlmax+1);
00083     PowSpec tps;
00084     if (nside_pixwin_in>0)
00085       {
00086       read_pixwin(datadir,nside_pixwin_in,temp);
00087       for (int l=0; l<=nlmax; ++l)
00088         temp[l] = 1/temp[l];
00089       alm.ScaleL (temp);
00090       }
00091     if (cl_in!="")
00092       {
00093       read_powspec_from_fits (cl_in,tps,1,alm.Lmax());
00094       for (int l=0; l<=nlmax; ++l)
00095         temp[l] = 1./sqrt(tps.tt(l));
00096       alm.ScaleL (temp);
00097       }
00098     if (nside_pixwin_out>0)
00099       {
00100       read_pixwin(datadir,nside_pixwin_out,temp);
00101       alm.ScaleL (temp);
00102       }
00103     if (cl_out!="")
00104       {
00105       read_powspec_from_fits (cl_out,tps,1,alm.Lmax());
00106       for (int l=0; l<=nlmax; ++l)
00107         temp[l] = sqrt(tps.tt(l));
00108       alm.ScaleL (temp);
00109       }
00110     if (fwhm_out>0) smoothWithGauss (alm, fwhm_out);
00111     if (cw_lmin>=0) applyCosineWindow(alm, cw_lmin, cw_lmax);
00112     write_Alm_to_fits (outfile,alm,nlmax,nmmax,planckType<T>());
00113     }
00114   else
00115     {
00116     int nlmax, nmmax;
00117     get_almsize_pol(infile, nlmax, nmmax);
00118     Alm<xcomplex<T> > almT, almG, almC;
00119     read_Alm_from_fits(infile,almT,almG,almC,nlmax,nmmax,2);
00120     if (fwhm_in>0) smoothWithGauss (almT, almG, almC, -fwhm_in);
00121     arr<double> temp(nlmax+1), pol(nlmax+1);
00122     if (nside_pixwin_in>0)
00123       {
00124       read_pixwin(datadir,nside_pixwin_in,temp,pol);
00125       for (int l=0; l<=nlmax; ++l)
00126         { temp[l] = 1/temp[l]; if (pol[l]!=0.) pol[l] = 1/pol[l]; }
00127       almT.ScaleL(temp); almG.ScaleL(pol); almC.ScaleL(pol);
00128       }
00129     if (cl_in!="")
00130       planck_fail ("power spectra not (yet) supported with polarisation");
00131     if (nside_pixwin_out>0)
00132       {
00133       read_pixwin(datadir,nside_pixwin_out,temp,pol);
00134       almT.ScaleL(temp); almG.ScaleL(pol); almC.ScaleL(pol);
00135       }
00136     if (cl_out!="")
00137       planck_fail ("power spectra not (yet) supported with polarisation");
00138     if (fwhm_out>0) smoothWithGauss (almT, almG, almC, fwhm_out);
00139     if (cw_lmin>=0) applyCosineWindow(almT, almG, almC, cw_lmin, cw_lmax);
00140     write_Alm_to_fits (outfile,almT,almG,almC,nlmax,nmmax,planckType<T>());
00141     }
00142   }
00143 
00144 } // unnamed namespace
00145 
00146 int mult_alm_module (int argc, const char **argv)
00147   {
00148   module_startup ("mult_alm", argc, argv);
00149   paramfile params (getParamsFromCmdline(argc,argv));
00150 
00151   bool dp = params.find<bool> ("double_precision",false);
00152   dp ? mult_alm<double>(params) : mult_alm<float>(params);
00153 
00154   return 0;
00155   }

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