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 "paramfile.h"
00033 #include "healpix_map.h"
00034 #include "healpix_map_fitsio.h"
00035 #include "fitshandle.h"
00036 #include "levels_facilities.h"
00037 #include "geom_utils.h"
00038 #include "xcomplex.h"
00039 #include "announce.h"
00040
00041 using namespace std;
00042
00043 namespace {
00044
00045 double alpha (const pointing &p1, const pointing &p2)
00046 {
00047 vec3 v1(p1), v2(p2);
00048 vec3 dir(v2-v1);
00049 return orientation (v2, dir) - orientation (v1,dir);
00050 }
00051
00052 template<typename T> void degrade_pol (const Healpix_Map<T> &q1,
00053 const Healpix_Map<T> &u1, Healpix_Map<T> &q2, Healpix_Map<T> &u2,
00054 bool pessimistic)
00055 {
00056 planck_assert(q1.conformable(u1) && q2.conformable(u2), "map mismatch");
00057 planck_assert(q2.Nside()<q1.Nside(),"this is no degrade");
00058 int fact = q1.Nside()/q2.Nside();
00059 planck_assert (q1.Nside()==q2.Nside()*fact,
00060 "the larger Nside must be a multiple of the smaller one");
00061
00062 int minhits = pessimistic ? fact*fact : 1;
00063 #pragma omp parallel
00064 {
00065 int m, npix=q2.Npix();
00066 #pragma omp for schedule (static)
00067 for (m=0; m<npix; ++m)
00068 {
00069 int x,y,f;
00070 q2.pix2xyf(m,x,y,f);
00071 int hits = 0;
00072 xcomplex<double> sum = 0;
00073 for (int j=fact*y; j<fact*(y+1); ++j)
00074 for (int i=fact*x; i<fact*(x+1); ++i)
00075 {
00076 int opix = q1.xyf2pix(i,j,f);
00077 if (!(approx<double>(q1[opix],Healpix_undef)
00078 ||approx<double>(u1[opix],Healpix_undef)))
00079 {
00080 ++hits;
00081 xcomplex<double> val(q1[opix],u1[opix]);
00082 double ang=alpha(q2.pix2ang(m),q1.pix2ang(opix));
00083 xcomplex<double> mul(cos(2*ang),sin(2*ang));
00084 sum += val*mul;
00085 }
00086 }
00087 q2[m] = T((hits<minhits) ? Healpix_undef : sum.real()/hits);
00088 u2[m] = T((hits<minhits) ? Healpix_undef : sum.imag()/hits);
00089 }
00090 }
00091 }
00092
00093 template<typename T> void udgrade_cxx (paramfile ¶ms)
00094 {
00095 string infile = params.template find<string>("infile");
00096 string outfile = params.template find<string>("outfile");
00097 int nside = params.template find<int>("nside");
00098 bool polarisation = params.template find<bool>("polarisation",false);
00099 bool pessimistic = params.template find<bool>("pessimistic",false);
00100
00101 if (!polarisation)
00102 {
00103 Healpix_Map<T> inmap;
00104 read_Healpix_map_from_fits(infile,inmap,1,2);
00105 Healpix_Map<T> outmap (nside,inmap.Scheme(),SET_NSIDE);
00106
00107 outmap.Import(inmap,pessimistic);
00108 write_Healpix_map_to_fits (outfile,outmap,planckType<T>());
00109 }
00110 else
00111 {
00112 Healpix_Map<T> inmap;
00113 read_Healpix_map_from_fits(infile,inmap,1,2);
00114 Healpix_Map<T> outmapT (nside,inmap.Scheme(),SET_NSIDE),
00115 outmapQ (nside,inmap.Scheme(),SET_NSIDE),
00116 outmapU (nside,inmap.Scheme(),SET_NSIDE);
00117
00118
00119
00120 outmapT.Import(inmap,pessimistic);
00121 if ((outmapQ.Nside()<inmap.Nside())
00122 && params.template find<bool>("parallel_transport",true))
00123 {
00124 cout << "Experimental: polarised degrade with parallel transport" << endl;
00125 read_Healpix_map_from_fits(infile,inmap,2,2);
00126 Healpix_Map<T> inmap2;
00127 read_Healpix_map_from_fits(infile,inmap2,3,2);
00128 degrade_pol (inmap, inmap2, outmapQ, outmapU, pessimistic);
00129 }
00130 else
00131 {
00132 cout << "WARNING: polarised degrade without parallel transport" << endl;
00133 read_Healpix_map_from_fits(infile,inmap,2,2);
00134 outmapQ.Import(inmap,pessimistic);
00135 read_Healpix_map_from_fits(infile,inmap,3,2);
00136 outmapU.Import(inmap,pessimistic);
00137 }
00138 write_Healpix_map_to_fits (outfile,outmapT,outmapQ,outmapU,planckType<T>());
00139 }
00140 }
00141
00142 }
00143
00144 int udgrade_cxx_module (int argc, const char **argv)
00145 {
00146 module_startup ("udgrade_cxx", argc, argv);
00147 paramfile params (getParamsFromCmdline(argc,argv));
00148
00149 bool dp = params.find<bool> ("double_precision",false);
00150 dp ? udgrade_cxx<double>(params) : udgrade_cxx<float>(params);
00151
00152 return 0;
00153 }