1 | #include "machdefs.h"
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <math.h>
|
---|
4 | #include <typeinfo>
|
---|
5 | #include <iostream>
|
---|
6 | #include <string>
|
---|
7 | #include <complex>
|
---|
8 |
|
---|
9 | #include "datatype.h"
|
---|
10 |
|
---|
11 | #include "nomskymapadapter.h"
|
---|
12 | #include "skymap.h"
|
---|
13 | #include "pitvmaad.h"
|
---|
14 | #include "complexios.h"
|
---|
15 |
|
---|
16 | #include "fitsspherehealpix.h"
|
---|
17 | #include "fitslocalmap.h"
|
---|
18 |
|
---|
19 |
|
---|
20 | // Classe array adapter pour localMap
|
---|
21 | template <class T>
|
---|
22 | class LocalMapArrAdapter : public P2DArrayAdapter {
|
---|
23 | public:
|
---|
24 | LocalMapArrAdapter(LocalMap<T>* lm, bool d=false) :
|
---|
25 | P2DArrayAdapter(lm->SizeX(), lm->SizeY())
|
---|
26 | { ad = d; map = lm; }
|
---|
27 |
|
---|
28 | virtual ~LocalMapArrAdapter() { if (ad) delete map; }
|
---|
29 | virtual double Value(int ix, int iy) { return((*map)(ix, iy)); }
|
---|
30 |
|
---|
31 | protected :
|
---|
32 | bool ad;
|
---|
33 | LocalMap<T>* map;
|
---|
34 | };
|
---|
35 |
|
---|
36 | /* --Methode-- */
|
---|
37 | double LocalMapArrAdapter< complex<float> >::Value(int ix, int iy)
|
---|
38 | {
|
---|
39 | double re,im;
|
---|
40 | re = (*map)(iy, ix).real();
|
---|
41 | im = (*map)(iy, ix).imag();
|
---|
42 | return(sqrt(re*re+im*im));
|
---|
43 | }
|
---|
44 | /* --Methode-- */
|
---|
45 | double LocalMapArrAdapter< complex<double> >::Value(int ix, int iy)
|
---|
46 | {
|
---|
47 | double re,im;
|
---|
48 | re = (*map)(iy, ix).real();
|
---|
49 | im = (*map)(iy, ix).imag();
|
---|
50 | return(sqrt(re*re+im*im));
|
---|
51 | }
|
---|
52 |
|
---|
53 | //----------------------------------------------------------------
|
---|
54 | // Class Adaptateur d'objet (Pour NamedObjMgr) d'objet PixelMap<T>
|
---|
55 | //----------------------------------------------------------------
|
---|
56 |
|
---|
57 |
|
---|
58 | /* --Methode-- */
|
---|
59 | template <class T>
|
---|
60 | NOMAdapter_PixelMap<T>::NOMAdapter_PixelMap(PixelMap<T> * o)
|
---|
61 | : NObjMgrAdapter(o)
|
---|
62 | {
|
---|
63 | mMap = o;
|
---|
64 | }
|
---|
65 |
|
---|
66 | /* --Methode-- */
|
---|
67 | template <class T>
|
---|
68 | NOMAdapter_PixelMap<T>::~NOMAdapter_PixelMap()
|
---|
69 | {
|
---|
70 | }
|
---|
71 |
|
---|
72 | /* --Methode-- */
|
---|
73 | template <class T>
|
---|
74 | NObjMgrAdapter* NOMAdapter_PixelMap<T>::Clone(AnyDataObj* o)
|
---|
75 | {
|
---|
76 | PixelMap<T>* m = dynamic_cast<PixelMap<T> *>(o);
|
---|
77 | if (m) return ( new NOMAdapter_PixelMap<T>(m) );
|
---|
78 | return ( new NObjMgrAdapter(o) );
|
---|
79 | }
|
---|
80 |
|
---|
81 | /* --Methode-- */
|
---|
82 | template <class T>
|
---|
83 | string NOMAdapter_PixelMap<T>::GetDataObjType()
|
---|
84 | {
|
---|
85 | string type = "PixelMap< ";
|
---|
86 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
87 | if (lm != NULL) type = "LocalMap< ";
|
---|
88 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
|
---|
89 | if (st != NULL) type = "SphereThetaPhi< ";
|
---|
90 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
|
---|
91 | if (sg != NULL) type = "SphereHEALPix< ";
|
---|
92 |
|
---|
93 | // type += DecodeTypeIdName(typeid(T).name());
|
---|
94 | type += DataTypeInfo<T>::getTypeName();
|
---|
95 | type += " > ";
|
---|
96 | return(type);
|
---|
97 | }
|
---|
98 |
|
---|
99 | /* --Methode-- */
|
---|
100 | template <class T>
|
---|
101 | AnyDataObj* NOMAdapter_PixelMap<T>::CloneDataObj(bool share)
|
---|
102 | {
|
---|
103 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
104 | if (lm != NULL) return( new LocalMap<T>(*lm, share) );
|
---|
105 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
|
---|
106 | if (st != NULL) return( new SphereThetaPhi<T>(*st, share) );
|
---|
107 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
|
---|
108 | if (sg != NULL) return( new SphereHEALPix<T>(*sg, share) );
|
---|
109 | return(NULL);
|
---|
110 | }
|
---|
111 |
|
---|
112 | /* --Methode-- */
|
---|
113 | template <class T>
|
---|
114 | void NOMAdapter_PixelMap<T>::ReadFits(string const & flnm)
|
---|
115 | {
|
---|
116 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
117 | if (lm != NULL) {
|
---|
118 | FitsInFile fis(flnm);
|
---|
119 | fis >> (*lm);
|
---|
120 | return;
|
---|
121 | }
|
---|
122 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
|
---|
123 | if (sg != NULL) {
|
---|
124 | FitsInFile fis(flnm);
|
---|
125 | fis >> (*sg);
|
---|
126 | return;
|
---|
127 | }
|
---|
128 | string s = typeid(*mMap).name();
|
---|
129 | cout << " NOMAdapter_PixelMap<T>::ReadFits() - Error "
|
---|
130 | << " Not supported for " << s << endl;
|
---|
131 | return;
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | /* --Methode-- */
|
---|
136 | template <class T>
|
---|
137 | void NOMAdapter_PixelMap<T>::SaveFits(string const & flnm)
|
---|
138 | {
|
---|
139 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
140 | if (lm != NULL) {
|
---|
141 | FitsOutFile fos(flnm);
|
---|
142 | fos << (*lm);
|
---|
143 | return;
|
---|
144 | }
|
---|
145 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
|
---|
146 | if (sg != NULL) {
|
---|
147 | FitsOutFile fos(flnm);
|
---|
148 | fos << (*sg);
|
---|
149 | return;
|
---|
150 | }
|
---|
151 | string s = typeid(*mMap).name();
|
---|
152 | cout << " NOMAdapter_PixelMap<T>::SaveFits() - Error "
|
---|
153 | << " Not supported for " << s << endl;
|
---|
154 | return;
|
---|
155 | }
|
---|
156 |
|
---|
157 | // ---- Specialisation pour complexes -----
|
---|
158 | void NOMAdapter_PixelMap< complex<r_4> >::ReadFits(string const & flnm)
|
---|
159 | {
|
---|
160 | cout << " void NOMAdapter_PixelMap< complex<r_4> >::ReadFits() - Error "
|
---|
161 | << " Not supported (complex data type)" << endl;
|
---|
162 | }
|
---|
163 | void NOMAdapter_PixelMap< complex<r_4> >::SaveFits(string const & flnm)
|
---|
164 | {
|
---|
165 | cout << " void NOMAdapter_PixelMap< complex<r_4> >::SaveFits() - Error "
|
---|
166 | << " Not supported (complex data type)" << endl;
|
---|
167 | }
|
---|
168 | void NOMAdapter_PixelMap< complex<r_8> >::ReadFits(string const & flnm)
|
---|
169 | {
|
---|
170 | cout << " void NOMAdapter_PixelMap< complex<r_4> >::ReadFits() - Error "
|
---|
171 | << " Not supported (complex data type)" << endl;
|
---|
172 | }
|
---|
173 | void NOMAdapter_PixelMap< complex<r_8> >::SaveFits(string const & flnm)
|
---|
174 | {
|
---|
175 | cout << " void NOMAdapter_PixelMap< complex<r_8> >::SaveFits() - Error "
|
---|
176 | << " Not supported (complex data type)" << endl;
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | /* --Methode-- */
|
---|
181 | template <class T>
|
---|
182 | void NOMAdapter_PixelMap<T>::SavePPF(POutPersist& pos, string const & nom)
|
---|
183 | {
|
---|
184 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
185 | if (lm != NULL) {
|
---|
186 | FIO_LocalMap<T> fio(lm);
|
---|
187 | fio.Write(pos, nom);
|
---|
188 | return;
|
---|
189 | }
|
---|
190 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
|
---|
191 | if (st != NULL) {
|
---|
192 | FIO_SphereThetaPhi<T> fio(st);
|
---|
193 | fio.Write(pos, nom);
|
---|
194 | return;
|
---|
195 | }
|
---|
196 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
|
---|
197 | if (sg != NULL) {
|
---|
198 | FIO_SphereHEALPix<T> fio(sg);
|
---|
199 | fio.Write(pos, nom);
|
---|
200 | return;
|
---|
201 | }
|
---|
202 | string s = typeid(*mMap).name();
|
---|
203 | cout << "NOMAdapter_PixelMap<T>::SavePPF() - Error : Not supported for " << s << endl;
|
---|
204 | }
|
---|
205 |
|
---|
206 | /* --Methode-- */
|
---|
207 | template <class T>
|
---|
208 | void NOMAdapter_PixelMap<T>::Print(ostream& os)
|
---|
209 | {
|
---|
210 | string s = typeid(*mMap).name();
|
---|
211 | T moy, sig;
|
---|
212 | MeanSig(moy, sig);
|
---|
213 | cout << "SkyMap Type: " << s << " NbPixels= " << mMap->NbPixels() << endl;
|
---|
214 | cout << " Mean= " << moy << " Sig2= " << sig << endl;
|
---|
215 | }
|
---|
216 |
|
---|
217 | // -- Fonction pour convertir un X,Y en Theta-Phi sur projection MolleWeide --
|
---|
218 | char * _SphMollweideProj_XY2ThetaPhi(P2DArrayAdapter * aa, int ix, int iy);
|
---|
219 |
|
---|
220 | /* --Methode-- */
|
---|
221 | template <class T>
|
---|
222 | P2DArrayAdapter* NOMAdapter_PixelMap<T>::Get2DArray(string &)
|
---|
223 | {
|
---|
224 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
225 | if (lm != NULL) return(new LocalMapArrAdapter<T>(lm, false));
|
---|
226 | int nr = 250;
|
---|
227 | int nc = 500;
|
---|
228 | SphericalMap<T>* sm = dynamic_cast< SphericalMap<T> *>(mMap);
|
---|
229 | if (sm != NULL) { nr = sqrt(0.75*mMap->NbPixels()); nc = 2*nr; }
|
---|
230 | TMatrix<T> * mtx = new TMatrix<T>(nr, nc);
|
---|
231 | Project_Mol(*mtx);
|
---|
232 | POTMatrixAdapter<T> * potma = new POTMatrixAdapter<T>(mtx, true);
|
---|
233 | potma->SetInfoStringFunction(_SphMollweideProj_XY2ThetaPhi);
|
---|
234 | return ( potma );
|
---|
235 | }
|
---|
236 |
|
---|
237 | /* --Methode-- */
|
---|
238 | template <class T>
|
---|
239 | NTupleInterface* NOMAdapter_PixelMap<T>::GetNTupleInterface(bool& adel)
|
---|
240 | {
|
---|
241 | adel = true;
|
---|
242 | return( new NTupInt_PixelMap<T>(mMap) );
|
---|
243 | }
|
---|
244 |
|
---|
245 | /* --Methode-- */
|
---|
246 | template <class T>
|
---|
247 | void NOMAdapter_PixelMap<T>::MeanSig(T& gmoy, T& gsig)
|
---|
248 | {
|
---|
249 | gmoy=0.;
|
---|
250 | gsig = 0.;
|
---|
251 | T valok;
|
---|
252 | for(int k=0; k<mMap->NbPixels(); k++) {
|
---|
253 | valok = (*mMap)(k);
|
---|
254 | gmoy += valok; gsig += valok*valok;
|
---|
255 | }
|
---|
256 | gmoy /= (T)mMap->NbPixels();
|
---|
257 | gsig = gsig/(T)mMap->NbPixels() - gmoy*gmoy;
|
---|
258 |
|
---|
259 | }
|
---|
260 |
|
---|
261 | /* --Methode-- */
|
---|
262 | template <class T>
|
---|
263 | void NOMAdapter_PixelMap<T>::Project_Mol(TMatrix<T> & mtx, T defval)
|
---|
264 | {
|
---|
265 | r_8 xa, yd, teta,phi, facteur;
|
---|
266 | int_4 l,c,k;
|
---|
267 | int_4 nl = mtx.NRows();
|
---|
268 | int_4 nc = mtx.NCols();
|
---|
269 | mtx = defval; // On met tout a defval
|
---|
270 | // cout << " NRows= " << nl << " NCols= " << nc << endl;
|
---|
271 | for(l=0; l<nl; l++) {
|
---|
272 | yd = (r_8)(l+0.5)/(r_8)nl-0.5;
|
---|
273 | facteur=2.*M_PI/sin(acos((double)yd*2));
|
---|
274 | teta = (yd+0.5)*Pi;
|
---|
275 | // teta = (0.5-yd)*M_PI;
|
---|
276 | for(c=0; c<nc; c++) {
|
---|
277 | xa = (r_8)(c+0.5)/(r_8)nc-0.5;
|
---|
278 | phi = xa*facteur+M_PI;
|
---|
279 | if ( (phi <= 2*M_PI) && (phi >= 0.) ) {
|
---|
280 | k = mMap->PixIndexSph(teta, phi);
|
---|
281 | mtx(l,c) = (*mMap)(k);
|
---|
282 | }
|
---|
283 | }
|
---|
284 | }
|
---|
285 | }
|
---|
286 |
|
---|
287 | static char m_buff[128];
|
---|
288 | char * _SphMollweideProj_XY2ThetaPhi(P2DArrayAdapter * aa, int ix, int iy)
|
---|
289 | {
|
---|
290 | r_8 xa, yd, teta,phi, facteur;
|
---|
291 | int_4 nl = aa->YSize();
|
---|
292 | int_4 nc = aa->XSize();
|
---|
293 | int l, c;
|
---|
294 | aa->IJ2xy(ix, iy, c, l);
|
---|
295 | yd = (r_8)(l+0.5)/(r_8)nl-0.5;
|
---|
296 | facteur=2.*M_PI/sin(acos((double)yd*2));
|
---|
297 | teta = (yd+0.5)*Pi;
|
---|
298 | xa = (r_8)(c+0.5)/(r_8)nc-0.5;
|
---|
299 | phi = xa*facteur+M_PI;
|
---|
300 | if ( (phi <= 2*M_PI) && (phi >= 0.) )
|
---|
301 | sprintf(m_buff,"(l,b=%5.1f,%5.1f)", phi*180./M_PI, 90.-teta*180./M_PI);
|
---|
302 | else
|
---|
303 | sprintf(m_buff,"(l,b=?,?)");
|
---|
304 |
|
---|
305 | return (m_buff);
|
---|
306 | }
|
---|
307 |
|
---|
308 | // -------------------------------------------------------------
|
---|
309 |
|
---|
310 | /* --Methode-- */
|
---|
311 | template <class T>
|
---|
312 | NTupInt_PixelMap<T>::NTupInt_PixelMap(PixelMap<T>* m)
|
---|
313 | {
|
---|
314 | mMap = m;
|
---|
315 | }
|
---|
316 |
|
---|
317 | /* --Methode-- */
|
---|
318 | template <class T>
|
---|
319 | NTupInt_PixelMap<T>::~NTupInt_PixelMap()
|
---|
320 | {
|
---|
321 | }
|
---|
322 |
|
---|
323 | /* --Methode-- */
|
---|
324 | template <class T>
|
---|
325 | uint_4 NTupInt_PixelMap<T>::NbLines() const
|
---|
326 | {
|
---|
327 | return( mMap->NbPixels() );
|
---|
328 | }
|
---|
329 |
|
---|
330 | /* --Methode-- */
|
---|
331 | template <class T>
|
---|
332 | uint_4 NTupInt_PixelMap<T>::NbColumns() const
|
---|
333 | {
|
---|
334 | return(8);
|
---|
335 | }
|
---|
336 |
|
---|
337 | /* --Methode-- */
|
---|
338 | template <class T>
|
---|
339 | r_8* NTupInt_PixelMap<T>::GetLineD(int n) const
|
---|
340 | {
|
---|
341 | int i;
|
---|
342 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
|
---|
343 | for(i=0; i<8; i++) mRet[i] = 0.;
|
---|
344 | else {
|
---|
345 | double teta,phi;
|
---|
346 | mMap->PixThetaPhi(n, teta, phi);
|
---|
347 | mRet[0] = n; mRet[1] = mMap->PixVal(n);
|
---|
348 | mRet[2] = mRet[1]; mRet[3] = 0.;
|
---|
349 | mRet[4] = mRet[1]; mRet[5] = 0.;
|
---|
350 | mRet[6] = teta; mRet[7] = phi;
|
---|
351 | }
|
---|
352 | return(mRet);
|
---|
353 | }
|
---|
354 |
|
---|
355 | /* --Methode-- */
|
---|
356 | template <class T>
|
---|
357 | string NTupInt_PixelMap<T>::VarList_C(const char* nx) const
|
---|
358 | {
|
---|
359 | string nomx;
|
---|
360 | if (nx) nomx = nx;
|
---|
361 | else nomx = "_xh_";
|
---|
362 | string vardec = "double i,k,val,real,imag,mod,phas,teta,phi; \n";
|
---|
363 | vardec += "i = " + nomx + "[0]; k = " + nomx + "[0]; val = " + nomx + "[1]; \n";
|
---|
364 | vardec += "real = " + nomx + "[2]; imag = " + nomx + "[3]; \n";
|
---|
365 | vardec += "mod = " + nomx + "[4]; phas = " + nomx + "[5]; \n";
|
---|
366 | vardec += "teta = " + nomx + "[6]; phi = " + nomx + "[7]; \n";
|
---|
367 | return(vardec);
|
---|
368 | }
|
---|
369 |
|
---|
370 | r_8* NTupInt_PixelMap< complex<float> >::GetLineD(int n) const
|
---|
371 | {
|
---|
372 | int i;
|
---|
373 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
|
---|
374 | for(i=0; i<8; i++) mRet[i] = 0.;
|
---|
375 | else {
|
---|
376 | double teta,phi;
|
---|
377 | mMap->PixThetaPhi(n, teta, phi);
|
---|
378 | mRet[0] = n;
|
---|
379 | mRet[2] = mMap->PixVal(n).real(); mRet[3] = mMap->PixVal(n).imag();
|
---|
380 | mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]);
|
---|
381 | mRet[5] = atan2(mRet[3], mRet[2]);
|
---|
382 | mRet[6] = teta; mRet[7] = phi;
|
---|
383 | }
|
---|
384 | return(mRet);
|
---|
385 | }
|
---|
386 |
|
---|
387 | r_8* NTupInt_PixelMap< complex<double> >::GetLineD(int n) const
|
---|
388 | {
|
---|
389 | int i;
|
---|
390 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
|
---|
391 | for(i=0; i<8; i++) mRet[i] = 0.;
|
---|
392 | else {
|
---|
393 | double teta,phi;
|
---|
394 | mMap->PixThetaPhi(n, teta, phi);
|
---|
395 | mRet[0] = n;
|
---|
396 | mRet[2] = mMap->PixVal(n).real(); mRet[3] = mMap->PixVal(n).imag();
|
---|
397 | mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]);
|
---|
398 | mRet[5] = atan2(mRet[3], mRet[2]);
|
---|
399 | mRet[6] = teta; mRet[7] = phi;
|
---|
400 | }
|
---|
401 | return(mRet);
|
---|
402 | }
|
---|
403 |
|
---|
404 |
|
---|
405 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
406 | #pragma define_template NOMAdapter_PixelMap<int_4>
|
---|
407 | #pragma define_template NOMAdapter_PixelMap<r_4>
|
---|
408 | #pragma define_template NOMAdapter_PixelMap<r_8>
|
---|
409 | #pragma define_template NOMAdapter_PixelMap< complex<float> >
|
---|
410 | #pragma define_template NOMAdapter_PixelMap< complex<double> >
|
---|
411 | #pragma define_template NTupInt_PixelMap<int_4>
|
---|
412 | #pragma define_template NTupInt_PixelMap<r_4>
|
---|
413 | #pragma define_template NTupInt_PixelMap<r_8>
|
---|
414 | #pragma define_template NTupInt_PixelMap< complex<float> >
|
---|
415 | #pragma define_template NTupInt_PixelMap< complex<double> >
|
---|
416 | #endif
|
---|
417 |
|
---|
418 | #if defined(ANSI_TEMPLATES)
|
---|
419 | template class NOMAdapter_PixelMap<int_4>;
|
---|
420 | template class NOMAdapter_PixelMap<r_4>;
|
---|
421 | template class NOMAdapter_PixelMap<r_8>;
|
---|
422 | template class NOMAdapter_PixelMap< complex<float> >;
|
---|
423 | template class NOMAdapter_PixelMap< complex<double> >;
|
---|
424 | template class NTupInt_PixelMap<int_4>;
|
---|
425 | template class NTupInt_PixelMap<r_4>;
|
---|
426 | template class NTupInt_PixelMap<r_8>;
|
---|
427 | template class NTupInt_PixelMap< complex<float> >;
|
---|
428 | template class NTupInt_PixelMap< complex<double> >;
|
---|
429 | #endif
|
---|