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