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