source: Sophya/trunk/SophyaProg/Tests/tspm.cc@ 2981

Last change on this file since 2981 was 2981, checked in by ansari, 19 years ago

petite adaptation suite HEALPix-NESTED , Reza 21/6/2006

File size: 3.7 KB
Line 
1#include <iostream>
2#include "sopnamsp.h"
3#include "skymapinit.h"
4#include "skymap.h"
5
6#include "tod.h"
7#include "timing.h"
8
9template <class T>
10void 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}
23
24int main(int narg, char* arg[])
25{
26 double teta,phi;
27 double gmoy, gsig;
28
29 SophyaInit();
30 InitTim(); // Initializing the CPU timer
31 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) {
32 cout << " tspm [HEALPix_M=32] [M_TetaPhi=64] : Spherical Map Test " << endl;
33 exit(0);
34 }
35
36 int m=32;
37 if (narg >1) m = atoi(arg[1]);
38 cout << " ===== HEALPix Spherical Map Test M= " << m << endl;
39
40 SphereHEALPix<double> sph(m);
41
42 cout << "Filling spherical map NPixels= " << sph.NbPixels() << endl;
43 int j;
44 for (j=0;j<sph.NbPixels();j++)
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
52 MeanSig(sph, gmoy, gsig);
53 cout << "SphereHEALPix<double> Mean= " << gmoy << " Sigma = " << gsig << endl;
54 PrtTim("End of Mean-Sig ");
55
56// Writing to a PPF file
57 {
58 POutPersist s("sphg.ppf");
59 FIO_SphereHEALPix<double> fiog(&sph) ;
60 fiog.Write(s);
61 cout << "SphereHEALPix<double> written to sphg.ppf " << endl;
62 }
63
64 // Reading from the file
65 {
66 FIO_SphereHEALPix<double> fiog(string("sphg.ppf"));
67 SphereHEALPix<double> sph2 = fiog;
68 PrtTim("End of Write/Read ");
69
70 cout << " Spherical map from file sphg.ppf NPixels= " << sph2.NbPixels() << endl;
71
72 int ndiff = 0;
73 for(int k=0; k<sph2.NbPixels(); k++) {
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 }
79 }
80 MeanSig(sph, gmoy, gsig);
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
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;
94 for (j=0;j<spht.NbPixels();j++)
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
136 cout << " ===== Fin de TSPM_Test ======== " << endl;
137 return 0;
138}
Note: See TracBrowser for help on using the repository browser.