00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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 ¶ms)
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
00064 string datadir;
00065 if ((nside_pixwin_in>0) || (nside_pixwin_out>0))
00066 datadir = params.template find<string>("healpix_data");
00067
00068 bool polarisation = params.template find<bool>("polarisation");
00069 if (!polarisation)
00070 {
00071 int nlmax, nmmax;
00072 get_almsize(infile, nlmax, nmmax, 2);
00073 Alm<xcomplex<T> > alm;
00074 read_Alm_from_fits(infile,alm,nlmax,nmmax,2);
00075 if (fwhm_in>0) smoothWithGauss (alm, -fwhm_in);
00076 arr<double> temp(nlmax+1);
00077 PowSpec tps;
00078 if (nside_pixwin_in>0)
00079 {
00080 read_pixwin(datadir,nside_pixwin_in,temp);
00081 for (int l=0; l<=nlmax; ++l)
00082 temp[l] = 1/temp[l];
00083 alm.ScaleL (temp);
00084 }
00085 if (cl_in!="")
00086 {
00087 read_powspec_from_fits (cl_in,tps,1,alm.Lmax());
00088 for (int l=0; l<=nlmax; ++l)
00089 temp[l] = 1./sqrt(tps.tt(l));
00090 alm.ScaleL (temp);
00091 }
00092 if (nside_pixwin_out>0)
00093 {
00094 read_pixwin(datadir,nside_pixwin_out,temp);
00095 alm.ScaleL (temp);
00096 }
00097 if (cl_out!="")
00098 {
00099 read_powspec_from_fits (cl_out,tps,1,alm.Lmax());
00100 for (int l=0; l<=nlmax; ++l)
00101 temp[l] = sqrt(tps.tt(l));
00102 alm.ScaleL (temp);
00103 }
00104 if (fwhm_out>0) smoothWithGauss (alm, fwhm_out);
00105 write_Alm_to_fits (outfile,alm,nlmax,nmmax,planckType<T>());
00106 }
00107 else
00108 {
00109 int nlmax, nmmax;
00110 get_almsize_pol(infile, nlmax, nmmax);
00111 Alm<xcomplex<T> > almT, almG, almC;
00112 read_Alm_from_fits(infile,almT,almG,almC,nlmax,nmmax,2);
00113 if (fwhm_in>0) smoothWithGauss (almT, almG, almC, -fwhm_in);
00114 arr<double> temp(nlmax+1), pol(nlmax+1);
00115 if (nside_pixwin_in>0)
00116 {
00117 read_pixwin(datadir,nside_pixwin_in,temp,pol);
00118 for (int l=0; l<=nlmax; ++l)
00119 { temp[l] = 1/temp[l]; if (pol[l]!=0) pol[l] = 1/pol[l]; }
00120 almT.ScaleL(temp); almG.ScaleL(pol); almC.ScaleL(pol);
00121 }
00122 if (cl_in!="")
00123 planck_fail ("power spectra not (yet) supported with polarisation");
00124 if (nside_pixwin_out>0)
00125 {
00126 read_pixwin(datadir,nside_pixwin_out,temp,pol);
00127 almT.ScaleL(temp); almG.ScaleL(pol); almC.ScaleL(pol);
00128 }
00129 if (cl_out!="")
00130 planck_fail ("power spectra not (yet) supported with polarisation");
00131 if (fwhm_out>0) smoothWithGauss (almT, almG, almC, fwhm_out);
00132 write_Alm_to_fits (outfile,almT,almG,almC,nlmax,nmmax,planckType<T>());
00133 }
00134 }
00135
00136 }
00137
00138 int mult_alm_module (int argc, const char **argv)
00139 {
00140 module_startup ("mult_alm", argc, argv);
00141 paramfile params (getParamsFromCmdline(argc,argv));
00142
00143 bool dp = params.find<bool> ("double_precision",false);
00144 dp ? mult_alm<double>(params) : mult_alm<float>(params);
00145
00146 return 0;
00147 }