[585] | 1 | #include "machdefs.h"
|
---|
| 2 | #include <stdlib.h>
|
---|
[594] | 3 | #include <math.h>
|
---|
[585] | 4 | #include <typeinfo>
|
---|
| 5 | #include <iostream.h>
|
---|
| 6 | #include <string>
|
---|
| 7 | #include <complex>
|
---|
| 8 |
|
---|
[1224] | 9 | #include "datatype.h"
|
---|
| 10 |
|
---|
[585] | 11 | #include "nomskymapadapter.h"
|
---|
[855] | 12 | #include "skymap.h"
|
---|
[594] | 13 | #include "pitvmaad.h"
|
---|
| 14 | #include "complexios.h"
|
---|
[585] | 15 |
|
---|
[1321] | 16 | #include "fitsspherehealpix.h"
|
---|
| 17 | #include "fitslocalmap.h"
|
---|
| 18 |
|
---|
| 19 |
|
---|
[594] | 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) :
|
---|
[1164] | 25 | P2DArrayAdapter(lm->SizeX(), lm->SizeY())
|
---|
[594] | 26 | { ad = d; map = lm; }
|
---|
[585] | 27 |
|
---|
[594] | 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 |
|
---|
[585] | 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)
|
---|
[594] | 61 | : NObjMgrAdapter(o)
|
---|
[585] | 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>
|
---|
[1165] | 83 | string NOMAdapter_PixelMap<T>::GetDataObjType()
|
---|
[585] | 84 | {
|
---|
[1165] | 85 | string type = "PixelMap< ";
|
---|
[585] | 86 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
[1165] | 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 |
|
---|
[1224] | 93 | // type += DecodeTypeIdName(typeid(T).name());
|
---|
[1237] | 94 | type += DataTypeInfo<T>::getTypeName();
|
---|
[1165] | 95 | type += " > ";
|
---|
| 96 | return(type);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /* --Methode-- */
|
---|
| 100 | template <class T>
|
---|
[1315] | 101 | AnyDataObj* NOMAdapter_PixelMap<T>::CloneDataObj(bool share)
|
---|
[1165] | 102 | {
|
---|
| 103 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
[1315] | 104 | if (lm != NULL) return( new LocalMap<T>(*lm, share) );
|
---|
[585] | 105 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
|
---|
[1315] | 106 | if (st != NULL) return( new SphereThetaPhi<T>(*st, share) );
|
---|
[855] | 107 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
|
---|
[1315] | 108 | if (sg != NULL) return( new SphereHEALPix<T>(*sg, share) );
|
---|
[585] | 109 | return(NULL);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | /* --Methode-- */
|
---|
| 113 | template <class T>
|
---|
[1321] | 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>
|
---|
[585] | 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 | }
|
---|
[855] | 196 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
|
---|
[585] | 197 | if (sg != NULL) {
|
---|
[855] | 198 | FIO_SphereHEALPix<T> fio(sg);
|
---|
[585] | 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();
|
---|
[594] | 211 | T moy, sig;
|
---|
| 212 | MeanSig(moy, sig);
|
---|
[585] | 213 | cout << "SkyMap Type: " << s << " NbPixels= " << mMap->NbPixels() << endl;
|
---|
[594] | 214 | cout << " Mean= " << moy << " Sig2= " << sig << endl;
|
---|
[585] | 215 | }
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | /* --Methode-- */
|
---|
| 219 | template <class T>
|
---|
| 220 | P2DArrayAdapter* NOMAdapter_PixelMap<T>::Get2DArray(string &)
|
---|
| 221 | {
|
---|
[594] | 222 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
| 223 | if (lm != NULL) return(new LocalMapArrAdapter<T>(lm, false));
|
---|
| 224 | int nr = 250;
|
---|
| 225 | int nc = 500;
|
---|
| 226 | SphericalMap<T>* sm = dynamic_cast< SphericalMap<T> *>(mMap);
|
---|
| 227 | if (sm != NULL) { nr = sqrt(0.75*mMap->NbPixels()); nc = 2*nr; }
|
---|
| 228 | TMatrix<T> * mtx = new TMatrix<T>(nr, nc);
|
---|
| 229 | Project_Mol(*mtx);
|
---|
| 230 | return (new POTMatrixAdapter<T>(mtx, true) );
|
---|
[585] | 231 | }
|
---|
| 232 |
|
---|
| 233 | /* --Methode-- */
|
---|
| 234 | template <class T>
|
---|
| 235 | NTupleInterface* NOMAdapter_PixelMap<T>::GetNTupleInterface(bool& adel)
|
---|
| 236 | {
|
---|
| 237 | adel = true;
|
---|
| 238 | return( new NTupInt_PixelMap<T>(mMap) );
|
---|
| 239 | }
|
---|
| 240 |
|
---|
[594] | 241 | /* --Methode-- */
|
---|
| 242 | template <class T>
|
---|
| 243 | void NOMAdapter_PixelMap<T>::MeanSig(T& gmoy, T& gsig)
|
---|
| 244 | {
|
---|
| 245 | gmoy=0.;
|
---|
| 246 | gsig = 0.;
|
---|
| 247 | T valok;
|
---|
| 248 | for(int k=0; k<mMap->NbPixels(); k++) {
|
---|
| 249 | valok = (*mMap)(k);
|
---|
| 250 | gmoy += valok; gsig += valok*valok;
|
---|
| 251 | }
|
---|
| 252 | gmoy /= (T)mMap->NbPixels();
|
---|
| 253 | gsig = gsig/(T)mMap->NbPixels() - gmoy*gmoy;
|
---|
[585] | 254 |
|
---|
[594] | 255 | }
|
---|
[585] | 256 |
|
---|
[594] | 257 | /* --Methode-- */
|
---|
| 258 | template <class T>
|
---|
| 259 | void NOMAdapter_PixelMap<T>::Project_Mol(TMatrix<T> & mtx, T defval)
|
---|
| 260 | {
|
---|
| 261 | r_8 xa, yd, teta,phi, facteur;
|
---|
| 262 | int_4 l,c,k;
|
---|
| 263 | int_4 nl = mtx.NRows();
|
---|
| 264 | int_4 nc = mtx.NCols();
|
---|
[815] | 265 | mtx = defval; // On met tout a defval
|
---|
[594] | 266 | // cout << " NRows= " << nl << " NCols= " << nc << endl;
|
---|
| 267 | for(l=0; l<nl; l++) {
|
---|
| 268 | yd = (r_8)(l+0.5)/(r_8)nl-0.5;
|
---|
| 269 | facteur=2.*M_PI/sin(acos((double)yd*2));
|
---|
| 270 | teta = (yd+0.5)*Pi;
|
---|
| 271 | // teta = (0.5-yd)*M_PI;
|
---|
| 272 | for(c=0; c<nc; c++) {
|
---|
| 273 | xa = (r_8)(c+0.5)/(r_8)nc-0.5;
|
---|
| 274 | phi = xa*facteur+M_PI;
|
---|
| 275 | if ( (phi <= 2*M_PI) && (phi >= 0.) ) {
|
---|
| 276 | k = mMap->PixIndexSph(teta, phi);
|
---|
| 277 | mtx(l,c) = (*mMap)(k);
|
---|
| 278 | }
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 |
|
---|
[585] | 283 | // -------------------------------------------------------------
|
---|
| 284 |
|
---|
| 285 | /* --Methode-- */
|
---|
| 286 | template <class T>
|
---|
| 287 | NTupInt_PixelMap<T>::NTupInt_PixelMap(PixelMap<T>* m)
|
---|
| 288 | {
|
---|
| 289 | mMap = m;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | /* --Methode-- */
|
---|
| 293 | template <class T>
|
---|
| 294 | NTupInt_PixelMap<T>::~NTupInt_PixelMap()
|
---|
| 295 | {
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | /* --Methode-- */
|
---|
| 299 | template <class T>
|
---|
| 300 | uint_4 NTupInt_PixelMap<T>::NbLines() const
|
---|
| 301 | {
|
---|
| 302 | return( mMap->NbPixels() );
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | /* --Methode-- */
|
---|
| 306 | template <class T>
|
---|
| 307 | uint_4 NTupInt_PixelMap<T>::NbColumns() const
|
---|
| 308 | {
|
---|
| 309 | return(8);
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | /* --Methode-- */
|
---|
| 313 | template <class T>
|
---|
| 314 | r_8* NTupInt_PixelMap<T>::GetLineD(int n) const
|
---|
| 315 | {
|
---|
| 316 | int i;
|
---|
| 317 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
|
---|
| 318 | for(i=0; i<8; i++) mRet[i] = 0.;
|
---|
| 319 | else {
|
---|
| 320 | double teta,phi;
|
---|
| 321 | mMap->PixThetaPhi(n, teta, phi);
|
---|
| 322 | mRet[0] = n; mRet[1] = mMap->PixVal(n);
|
---|
| 323 | mRet[2] = mRet[1]; mRet[3] = 0.;
|
---|
| 324 | mRet[4] = mRet[1]; mRet[5] = 0.;
|
---|
| 325 | mRet[6] = teta; mRet[7] = phi;
|
---|
| 326 | }
|
---|
| 327 | return(mRet);
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | /* --Methode-- */
|
---|
| 331 | template <class T>
|
---|
| 332 | string NTupInt_PixelMap<T>::VarList_C(const char* nx) const
|
---|
| 333 | {
|
---|
| 334 | string nomx;
|
---|
| 335 | if (nx) nomx = nx;
|
---|
| 336 | else nomx = "_xh_";
|
---|
| 337 | string vardec = "double i,k,val,real,imag,mod,phas,teta,phi; \n";
|
---|
| 338 | vardec += "i = " + nomx + "[0]; k = " + nomx + "[0]; val = " + nomx + "[1]; \n";
|
---|
| 339 | vardec += "real = " + nomx + "[2]; imag = " + nomx + "[3]; \n";
|
---|
| 340 | vardec += "mod = " + nomx + "[4]; phas = " + nomx + "[5]; \n";
|
---|
| 341 | vardec += "teta = " + nomx + "[6]; phi = " + nomx + "[7]; \n";
|
---|
| 342 | return(vardec);
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | r_8* NTupInt_PixelMap< complex<float> >::GetLineD(int n) const
|
---|
| 346 | {
|
---|
| 347 | int i;
|
---|
| 348 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
|
---|
| 349 | for(i=0; i<8; i++) mRet[i] = 0.;
|
---|
| 350 | else {
|
---|
| 351 | double teta,phi;
|
---|
| 352 | mMap->PixThetaPhi(n, teta, phi);
|
---|
| 353 | mRet[0] = n;
|
---|
| 354 | mRet[2] = mMap->PixVal(n).real(); mRet[3] = mMap->PixVal(n).imag();
|
---|
| 355 | mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]);
|
---|
| 356 | mRet[5] = atan2(mRet[3], mRet[2]);
|
---|
| 357 | mRet[6] = teta; mRet[7] = phi;
|
---|
| 358 | }
|
---|
| 359 | return(mRet);
|
---|
| 360 | }
|
---|
| 361 |
|
---|
| 362 | r_8* NTupInt_PixelMap< complex<double> >::GetLineD(int n) const
|
---|
| 363 | {
|
---|
| 364 | int i;
|
---|
| 365 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
|
---|
| 366 | for(i=0; i<8; i++) mRet[i] = 0.;
|
---|
| 367 | else {
|
---|
| 368 | double teta,phi;
|
---|
| 369 | mMap->PixThetaPhi(n, teta, phi);
|
---|
| 370 | mRet[0] = n;
|
---|
| 371 | mRet[2] = mMap->PixVal(n).real(); mRet[3] = mMap->PixVal(n).imag();
|
---|
| 372 | mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]);
|
---|
| 373 | mRet[5] = atan2(mRet[3], mRet[2]);
|
---|
| 374 | mRet[6] = teta; mRet[7] = phi;
|
---|
| 375 | }
|
---|
| 376 | return(mRet);
|
---|
| 377 | }
|
---|
| 378 |
|
---|
| 379 |
|
---|
| 380 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 381 | #pragma define_template NOMAdapter_PixelMap<r_4>
|
---|
| 382 | #pragma define_template NOMAdapter_PixelMap<r_8>
|
---|
| 383 | #pragma define_template NOMAdapter_PixelMap< complex<float> >
|
---|
| 384 | #pragma define_template NOMAdapter_PixelMap< complex<double> >
|
---|
| 385 | #pragma define_template NTupInt_PixelMap<r_4>
|
---|
| 386 | #pragma define_template NTupInt_PixelMap<r_8>
|
---|
| 387 | #pragma define_template NTupInt_PixelMap< complex<float> >
|
---|
| 388 | #pragma define_template NTupInt_PixelMap< complex<double> >
|
---|
| 389 | #endif
|
---|
| 390 |
|
---|
| 391 | #if defined(ANSI_TEMPLATES)
|
---|
| 392 | template class NOMAdapter_PixelMap<r_4>;
|
---|
| 393 | template class NOMAdapter_PixelMap<r_8>;
|
---|
| 394 | template class NOMAdapter_PixelMap< complex<float> >;
|
---|
| 395 | template class NOMAdapter_PixelMap< complex<double> >;
|
---|
| 396 | template class NTupInt_PixelMap<r_4>;
|
---|
| 397 | template class NTupInt_PixelMap<r_8>;
|
---|
| 398 | template class NTupInt_PixelMap< complex<float> >;
|
---|
| 399 | template class NTupInt_PixelMap< complex<double> >;
|
---|
| 400 | #endif
|
---|