| 1 | #include <iostream>
 | 
|---|
| 2 | #include "skymapinit.h"
 | 
|---|
| 3 | #include "skymap.h"
 | 
|---|
| 4 | 
 | 
|---|
| 5 | #include "tod.h"
 | 
|---|
| 6 | #include "timing.h"
 | 
|---|
| 7 | 
 | 
|---|
| 8 | template <class T>
 | 
|---|
| 9 | void  MeanSig(PixelMap<T> const & map, double& gmoy, double& gsig)
 | 
|---|
| 10 | {
 | 
|---|
| 11 |   gmoy=0.;
 | 
|---|
| 12 |   gsig = 0.;
 | 
|---|
| 13 |   double valok;
 | 
|---|
| 14 |   for(int k=0; k<map.NbPixels(); k++) {
 | 
|---|
| 15 |     valok = map(k);
 | 
|---|
| 16 |     gmoy += valok;  gsig += valok*valok;
 | 
|---|
| 17 |   }
 | 
|---|
| 18 |   gmoy /= (double)map.NbPixels();
 | 
|---|
| 19 |   gsig = gsig/(double)map.NbPixels() - gmoy*gmoy;
 | 
|---|
| 20 |   if (gsig >= 0.) gsig = sqrt(gsig);
 | 
|---|
| 21 | }
 | 
|---|
| 22 | 
 | 
|---|
| 23 | int main(int narg, char* arg[]) 
 | 
