36 #include "libsharp/sharp_cxx.h"    42 void checkLmaxNside(tsize lmax, tsize nside)
    45     cout << 
"\nWARNING: map analysis requested with lmax>4*nside...\n"    46             "is this really what you want?\n\n";
    52   Alm<xcomplex<T> > &alm, 
const arr<double> &weight, 
bool add_alm)
    54   planck_assert (map.
Scheme()==
RING, 
"map2alm: map must be in RING scheme");
    55   planck_assert (
int(weight.size())>=2*map.
Nside(),
    56     "map2alm: weight array has too few entries");
    57   planck_assert (map.
fullyDefined(),
"map contains undefined pixels");
    58   checkLmaxNside(alm.Lmax(), map.
Nside());
    61   job.set_weighted_Healpix_geometry (map.
Nside(),&weight[0]);
    62   job.set_triangular_alm_info (alm.Lmax(), alm.Mmax());
    63   job.map2alm(&map[0], &alm(0,0), add_alm);
    67   Alm<xcomplex<float> > &alm, 
const arr<double> &weight,
    70   Alm<xcomplex<double> > &alm, 
const arr<double> &weight,
    74   Alm<xcomplex<T> > &alm, 
bool add_alm)
    77     "alm2map_adjoint: map must be in RING scheme");
    78   planck_assert (map.
fullyDefined(),
"map contains undefined pixels");
    79   checkLmaxNside(alm.Lmax(), map.
Nside());
    82   job.set_Healpix_geometry (map.
Nside());
    83   job.set_triangular_alm_info (alm.Lmax(), alm.Mmax());
    84   job.alm2map_adjoint(&map[0], &alm(0,0), add_alm);
    88   Alm<xcomplex<float> > &alm, 
bool add_alm);
    90   Alm<xcomplex<double> > &alm, 
bool add_alm);
    93   Alm<xcomplex<T> > &alm, 
int num_iter, 
const arr<double> &weight)
    96   for (
int iter=1; iter<=num_iter; ++iter)
   100     for (
int m=0; m<map.
Npix(); ++m)
   101       map2[m] = map[m]-map2[m];
   107   Alm<xcomplex<float> > &alm, 
int num_iter,
   108   const arr<double> &weight);
   110   Alm<xcomplex<double> > &alm, 
int num_iter,
   111   const arr<double> &weight);
   113 template<
typename T> 
void map2alm_iter2 (
const Healpix_Map<T> &map,
   114   Alm<xcomplex<T> > &alm, 
double err_abs, 
double err_rel)
   116   double x_err_abs=1./err_abs, x_err_rel=1./err_rel;
   117   arr<double> wgt(2*map.
Nside());
   126     for (
int m=0; m<map.
Npix(); ++m)
   128       double err = abs(map[m]-map2[m]);
   129       double rel = (map[m]!=0) ? abs(err/map[m]) : 1e300;
   130       errmeasure = max(errmeasure,min(err*x_err_abs,rel*x_err_rel));
   131       map2[m] = map[m]-map2[m];
   134     if (errmeasure<1) 
break;
   139   Alm<xcomplex<double> > &alm, 
double err_abs, 
double err_rel);
   142 template<
typename T> 
void map2alm_spin
   144    Alm<xcomplex<T> > &alm1, 
Alm<xcomplex<T> > &alm2,
   145    int spin, 
const arr<double> &weight, 
bool add_alm)
   147   planck_assert (spin>0, 
"map2alm_spin: spin must be positive");
   149     "map2alm_spin: maps must be in RING scheme");
   151     "map2alm_spin: maps are not conformable");
   152   planck_assert (alm1.conformable(alm1),
   153     "map2alm_spin: a_lm are not conformable");
   154   planck_assert (
int(weight.size())>=2*map1.
Nside(),
   155     "map2alm_spin: weight array has too few entries");
   157     "map contains undefined pixels");
   158   checkLmaxNside(alm1.Lmax(), map1.
Nside());
   161   job.set_weighted_Healpix_geometry (map1.
Nside(),&weight[0]);
   162   job.set_triangular_alm_info (alm1.Lmax(), alm1.Mmax());
   163   job.map2alm_spin(&map1[0],&map2[0],&alm1(0,0),&alm2(0,0),spin,add_alm);
   166 template void map2alm_spin
   168    Alm<xcomplex<float> > &alm1, 
Alm<xcomplex<float> > &alm2,
   169    int spin, 
