source: Sophya/trunk/SophyaProg/Tests/tspm2.cc@ 591

Last change on this file since 591 was 591, checked in by ansari, 26 years ago

corrections diverses et ajout tspm2.cc - Reza 17/11/99

File size: 5.6 KB
Line 
1#include <iostream.h>
2#include <math.h>
3#include "sambainit.h"
4#include "spheregorski.h"
5#include "spherethetaphi.h"
6
7#include "tod.h"
8#include "fitsioserver.h"
9#include "nbrandom.h"
10
11#include "timing.h"
12
13template <class T>
14void 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
28template <class T>
29void 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.Reset(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}
53template <class T>
54void Project_Mol_Old(PixelMap<T> const & map, ImageR4 & img, float defval=-999.)
55{
56 r_8 xa, yd, teta,phi, facteur;
57 int_4 i,j,k,n;
58 printf("Xsize= %d Ysize= %d NPix= %d\n",img.XSize(),img.YSize(),img.XSize()*img.YSize() );
59 n = 0;
60 for(j=0; j<img.YSize(); j++) {
61 yd = (r_4)(j+0.5)/(r_4)img.YSize()-0.5;
62 facteur=2.*M_PI/sin(acos((double)yd*2));
63 teta = (yd+0.5)*M_PI;
64 // teta = (0.5-yd)*M_PI;
65 for(i=0; i<img.XSize(); i++) {
66 xa = (r_4)(i+0.5)/(r_4)img.XSize()-0.5;
67 phi = xa*facteur+M_PI;
68 if ( (phi <= 2*M_PI) && (phi >= 0.) ) {
69 k = map.PixIndexSph(teta, phi);
70 img(i,j) = map(k);
71 // if (n<20) {
72 // printf("i,j= %d %d -> %g %g -> k=%d -> val= %g \n",
73 // i,j,teta,phi,k,map(k)); n++; }
74 }
75 }
76 }
77
78}
79
80int main(int narg, char* arg[])
81{
82 double teta,phi;
83 double gmoy=0., gsig=0.;
84
85 PeidaInit();
86 InitTim(); // Initializing the CPU timer
87 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) {
88 cout << " tspm [Gorski_M=32] : Gorski Spherical Map Test " << endl;
89 exit(0);
90 }
91
92 int m=32;
93 if (narg >1) m = atoi(arg[1]);
94 cout << " ===== Gorski Spherical Map Test M= " << m << endl;
95
96 POutPersist s("spheres.ppf");
97 string nomobj;
98
99 {
100 SphereGorski<double> sph(m);
101
102 cout << "Filling spherical map NPixels= " << sph.NbPixels() << endl;
103 for (int j=0;j<sph.NbPixels();j++)
104 {
105 sph.PixThetaPhi(j,teta,phi);
106 sph(j)= 0.2* cos(3.*teta)*sin(8*phi);
107 }
108 PrtTim("End of Fill ");
109
110 {
111 FIO_SphereGorski<double> fiog(&sph) ;
112 nomobj = "sphg1";
113 fiog.Write(s, nomobj);
114 cout << "SphMap written to POutPersist with name " << nomobj << endl;
115 }
116
117 // On projete dans un fichier FITS
118 FitsIoServer fios;
119 fios.sinus_picture_projection(sph, "gsin1.fits");
120 fios.save(sph, "sph1.fits");
121
122 TMatrix<double> mtx(3*m, 6*m);
123 Project_Mol(sph, mtx);
124 fios.save(mtx, "mtx1.fits");
125
126 cout << " Project_Mol_Old(sph, img) " << endl;
127 ImageR4 img(6*m, 3*m);
128 Project_Mol_Old(sph, img);
129 img.CheckDyn();
130 cout << img;
131 fios.save(img, "img1.fits");
132 cout << " Apres writeFits " << endl;
133 img.CheckDyn();
134 cout << img;
135 /*
136 ImageR4 imgr;
137 fios.load(imgr, "img1.fits");
138 cout << " Apres readFits " << endl;
139 imgr.CheckDyn();
140 cout << imgr;
141 */
142
143 // Computing mean and sigma on the sphere
144 MeanSig(sph, gmoy, gsig);
145 cout << "SphMap Mean= " << gmoy << " Sigma = " << gsig << endl;
146 PrtTim("End of Mean-Sig ");
147 }
148 {
149 SphereGorski<double> sph(m);
150
151 cout << "Filling spherical map2 NPixels= " << sph.NbPixels() << endl;
152 for (int j=0;j<sph.NbPixels();j++)
153 {
154 sph.PixThetaPhi(j,teta,phi);
155 if (teta < 0.3) sph(j) = 30.;
156 else if ((teta>1.4) && (teta<1.6) ) sph(j) = 20.;
157 else {
158 if (phi < 2.) sph(j) = 2.;
159 else if (phi > 3.) sph(j) = 5.;
160 else sph(j) = 0.;
161 }
162 }
163 PrtTim("End of Fill2 ");
164
165 {
166 FIO_SphereGorski<double> fiog(&sph) ;
167 nomobj = "sphg2";
168 fiog.Write(s, nomobj);
169 cout << "SphMap written to POutPersist with name " << nomobj << endl;
170 }
171
172
173 // On projete dans un fichier FITS
174 FitsIoServer fios;
175 fios.sinus_picture_projection(sph, "gsin2.fits");
176 fios.save(sph, "sph2.fits");
177
178 TMatrix<double> mtx(3*m, 6*m);
179 Project_Mol(sph, mtx);
180 fios.save(mtx, "mtx2.fits");
181
182
183 cout << " Project_Mol_Old(sph, img) " << endl;
184 ImageR4 img(6*m, 3*m);
185 Project_Mol_Old(sph, img);
186 img.CheckDyn();
187 cout << img;
188 fios.save(img, "img2.fits");
189 cout << " Apres writeFits " << endl;
190 img.CheckDyn();
191 cout << img;
192
193 // Computing mean and sigma on the sphere
194 MeanSig(sph, gmoy, gsig);
195 cout << "SphMap2 Mean= " << gmoy << " Sigma = " << gsig << endl;
196 PrtTim("End of Mean-Sig2 ");
197 }
198
199 {
200 SphereThetaPhi< complex<float> > sphc(m*10);
201
202 cout << "Filling spherical map3 SphereThetaPhi(complex) NPixels= " << sphc.NbPixels() << endl;
203 for (int j=0;j<sphc.NbPixels();j++)
204 {
205 sphc.PixThetaPhi(j,teta,phi);
206 if (teta < 0.3) sphc(j) = (30., drandpm1()*3.);
207 else if ((teta>1.4) && (teta<1.6) ) sphc(j) = (20., NorRand());
208 else {
209 if (phi < 2.) sphc(j) = 2.;
210 else if (phi > 3.) sphc(j) = 5.;
211 else sphc(j) = 0.;
212 }
213 }
214 PrtTim("End of Fill2 ");
215
216 {
217 FIO_SphereThetaPhi< complex<float> > fio(&sphc) ;
218 nomobj = "sphtp";
219 fio.Write(s, nomobj);
220 cout << "SphMap written to POutPersist with name " << nomobj << endl;
221 }
222 }
223 cout << " ===== Fin de TSPM2_Test ======== " << endl;
224 return 0;
225}
Note: See TracBrowser for help on using the repository browser.