|---|
| 24 | {
 | 
|---|
| 25 |   double teta,phi;
 | 
|---|
| 26 |   double gmoy, gsig;
 | 
|---|
| 27 | 
 | 
|---|
| 28 |   SophyaInit();
 | 
|---|
| 29 |   InitTim();   // Initializing the CPU timer 
 | 
|---|
| 30 |   if ((narg > 1) && (strcmp(arg[1],"-h") == 0) )  {
 | 
|---|
| 31 |     cout << " tspm [HEALPix_M=32] [M_TetaPhi=64] : Spherical Map Test " << endl;
 | 
|---|
| 32 |     exit(0);
 | 
|---|
| 33 |     }
 | 
|---|
| 34 | 
 | 
|---|
| 35 |   int  m=32;
 | 
|---|
| 36 |   if (narg >1)  m = atoi(arg[1]);
 | 
|---|
| 37 |   cout <<  " ===== HEALPix Spherical Map Test M= " << m << endl;
 | 
|---|
| 38 | 
 | 
|---|
| 39 |   SphereHEALPix<double> sph(m);
 | 
|---|
| 40 | 
 | 
|---|
| 41 |   cout << "Filling spherical map NPixels= " << sph.NbPixels() << endl;
 | 
|---|
| 42 |   int j;
 | 
|---|
| 43 |   for (j=0;j<sph.NbPixels();j++) 
 | 
|---|
| 44 |     {
 | 
|---|
| 45 |       sph.PixThetaPhi(j,teta,phi);
 | 
|---|
| 46 |       sph(j)= 0.2* cos(3.*teta)*sin(8*phi);
 | 
|---|
| 47 |     }
 | 
|---|
| 48 |   PrtTim("End of Fill ");
 | 
|---|
| 49 | 
 | 
|---|
| 50 |   // Computing mean and sigma on the sphere 
 | 
|---|
| 51 |   MeanSig(sph, gmoy, gsig);
 | 
|---|
| 52 |   cout << "SphereHEALPix<double> Mean= " << gmoy << "  Sigma = " << gsig << endl;
 | 
|---|
| 53 |   PrtTim("End of Mean-Sig ");
 | 
|---|
| 54 | 
 | 
|---|
| 55 | //  Writing to a PPF file
 | 
|---|
| 56 |   {
 | 
|---|
| 57 |   POutPersist s("sphg.ppf"); 
 | 
|---|
| 58 |   FIO_SphereHEALPix<double> fiog(&sph) ;
 | 
|---|
| 59 |   fiog.Write(s);
 | 
|---|
| 60 |   cout << "SphereHEALPix<double>  written to sphg.ppf "  << endl;
 | 
|---|
| 61 |   }
 | 
|---|
| 62 | 
 | 
|---|
| 63 |   // Reading from the file
 | 
|---|
| 64 |   {
 | 
|---|
| 65 |   FIO_SphereHEALPix<double> fiog("sphg.ppf");
 | 
|---|
| 66 |   SphereHEALPix<double>  sph2 = fiog;
 | 
|---|
| 67 |   PrtTim("End of Write/Read ");
 | 
|---|
| 68 | 
 | 
|---|
| 69 |   cout << " Spherical map from file sphg.ppf NPixels= " << sph2.NbPixels() << endl;
 | 
|---|
| 70 | 
 | 
|---|
| 71 |   int ndiff = 0;
 | 
|---|
| 72 |   for(int k=0; k<sph2.NbPixels(); k++) {
 | 
|---|
| 73 | //    if ((sph2(k)-sph(k)) > 1.e-49)  { 
 | 
|---|
| 74 |     if ( sph2(k) != sph(k) )   { 
 | 
|---|
| 75 |       ndiff++;
 | 
|---|
| 76 |       if (ndiff < 20)  cout << "!!!Diff: K= " << k << " SPH2= " << sph2(k) << " SPH= " << sph(k) << endl;
 | 
|---|
| 77 |     }
 | 
|---|
| 78 |   }
 | 
|---|
| 79 |   MeanSig(sph, gmoy, gsig);
 | 
|---|
| 80 |   cout << "SphMapFromFile Mean= " << gmoy << "  Sigma = " << gsig << endl;
 | 
|---|
| 81 |   cout << " NDiff = " << ndiff << " (should be zero = 0) " << endl;
 | 
|---|
| 82 |   PrtTim("End of Mean-Sig ");
 | 
|---|
| 83 |   }
 | 
|---|
| 84 | 
 | 
|---|
| 85 | 
 | 
|---|
| 86 |   int  mt=64;
 | 
|---|
| 87 |   if (narg > 2)  mt = atoi(arg[2]);
 | 
|---|
| 88 |   cout <<  "\n ===== ThetaPhi Spherical Map Test MT= " << mt << endl;
 | 
|---|
| 89 | 
 | 
|---|
| 90 |   SphereThetaPhi<float> spht(m);
 | 
|---|
| 91 | 
 | 
|---|
| 92 |   cout << "Filling spherical map NPixels= " << spht.NbPixels() << endl;
 | 
|---|
| 93 |   for (j=0;j<spht.NbPixels();j++) 
 | 
|---|
| 94 |     {
 | 
|---|
| 95 |       spht.PixThetaPhi(j,teta,phi);
 | 
|---|
| 96 |       spht(j)= 0.5* cos(5.*teta)*sin(10.*phi);
 | 
|---|
| 97 |     }
 | 
|---|
| 98 |   PrtTim("End of Fill ");
 | 
|---|
| 99 | 
 | 
|---|
| 100 |   // Computing mean and sigma on the sphere 
 | 
|---|
| 101 |   MeanSig(spht, gmoy, gsig);
 | 
|---|
| 102 |   cout << "SphereThetaPhi<float> Mean= " << gmoy << "  Sigma = " << gsig << endl;
 | 
|---|
| 103 |   PrtTim("End of Mean-Sig ");
 | 
|---|
| 104 | 
 | 
|---|
| 105 | //  Writing to a PPF file
 | 
|---|
| 106 |   {
 | 
|---|
| 107 |   POutPersist s("spht.ppf"); 
 | 
|---|
| 108 |   FIO_SphereThetaPhi<float> fiog(spht) ;
 | 
|---|
| 109 |   fiog.Write(s);
 | 
|---|
| 110 |   cout << "SphereThetaPhi<float> written to spht.ppf "  << endl;
 | 
|---|
| 111 |   }
 | 
|---|
| 112 | 
 | 
|---|
| 113 |   // Reading from the file
 | 
|---|
| 114 |   {
 | 
|---|
| 115 |   FIO_SphereThetaPhi<float> fiog("spht.ppf");
 | 
|---|
| 116 |   SphereThetaPhi<float>  sph2 = fiog;
 | 
|---|
| 117 |   PrtTim("End of Write/Read ");
 | 
|---|
| 118 | 
 | 
|---|
| 119 |   cout << " Spherical map from file sph.ppf NPixels= " << sph2.NbPixels() << endl;
 | 
|---|
| 120 | 
 | 
|---|
| 121 |   int ndiff = 0;
 | 
|---|
| 122 |   for(int k=0; k<sph2.NbPixels(); k++) {
 | 
|---|
| 123 | //    if ((sph2(k)-sph(k)) > 1.e-49)  { 
 | 
|---|
| 124 |     if ( sph2(k) != spht(k) )   { 
 | 
|---|
| 125 |       ndiff++;
 | 
|---|
| 126 |       if (ndiff < 20)  cout << "!!!Diff: K= " << k << " SPH2= " << sph2(k) << " SPH= " << sph(k) << endl;
 | 
|---|
| 127 |     }
 | 
|---|
| 128 |   }
 | 
|---|
| 129 |   MeanSig(sph, gmoy, gsig);
 | 
|---|
| 130 |   cout << "SphMapFromFile Mean= " << gmoy << "  Sigma = " << gsig << endl;
 | 
|---|
| 131 |   cout << " NDiff = " << ndiff << " (should be zero = 0) " << endl;
 | 
|---|
| 132 |   PrtTim("End of Mean-Sig ");
 | 
|---|
| 133 |   }
 | 
|---|
| 134 | 
 | 
|---|
| 135 |   cout <<  " ===== Fin de TSPM_Test ======== " << endl;
 | 
|---|
| 136 |   return 0;
 | 
|---|
| 137 | }
 | 
|---|