const arr<double> &weight, 
bool add_alm);
   170 template void map2alm_spin
   172    Alm<xcomplex<double> > &alm1, 
Alm<xcomplex<double> > &alm2,
   173    int spin, 
const arr<double> &weight, 
bool add_alm);
   175 template<
typename T> 
void alm2map_spin_adjoint
   177    Alm<xcomplex<T> > &alm1, 
Alm<xcomplex<T> > &alm2,
   178    int spin, 
bool add_alm)
   180   planck_assert (spin>0, 
"alm2map_spin_adjoint: spin must be positive");
   182     "alm2map_spin_adjoint: maps must be in RING scheme");
   184     "alm2map_spin_adjoint: maps are not conformable");
   185   planck_assert (alm1.conformable(alm1),
   186     "alm2map_spin_adjoint: a_lm are not conformable");
   188     "map contains undefined pixels");
   189   checkLmaxNside(alm1.Lmax(), map1.
Nside());
   192   job.set_Healpix_geometry (map1.
Nside());
   193   job.set_triangular_alm_info (alm1.Lmax(), alm1.Mmax());
   194   job.alm2map_spin_adjoint(&map1[0],&map2[0],&alm1(0,0),&alm2(0,0),spin,
   198 template void alm2map_spin_adjoint
   200    Alm<xcomplex<float> > &alm1, 
Alm<xcomplex<float> > &alm2,
   201    int spin, 
bool add_alm);
   202 template void alm2map_spin_adjoint
   204    Alm<xcomplex<double> > &alm1, 
Alm<xcomplex<double> > &alm2,
   205    int spin, 
bool add_alm);
   207 template<
typename T> 
void map2alm_spin_iter2
   209    Alm<xcomplex<T> > &alm1, 
Alm<xcomplex<T> > &alm2,
   210    int spin, 
double err_abs, 
double err_rel)
   212   planck_assert (spin>0, 
"map2alm_spin: spin must be positive");
   213   arr<double> wgt(2*map1.
Nside());
   216   alm1.SetToZero(); alm2.SetToZero();
   219     map2alm_spin(map1b,map2b,alm1,alm2,spin,wgt,
true);
   220     alm2map_spin(alm1,alm2,map1b,map2b,spin);
   222     for (
int m=0; m<map1.
Npix(); ++m)
   224       double err = abs(map1[m]-map1b[m]);
   225       double rel = (map1[m]!=0) ? abs(err/map1[m]) : 1e300;
   226       errmeasure = max(errmeasure,min(err/err_abs,rel/err_rel));
   227       map1b[m] = map1[m]-map1b[m];
   228       err = abs(map2[m]-map2b[m]);
   229       rel = (map2[m]!=0) ? abs(err/map2[m]) : 1e300;
   230       errmeasure = max(errmeasure,min(err/err_abs,rel/err_rel));
   231       map2b[m] = map2[m]-map2b[m];
   234     if (errmeasure<1) 
break;
   238 template void map2alm_spin_iter2
   240    Alm<xcomplex<double> > &alm1, 
Alm<xcomplex<double> > &alm2,
   241    int spin, 
double err_abs, 
double err_rel);
   247    Alm<xcomplex<T> > &almT,
   248    Alm<xcomplex<T> > &almG,
   249    Alm<xcomplex<T> > &almC,
   250    const arr<double> &weight,
   254     "map2alm_pol: maps must be in RING scheme");
   256     "map2alm_pol: maps are not conformable");
   257   planck_assert (almT.conformable(almG) && almT.conformable(almC),
   258     "map2alm_pol: a_lm are not conformable");
   259   planck_assert (
int(weight.size())>=2*mapT.
Nside(),
   260     "map2alm_pol: weight array has too few entries");
   262     "map contains undefined pixels");
   263   checkLmaxNside(almT.Lmax(), mapT.
Nside());
   266   job.set_weighted_Healpix_geometry (mapT.
Nside(),&weight[0]);
   267   job.set_triangular_alm_info (almT.Lmax(), almT.Mmax());
   268   job.map2alm(&mapT[0], &almT(0,0), add_alm);
   269   job.map2alm_spin(&mapQ[0],&mapU[0],&almG(0,0),&almC(0,0),2,add_alm);
   276    Alm<xcomplex<float> > &almT,
   277    Alm<xcomplex<float> > &almG,
   278    Alm<xcomplex<float> > &almC,
   279    const arr<double> &weight,
   285    Alm<xcomplex<double> > &almT,
   286    Alm<xcomplex<double> > &almG,
   287    Alm<xcomplex<double> > &almC,
   288    const arr<double> &weight,
   291 template<
