1 | #include <iostream.h>
|
---|
2 | #include <math.h>
|
---|
3 | #include "sambainit.h"
|
---|
4 | #include "skymap.h"
|
---|
5 |
|
---|
6 | #include "tod.h"
|
---|
7 | #include "fitstarray.h"
|
---|
8 | #include "fitsspherehealpix.h"
|
---|
9 | #include "nbrandom.h"
|
---|
10 |
|
---|
11 | #include "timing.h"
|
---|
12 |
|
---|
13 | template <class T>
|
---|
14 | void MeanSig(PixelMap<T> const & map, double& gmoy, double& gsig)
|
---|
15 | {
|
---|
16 | gmoy=0.;
|
---|
17 | gsig = 0.;
|
---|
18 | double valok;
|
---|
19 | for(int k=0; k<map.NbPixels(); k++) {
|
---|
20 | valok = map(k);
|
---|
21 | gmoy += valok; gsig += valok*valok;
|
---|
22 | }
|
---|
23 | gmoy /= (double)map.NbPixels();
|
---|
24 | gsig = gsig/(double)map.NbPixels() - gmoy*gmoy;
|
---|
25 | if (gsig >= 0.) gsig = sqrt(gsig);
|
---|
26 | }
|
---|
27 |
|
---|
28 | template <class T>
|
---|
29 | void Project_Mol(PixelMap<T> const & map, TMatrix<T> & mtx, T defval=-999.)
|
---|
30 | {
|
---|
31 | r_8 xa, yd, teta,phi, facteur;
|
---|
32 | int_4 l,c,k;
|
---|
33 | int_4 nl = mtx.NRows();
|
---|
34 | int_4 nc = mtx.NCols();
|
---|
35 | mtx = defval; // On met tout a defval
|
---|
36 | cout << " NRows= " << nl << " NCols= " << nc << endl;
|
---|
37 | for(l=0; l<nl; l++) {
|
---|
38 | yd = (r_8)(l+0.5)/(r_8)nl-0.5;
|
---|
39 | facteur=2.*M_PI/sin(acos((double)yd*2));
|
---|
40 | teta = (yd+0.5)*Pi;
|
---|
41 | // teta = (0.5-yd)*M_PI;
|
---|
42 | for(c=0; c<nc; c++) {
|
---|
43 | xa = (r_8)(c+0.5)/(r_8)nc-0.5;
|
---|
44 | phi = xa*facteur+M_PI;
|
---|
45 | if ( (phi <= 2*M_PI) && (phi >= 0.) ) {
|
---|
46 | k = map.PixIndexSph(teta, phi);
|
---|
47 | mtx(l,c) = map(k);
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | }
|
---|
53 |
|
---|
54 | int main(int narg, char* arg[])
|
---|
55 | {
|
---|
56 | double teta,phi;
|
---|
57 | double gmoy=0., gsig=0.;
|
---|
58 |
|
---|
59 | SophyaInit();
|
---|
60 | InitTim(); // Initializing the CPU timer
|
---|
61 | if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) {
|
---|
62 | cout << " tspm [HEALPix_M=32] : HEALPix Spherical Map Test " << endl;
|
---|
63 | exit(0);
|
---|
64 | }
|
---|
65 |
|
---|
66 | int m=32;
|
---|
67 | if (narg >1) m = atoi(arg[1]);
|
---|
68 | cout << " ===== HEALPix Spherical Map Test M= " << m << endl;
|
---|
69 |
|
---|
70 | try {
|
---|
71 |
|
---|
72 | POutPersist s("spheres.ppf");
|
---|
73 | string nomobj;
|
---|
74 |
|
---|
75 | {
|
---|
76 | SphereHEALPix<double> sph(m);
|
---|
77 |
|
---|
78 | cout << "Filling spherical map NPixels= " << sph.NbPixels() << endl;
|
---|
79 | for (int j=0;j<sph.NbPixels();j++)
|
---|
80 | {
|
---|
81 | sph.PixThetaPhi(j,teta,phi);
|
---|
82 | sph(j)= 0.2* cos(3.*teta)*sin(8*phi);
|
---|
83 | }
|
---|
84 | PrtTim("End of Fill ");
|
---|
85 |
|
---|
86 | {
|
---|
87 | FIO_SphereHEALPix<double> fiog(&sph) ;
|
---|
88 | nomobj = "sphg1";
|
---|
89 | fiog.Write(s, nomobj);
|
---|
90 | cout << "SphMap SphereHEALPix<double> written to POutPersist with name " << nomobj << endl;
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | TMatrix<double> mtx(3*m, 6*m);
|
---|
95 | cout << " Project_Mol(sph, mtx) " << endl;
|
---|
96 | Project_Mol(sph, mtx);
|
---|
97 | {
|
---|
98 | cout << " Writing to FITS prjmol1.fits " << endl;
|
---|
99 | FITS_TArray<double> fios(mtx);
|
---|
100 | fios.Write("prjmol1.fits");
|
---|
101 | }
|
---|
102 |
|
---|
103 | // Computing mean and sigma on the sphere
|
---|
104 | MeanSig(sph, gmoy, gsig);
|
---|
105 | cout << "SphMap Mean= " << gmoy << " Sigma = " << gsig << endl;
|
---|
106 | PrtTim("End of Mean-Sig ");
|
---|
107 | }
|
---|
108 |
|
---|
109 | {
|
---|
110 | SphereHEALPix<float> sph(m);
|
---|
111 |
|
---|
112 | cout << "Filling spherical map2 NPixels= " << sph.NbPixels() << endl;
|
---|
113 | for (int j=0;j<sph.NbPixels();j++)
|
---|
114 | {
|
---|
115 | sph.PixThetaPhi(j,teta,phi);
|
---|
116 | if (teta < 0.3) sph(j) = 30.;
|
---|
117 | else if ((teta>1.4) && (teta<1.6) ) sph(j) = 20.;
|
---|
118 | else {
|
---|
119 | if (phi < 2.) sph(j) = 2.;
|
---|
120 | else if (phi > 3.) sph(j) = 5.;
|
---|
121 | else sph(j) = 0.;
|
---|
122 | }
|
---|
123 | }
|
---|
124 | PrtTim("End of Fill2 ");
|
---|
125 |
|
---|
126 | {
|
---|
127 | FIO_SphereHEALPix<float> fiog(&sph) ;
|
---|
128 | nomobj = "sphg2";
|
---|
129 | fiog.Write(s, nomobj);
|
---|
130 | cout << "SphMap SphereHEALPix<float> written to POutPersist with name " << nomobj << endl;
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 | // On projete dans un fichier FITS
|
---|
135 | {
|
---|
136 | cout << "Test of Write/Read SphereHEALPix<float> to FITS (sphg_r4.fits) " << endl;
|
---|
137 | FITS_SphereHEALPix<r_4> fiosw(sph);
|
---|
138 | fiosw.Write("sphg_r4.fits");
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | SphereHEALPix<float> sphr;
|
---|
143 | {
|
---|
144 | FITS_SphereHEALPix<r_4> fiosr("sphg_r4.fits");
|
---|
145 | sphr = fiosr;
|
---|
146 | cout << " Read from file - SphereHEALPix<float> NPixels= " << sphr.NbPixels() << endl;
|
---|
147 | int ndiff = 0;
|
---|
148 | for(int k=0; k<sphr.NbPixels(); k++) {
|
---|
149 | if ( sphr(k) != sph(k) ) {
|
---|
150 | ndiff++;
|
---|
151 | if (ndiff < 20) cout << "!!!Diff: K= " << k << " SPHR= " << sphr(k) << " SPH= " << sph(k) << endl;
|
---|
152 | }
|
---|
153 | }
|
---|
154 | cout << " ReadFrom FITS NDiff = " << ndiff << " (should be zero = 0) " << endl;
|
---|
155 |
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | TMatrix<float> mtx(3*m, 6*m);
|
---|
160 | Project_Mol(sph, mtx);
|
---|
161 | {
|
---|
162 | cout << " Writing to FITS prjmol2.fits " << endl;
|
---|
163 | FITS_TArray<double> fios(mtx);
|
---|
164 | fios.Write("prjmol2.fits");
|
---|
165 | }
|
---|
166 |
|
---|
167 | // Computing mean and sigma on the sphere
|
---|
168 | MeanSig(sph, gmoy, gsig);
|
---|
169 | cout << "SphMap2 Mean= " << gmoy << " Sigma = " << gsig << endl;
|
---|
170 | PrtTim("End of Mean-Sig2 ");
|
---|
171 | }
|
---|
172 |
|
---|
173 | {
|
---|
174 | SphereThetaPhi< complex<float> > sphc(m*10);
|
---|
175 |
|
---|
176 | cout << "Filling spherical map3 SphereThetaPhi(complex) NPixels= " << sphc.NbPixels() << endl;
|
---|
177 | for (int j=0;j<sphc.NbPixels();j++)
|
---|
178 | {
|
---|
179 | sphc.PixThetaPhi(j,teta,phi);
|
---|
180 | if (teta < 0.3) sphc(j) = (30., drandpm1()*3.);
|
---|
181 | else if ((teta>1.4) && (teta<1.6) ) sphc(j) = (20., NorRand());
|
---|
182 | else {
|
---|
183 | if (phi < 2.) sphc(j) = 2.;
|
---|
184 | else if (phi > 3.) sphc(j) = 5.;
|
---|
185 | else sphc(j) = 0.;
|
---|
186 | }
|
---|
187 | }
|
---|
188 | PrtTim("End of Fill2 ");
|
---|
189 |
|
---|
190 | {
|
---|
191 | FIO_SphereThetaPhi< complex<float> > fio(&sphc) ;
|
---|
192 | nomobj = "sphtp";
|
---|
193 | fio.Write(s, nomobj);
|
---|
194 | cout << "SphMap written to POutPersist with name " << nomobj << endl;
|
---|
195 | }
|
---|
196 | }
|
---|
197 | }
|
---|
198 | catch (PThrowable & exc) {
|
---|
199 | cerr << "tspm2: Catched Exception " << (string)typeid(exc).name()
|
---|
200 | << " - Msg= " << exc.Msg() << endl;
|
---|
201 | }
|
---|
202 | catch (...) {
|
---|
203 | cerr << "tspm2: some other exception was caught ! " << endl;
|
---|
204 | }
|
---|
205 |
|
---|
206 | cout << " ===== Fin de TSPM2_Test ======== " << endl;
|
---|
207 | return 0;
|
---|
208 | }
|
---|