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