typename T> 
void alm2map_pol_adjoint
   295    Alm<xcomplex<T> > &almT,
   296    Alm<xcomplex<T> > &almG,
   297    Alm<xcomplex<T> > &almC,
   301     "alm2map_pol_adjoint: maps must be in RING scheme");
   303     "alm2map_pol_adjoint: maps are not conformable");
   304   planck_assert (almT.conformable(almG) && almT.conformable(almC),
   305     "alm2map_pol_adjoint: a_lm are not conformable");
   307     "map contains undefined pixels");
   308   checkLmaxNside(almT.Lmax(), mapT.
Nside());
   311   job.set_Healpix_geometry (mapT.
Nside());
   312   job.set_triangular_alm_info (almT.Lmax(), almT.Mmax());
   313   job.alm2map_adjoint(&mapT[0], &almT(0,0), add_alm);
   314   job.alm2map_spin_adjoint(&mapQ[0],&mapU[0],&almG(0,0),&almC(0,0),2,add_alm);
   317 template void alm2map_pol_adjoint
   321    Alm<xcomplex<float> > &almT,
   322    Alm<xcomplex<float> > &almG,
   323    Alm<xcomplex<float> > &almC,
   325 template void alm2map_pol_adjoint
   329    Alm<xcomplex<double> > &almT,
   330    Alm<xcomplex<double> > &almG,
   331    Alm<xcomplex<double> > &almC,
   338    Alm<xcomplex<T> > &almT,
   339    Alm<xcomplex<T> > &almG,
   340    Alm<xcomplex<T> > &almC,
   342    const arr<double> &weight)
   345   for (
int iter=1; iter<=num_iter; ++iter)
   352     for (
int m=0; m<mapT.
Npix(); ++m)
   354       mapT2[m] = mapT[m]-mapT2[m];
   355       mapQ2[m] = mapQ[m]-mapQ2[m];
   356       mapU2[m] = mapU[m]-mapU2[m];
   358     map2alm_pol(mapT2,mapQ2,mapU2,almT,almG,almC,weight,
true);
   366    Alm<xcomplex<float> > &almT,
   367    Alm<xcomplex<float> > &almG,
   368    Alm<xcomplex<float> > &almC,
   370    const arr<double> &weight);
   375    Alm<xcomplex<double> > &almT,
   376    Alm<xcomplex<double> > &almG,
   377    Alm<xcomplex<double> > &almC,
   379    const arr<double> &weight);
   381 template<
typename T> 
void map2alm_pol_iter2
   385    Alm<xcomplex<T> > &almT,
   386    Alm<xcomplex<T> > &almG,
   387    Alm<xcomplex<T> > &almC,
   388    double err_abs, 
double err_rel)
   390   arr<double> wgt(2*mapT.
Nside());
   393   almT.SetToZero(); almG.SetToZero(); almC.SetToZero();
   396     map2alm_pol(mapT2,mapQ2,mapU2,almT,almG,almC,wgt,
true);
   399     for (
int m=0; m<mapT.
Npix(); ++m)
   401       double err = abs(mapT[m]-mapT2[m]);
   402       double rel = (mapT[m]!=0) ? abs(err/mapT[m]) : 1e300;
   403       errmeasure = max(errmeasure,min(err/err_abs,rel/err_rel));
   404       mapT2[m] = mapT[m]-mapT2[m];
   405       err = abs(mapQ[m]-mapQ2[m]);
   406       rel = (mapQ[m]!=0) ? abs(err/mapQ[m]) : 1e300;
   407       errmeasure = max(errmeasure,min(err/err_abs,rel/err_rel));
   408       mapQ2[m] = mapQ[m]-mapQ2[m];
   409       err = abs(mapU[m]-mapU2[m]);
   410       rel = (mapU[m]!=0) ? abs(err/mapU[m]) : 1e300;
   411       errmeasure = max(errmeasure,min(err/err_abs,rel/err_rel));
   412       mapU2[m] = mapU[m]-mapU2[m];
   415     if (errmeasure<1) 
break;
   419 template void map2alm_pol_iter2
   423    Alm<xcomplex<double> > &almT,
   424    Alm<xcomplex<double> > &almG,
   425    Alm<xcomplex<double> > &almC,
   426    double err_abs, 
double err_rel);
   429 template<
