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