| 1 | #include "machdefs.h" | 
|---|
| 2 | #include <math.h> | 
|---|
| 3 | #include <complex> | 
|---|
| 4 |  | 
|---|
| 5 | #include "pexceptions.h" | 
|---|
| 6 | #include "fiondblock.h" | 
|---|
| 7 | #include "spherehealpix.h" | 
|---|
| 8 | #include "strutil.h" | 
|---|
| 9 |  | 
|---|
| 10 | extern "C" | 
|---|
| 11 | { | 
|---|
| 12 | #include <stdio.h> | 
|---|
| 13 | #include <stdlib.h> | 
|---|
| 14 | #include <unistd.h> | 
|---|
| 15 | } | 
|---|
| 16 |  | 
|---|
| 17 | using namespace SOPHYA; | 
|---|
| 18 |  | 
|---|
| 19 | /*! | 
|---|
| 20 | \class SOPHYA::SphereHEALPix | 
|---|
| 21 |  | 
|---|
| 22 | ******************************************************************* | 
|---|
| 23 | Pixelisation Gorski | 
|---|
| 24 |  | 
|---|
| 25 | \verbatim | 
|---|
| 26 |  | 
|---|
| 27 | ----------------------------------------------------------------------- | 
|---|
| 28 | version 0.8.2  Aug97 TAC  Eric Hivon, Kris Gorski | 
|---|
| 29 | ----------------------------------------------------------------------- | 
|---|
| 30 |  | 
|---|
| 31 | the sphere is split in 12 diamond-faces containing nside**2 pixels each | 
|---|
| 32 | the numbering of the pixels (in the nested scheme) is similar to | 
|---|
| 33 | quad-cube | 
|---|
| 34 | In each face the first pixel is in the lowest corner of the diamond | 
|---|
| 35 | the faces are                    (x,y) coordinate on each face | 
|---|
| 36 |  | 
|---|
| 37 | .   .   .   .   <--- North Pole | 
|---|
| 38 | / \ / \ / \ / \                          ^        ^ | 
|---|
| 39 | . 0 . 1 . 2 . 3 . <--- z = 2/3             \      / | 
|---|
| 40 | \ / \ / \ / \ /                        y   \    /  x | 
|---|
| 41 | 4 . 5 . 6 . 7 . 4 <--- equator               \  / | 
|---|
| 42 | / \ / \ / \ / \                              \/ | 
|---|
| 43 | . 8 . 9 .10 .11 . <--- z = -2/3              (0,0) : lowest corner | 
|---|
| 44 | \ / \ / \ / \ / | 
|---|
| 45 | .   .   .   .   <--- South Pole | 
|---|
| 46 | \endverbatim | 
|---|
| 47 | phi:0               2Pi | 
|---|
| 48 |  | 
|---|
| 49 | in the ring scheme pixels are numbered along the parallels | 
|---|
| 50 | the first parallel is the one closest to the north pole and so on | 
|---|
| 51 | on each parallel, pixels are numbered starting from the one closest | 
|---|
| 52 | to phi = 0 | 
|---|
| 53 |  | 
|---|
| 54 | nside MUST be a power of 2 (<= 8192) | 
|---|
| 55 |  | 
|---|
| 56 | */ | 
|---|
| 57 |  | 
|---|
| 58 | /* --Methode-- */ | 
|---|
| 59 |  | 
|---|
| 60 | template<class T> | 
|---|
| 61 | SphereHEALPix<T>::SphereHEALPix() : pixels_(), sliceBeginIndex_(), | 
|---|
| 62 | sliceLenght_() | 
|---|
| 63 |  | 
|---|
| 64 |  | 
|---|
| 65 | { | 
|---|
| 66 | InitNul(); | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | /*! \fn   SOPHYA::SphereHEALPix::SphereHEALPix(int_4 m) | 
|---|
| 70 |  | 
|---|
| 71 | \param <m> : "nside" of the Healpix algorithm | 
|---|
| 72 |  | 
|---|
| 73 | The total number of pixels will be Npix =  12*nside**2 | 
|---|
| 74 |  | 
|---|
| 75 | nside MUST be a power of 2 (<= 8192) | 
|---|
| 76 | */ | 
|---|
| 77 |  | 
|---|
| 78 | template<class T> | 
|---|
| 79 | SphereHEALPix<T>::SphereHEALPix(int_4 m) | 
|---|
| 80 |  | 
|---|
| 81 | { | 
|---|
| 82 |  | 
|---|
| 83 | if(m <= 0 || m > 8192) | 
|---|
| 84 | { | 
|---|
| 85 | cout << "SphereHEALPix : m hors bornes [0,8192], m= " << m << endl; | 
|---|
| 86 | throw RangeCheckError("SphereHEALPix<T>::SphereHEALPix() - Out of bound nside (< 8192)!"); | 
|---|
| 87 | } | 
|---|
| 88 | // verifier que m est une puissance de deux | 
|---|
| 89 | int x= m; | 
|---|
| 90 | while(x%2 == 0) x/=2; | 
|---|
| 91 | if(x != 1) | 
|---|
| 92 | { | 
|---|
| 93 | cout<<"SphereHEALPix: m doit etre une puissance de deux, m= "<<m<<endl; | 
|---|
| 94 | throw ParmError("SphereHEALPix<T>::SphereHEALPix() - nside != 2^n !"); | 
|---|
| 95 | } | 
|---|
| 96 | InitNul(); | 
|---|
| 97 | Pixelize(m); | 
|---|
| 98 | SetThetaSlices(); | 
|---|
| 99 | } | 
|---|
| 100 | //++ | 
|---|
| 101 | template<class T> | 
|---|
| 102 | SphereHEALPix<T>::SphereHEALPix(const SphereHEALPix<T>& s, bool share) | 
|---|
| 103 | : pixels_(s.pixels_, share), sliceBeginIndex_(s.sliceBeginIndex_, share), | 
|---|
| 104 | sliceLenght_(s.sliceLenght_, share) | 
|---|
| 105 | //    copy constructor | 
|---|
| 106 | //-- | 
|---|
| 107 | { | 
|---|
| 108 | nSide_= s.nSide_; | 
|---|
| 109 | nPix_ = s.nPix_; | 
|---|
| 110 | omeg_ = s.omeg_; | 
|---|
| 111 | if(s.mInfo_) mInfo_= new DVList(*s.mInfo_); | 
|---|
| 112 | } | 
|---|
| 113 | //++ | 
|---|
| 114 | template<class T> | 
|---|
| 115 | SphereHEALPix<T>::SphereHEALPix(const SphereHEALPix<T>& s) | 
|---|
| 116 | : pixels_(s.pixels_), sliceBeginIndex_(s.sliceBeginIndex_), | 
|---|
| 117 | sliceLenght_(s.sliceLenght_) | 
|---|
| 118 | //    copy constructor | 
|---|
| 119 | //-- | 
|---|
| 120 | { | 
|---|
| 121 | nSide_= s.nSide_; | 
|---|
| 122 | nPix_ = s.nPix_; | 
|---|
| 123 | omeg_ = s.omeg_; | 
|---|
| 124 | if(s.mInfo_) mInfo_= new DVList(*s.mInfo_); | 
|---|
| 125 | //  CloneOrShare(s); | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|
| 128 | //! Clone if \b a is not temporary, share if temporary | 
|---|
| 129 | /*! \sa NDataBlock::CloneOrShare(const NDataBlock<T>&) */ | 
|---|
| 130 | template<class T> | 
|---|
| 131 | void SphereHEALPix<T>::CloneOrShare(const SphereHEALPix<T>& a) | 
|---|
| 132 | { | 
|---|
| 133 | nSide_= a.nSide_; | 
|---|
| 134 | nPix_ = a.nPix_; | 
|---|
| 135 | omeg_ = a.omeg_; | 
|---|
| 136 | pixels_.CloneOrShare(a.pixels_); | 
|---|
| 137 | sliceBeginIndex_.CloneOrShare(a.sliceBeginIndex_); | 
|---|
| 138 | sliceLenght_.CloneOrShare(a.sliceLenght_); | 
|---|
| 139 | if (mInfo_) {delete mInfo_; mInfo_ = NULL;} | 
|---|
| 140 | if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_)); | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | //! Share data with a | 
|---|
| 144 | template<class T> | 
|---|
| 145 | void SphereHEALPix<T>::Share(const SphereHEALPix<T>& a) | 
|---|
| 146 | { | 
|---|
| 147 | nSide_= a.nSide_; | 
|---|
| 148 | nPix_ = a.nPix_; | 
|---|
| 149 | omeg_ = a.omeg_; | 
|---|
| 150 | pixels_.Share(a.pixels_); | 
|---|
| 151 | sliceBeginIndex_.Share(a.sliceBeginIndex_); | 
|---|
| 152 | sliceLenght_.Share(a.sliceLenght_); | 
|---|
| 153 | if (mInfo_) {delete mInfo_; mInfo_ = NULL;} | 
|---|
| 154 | if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_)); | 
|---|
| 155 | } | 
|---|
| 156 |  | 
|---|
| 157 | ////////////////////////// methodes de copie/share | 
|---|
| 158 | template<class T> | 
|---|
| 159 | SphereHEALPix<T>& SphereHEALPix<T>::Set(const SphereHEALPix<T>& a) | 
|---|
| 160 | { | 
|---|
| 161 | if (this != &a) | 
|---|
| 162 | { | 
|---|
| 163 |  | 
|---|
| 164 | if (a.NbPixels() < 1) | 
|---|
| 165 | throw RangeCheckError("SphereHEALPix<T>::Set(a ) - SphereHEALPix a not allocated ! "); | 
|---|
| 166 | if (NbPixels() < 1) CloneOrShare(a); | 
|---|
| 167 | else CopyElt(a); | 
|---|
| 168 |  | 
|---|
| 169 |  | 
|---|
| 170 | if (mInfo_) delete mInfo_; | 
|---|
| 171 | mInfo_ = NULL; | 
|---|
| 172 | if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_)); | 
|---|
| 173 | } | 
|---|
| 174 | return(*this); | 
|---|
| 175 | } | 
|---|
| 176 |  | 
|---|
| 177 | template<class T> | 
|---|
| 178 | SphereHEALPix<T>& SphereHEALPix<T>::CopyElt(const SphereHEALPix<T>& a) | 
|---|
| 179 | { | 
|---|
| 180 | if (NbPixels() < 1) | 
|---|
| 181 | throw RangeCheckError("SphereHEALPix<T>::CopyElt(const SphereHEALPix<T>& )  - Not Allocated SphereHEALPix ! "); | 
|---|
| 182 | if (NbPixels() != a.NbPixels()) | 
|---|
| 183 | throw(SzMismatchError("SphereHEALPix<T>::CopyElt(const SphereHEALPix<T>&) SizeMismatch")) ; | 
|---|
| 184 | nSide_= a.nSide_; | 
|---|
| 185 | nPix_ = a.nPix_; | 
|---|
| 186 | omeg_ = a.omeg_; | 
|---|
| 187 | int k; | 
|---|
| 188 | for (k=0; k< nPix_; k++) pixels_(k) = a.pixels_(k); | 
|---|
| 189 | for (k=0; k< a.sliceBeginIndex_.Size(); k++) sliceBeginIndex_(k) = a.sliceBeginIndex_(k); | 
|---|
| 190 | for (k=0; k< a.sliceLenght_.Size(); k++) sliceLenght_(k) = a.sliceLenght_(k); | 
|---|
| 191 | return(*this); | 
|---|
| 192 | } | 
|---|
| 193 |  | 
|---|
| 194 |  | 
|---|
| 195 |  | 
|---|
| 196 | //++ | 
|---|
| 197 | // Titre        Destructor | 
|---|
| 198 | //-- | 
|---|
| 199 | //++ | 
|---|
| 200 | template<class T> | 
|---|
| 201 | SphereHEALPix<T>::~SphereHEALPix() | 
|---|
| 202 |  | 
|---|
| 203 | //-- | 
|---|
| 204 | { | 
|---|
| 205 | } | 
|---|
| 206 |  | 
|---|
| 207 | //++ | 
|---|
| 208 | // Titre        Public Methods | 
|---|
| 209 | //-- | 
|---|
| 210 |  | 
|---|
| 211 | /*!  \fn   void SOPHYA::SphereHEALPix::Resize(int_4 m) | 
|---|
| 212 | \param <m>   "nside" of the Gorski algorithm | 
|---|
| 213 |  | 
|---|
| 214 | The total number of pixels will be Npix =  12*nside**2 | 
|---|
| 215 |  | 
|---|
| 216 | nside MUST be a power of 2 (<= 8192) | 
|---|
| 217 | */ | 
|---|
| 218 | template<class T> | 
|---|
| 219 | void SphereHEALPix<T>::Resize(int_4 m) | 
|---|
| 220 |  | 
|---|
| 221 |  | 
|---|
| 222 | { | 
|---|
| 223 | if (m<=0 || m> 8192) { | 
|---|
| 224 | cout << "SphereHEALPix : m hors bornes [0,8192], m= " << m << endl; | 
|---|
| 225 | exit(1); | 
|---|
| 226 | } | 
|---|
| 227 | // verifier que m est une puissance de deux | 
|---|
| 228 | int x= m; | 
|---|
| 229 | while (x%2==0) x/=2; | 
|---|
| 230 | if(x != 1) | 
|---|
| 231 | { | 
|---|
| 232 | cout<<"SphereHEALPix: m doit etre une puissance de deux, m= "<<m<<endl; | 
|---|
| 233 | exit(1); | 
|---|
| 234 | } | 
|---|
| 235 | InitNul(); | 
|---|
| 236 | Pixelize(m); | 
|---|
| 237 | SetThetaSlices(); | 
|---|
| 238 | } | 
|---|
| 239 |  | 
|---|
| 240 | template<class T> | 
|---|
| 241 | void  SphereHEALPix<T>::Pixelize( int_4 m) | 
|---|
| 242 |  | 
|---|
| 243 | //    prépare la pixelisation Gorski (m a la même signification | 
|---|
| 244 | //    que pour le constructeur) | 
|---|
| 245 | // | 
|---|
| 246 | // | 
|---|
| 247 | { | 
|---|
| 248 | // On memorise les arguments d'appel | 
|---|
| 249 | nSide_= m; | 
|---|
| 250 |  | 
|---|
| 251 | // Nombre total de pixels sur la sphere entiere | 
|---|
| 252 | nPix_= 12*nSide_*nSide_; | 
|---|
| 253 |  | 
|---|
| 254 | // pour le moment les tableaux qui suivent seront ranges dans l'ordre | 
|---|
| 255 | // de l'indexation GORSKY "RING" | 
|---|
| 256 | // on pourra ulterieurement changer de strategie et tirer profit | 
|---|
| 257 | // de la dualite d'indexation GORSKY (RING et NEST) : tout dependra | 
|---|
| 258 | // de pourquoi c'est faire | 
|---|
| 259 |  | 
|---|
| 260 | // Creation et initialisation du vecteur des contenus des pixels | 
|---|
| 261 | pixels_.ReSize(nPix_); | 
|---|
| 262 | pixels_.Reset(); | 
|---|
| 263 |  | 
|---|
| 264 | // solid angle per pixel | 
|---|
| 265 | omeg_= 4.0*Pi/nPix_; | 
|---|
| 266 | } | 
|---|
| 267 |  | 
|---|
| 268 | template<class T> | 
|---|
| 269 | void SphereHEALPix<T>::InitNul() | 
|---|
| 270 | // | 
|---|
| 271 | //    initialise à zéro les variables de classe | 
|---|
| 272 | { | 
|---|
| 273 | nSide_= 0; | 
|---|
| 274 | nPix_ = 0; | 
|---|
| 275 | omeg_ = 0.; | 
|---|
| 276 | //  pixels_.Reset();  -  Il ne faut pas mettre les pixels a zero si share ! | 
|---|
| 277 | } | 
|---|
| 278 |  | 
|---|
| 279 | /* --Methode-- */ | 
|---|
| 280 | /* Nombre de pixels du decoupage */ | 
|---|
| 281 | /*! \fn int_4 SOPHYA::SphereHEALPix::NbPixels() const | 
|---|
| 282 |  | 
|---|
| 283 | Return number of  pixels of the  splitting | 
|---|
| 284 | */ | 
|---|
| 285 | template<class T> | 
|---|
| 286 | int_4 SphereHEALPix<T>::NbPixels() const | 
|---|
| 287 | { | 
|---|
| 288 | return(nPix_); | 
|---|
| 289 | } | 
|---|
| 290 |  | 
|---|
| 291 |  | 
|---|
| 292 | /*! \fn uint_4 SOPHYA::SphereHEALPix::NbThetaSlices() const | 
|---|
| 293 |  | 
|---|
| 294 | \return number of slices in theta direction on the  sphere | 
|---|
| 295 | */ | 
|---|
| 296 | template<class T> | 
|---|
| 297 | uint_4 SphereHEALPix<T>::NbThetaSlices() const | 
|---|
| 298 | { | 
|---|
| 299 | uint_4 nbslices = uint_4(4*nSide_-1); | 
|---|
| 300 | if (nSide_<=0) | 
|---|
| 301 | { | 
|---|
| 302 | nbslices = 0; | 
|---|
| 303 | throw PException(" sphere not pixelized, NbSlice=0 "); | 
|---|
| 304 | } | 
|---|
| 305 | return nbslices; | 
|---|
| 306 | } | 
|---|
| 307 |  | 
|---|
| 308 | /*!  \fn void SOPHYA::SphereHEALPix::GetThetaSlice(int_4 index,r_8& theta,TVector<r_8>& phi,TVector<T>& value) const | 
|---|
| 309 |  | 
|---|
| 310 | For a theta-slice with index 'index', return : | 
|---|
| 311 |  | 
|---|
| 312 | the corresponding "theta" | 
|---|
| 313 |  | 
|---|
| 314 | a vector containing the phi's of the pixels of the slice | 
|---|
| 315 |  | 
|---|
| 316 | a vector containing the corresponding values of pixels | 
|---|
| 317 | */ | 
|---|
| 318 | template<class T> | 
|---|
| 319 | void SphereHEALPix<T>::GetThetaSlice(int_4 index,r_8& theta,TVector<r_8>& phi,TVector<T>& value) const | 
|---|
| 320 |  | 
|---|
| 321 | { | 
|---|
| 322 |  | 
|---|
| 323 | if (index<0 || index >= NbThetaSlices()) | 
|---|
| 324 | { | 
|---|
| 325 | cout << " SphereHEALPix::GetThetaSlice : Pixel index out of range" <<endl; | 
|---|
| 326 | throw RangeCheckError(" SphereHEALPix::GetThetaSlice : Pixel index out of range"); | 
|---|
| 327 | } | 
|---|
| 328 |  | 
|---|
| 329 |  | 
|---|
| 330 | int_4 iring= sliceBeginIndex_(index); | 
|---|
| 331 | int_4 lring  =  sliceLenght_(index); | 
|---|
| 332 |  | 
|---|
| 333 | phi.ReSize(lring); | 
|---|
| 334 | value.ReSize(lring); | 
|---|
| 335 |  | 
|---|
| 336 | double TH= 0.; | 
|---|
| 337 | double FI= 0.; | 
|---|
| 338 | for(int_4 kk = 0; kk < lring;kk++) | 
|---|
| 339 | { | 
|---|
| 340 | PixThetaPhi(kk+iring,TH,FI); | 
|---|
| 341 | phi(kk)= FI; | 
|---|
| 342 | value(kk)= PixVal(kk+iring); | 
|---|
| 343 | } | 
|---|
| 344 | theta= TH; | 
|---|
| 345 | } | 
|---|
| 346 | /*! \fn void SOPHYA::SphereHEALPix::GetThetaSlice(int_4 sliceIndex,r_8& theta, r_8& phi0, TVector<int_4>& pixelIndices,TVector<T>& value) const | 
|---|
| 347 |  | 
|---|
| 348 | For a theta-slice with index 'index', return : | 
|---|
| 349 |  | 
|---|
| 350 | the corresponding "theta" | 
|---|
| 351 |  | 
|---|
| 352 | the corresponding "phi" for first pixel of the slice | 
|---|
| 353 |  | 
|---|
| 354 | a vector containing indices of the pixels of the slice | 
|---|
| 355 |  | 
|---|
| 356 | (equally distributed in phi) | 
|---|
| 357 |  | 
|---|
| 358 | a vector containing the corresponding values of pixels | 
|---|
| 359 | */ | 
|---|
| 360 |  | 
|---|
| 361 | template<class T> | 
|---|
| 362 | void SphereHEALPix<T>::GetThetaSlice(int_4 sliceIndex,r_8& theta, r_8& phi0, TVector<int_4>& pixelIndices,TVector<T>& value) const | 
|---|
| 363 |  | 
|---|
| 364 | { | 
|---|
| 365 |  | 
|---|
| 366 | if (sliceIndex<0 || sliceIndex >= NbThetaSlices()) | 
|---|
| 367 | { | 
|---|
| 368 | cout << " SphereHEALPix::GetThetaSlice : Pixel index out of range" <<endl; | 
|---|
| 369 | throw RangeCheckError(" SphereHEALPix::GetThetaSlice : Pixel index out of range"); | 
|---|
| 370 | } | 
|---|
| 371 | int_4 iring= sliceBeginIndex_(sliceIndex); | 
|---|
| 372 | int_4 lring  =  sliceLenght_(sliceIndex); | 
|---|
| 373 | pixelIndices.ReSize(lring); | 
|---|
| 374 | value.ReSize(lring); | 
|---|
| 375 |  | 
|---|
| 376 | for(int_4 kk = 0; kk < lring;kk++) | 
|---|
| 377 | { | 
|---|
| 378 | pixelIndices(kk)= kk+iring; | 
|---|
| 379 | value(kk)= PixVal(kk+iring); | 
|---|
| 380 | } | 
|---|
| 381 | PixThetaPhi(iring, theta, phi0); | 
|---|
| 382 | } | 
|---|
| 383 |  | 
|---|
| 384 | template<class T> | 
|---|
| 385 | void SphereHEALPix<T>::SetThetaSlices() | 
|---|
| 386 | { | 
|---|
| 387 | sliceBeginIndex_.ReSize(4*nSide_-1); | 
|---|
| 388 | sliceLenght_.ReSize(4*nSide_-1); | 
|---|
| 389 | int sliceIndex; | 
|---|
| 390 | for (sliceIndex=0; sliceIndex<  nSide_-1; sliceIndex++) | 
|---|
| 391 | { | 
|---|
| 392 | sliceBeginIndex_(sliceIndex)  = 2*sliceIndex*(sliceIndex+1); | 
|---|
| 393 | sliceLenght_(sliceIndex) = 4*(sliceIndex+1); | 
|---|
| 394 | } | 
|---|
| 395 | for (sliceIndex= nSide_-1; sliceIndex<  3*nSide_; sliceIndex++) | 
|---|
| 396 | { | 
|---|
| 397 | sliceBeginIndex_(sliceIndex)  = 2*nSide_*(2*sliceIndex-nSide_+1); | 
|---|
| 398 | sliceLenght_(sliceIndex) = 4*nSide_; | 
|---|
| 399 | } | 
|---|
| 400 | for (sliceIndex= 3*nSide_; sliceIndex< 4*nSide_-1; sliceIndex++) | 
|---|
| 401 | { | 
|---|
| 402 | int_4 nc= 4*nSide_-1-sliceIndex; | 
|---|
| 403 | sliceBeginIndex_(sliceIndex)  = nPix_-2*nc*(nc+1); | 
|---|
| 404 | sliceLenght_(sliceIndex) = 4*nc; | 
|---|
| 405 | } | 
|---|
| 406 | } | 
|---|
| 407 |  | 
|---|
| 408 |  | 
|---|
| 409 | /*! \fn T& SOPHYA::SphereHEALPix::PixVal(int_4 k) | 
|---|
| 410 |  | 
|---|
| 411 | \return value of  pixel with "RING" index k | 
|---|
| 412 | */ | 
|---|
| 413 | template<class T> | 
|---|
| 414 | T& SphereHEALPix<T>::PixVal(int_4 k) | 
|---|
| 415 |  | 
|---|
| 416 | { | 
|---|
| 417 | if((k < 0) || (k >= nPix_)) | 
|---|
| 418 | { | 
|---|
| 419 | throw RangeCheckError("SphereHEALPix::PIxVal Pixel index out of range"); | 
|---|
| 420 | } | 
|---|
| 421 | return pixels_(k); | 
|---|
| 422 | } | 
|---|
| 423 |  | 
|---|
| 424 | /*! \fn T const& SOPHYA::SphereHEALPix::PixVal(int_4 k) const | 
|---|
| 425 |  | 
|---|
| 426 | \return value of  pixel with "RING" index k | 
|---|
| 427 | */ | 
|---|
| 428 | template<class T> | 
|---|
| 429 | T const& SphereHEALPix<T>::PixVal(int_4 k) const | 
|---|
| 430 |  | 
|---|
| 431 | { | 
|---|
| 432 | if((k < 0) || (k >= nPix_)) | 
|---|
| 433 | { | 
|---|
| 434 | throw RangeCheckError("SphereHEALPix::PIxVal Pixel index out of range"); | 
|---|
| 435 | } | 
|---|
| 436 | return *(pixels_.Data()+k); | 
|---|
| 437 | } | 
|---|
| 438 |  | 
|---|
| 439 | /*! \fn T& SOPHYA::SphereHEALPix::PixValNest(int_4 k) | 
|---|
| 440 |  | 
|---|
| 441 | \return value of  pixel with "NESTED" index k | 
|---|
| 442 | */ | 
|---|
| 443 | template<class T> | 
|---|
| 444 | T& SphereHEALPix<T>::PixValNest(int_4 k) | 
|---|
| 445 |  | 
|---|
| 446 | //-- | 
|---|
| 447 | { | 
|---|
| 448 | if((k < 0) || (k >= nPix_)) | 
|---|
| 449 | { | 
|---|
| 450 | throw RangeCheckError("SphereHEALPix::PIxValNest Pixel index out of range"); | 
|---|
| 451 | } | 
|---|
| 452 | return pixels_(nest2ring(nSide_,k)); | 
|---|
| 453 | } | 
|---|
| 454 |  | 
|---|
| 455 | /*!  \fn T const& SOPHYA::SphereHEALPix::PixValNest(int_4 k) const | 
|---|
| 456 |  | 
|---|
| 457 | \return value of  pixel with "NESTED" index k | 
|---|
| 458 | */ | 
|---|
| 459 |  | 
|---|
| 460 | template<class T> | 
|---|
| 461 | T const& SphereHEALPix<T>::PixValNest(int_4 k) const | 
|---|
| 462 |  | 
|---|
| 463 | { | 
|---|
| 464 | if((k < 0) || (k >= nPix_)) | 
|---|
| 465 | { | 
|---|
| 466 | throw RangeCheckError("SphereHEALPix::PIxValNest Pixel index out of range"); | 
|---|
| 467 | } | 
|---|
| 468 | int_4 pix= nest2ring(nSide_,k); | 
|---|
| 469 | return *(pixels_.Data()+pix); | 
|---|
| 470 | } | 
|---|
| 471 |  | 
|---|
| 472 | /*! \fn bool SOPHYA::SphereHEALPix::ContainsSph(double theta, double phi) const | 
|---|
| 473 |  | 
|---|
| 474 | \return true if teta,phi in map | 
|---|
| 475 | */ | 
|---|
| 476 | template<class T> | 
|---|
| 477 | bool SphereHEALPix<T>::ContainsSph(double theta, double phi) const | 
|---|
| 478 | { | 
|---|
| 479 | return(true); | 
|---|
| 480 | } | 
|---|
| 481 |  | 
|---|
| 482 | /*! \fn int_4 SOPHYA::SphereHEALPix::PixIndexSph(double theta,double phi) const | 
|---|
| 483 |  | 
|---|
| 484 | \return "RING" index of the pixel corresponding to direction (theta, phi). | 
|---|
| 485 | */ | 
|---|
| 486 | template<class T> | 
|---|
| 487 | int_4 SphereHEALPix<T>::PixIndexSph(double theta,double phi) const | 
|---|
| 488 |  | 
|---|
| 489 | { | 
|---|
| 490 | return ang2pix_ring(nSide_,theta,phi); | 
|---|
| 491 | } | 
|---|
| 492 |  | 
|---|
| 493 | /*! \fn int_4 SOPHYA::SphereHEALPix::PixIndexSphNest(double theta,double phi) const | 
|---|
| 494 |  | 
|---|
| 495 | \return "NESTED" index of the pixel corresponding to direction (theta, phi). | 
|---|
| 496 | */ | 
|---|
| 497 | template<class T> | 
|---|
| 498 | int_4 SphereHEALPix<T>::PixIndexSphNest(double theta,double  phi) const | 
|---|
| 499 |  | 
|---|
| 500 | { | 
|---|
| 501 | return ang2pix_nest(nSide_,theta,phi); | 
|---|
| 502 | } | 
|---|
| 503 |  | 
|---|
| 504 |  | 
|---|
| 505 | /* --Methode-- */ | 
|---|
| 506 | /*! \fn void SOPHYA::SphereHEALPix::PixThetaPhi(int_4 k,double& theta,double& phi) const | 
|---|
| 507 | \return (theta,phi) coordinates of middle of  pixel with "RING" index k | 
|---|
| 508 | */ | 
|---|
| 509 | template<class T> | 
|---|
| 510 | void SphereHEALPix<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const | 
|---|
| 511 | { | 
|---|
| 512 | pix2ang_ring(nSide_,k,theta,phi); | 
|---|
| 513 | } | 
|---|
| 514 |  | 
|---|
| 515 | /*! \fn T SOPHYA::SphereHEALPix::SetPixels(T v) | 
|---|
| 516 |  | 
|---|
| 517 | Set all pixels to value v | 
|---|
| 518 | */ | 
|---|
| 519 | template <class T> | 
|---|
| 520 | T SphereHEALPix<T>::SetPixels(T v) | 
|---|
| 521 | { | 
|---|
| 522 | pixels_.Reset(v); | 
|---|
| 523 | return(v); | 
|---|
| 524 | } | 
|---|
| 525 |  | 
|---|
| 526 |  | 
|---|
| 527 |  | 
|---|
| 528 | /*! \fn void SOPHYA::SphereHEALPix::PixThetaPhiNest(int_4 k,double& theta,double& phi) const | 
|---|
| 529 |  | 
|---|
| 530 | \return (theta,phi) coordinates of middle of  pixel with "NESTED" index k | 
|---|
| 531 | */ | 
|---|
| 532 | template<class T> | 
|---|
| 533 | void SphereHEALPix<T>::PixThetaPhiNest(int_4 k,double& theta,double& phi) const | 
|---|
| 534 |  | 
|---|
| 535 | { | 
|---|
| 536 | pix2ang_nest(nSide_,k,theta,phi); | 
|---|
| 537 | } | 
|---|
| 538 |  | 
|---|
| 539 |  | 
|---|
| 540 | /*! \fn int_4 SOPHYA::SphereHEALPix::NestToRing(int_4 k) const | 
|---|
| 541 |  | 
|---|
| 542 | translation from NESTED index  into RING index | 
|---|
| 543 | */ | 
|---|
| 544 | template<class T> | 
|---|
| 545 | int_4 SphereHEALPix<T>::NestToRing(int_4 k) const | 
|---|
| 546 |  | 
|---|
| 547 | { | 
|---|
| 548 | return  nest2ring(nSide_,k); | 
|---|
| 549 | } | 
|---|
| 550 |  | 
|---|
| 551 |  | 
|---|
| 552 | /*!  \fn  int_4 SOPHYA::SphereHEALPix::RingToNest(int_4 k) const | 
|---|
| 553 |  | 
|---|
| 554 | translation from  RING index  into NESTED index | 
|---|
| 555 | */ | 
|---|
| 556 | template<class T> | 
|---|
| 557 | int_4 SphereHEALPix<T>::RingToNest(int_4 k) const | 
|---|
| 558 | { | 
|---|
| 559 | return  ring2nest(nSide_,k); | 
|---|
| 560 | } | 
|---|
| 561 |  | 
|---|
| 562 | //   ...... Operations de calcul  ...... | 
|---|
| 563 |  | 
|---|
| 564 | //! Fill a SphereHEALPix with a constant value \b a | 
|---|
| 565 | template <class T> | 
|---|
| 566 | SphereHEALPix<T>& SphereHEALPix<T>::SetT(T a) | 
|---|
| 567 | { | 
|---|
| 568 | if (NbPixels() < 1) | 
|---|
| 569 | throw RangeCheckError("SphereHEALPix<T>::SetT(T )  - SphereHEALPix not dimensionned ! "); | 
|---|
| 570 | pixels_ = a; | 
|---|
| 571 | return (*this); | 
|---|
| 572 | } | 
|---|
| 573 |  | 
|---|
| 574 | /*! Add a constant value \b x to a SphereHEALPix */ | 
|---|
| 575 | template <class T> | 
|---|
| 576 | SphereHEALPix<T>& SphereHEALPix<T>::Add(T a) | 
|---|
| 577 | { | 
|---|
| 578 | if (NbPixels() < 1) | 
|---|
| 579 | throw RangeCheckError("SphereHEALPix<T>::Add(T )  - SphereHEALPix not dimensionned ! "); | 
|---|
| 580 | pixels_ += a; | 
|---|
| 581 | return (*this); | 
|---|
| 582 | } | 
|---|
| 583 |  | 
|---|
| 584 | /*! Substract a constant value \b a to a SphereHEALPix */ | 
|---|
| 585 | template <class T> | 
|---|
| 586 | SphereHEALPix<T>& SphereHEALPix<T>::Sub(T a,bool fginv) | 
|---|
| 587 | { | 
|---|
| 588 | if (NbPixels() < 1) | 
|---|
| 589 | throw RangeCheckError("SphereHEALPix<T>::Sub(T )  - SphereHEALPix not dimensionned ! "); | 
|---|
| 590 | pixels_.Sub(a,fginv); | 
|---|
| 591 | return (*this); | 
|---|
| 592 | } | 
|---|
| 593 |  | 
|---|
| 594 | /*! multiply a SphereHEALPix by a constant value \b a */ | 
|---|
| 595 | template <class T> | 
|---|
| 596 | SphereHEALPix<T>& SphereHEALPix<T>::Mul(T a) | 
|---|
| 597 | { | 
|---|
| 598 | if (NbPixels() < 1) | 
|---|
| 599 | throw RangeCheckError("SphereHEALPix<T>::Mul(T )  - SphereHEALPix not dimensionned ! "); | 
|---|
| 600 | pixels_ *= a; | 
|---|
| 601 | return (*this); | 
|---|
| 602 | } | 
|---|
| 603 |  | 
|---|
| 604 | /*! divide a SphereHEALPix by a constant value \b a */ | 
|---|
| 605 | template <class T> | 
|---|
| 606 | SphereHEALPix<T>& SphereHEALPix<T>::Div(T a) | 
|---|
| 607 | { | 
|---|
| 608 | if (NbPixels() < 1) | 
|---|
| 609 | throw RangeCheckError("SphereHEALPix<T>::Div(T )  - SphereHEALPix not dimensionned ! "); | 
|---|
| 610 | pixels_ /= a; | 
|---|
| 611 | return (*this); | 
|---|
| 612 | } | 
|---|
| 613 |  | 
|---|
| 614 | //  >>>> Operations avec 2nd membre de type SphereHEALPix | 
|---|
| 615 | //! Add two SphereHEALPix | 
|---|
| 616 |  | 
|---|
| 617 | template <class T> | 
|---|
| 618 | SphereHEALPix<T>& SphereHEALPix<T>::AddElt(const SphereHEALPix<T>& a) | 
|---|
| 619 | { | 
|---|
| 620 | if (NbPixels() != a.NbPixels() ) | 
|---|
| 621 | { | 
|---|
| 622 | throw(SzMismatchError("SphereHEALPix<T>::AddElt(const SphereHEALPix<T>&) SizeMismatch")) ; | 
|---|
| 623 | } | 
|---|
| 624 | pixels_ += a.pixels_; | 
|---|
| 625 | return (*this); | 
|---|
| 626 | } | 
|---|
| 627 |  | 
|---|
| 628 | //! Substract two SphereHEALPix | 
|---|
| 629 | template <class T> | 
|---|
| 630 | SphereHEALPix<T>& SphereHEALPix<T>::SubElt(const SphereHEALPix<T>& a) | 
|---|
| 631 | { | 
|---|
| 632 | if (NbPixels() != a.NbPixels() ) | 
|---|
| 633 | { | 
|---|
| 634 | throw(SzMismatchError("SphereHEALPix<T>::SubElt(const SphereHEALPix<T>&) SizeMismatch")) ; | 
|---|
| 635 | } | 
|---|
| 636 | pixels_ -= a.pixels_; | 
|---|
| 637 | return (*this); | 
|---|
| 638 | } | 
|---|
| 639 |  | 
|---|
| 640 | //! Multiply two SphereHEALPix (elements by elements) | 
|---|
| 641 | template <class T> | 
|---|
| 642 | SphereHEALPix<T>& SphereHEALPix<T>::MulElt(const SphereHEALPix<T>& a) | 
|---|
| 643 | { | 
|---|
| 644 | if (NbPixels() != a.NbPixels() ) | 
|---|
| 645 | { | 
|---|
| 646 | throw(SzMismatchError("SphereHEALPix<T>::MulElt(const SphereHEALPix<T>&) SizeMismatch")) ; | 
|---|
| 647 | } | 
|---|
| 648 | pixels_ *= a.pixels_; | 
|---|
| 649 | return (*this); | 
|---|
| 650 | } | 
|---|
| 651 |  | 
|---|
| 652 | //! Divide two SphereHEALPix (elements by elements) - No protection for divide by 0 | 
|---|
| 653 | template <class T> | 
|---|
| 654 | SphereHEALPix<T>& SphereHEALPix<T>::DivElt(const SphereHEALPix<T>& a) | 
|---|
| 655 | { | 
|---|
| 656 | if (NbPixels() != a.NbPixels() ) | 
|---|
| 657 | { | 
|---|
| 658 | throw(SzMismatchError("SphereHEALPix<T>::DivElt(const SphereHEALPix<T>&) SizeMismatch")) ; | 
|---|
| 659 | } | 
|---|
| 660 | pixels_ /= a.pixels_; | 
|---|
| 661 | return (*this); | 
|---|
| 662 | } | 
|---|
| 663 |  | 
|---|
| 664 |  | 
|---|
| 665 |  | 
|---|
| 666 |  | 
|---|
| 667 | template <class T> | 
|---|
| 668 | void SphereHEALPix<T>::print(ostream& os) const | 
|---|
| 669 | { | 
|---|
| 670 | if(mInfo_) os << "  DVList Info= " << *mInfo_ << endl; | 
|---|
| 671 | // | 
|---|
| 672 | os << " nSide_ = " << nSide_  << endl; | 
|---|
| 673 | os << " nPix_   = " << nPix_   << endl; | 
|---|
| 674 | os << " omeg_ = " << omeg_   << endl; | 
|---|
| 675 |  | 
|---|
| 676 | os << " content of pixels : "; | 
|---|
| 677 | for(int i=0; i < nPix_; i++) | 
|---|
| 678 | { | 
|---|
| 679 | if(i%5 == 0) os << endl; | 
|---|
| 680 | os <<  pixels_(i) <<", "; | 
|---|
| 681 | } | 
|---|
| 682 | os << endl; | 
|---|
| 683 |  | 
|---|
| 684 |  | 
|---|
| 685 | } | 
|---|
| 686 |  | 
|---|
| 687 |  | 
|---|
| 688 |  | 
|---|
| 689 | //******************************************************************* | 
|---|
| 690 |  | 
|---|
| 691 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
| 692 | #pragma define_template SphereHEALPix<uint_2> | 
|---|
| 693 | #pragma define_template SphereHEALPix<int_4> | 
|---|
| 694 | #pragma define_template SphereHEALPix<r_8> | 
|---|
| 695 | #pragma define_template SphereHEALPix<r_4> | 
|---|
| 696 | #pragma define_template SphereHEALPix< complex<r_4> > | 
|---|
| 697 | #pragma define_template SphereHEALPix< complex<r_8> > | 
|---|
| 698 | #endif | 
|---|
| 699 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) | 
|---|
| 700 | template class SphereHEALPix<uint_2>; | 
|---|
| 701 | template class SphereHEALPix<int_4>; | 
|---|
| 702 | template class SphereHEALPix<r_8>; | 
|---|
| 703 | template class SphereHEALPix<r_4>; | 
|---|
| 704 | template class SphereHEALPix< complex<r_4> >; | 
|---|
| 705 | template class SphereHEALPix< complex<r_8> >; | 
|---|
| 706 | #endif | 
|---|
| 707 |  | 
|---|