typename T> 
void alm2map (
const Alm<xcomplex<T> > &alm,
   432   planck_assert (map.
Scheme()==
RING, 
"alm2map: map must be in RING scheme");
   435   job.set_Healpix_geometry (map.
Nside());
   436   job.set_triangular_alm_info (alm.Lmax(), alm.Mmax());
   437   job.alm2map(&alm(0,0), &map[0], add_map);
   440 template void alm2map (
const Alm<xcomplex<double> > &alm,
   442 template void alm2map (
const Alm<xcomplex<float> > &alm,
   445 template<
typename T> 
void alm2map_spin
   446   (
const Alm<xcomplex<T> > &alm1, 
const Alm<xcomplex<T> > &alm2,
   449   planck_assert (spin>0, 
"alm2map_spin: spin must be positive");
   451     "alm2map_spin: maps must be in RING scheme");
   453     "alm2map_spin: maps are not conformable");
   454   planck_assert (alm1.conformable(alm2),
   455     "alm2map_spin: a_lm are not conformable");
   458   job.set_Healpix_geometry (map1.
Nside());
   459   job.set_triangular_alm_info (alm1.Lmax(), alm1.Mmax());
   460   job.alm2map_spin(&alm1(0,0),&alm2(0,0),&map1[0],&map2[0],spin,add_map);
   463 template void alm2map_spin
   464   (
const Alm<xcomplex<double> > &alm1, 
const Alm<xcomplex<double> > &alm2,
   466 template void alm2map_spin
   467   (
const Alm<xcomplex<float> > &alm1, 
const Alm<xcomplex<float> > &alm2,
   472   (
const Alm<xcomplex<T> > &almT,
   473    const Alm<xcomplex<T> > &almG,
   474    const Alm<xcomplex<T> > &almC,
   481     "alm2map_pol: maps must be in RING scheme");
   483     "alm2map_pol: maps are not conformable");
   484   planck_assert (almT.conformable(almG) && almT.conformable(almC),
   485     "alm2map_pol: a_lm are not conformable");
   488   job.set_Healpix_geometry (mapT.
Nside());
   489   job.set_triangular_alm_info (almT.Lmax(), almT.Mmax());
   490   job.alm2map(&almT(0,0), &mapT[0], add_map);
   491   job.alm2map_spin(&almG(0,0), &almC(0,0), &mapQ[0], &mapU[0], 2, add_map);
   495                            const Alm<xcomplex<double> > &almG,
   496                            const Alm<xcomplex<double> > &almC,
   503                            const Alm<xcomplex<float> > &almG,
   504                            const Alm<xcomplex<float> > &almC,
   512   (
const Alm<xcomplex<T> > &alm,
   518     "alm2map_der1: maps must be in RING scheme");
   520     "alm2map_der1: maps are not conformable");
   523   job.set_Healpix_geometry (map.
Nside());
   524   job.set_triangular_alm_info (alm.Lmax(), alm.Mmax());
   525   job.alm2map(&alm(0,0), &map[0], 
false);
   526   job.alm2map_der1(&alm(0,0), &mapdth[0], &mapdph[0], 
false);
 bool fullyDefined() const
void alm2map_der1(const Alm< xcomplex< T > > &alm, Healpix_Map< T > &map, Healpix_Map< T > &mapdth, Healpix_Map< T > &mapdph)
void map2alm_pol(const Healpix_Map< T > &mapT, const Healpix_Map< T > &mapQ, const Healpix_Map< T > &mapU, Alm< xcomplex< T > > &almT, Alm< xcomplex< T > > &almG, Alm< xcomplex< T > > &almC, const arr< double > &weight, bool add_alm)
void map2alm(const Healpix_Map< T > &map, Alm< xcomplex< T > > &alm, const arr< double > &weight, bool add_alm)
void map2alm_pol_iter(const Healpix_Map< T > &mapT, const Healpix_Map< T > &mapQ, const Healpix_Map< T > &mapU, Alm< xcomplex< T > > &almT, Alm< xcomplex< T > > &almG, Alm< xcomplex< T > > &almC, int num_iter, const arr< double > &weight)
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 alm2map_adjoint(const Healpix_Map< T > &map, Alm< xcomplex< T > > &alm, bool add_alm)
Healpix_Ordering_Scheme Scheme() const
void map2alm_iter(const Healpix_Map< T > &map, Alm< xcomplex< T > > &alm, int num_iter, const arr< double > &weight)
void alm2map(const Alm< xcomplex< T > > &alm, Healpix_Map< T > &map, bool add_map)
bool conformable(const T_Healpix_Base &other) const