[228] | 1 | #include "spheregorski.h"
|
---|
| 2 | #include "strutil.h"
|
---|
[470] | 3 | #include <complex>
|
---|
| 4 | #include "piocmplx.h"
|
---|
| 5 |
|
---|
| 6 | extern "C"
|
---|
| 7 | {
|
---|
[228] | 8 | #include <stdio.h>
|
---|
| 9 | #include <stdlib.h>
|
---|
| 10 | #include <unistd.h>
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 |
|
---|
[470] | 14 | //*******************************************************************
|
---|
| 15 | // Class PIXELS_XY
|
---|
[473] | 16 | // Construction des tableaux necessaires a la traduction des indices RING en
|
---|
| 17 | // indices NESTED (ou l'inverse)
|
---|
[470] | 18 | //*******************************************************************
|
---|
| 19 |
|
---|
| 20 | PIXELS_XY::PIXELS_XY()
|
---|
| 21 | {
|
---|
| 22 | pix2x_.ReSize(1024);
|
---|
| 23 | pix2x_.Reset();
|
---|
| 24 | pix2y_.ReSize(1024);
|
---|
| 25 | pix2y_.Reset();
|
---|
| 26 | x2pix_.ReSize(128);
|
---|
| 27 | x2pix_.Reset();
|
---|
| 28 | y2pix_.ReSize(128);
|
---|
| 29 | y2pix_.Reset();
|
---|
| 30 | mk_pix2xy();
|
---|
| 31 | mk_xy2pix();
|
---|
[228] | 32 | }
|
---|
[470] | 33 |
|
---|
| 34 | PIXELS_XY& PIXELS_XY::instance()
|
---|
| 35 | {
|
---|
| 36 | static PIXELS_XY single;
|
---|
| 37 | return (single);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | void PIXELS_XY::mk_pix2xy()
|
---|
| 41 | {
|
---|
| 42 | /*
|
---|
| 43 | ==================================================
|
---|
| 44 | subroutine mk_pix2xy
|
---|
| 45 | ==================================================
|
---|
| 46 | c constructs the array giving x and y in the face from pixel number
|
---|
| 47 | c for the nested (quad-cube like) ordering of pixels
|
---|
| 48 | c
|
---|
| 49 | c the bits corresponding to x and y are interleaved in the pixel number
|
---|
| 50 | c one breaks up the pixel number by even and odd bits
|
---|
| 51 | ==================================================
|
---|
[473] | 52 | */
|
---|
[470] | 53 | // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
|
---|
| 54 | // (16/12/98)
|
---|
| 55 |
|
---|
| 56 | int kpix, jpix, IX, IY, IP, ID;
|
---|
| 57 |
|
---|
| 58 | for(kpix = 0; kpix < 1024; kpix++)
|
---|
| 59 | {
|
---|
| 60 | jpix = kpix;
|
---|
| 61 | IX = 0;
|
---|
| 62 | IY = 0;
|
---|
| 63 | IP = 1 ;// ! bit position (in x and y)
|
---|
| 64 | while( jpix!=0 )
|
---|
| 65 | { // ! go through all the bits
|
---|
| 66 | ID=jpix%2;// ! bit value (in kpix), goes in ix
|
---|
| 67 | jpix = jpix/2;
|
---|
| 68 | IX = ID*IP+IX;
|
---|
| 69 |
|
---|
| 70 | ID=jpix%2;// ! bit value (in kpix), goes in iy
|
---|
| 71 | jpix = jpix/2;
|
---|
| 72 | IY = ID*IP+IY;
|
---|
| 73 |
|
---|
| 74 | IP = 2*IP;// ! next bit (in x and y)
|
---|
| 75 | }
|
---|
| 76 | pix2x_(kpix) = IX;// ! in 0,31
|
---|
| 77 | pix2y_(kpix) = IY;// ! in 0,31
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | void PIXELS_XY::mk_xy2pix()
|
---|
| 82 | {
|
---|
| 83 | /*
|
---|
| 84 | =================================================
|
---|
| 85 | subroutine mk_xy2pix
|
---|
| 86 | =================================================
|
---|
| 87 | c sets the array giving the number of the pixel lying in (x,y)
|
---|
| 88 | c x and y are in {1,128}
|
---|
| 89 | c the pixel number is in {0,128**2-1}
|
---|
| 90 | c
|
---|
| 91 | c if i-1 = sum_p=0 b_p * 2^p
|
---|
| 92 | c then ix = sum_p=0 b_p * 4^p
|
---|
| 93 | c iy = 2*ix
|
---|
| 94 | c ix + iy in {0, 128**2 -1}
|
---|
| 95 | =================================================
|
---|
[473] | 96 | */
|
---|
[470] | 97 | // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
|
---|
| 98 | // (16/12/98)
|
---|
| 99 |
|
---|
| 100 | int K,IP,I,J,ID;
|
---|
| 101 | for(I = 1; I <= 128; I++)
|
---|
| 102 | {
|
---|
| 103 | J = I-1;// !pixel numbers
|
---|
| 104 | K = 0;//
|
---|
| 105 | IP = 1;//
|
---|
| 106 | truc : if( J==0 )
|
---|
| 107 | {
|
---|
| 108 | x2pix_(I-1) = K;
|
---|
| 109 | y2pix_(I-1) = 2*K;
|
---|
| 110 | }
|
---|
| 111 | else
|
---|
| 112 | {
|
---|
| 113 | ID = (int)fmod(J,2);
|
---|
| 114 | J = J/2;
|
---|
| 115 | K = IP*ID+K;
|
---|
| 116 | IP = IP*4;
|
---|
| 117 | goto truc;
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[228] | 122 | //*******************************************************************
|
---|
| 123 | //++
|
---|
| 124 | // Class SphereGorski
|
---|
| 125 | //
|
---|
| 126 | // include spheregorski.h strutil.h
|
---|
| 127 | //
|
---|
| 128 | // Pixelisation Gorski
|
---|
| 129 | //
|
---|
| 130 | //
|
---|
| 131 | //| -----------------------------------------------------------------------
|
---|
| 132 | //| version 0.8.2 Aug97 TAC Eric Hivon, Kris Gorski
|
---|
| 133 | //| -----------------------------------------------------------------------
|
---|
| 134 | //
|
---|
| 135 | // the sphere is split in 12 diamond-faces containing nside**2 pixels each
|
---|
| 136 | //
|
---|
| 137 | // the numbering of the pixels (in the nested scheme) is similar to
|
---|
| 138 | // quad-cube
|
---|
| 139 | // In each face the first pixel is in the lowest corner of the diamond
|
---|
| 140 | //
|
---|
| 141 | // the faces are (x,y) coordinate on each face
|
---|
| 142 | //| . . . . <--- North Pole
|
---|
| 143 | //| / \ / \ / \ / \ ^ ^
|
---|
| 144 | //| . 0 . 1 . 2 . 3 . <--- z = 2/3 \ /
|
---|
| 145 | //| \ / \ / \ / \ / y \ / x
|
---|
| 146 | //| 4 . 5 . 6 . 7 . 4 <--- equator \ /
|
---|
| 147 | //| / \ / \ / \ / \ \/
|
---|
| 148 | //| . 8 . 9 .10 .11 . <--- z = -2/3 (0,0) : lowest corner
|
---|
| 149 | //| \ / \ / \ / \ /
|
---|
| 150 | //| . . . . <--- South Pole
|
---|
| 151 | //|
|
---|
| 152 | // phi:0 2Pi
|
---|
| 153 | //
|
---|
| 154 | // in the ring scheme pixels are numbered along the parallels
|
---|
| 155 | // the first parallel is the one closest to the north pole and so on
|
---|
| 156 | // on each parallel, pixels are numbered starting from the one closest
|
---|
| 157 | // to phi = 0
|
---|
| 158 | //
|
---|
| 159 | // nside DOIT OBLIGATOIREMENT ETRE UNE PUISSANCE DE 2 (<= 8192)
|
---|
| 160 | //--
|
---|
| 161 | //++
|
---|
| 162 | //
|
---|
| 163 | // Links Parents
|
---|
| 164 | //
|
---|
| 165 | // SphericalMap
|
---|
| 166 | //--
|
---|
| 167 | //++
|
---|
| 168 | //
|
---|
| 169 | // Links Descendants
|
---|
| 170 | //
|
---|
| 171 | //
|
---|
| 172 | //--
|
---|
| 173 |
|
---|
| 174 | /* --Methode-- */
|
---|
| 175 | //++
|
---|
| 176 | // Titre Constructeurs
|
---|
| 177 | //--
|
---|
| 178 | //++
|
---|
| 179 |
|
---|
[470] | 180 | template<class T>
|
---|
| 181 | SphereGorski<T>::SphereGorski()
|
---|
[228] | 182 |
|
---|
| 183 | //--
|
---|
| 184 | {
|
---|
| 185 | InitNul();
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | //++
|
---|
[470] | 189 | template<class T>
|
---|
[473] | 190 | SphereGorski<T>::SphereGorski(int m)
|
---|
[228] | 191 |
|
---|
| 192 | // Constructeur : m est la variable nside de l'algorithme de Gorski
|
---|
| 193 | // le nombre total de pixels sera Npix = 12*nside**2
|
---|
| 194 | // m DOIT OBLIGATOIREMENT ETRE UNE PUISSANCE DE 2 (<= 8192)
|
---|
| 195 | //--
|
---|
| 196 | {
|
---|
[470] | 197 |
|
---|
| 198 | if(m <= 0 || m > 8192)
|
---|
| 199 | {
|
---|
| 200 | cout << "SphereGorski : m hors bornes [0,8192], m= " << m << endl;
|
---|
| 201 | exit(1);
|
---|
| 202 | }
|
---|
| 203 | // verifier que m est une puissance de deux
|
---|
[473] | 204 | int x= m;
|
---|
[470] | 205 | while(x%2 == 0) x/=2;
|
---|
| 206 | if(x != 1)
|
---|
| 207 | {
|
---|
| 208 | cout<<"SphereGorski: m doit etre une puissance de deux, m= "<<m<<endl;
|
---|
| 209 | exit(1);
|
---|
| 210 | }
|
---|
[228] | 211 | InitNul();
|
---|
| 212 | Pixelize(m);
|
---|
| 213 | }
|
---|
| 214 |
|
---|
[470] | 215 | template<class T>
|
---|
| 216 | SphereGorski<T>::SphereGorski(const SphereGorski<T>& s)
|
---|
| 217 | {
|
---|
| 218 | cout << " constructeur de recopie " << endl;
|
---|
| 219 | if(s.mInfo_) mInfo_= new DVList(*s.mInfo_);
|
---|
[228] | 220 |
|
---|
[470] | 221 | nSide_= s.nSide_;
|
---|
| 222 | nPix_ = s.nPix_;
|
---|
| 223 | omeg_ = s.omeg_;
|
---|
[228] | 224 |
|
---|
[470] | 225 | pixels_= s.pixels_;
|
---|
[228] | 226 |
|
---|
[470] | 227 | }
|
---|
[228] | 228 |
|
---|
| 229 | //++
|
---|
| 230 | // Titre Destructeur
|
---|
| 231 | //--
|
---|
| 232 | //++
|
---|
[470] | 233 | template<class T>
|
---|
| 234 | SphereGorski<T>::~SphereGorski()
|
---|
[228] | 235 |
|
---|
| 236 | //--
|
---|
| 237 | {
|
---|
[470] | 238 | InitNul();
|
---|
[228] | 239 | }
|
---|
| 240 |
|
---|
| 241 | //++
|
---|
| 242 | // Titre Méthodes
|
---|
| 243 | //--
|
---|
| 244 |
|
---|
[470] | 245 | //++
|
---|
| 246 | template<class T>
|
---|
[473] | 247 | void SphereGorski<T>::Resize(int m)
|
---|
[228] | 248 |
|
---|
[470] | 249 | // m est la variable nside de l'algorithme de Gorski
|
---|
| 250 | // le nombre total de pixels sera Npix = 12*nside**2
|
---|
| 251 | // m DOIT OBLIGATOIREMENT ETRE UNE PUISSANCE DE 2 (<= 8192)
|
---|
| 252 | //--
|
---|
| 253 | {
|
---|
| 254 | if (m<=0 || m> 8192) {
|
---|
| 255 | cout << "SphereGorski : m hors bornes [0,8192], m= " << m << endl;
|
---|
| 256 | exit(1);
|
---|
| 257 | }
|
---|
| 258 | // verifier que m est une puissance de deux
|
---|
[473] | 259 | int x= m;
|
---|
[470] | 260 | while (x%2==0) x/=2;
|
---|
| 261 | if(x != 1)
|
---|
| 262 | {
|
---|
| 263 | cout<<"SphereGorski: m doit etre une puissance de deux, m= "<<m<<endl;
|
---|
| 264 | exit(1);
|
---|
| 265 | }
|
---|
| 266 | InitNul();
|
---|
| 267 | Pixelize(m);
|
---|
| 268 | }
|
---|
[228] | 269 |
|
---|
[470] | 270 | template<class T>
|
---|
[473] | 271 | void SphereGorski<T>::Pixelize( int m)
|
---|
[228] | 272 |
|
---|
| 273 | // prépare la pixelisation Gorski (m a la même signification
|
---|
| 274 | // que pour le constructeur)
|
---|
| 275 | //
|
---|
| 276 | //
|
---|
| 277 | //--
|
---|
| 278 | {
|
---|
| 279 | // On memorise les arguments d'appel
|
---|
[473] | 280 | nSide_= m;
|
---|
[470] | 281 |
|
---|
[228] | 282 | // Nombre total de pixels sur la sphere entiere
|
---|
[473] | 283 | nPix_= 12*nSide_*nSide_;
|
---|
[228] | 284 |
|
---|
[470] | 285 | // pour le moment les tableaux qui suivent seront ranges dans l'ordre
|
---|
| 286 | // de l'indexation GORSKY "RING"
|
---|
| 287 | // on pourra ulterieurement changer de strategie et tirer profit
|
---|
| 288 | // de la dualite d'indexation GORSKY (RING et NEST) : tout dependra
|
---|
| 289 | // de pourquoi c'est faire
|
---|
[228] | 290 |
|
---|
| 291 | // Creation et initialisation du vecteur des contenus des pixels
|
---|
[470] | 292 | pixels_.ReSize(nPix_);
|
---|
| 293 | pixels_.Reset();
|
---|
[228] | 294 |
|
---|
| 295 | // solid angle per pixel
|
---|
[473] | 296 | omeg_= 4.0*Pi/nPix_;
|
---|
[228] | 297 | }
|
---|
| 298 |
|
---|
[470] | 299 | template<class T>
|
---|
| 300 | void SphereGorski<T>::InitNul()
|
---|
[228] | 301 | //
|
---|
| 302 | // initialise à zéro les variables de classe
|
---|
| 303 | {
|
---|
[470] | 304 | nSide_= 0;
|
---|
| 305 | nPix_ = 0;
|
---|
| 306 | omeg_ = 0.;
|
---|
| 307 | pixels_.Reset();
|
---|
[228] | 308 |
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | /* --Methode-- */
|
---|
| 312 | //++
|
---|
[470] | 313 | template<class T>
|
---|
[473] | 314 | int SphereGorski<T>::NbPixels() const
|
---|
[228] | 315 |
|
---|
| 316 | // Retourne le nombre de pixels du découpage
|
---|
| 317 | //--
|
---|
[470] | 318 | {
|
---|
[228] | 319 | return(nPix_);
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | //++
|
---|
[470] | 323 | template<class T>
|
---|
[473] | 324 | int SphereGorski<T>::NbThetaSlices() const
|
---|
[228] | 325 |
|
---|
| 326 | // Retourne le nombre de tranches en theta sur la sphere
|
---|
| 327 | //--
|
---|
[470] | 328 | {
|
---|
[473] | 329 | return int(4*nSide_-1);
|
---|
[470] | 330 | }
|
---|
[228] | 331 |
|
---|
| 332 | //++
|
---|
[470] | 333 | template<class T>
|
---|
[473] | 334 | void SphereGorski<T>::GetThetaSlice(int index,double& theta,TVector<double>& phi,TVector<T>& value) const
|
---|
[228] | 335 |
|
---|
| 336 | // Retourne, pour la tranche en theta d'indice 'index' le theta
|
---|
| 337 | // correspondant, un vecteur (Peida) contenant les phi des pixels de
|
---|
| 338 | // la tranche, un vecteur (Peida) contenant les valeurs de pixel
|
---|
| 339 | // correspondantes
|
---|
| 340 | //--
|
---|
| 341 | {
|
---|
[470] | 342 | cout << "entree GetThetaSlice, couche no " << index << endl;
|
---|
[228] | 343 |
|
---|
[470] | 344 | if (index<0 || index > NbThetaSlices())
|
---|
| 345 | {
|
---|
| 346 | // THROW(out_of_range("SphereGorski::PIxVal Pixel index out of range"));
|
---|
| 347 | cout << " SphereGorski::GetThetaSlice : exceptions a mettre en place" <<endl;
|
---|
| 348 | THROW(rangeCheckErr);
|
---|
| 349 | }
|
---|
[228] | 350 |
|
---|
[473] | 351 | int iring= 0;
|
---|
[470] | 352 | int lring = 0;
|
---|
| 353 | if(index < nSide_-1)
|
---|
| 354 | {
|
---|
| 355 | iring= 2*index*(index+1);
|
---|
| 356 | lring= 4*(index+1);
|
---|
| 357 | }
|
---|
| 358 | else if(index < 3*nSide_)
|
---|
| 359 | {
|
---|
| 360 | iring= 2*nSide_*(2*index-nSide_+1);
|
---|
| 361 | lring= 4*nSide_;
|
---|
| 362 | }
|
---|
| 363 | else
|
---|
| 364 | {
|
---|
| 365 | int nc= 4*nSide_-1-index;
|
---|
| 366 | iring = nPix_-2*nc*(nc+1);
|
---|
| 367 | lring = 4*nc;
|
---|
| 368 | }
|
---|
| 369 |
|
---|
| 370 | phi.ReSize(lring);
|
---|
| 371 | value.ReSize(lring);
|
---|
[473] | 372 | double TH= 0.;
|
---|
| 373 | double FI= 0.;
|
---|
[470] | 374 | for(int kk = 0; kk < lring;kk++)
|
---|
| 375 | {
|
---|
[473] | 376 | PixThetaPhi(kk+iring,TH,FI);
|
---|
| 377 | phi(kk)= FI;
|
---|
[470] | 378 | value(kk)= PixVal(kk+iring);
|
---|
| 379 | }
|
---|
| 380 | theta= TH;
|
---|
[228] | 381 | }
|
---|
| 382 |
|
---|
| 383 | /* --Methode-- */
|
---|
| 384 | //++
|
---|
[470] | 385 | template<class T>
|
---|
[473] | 386 | T& SphereGorski<T>::PixVal(int k)
|
---|
[228] | 387 |
|
---|
| 388 | // Retourne la valeur du contenu du pixel d'indice "RING" k
|
---|
| 389 | //--
|
---|
| 390 | {
|
---|
[470] | 391 | if((k < 0) || (k >= nPix_))
|
---|
| 392 | {
|
---|
| 393 | // THROW(out_of_range("SphereGorski::PIxVal Pixel index out of range"));
|
---|
| 394 | cout << " SphereGorski::PIxVal : exceptions a mettre en place" <<endl;
|
---|
| 395 | THROW(rangeCheckErr);
|
---|
| 396 | }
|
---|
| 397 | return pixels_(k);
|
---|
[228] | 398 | }
|
---|
| 399 |
|
---|
| 400 | /* --Methode-- */
|
---|
| 401 | //++
|
---|
[470] | 402 | template<class T>
|
---|
[473] | 403 | T const& SphereGorski<T>::PixVal(int k) const
|
---|
[228] | 404 |
|
---|
| 405 | // Retourne la valeur du contenu du pixel d'indice "RING" k
|
---|
| 406 | //--
|
---|
| 407 | {
|
---|
[470] | 408 | if((k < 0) || (k >= nPix_))
|
---|
| 409 | {
|
---|
| 410 | //THROW(out_of_range("SphereGorski::PIxVal Pixel index out of range"));
|
---|
| 411 | cout << " SphereGorski::PIxVal : exceptions a mettre en place" <<endl;
|
---|
| 412 | THROW(rangeCheckErr);
|
---|
| 413 | }
|
---|
| 414 | return *(pixels_.Data()+k);
|
---|
[228] | 415 | }
|
---|
| 416 |
|
---|
| 417 | //++
|
---|
[470] | 418 | template<class T>
|
---|
[473] | 419 | T& SphereGorski<T>::PixValNest(int k)
|
---|
[228] | 420 |
|
---|
| 421 | // Retourne la valeur du contenu du pixel d'indice "NESTED" k
|
---|
| 422 | //--
|
---|
| 423 | {
|
---|
[470] | 424 | if((k < 0) || (k >= nPix_))
|
---|
| 425 | {
|
---|
| 426 | //THROW(out_of_range("SphereGorski::PIxValNest Pixel index out of range"));
|
---|
| 427 | cout<<" SphereGorski::PIxValNest : exceptions a mettre en place" <<endl;
|
---|
| 428 | THROW(rangeCheckErr);
|
---|
| 429 | }
|
---|
| 430 | return pixels_(nest2ring(nSide_,k));
|
---|
[228] | 431 | }
|
---|
| 432 | //++
|
---|
| 433 |
|
---|
[470] | 434 | template<class T>
|
---|
[473] | 435 | T const& SphereGorski<T>::PixValNest(int k) const
|
---|
[228] | 436 |
|
---|
| 437 | // Retourne la valeur du contenu du pixel d'indice "NESTED" k
|
---|
| 438 | //--
|
---|
| 439 | {
|
---|
[470] | 440 | if((k < 0) || (k >= nPix_))
|
---|
| 441 | {
|
---|
| 442 | //THROW(out_of_range("SphereGorski::PIxValNest Pixel index out of range"));
|
---|
| 443 | cout<<" SphereGorski::PIxValNest : exceptions a mettre en place" <<endl;
|
---|
| 444 | THROW(rangeCheckErr);
|
---|
[228] | 445 | }
|
---|
[473] | 446 | int pix= nest2ring(nSide_,k);
|
---|
[470] | 447 | return *(pixels_.Data()+pix);
|
---|
[228] | 448 | }
|
---|
| 449 |
|
---|
| 450 | /* --Methode-- */
|
---|
| 451 | //++
|
---|
[470] | 452 | template<class T>
|
---|
[473] | 453 | int SphereGorski<T>::PixIndexSph(double theta,double phi) const
|
---|
[228] | 454 |
|
---|
| 455 | // Retourne l'indice "RING" du pixel vers lequel pointe une direction
|
---|
| 456 | // définie par ses coordonnées sphériques
|
---|
| 457 | //--
|
---|
| 458 | {
|
---|
[473] | 459 | return ang2pix_ring(nSide_,theta,phi);
|
---|
[228] | 460 | }
|
---|
| 461 |
|
---|
| 462 | //++
|
---|
[470] | 463 | template<class T>
|
---|
[473] | 464 | int SphereGorski<T>::PixIndexSphNest(double theta,double phi) const
|
---|
[228] | 465 |
|
---|
| 466 | // Retourne l'indice NESTED" du pixel vers lequel pointe une direction
|
---|
| 467 | // définie par ses coordonnées sphériques
|
---|
| 468 | //--
|
---|
| 469 | {
|
---|
[473] | 470 | return ang2pix_nest(nSide_,theta,phi);
|
---|
[228] | 471 | }
|
---|
| 472 |
|
---|
| 473 |
|
---|
| 474 | /* --Methode-- */
|
---|
| 475 | //++
|
---|
[470] | 476 | template<class T>
|
---|
[473] | 477 | void SphereGorski<T>::PixThetaPhi(int k,double& theta,double& phi) const
|
---|
[228] | 478 |
|
---|
[473] | 479 | // Retourne les coordonnées (theta,phi) du milieu du pixel d'indice "RING" k
|
---|
[228] | 480 | //--
|
---|
| 481 | {
|
---|
[473] | 482 | pix2ang_ring(nSide_,k,theta,phi);
|
---|
[228] | 483 | }
|
---|
| 484 |
|
---|
| 485 | //++
|
---|
[470] | 486 | template<class T>
|
---|
[473] | 487 | double SphereGorski<T>::PixSolAngle(int dummy) const
|
---|
[228] | 488 | // Pixel Solid angle (steradians)
|
---|
| 489 | // All the pixels have the same solid angle. The dummy argument is
|
---|
| 490 | // for compatibility with eventual pixelizations which would not
|
---|
| 491 | // fulfil this requirement.
|
---|
| 492 | //--
|
---|
| 493 | {
|
---|
| 494 | return omeg_;
|
---|
| 495 | }
|
---|
| 496 |
|
---|
| 497 | //++
|
---|
[470] | 498 | template<class T>
|
---|
[473] | 499 | void SphereGorski<T>::PixThetaPhiNest(int k,double& theta,double& phi) const
|
---|
[228] | 500 |
|
---|
[473] | 501 | // Retourne les coordonnées (theta,phi) du milieu du pixel d'indice
|
---|
[228] | 502 | // NESTED k
|
---|
| 503 | //--
|
---|
| 504 | {
|
---|
[473] | 505 | pix2ang_nest(nSide_,k,theta,phi);
|
---|
[228] | 506 | }
|
---|
| 507 |
|
---|
| 508 | //++
|
---|
[470] | 509 | template<class T>
|
---|
[473] | 510 | int SphereGorski<T>::NestToRing(int k) const
|
---|
[228] | 511 |
|
---|
| 512 | // conversion d'index NESTD en un index RING
|
---|
| 513 | //
|
---|
| 514 | //--
|
---|
| 515 | {
|
---|
| 516 | return nest2ring(nSide_,k);
|
---|
| 517 | }
|
---|
[470] | 518 |
|
---|
[228] | 519 | //++
|
---|
[470] | 520 | template<class T>
|
---|
[473] | 521 | int SphereGorski<T>::RingToNest(int k) const
|
---|
[228] | 522 | //
|
---|
| 523 | // conversion d'index RING en un index NESTED
|
---|
| 524 | //
|
---|
| 525 | //--
|
---|
| 526 | {
|
---|
| 527 | return ring2nest(nSide_,k);
|
---|
| 528 | }
|
---|
[470] | 529 |
|
---|
[228] | 530 |
|
---|
[470] | 531 | template<class T>
|
---|
[473] | 532 | int SphereGorski<T>::nest2ring(int nside, int ipnest) const
|
---|
| 533 | {
|
---|
[228] | 534 | /*
|
---|
[470] | 535 | ====================================================
|
---|
[228] | 536 | subroutine nest2ring(nside, ipnest, ipring)
|
---|
[470] | 537 | ====================================================
|
---|
[228] | 538 | c conversion from NESTED to RING pixel number
|
---|
[470] | 539 | ====================================================
|
---|
[473] | 540 | */
|
---|
[228] | 541 | // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
|
---|
| 542 | // (16/12/98)
|
---|
[470] | 543 |
|
---|
| 544 | const PIXELS_XY& PXY= PIXELS_XY::instance();
|
---|
[228] | 545 |
|
---|
[470] | 546 | int npix, npface, face_num, ncap, n_before;
|
---|
| 547 | int ipf, ip_low, ip_trunc, ip_med, ip_hi;
|
---|
| 548 | int ix, iy, jrt, jr, nr, jpt, jp, kshift, nl4;
|
---|
| 549 | int ns_max=8192;
|
---|
| 550 | int jrll[12]={2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4};
|
---|
| 551 | int jpll[12]={1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7};
|
---|
| 552 |
|
---|
| 553 | if( nside<1 || nside>ns_max ) {
|
---|
| 554 | cout << "nside out of range" << endl;
|
---|
| 555 | exit(0);
|
---|
| 556 | }
|
---|
| 557 | npix = 12 * nside* nside;
|
---|
| 558 | if( ipnest<0 || ipnest>npix-1 ) {
|
---|
| 559 | cout << "ipnest out of range" << endl;
|
---|
| 560 | exit(0);
|
---|
| 561 | }
|
---|
[228] | 562 |
|
---|
[470] | 563 | ncap = 2* nside*( nside-1);// ! number of points in the North Polar cap
|
---|
| 564 | nl4 = 4* nside;
|
---|
| 565 |
|
---|
| 566 | //c finds the face, and the number in the face
|
---|
| 567 | npface = nside* nside;
|
---|
| 568 | //cccccc ip = ipnest - 1 ! in {0,npix-1}
|
---|
| 569 |
|
---|
| 570 | face_num = ipnest/npface;// ! face number in {0,11}
|
---|
| 571 | ipf =ipnest%npface;// ! pixel number in the face {0,npface-1}
|
---|
| 572 | //c finds the x,y on the face (starting from the lowest corner)
|
---|
| 573 | //c from the pixel number
|
---|
| 574 | ip_low=ipf%1024; // ! content of the last 10 bits
|
---|
| 575 | ip_trunc = ipf/1024; // ! truncation of the last 10 bits
|
---|
| 576 | ip_med=ip_trunc%1024; // ! content of the next 10 bits
|
---|
| 577 | ip_hi = ip_trunc/1024;// ! content of the high weight 10 bits
|
---|
| 578 |
|
---|
| 579 | ix = 1024*PXY.pix2x_(ip_hi)+32*PXY.pix2x_(ip_med)+PXY.pix2x_(ip_low);
|
---|
| 580 | iy = 1024*PXY.pix2y_(ip_hi)+32*PXY.pix2y_(ip_med)+PXY.pix2y_(ip_low);
|
---|
| 581 |
|
---|
| 582 | //c transforms this in (horizontal, vertical) coordinates
|
---|
| 583 | jrt = ix + iy;// ! 'vertical' in {0,2*(nside-1)}
|
---|
| 584 | jpt = ix - iy;// ! 'horizontal' in {-nside+1,nside-1}
|
---|
| 585 |
|
---|
| 586 | //c computes the z coordinate on the sphere
|
---|
| 587 | // jr = jrll[face_num+1]*nside - jrt - 1;// ! ring number in {1,4*nside-1}
|
---|
| 588 | jr = jrll[face_num]*nside - jrt - 1;
|
---|
| 589 | nr = nside;// ! equatorial region (the most frequent)
|
---|
| 590 | n_before = ncap + nl4 * (jr - nside);
|
---|
| 591 | kshift=(jr - nside)%2;
|
---|
| 592 | if( jr<nside ) {//then ! north pole region
|
---|
| 593 | nr = jr;
|
---|
| 594 | n_before = 2 * nr * (nr - 1);
|
---|
| 595 | kshift = 0;
|
---|
| 596 | }
|
---|
| 597 | else if( jr>3*nside ) {//then ! south pole region
|
---|
| 598 | nr = nl4 - jr;
|
---|
| 599 | n_before = npix - 2 * (nr + 1) * nr;
|
---|
| 600 | kshift = 0;
|
---|
| 601 | }
|
---|
| 602 |
|
---|
| 603 | //c computes the phi coordinate on the sphere, in [0,2Pi]
|
---|
| 604 | jp = (jpll[face_num]*nr + jpt + 1 + kshift)/2;// ! 'phi' number in the ring in {1,4*nr}
|
---|
| 605 |
|
---|
| 606 | if( jp>nl4 ) jp = jp - nl4;
|
---|
| 607 | if( jp<1 ) jp = jp + nl4;
|
---|
| 608 |
|
---|
| 609 | int aux=n_before + jp - 1;
|
---|
| 610 | return (n_before + jp - 1);// ! in {0, npix-1}
|
---|
[228] | 611 | }
|
---|
| 612 |
|
---|
[470] | 613 | template<class T>
|
---|
| 614 | int SphereGorski<T>::ring2nest(int nside, int ipring) const
|
---|
| 615 | {
|
---|
[228] | 616 | /*
|
---|
[470] | 617 | ==================================================
|
---|
[228] | 618 | subroutine ring2nest(nside, ipring, ipnest)
|
---|
[470] | 619 | ==================================================
|
---|
[228] | 620 | c conversion from RING to NESTED pixel number
|
---|
[470] | 621 | ==================================================
|
---|
[473] | 622 | */
|
---|
[228] | 623 | // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
|
---|
| 624 | // (16/12/98)
|
---|
| 625 |
|
---|
[470] | 626 | const PIXELS_XY& PXY= PIXELS_XY::instance();
|
---|
| 627 |
|
---|
[228] | 628 | double fihip, hip;
|
---|
| 629 | int npix, nl2, nl4, ncap, ip, iphi, ipt, ipring1;
|
---|
| 630 | int kshift, face_num, nr;
|
---|
| 631 | int irn, ire, irm, irs, irt, ifm , ifp;
|
---|
| 632 | int ix, iy, ix_low, ix_hi, iy_low, iy_hi, ipf;
|
---|
| 633 | int ns_max(8192);
|
---|
| 634 |
|
---|
| 635 | // coordinate of the lowest corner of each face
|
---|
| 636 | int jrll[12]={2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4};// ! in unit of nside
|
---|
| 637 | int jpll[12]={1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7};//! in unit of nside/2
|
---|
| 638 |
|
---|
| 639 | if( nside<1 || nside>ns_max ) {
|
---|
| 640 | cout << "nside out of range" << endl;
|
---|
| 641 | exit(0);
|
---|
| 642 | }
|
---|
| 643 | npix = 12 * nside*nside;
|
---|
| 644 | if( ipring<0 || ipring>npix-1 ) {
|
---|
| 645 | cout << "ipring out of range" << endl;
|
---|
| 646 | exit(0);
|
---|
| 647 | }
|
---|
| 648 |
|
---|
| 649 | nl2 = 2*nside;
|
---|
| 650 | nl4 = 4*nside;
|
---|
| 651 | npix = 12*nside*nside;// ! total number of points
|
---|
| 652 | ncap = 2*nside*(nside-1);// ! points in each polar cap, =0 for nside =1
|
---|
| 653 | ipring1 = ipring + 1;
|
---|
| 654 |
|
---|
| 655 | //c finds the ring number, the position of the ring and the face number
|
---|
| 656 | if( ipring1<=ncap ) {//then
|
---|
| 657 |
|
---|
| 658 | hip = ipring1/2.;
|
---|
| 659 | fihip = (int)floor ( hip );
|
---|
| 660 | irn = (int)floor( sqrt( hip - sqrt(fihip) ) ) + 1;// ! counted from North pole
|
---|
| 661 | iphi = ipring1 - 2*irn*(irn - 1);
|
---|
| 662 |
|
---|
| 663 | kshift = 0;
|
---|
| 664 | nr = irn ;// ! 1/4 of the number of points on the current ring
|
---|
| 665 | face_num = (iphi-1) / irn;// ! in {0,3}
|
---|
| 666 | }
|
---|
| 667 | else if( ipring1<=nl2*(5*nside+1) ) {//then
|
---|
| 668 |
|
---|
| 669 | ip = ipring1 - ncap - 1;
|
---|
| 670 | irn = (int)floor( ip / nl4 ) + nside;// ! counted from North pole
|
---|
| 671 | iphi = (int)fmod(ip,nl4) + 1;
|
---|
| 672 |
|
---|
| 673 | kshift = (int)fmod(irn+nside,2);// ! 1 if irn+nside is odd, 0 otherwise
|
---|
| 674 | nr = nside;
|
---|
| 675 | ire = irn - nside + 1;// ! in {1, 2*nside +1}
|
---|
| 676 | irm = nl2 + 2 - ire;
|
---|
| 677 | ifm = (iphi - ire/2 + nside -1) / nside;// ! face boundary
|
---|
| 678 | ifp = (iphi - irm/2 + nside -1) / nside;
|
---|
| 679 | if( ifp==ifm ) {//then ! faces 4 to 7
|
---|
| 680 | face_num = (int)fmod(ifp,4) + 4;
|
---|
| 681 | }
|
---|
| 682 | else if( ifp + 1==ifm ) {//then ! (half-)faces 0 to 3
|
---|
| 683 | face_num = ifp;
|
---|
| 684 | }
|
---|
| 685 | else if( ifp - 1==ifm ) {//then ! (half-)faces 8 to 11
|
---|
| 686 | face_num = ifp + 7;
|
---|
| 687 | }
|
---|
| 688 | }
|
---|
| 689 | else {
|
---|
| 690 |
|
---|
| 691 | ip = npix - ipring1 + 1;
|
---|
| 692 | hip = ip/2.;
|
---|
| 693 | fihip = floor ( hip );
|
---|
| 694 | irs = (int)floor( sqrt( hip - sqrt(fihip) ) ) + 1;// ! counted from South pole
|
---|
| 695 | iphi = 4*irs + 1 - (ip - 2*irs*(irs-1));
|
---|
| 696 |
|
---|
| 697 | kshift = 0;
|
---|
| 698 | nr = irs;
|
---|
| 699 | irn = nl4 - irs;
|
---|
| 700 | face_num = (iphi-1) / irs + 8;// ! in {8,11}
|
---|
| 701 | }
|
---|
| 702 |
|
---|
| 703 | //c finds the (x,y) on the face
|
---|
| 704 | irt = irn - jrll[face_num]*nside + 1;// ! in {-nside+1,0}
|
---|
| 705 | ipt = 2*iphi - jpll[face_num]*nr - kshift - 1;// ! in {-nside+1,nside-1}
|
---|
| 706 |
|
---|
| 707 |
|
---|
| 708 | if( ipt>=nl2 ) ipt = ipt - 8*nside;// ! for the face #4
|
---|
| 709 |
|
---|
| 710 | ix = (ipt - irt ) / 2;
|
---|
| 711 | iy = -(ipt + irt ) / 2;
|
---|
| 712 |
|
---|
| 713 | ix_low = (int)fmod(ix,128);
|
---|
| 714 | ix_hi = ix/128;
|
---|
| 715 | iy_low = (int)fmod(iy,128);
|
---|
| 716 | iy_hi = iy/128;
|
---|
[470] | 717 | ipf=(PXY.x2pix_(ix_hi)+PXY.y2pix_(iy_hi))*(128*128)+(PXY.x2pix_(ix_low)+PXY.y2pix_(iy_low));
|
---|
[228] | 718 |
|
---|
| 719 | return (ipf + face_num* nside *nside);// ! in {0, 12*nside**2 - 1}
|
---|
| 720 | }
|
---|
| 721 |
|
---|
[470] | 722 | template<class T>
|
---|
| 723 | int SphereGorski<T>::ang2pix_ring(int nside, double theta, double phi) const
|
---|
| 724 | {
|
---|
[228] | 725 | /*
|
---|
[470] | 726 | ==================================================
|
---|
[228] | 727 | c gives the pixel number ipix (RING)
|
---|
| 728 | c corresponding to angles theta and phi
|
---|
[470] | 729 | c==================================================
|
---|
[473] | 730 | */
|
---|
[228] | 731 | // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
|
---|
| 732 | // (16/12/98)
|
---|
| 733 |
|
---|
| 734 | int nl2, nl4, ncap, npix, jp, jm, ipix1;
|
---|
| 735 | double z, za, tt, tp, tmp;
|
---|
| 736 | int ir, ip, kshift;
|
---|
| 737 |
|
---|
| 738 | double piover2(Pi/2.);
|
---|
| 739 | double twopi(2.*Pi);
|
---|
| 740 | double z0(2./3.);
|
---|
| 741 | int ns_max(8192);
|
---|
| 742 |
|
---|
| 743 | if( nside<1 || nside>ns_max ) {
|
---|
| 744 | cout << "nside out of range" << endl;
|
---|
| 745 | exit(0);
|
---|
| 746 | }
|
---|
| 747 |
|
---|
| 748 | if( theta<0. || theta>Pi) {
|
---|
| 749 | cout << "theta out of range" << endl;
|
---|
| 750 | exit(0);
|
---|
| 751 | }
|
---|
| 752 |
|
---|
| 753 | z = cos(theta);
|
---|
| 754 | za = fabs(z);
|
---|
| 755 | if( phi >= twopi) phi = phi - twopi;
|
---|
| 756 | if (phi < 0.) phi = phi + twopi;
|
---|
| 757 | tt = phi / piover2;// ! in [0,4)
|
---|
| 758 |
|
---|
| 759 | nl2 = 2*nside;
|
---|
| 760 | nl4 = 4*nside;
|
---|
| 761 | ncap = nl2*(nside-1);// ! number of pixels in the north polar cap
|
---|
| 762 | npix = 12*nside*nside;
|
---|
| 763 |
|
---|
| 764 | if( za <= z0 ) {
|
---|
| 765 |
|
---|
| 766 | jp = (int)floor(nside*(0.5 + tt - z*0.75));// ! index of ascending edge line
|
---|
| 767 | jm = (int)floor(nside*(0.5 + tt + z*0.75));// ! index of descending edge line
|
---|
| 768 |
|
---|
| 769 | ir = nside + 1 + jp - jm;// ! in {1,2n+1} (ring number counted from z=2/3)
|
---|
| 770 | kshift = 0;
|
---|
| 771 | if (fmod(ir,2)==0.) kshift = 1;// ! kshift=1 if ir even, 0 otherwise
|
---|
| 772 |
|
---|
| 773 | ip = (int)floor( ( jp+jm - nside + kshift + 1 ) / 2 ) + 1;// ! in {1,4n}
|
---|
| 774 | if( ip>nl4 ) ip = ip - nl4;
|
---|
| 775 |
|
---|
| 776 | ipix1 = ncap + nl4*(ir-1) + ip ;
|
---|
| 777 | }
|
---|
| 778 | else {
|
---|
| 779 |
|
---|
| 780 | tp = tt - floor(tt);// !MOD(tt,1.d0)
|
---|
| 781 | tmp = sqrt( 3.*(1. - za) );
|
---|
| 782 |
|
---|
| 783 | jp = (int)floor( nside * tp * tmp );// ! increasing edge line index
|
---|
| 784 | jm = (int)floor( nside * (1. - tp) * tmp );// ! decreasing edge line index
|
---|
| 785 |
|
---|
| 786 | ir = jp + jm + 1;// ! ring number counted from the closest pole
|
---|
| 787 | ip = (int)floor( tt * ir ) + 1;// ! in {1,4*ir}
|
---|
| 788 | if( ip>4*ir ) ip = ip - 4*ir;
|
---|
| 789 |
|
---|
| 790 | ipix1 = 2*ir*(ir-1) + ip;
|
---|
| 791 | if( z<=0. ) {
|
---|
| 792 | ipix1 = npix - 2*ir*(ir+1) + ip;
|
---|
| 793 | }
|
---|
| 794 | }
|
---|
| 795 | return (ipix1 - 1);// ! in {0, npix-1}
|
---|
| 796 | }
|
---|
| 797 |
|
---|
[470] | 798 | template<class T>
|
---|
| 799 | int SphereGorski<T>::ang2pix_nest(int nside, double theta, double phi) const
|
---|
| 800 | {
|
---|
[228] | 801 | /*
|
---|
[470] | 802 | ==================================================
|
---|
[228] | 803 | subroutine ang2pix_nest(nside, theta, phi, ipix)
|
---|
[470] | 804 | ==================================================
|
---|
[228] | 805 | c gives the pixel number ipix (NESTED)
|
---|
| 806 | c corresponding to angles theta and phi
|
---|
| 807 | c
|
---|
| 808 | c the computation is made to the highest resolution available (nside=8192)
|
---|
| 809 | c and then degraded to that required (by integer division)
|
---|
| 810 | c this doesn't cost more, and it makes sure
|
---|
| 811 | c that the treatement of round-off will be consistent
|
---|
| 812 | c for every resolution
|
---|
[470] | 813 | ==================================================
|
---|
[473] | 814 | */
|
---|
[228] | 815 | // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
|
---|
| 816 | // (16/12/98)
|
---|
[470] | 817 |
|
---|
| 818 | const PIXELS_XY& PXY= PIXELS_XY::instance();
|
---|
| 819 |
|
---|
| 820 | double z, za, z0, tt, tp, tmp;
|
---|
| 821 | int face_num,jp,jm;
|
---|
| 822 | int ifp, ifm;
|
---|
| 823 | int ix, iy, ix_low, ix_hi, iy_low, iy_hi, ipf, ntt;
|
---|
| 824 | double piover2(Pi/2.), twopi(2.*Pi);
|
---|
| 825 | int ns_max(8192);
|
---|
| 826 |
|
---|
| 827 | if( nside<1 || nside>ns_max ) {
|
---|
| 828 | cout << "nside out of range" << endl;
|
---|
| 829 | exit(0);
|
---|
| 830 | }
|
---|
| 831 | if( theta<0 || theta>Pi ) {
|
---|
| 832 | cout << "theta out of range" << endl;
|
---|
| 833 | exit(0);
|
---|
| 834 | }
|
---|
| 835 | z = cos(theta);
|
---|
| 836 | za = fabs(z);
|
---|
| 837 | z0 = 2./3.;
|
---|
| 838 | if( phi>=twopi ) phi = phi - twopi;
|
---|
| 839 | if( phi<0. ) phi = phi + twopi;
|
---|
| 840 | tt = phi / piover2;// ! in [0,4[
|
---|
| 841 | if( za<=z0 ) { // then ! equatorial region
|
---|
[228] | 842 |
|
---|
[470] | 843 | //(the index of edge lines increase when the longitude=phi goes up)
|
---|
| 844 | jp = (int)floor(ns_max*(0.5 + tt - z*0.75));// ! ascending edge line index
|
---|
| 845 | jm = (int)floor(ns_max*(0.5 + tt + z*0.75));// ! descending edge line index
|
---|
| 846 |
|
---|
| 847 | //c finds the face
|
---|
| 848 | ifp = jp / ns_max;// ! in {0,4}
|
---|
| 849 | ifm = jm / ns_max;
|
---|
[473] | 850 | if( ifp==ifm ) face_num = (int)fmod(ifp,4) + 4; //then ! faces 4 to 7
|
---|
[470] | 851 | else if( ifp<ifm ) face_num = (int)fmod(ifp,4); // (half-)faces 0 to 3
|
---|
| 852 | else face_num = (int)fmod(ifm,4) + 8;//! (half-)faces 8 to 11
|
---|
| 853 |
|
---|
| 854 | ix = (int)fmod(jm, ns_max);
|
---|
| 855 | iy = ns_max - (int)fmod(jp, ns_max) - 1;
|
---|
| 856 | }
|
---|
| 857 | else { //! polar region, za > 2/3
|
---|
| 858 |
|
---|
| 859 | ntt = (int)floor(tt);
|
---|
| 860 | if( ntt>=4 ) ntt = 3;
|
---|
| 861 | tp = tt - ntt;
|
---|
| 862 | tmp = sqrt( 3.*(1. - za) );// ! in ]0,1]
|
---|
| 863 |
|
---|
| 864 | //(the index of edge lines increase when distance from the closest pole goes up)
|
---|
| 865 | jp = (int)floor(ns_max*tp*tmp); // ! line going toward the pole as phi increases
|
---|
| 866 | jm = (int)floor(ns_max*(1.-tp)*tmp); // ! that one goes away of the closest pole
|
---|
| 867 | jp = (int)min(ns_max-1, jp);// ! for points too close to the boundary
|
---|
| 868 | jm = (int)min(ns_max-1, jm);
|
---|
| 869 |
|
---|
| 870 | // finds the face and pixel's (x,y)
|
---|
| 871 | if( z>=0 ) {
|
---|
| 872 | face_num = ntt;// ! in {0,3}
|
---|
| 873 | ix = ns_max - jm - 1;
|
---|
| 874 | iy = ns_max - jp - 1;
|
---|
| 875 | }
|
---|
| 876 | else {
|
---|
| 877 | face_num = ntt + 8;// ! in {8,11}
|
---|
| 878 | ix = jp;
|
---|
| 879 | iy = jm;
|
---|
| 880 | }
|
---|
| 881 | }
|
---|
| 882 |
|
---|
| 883 | ix_low = (int)fmod(ix,128);
|
---|
| 884 | ix_hi = ix/128;
|
---|
| 885 | iy_low = (int)fmod(iy,128);
|
---|
| 886 | iy_hi = iy/128;
|
---|
| 887 | ipf= (PXY.x2pix_(ix_hi)+PXY.y2pix_(iy_hi))*(128*128)+(PXY.x2pix_(ix_low)+PXY.y2pix_(iy_low));
|
---|
| 888 | ipf = ipf / pow(ns_max/nside,2);// ! in {0, nside**2 - 1}
|
---|
| 889 | return ( ipf + face_num*pow(nside,2));// ! in {0, 12*nside**2 - 1}
|
---|
[228] | 890 | }
|
---|
| 891 |
|
---|
[470] | 892 | template<class T>
|
---|
| 893 | void SphereGorski<T>::pix2ang_ring(int nside,int ipix,double& theta,double& phi) const {
|
---|
[228] | 894 | /*
|
---|
[470] | 895 | ===================================================
|
---|
[228] | 896 | c gives theta and phi corresponding to pixel ipix (RING)
|
---|
| 897 | c for a parameter nside
|
---|
[470] | 898 | ===================================================
|
---|
[473] | 899 | */
|
---|
[228] | 900 | // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
|
---|
| 901 | // (16/12/98)
|
---|
| 902 |
|
---|
| 903 | int nl2, nl4, npix, ncap, iring, iphi, ip, ipix1;
|
---|
| 904 | double fact1, fact2, fodd, hip, fihip;
|
---|
| 905 |
|
---|
| 906 | int ns_max(8192);
|
---|
| 907 |
|
---|
| 908 | if( nside<1 || nside>ns_max ) {
|
---|
| 909 | cout << "nside out of range" << endl;
|
---|
| 910 | exit(0);
|
---|
| 911 | }
|
---|
| 912 | npix = 12*nside*nside; // ! total number of points
|
---|
| 913 | if( ipix<0 || ipix>npix-1 ) {
|
---|
| 914 | cout << "ipix out of range" << endl;
|
---|
| 915 | exit(0);
|
---|
| 916 | }
|
---|
| 917 |
|
---|
| 918 | ipix1 = ipix + 1; // in {1, npix}
|
---|
| 919 | nl2 = 2*nside;
|
---|
| 920 | nl4 = 4*nside;
|
---|
| 921 | ncap = 2*nside*(nside-1);// ! points in each polar cap, =0 for nside =1
|
---|
| 922 | fact1 = 1.5*nside;
|
---|
| 923 | fact2 = 3.0*nside*nside;
|
---|
| 924 |
|
---|
| 925 | if( ipix1 <= ncap ) { //! North Polar cap -------------
|
---|
| 926 |
|
---|
| 927 | hip = ipix1/2.;
|
---|
| 928 | fihip = floor(hip);
|
---|
| 929 | iring = (int)floor( sqrt( hip - sqrt(fihip) ) ) + 1;// ! counted from North pole
|
---|
| 930 | iphi = ipix1 - 2*iring*(iring - 1);
|
---|
| 931 |
|
---|
| 932 | theta = acos( 1. - iring*iring / fact2 );
|
---|
| 933 | phi = (1.*iphi - 0.5) * Pi/(2.*iring);
|
---|
| 934 | // cout << theta << " " << phi << endl;
|
---|
| 935 | }
|
---|
| 936 | else if( ipix1 <= nl2*(5*nside+1) ) {//then ! Equatorial region ------
|
---|
| 937 |
|
---|
| 938 | ip = ipix1 - ncap - 1;
|
---|
| 939 | iring = (int)floor( ip / nl4 ) + nside;// ! counted from North pole
|
---|
| 940 | iphi = (int)fmod(ip,nl4) + 1;
|
---|
| 941 |
|
---|
| 942 | fodd = 0.5 * (1 + fmod((double)(iring+nside),2));// ! 1 if iring+nside is odd, 1/2 otherwise
|
---|
| 943 | theta = acos( (nl2 - iring) / fact1 );
|
---|
| 944 | phi = (1.*iphi - fodd) * Pi /(2.*nside);
|
---|
| 945 | }
|
---|
| 946 | else {//! South Polar cap -----------------------------------
|
---|
| 947 |
|
---|
| 948 | ip = npix - ipix1 + 1;
|
---|
| 949 | hip = ip/2.;
|
---|
| 950 | fihip = 1.*hip;
|
---|
| 951 | iring = (int)floor( sqrt( hip - sqrt(fihip) ) ) + 1;// ! counted from South pole
|
---|
| 952 | iphi = (int)(4.*iring + 1 - (ip - 2.*iring*(iring-1)));
|
---|
| 953 |
|
---|
| 954 | theta = acos( -1. + iring*iring / fact2 );
|
---|
| 955 | phi = (1.*iphi - 0.5) * Pi/(2.*iring);
|
---|
| 956 | // cout << theta << " " << phi << endl;
|
---|
| 957 | }
|
---|
| 958 | }
|
---|
| 959 |
|
---|
[470] | 960 | template<class T>
|
---|
| 961 | void SphereGorski<T>::pix2ang_nest(int nside,int ipix,double& theta,double& phi) const {
|
---|
[228] | 962 | /*
|
---|
[470] | 963 | ==================================================
|
---|
[228] | 964 | subroutine pix2ang_nest(nside, ipix, theta, phi)
|
---|
[470] | 965 | ==================================================
|
---|
[228] | 966 | c gives theta and phi corresponding to pixel ipix (NESTED)
|
---|
| 967 | c for a parameter nside
|
---|
[470] | 968 | ==================================================
|
---|
[473] | 969 | */
|
---|
[228] | 970 | // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
|
---|
| 971 | // (16/12/98)
|
---|
[470] | 972 |
|
---|
| 973 | const PIXELS_XY& PXY= PIXELS_XY::instance();
|
---|
[228] | 974 |
|
---|
[470] | 975 | int npix, npface, face_num;
|
---|
| 976 | int ipf, ip_low, ip_trunc, ip_med, ip_hi;
|
---|
| 977 | int ix, iy, jrt, jr, nr, jpt, jp, kshift, nl4;
|
---|
| 978 | double z, fn, fact1, fact2;
|
---|
| 979 | double piover2(Pi/2.);
|
---|
| 980 | int ns_max(8192);
|
---|
| 981 |
|
---|
| 982 | // ! coordinate of the lowest corner of each face
|
---|
| 983 | int jrll[12]={2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4};//! in unit of nside
|
---|
| 984 | int jpll[12]={1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7};// ! in unit of nside/2
|
---|
| 985 |
|
---|
| 986 | if( nside<1 || nside>ns_max ) {
|
---|
| 987 | cout << "nside out of range" << endl;
|
---|
| 988 | exit(0);
|
---|
| 989 | }
|
---|
| 990 | npix = 12 * nside*nside;
|
---|
| 991 | if( ipix<0 || ipix>npix-1 ) {
|
---|
| 992 | cout << "ipix out of range" << endl;
|
---|
| 993 | exit(0);
|
---|
| 994 | }
|
---|
| 995 |
|
---|
| 996 | fn = 1.*nside;
|
---|
| 997 | fact1 = 1./(3.*fn*fn);
|
---|
| 998 | fact2 = 2./(3.*fn);
|
---|
| 999 | nl4 = 4*nside;
|
---|
[228] | 1000 |
|
---|
[470] | 1001 | //c finds the face, and the number in the face
|
---|
| 1002 | npface = nside*nside;
|
---|
| 1003 |
|
---|
| 1004 | face_num = ipix/npface;// ! face number in {0,11}
|
---|
| 1005 | ipf = (int)fmod(ipix,npface);// ! pixel number in the face {0,npface-1}
|
---|
| 1006 |
|
---|
| 1007 | //c finds the x,y on the face (starting from the lowest corner)
|
---|
| 1008 | //c from the pixel number
|
---|
| 1009 | ip_low = (int)fmod(ipf,1024);// ! content of the last 10 bits
|
---|
| 1010 | ip_trunc = ipf/1024 ;// ! truncation of the last 10 bits
|
---|
| 1011 | ip_med = (int)fmod(ip_trunc,1024);// ! content of the next 10 bits
|
---|
| 1012 | ip_hi = ip_trunc/1024 ;//! content of the high weight 10 bits
|
---|
| 1013 |
|
---|
| 1014 | ix = 1024*PXY.pix2x_(ip_hi)+32*PXY.pix2x_(ip_med)+PXY.pix2x_(ip_low);
|
---|
| 1015 | iy = 1024*PXY.pix2y_(ip_hi)+32*PXY.pix2y_(ip_med)+PXY.pix2y_(ip_low);
|
---|
| 1016 |
|
---|
| 1017 | //c transforms this in (horizontal, vertical) coordinates
|
---|
| 1018 | jrt = ix + iy;// ! 'vertical' in {0,2*(nside-1)}
|
---|
| 1019 | jpt = ix - iy;// ! 'horizontal' in {-nside+1,nside-1}
|
---|
| 1020 |
|
---|
| 1021 | //c computes the z coordinate on the sphere
|
---|
| 1022 | // jr = jrll[face_num+1]*nside - jrt - 1;// ! ring number in {1,4*nside-1}
|
---|
| 1023 | jr = jrll[face_num]*nside - jrt - 1;
|
---|
| 1024 | nr = nside;// ! equatorial region (the most frequent)
|
---|
| 1025 | z = (2*nside-jr)*fact2;
|
---|
| 1026 | kshift = (int)fmod(jr - nside, 2);
|
---|
| 1027 | if( jr<nside ) { //then ! north pole region
|
---|
| 1028 | nr = jr;
|
---|
| 1029 | z = 1. - nr*nr*fact1;
|
---|
| 1030 | kshift = 0;
|
---|
| 1031 | }
|
---|
| 1032 | else {
|
---|
| 1033 | if( jr>3*nside ) {// then ! south pole region
|
---|
| 1034 | nr = nl4 - jr;
|
---|
| 1035 | z = - 1. + nr*nr*fact1;
|
---|
| 1036 | kshift = 0;
|
---|
| 1037 | }
|
---|
| 1038 | }
|
---|
| 1039 | theta = acos(z);
|
---|
| 1040 |
|
---|
| 1041 | //c computes the phi coordinate on the sphere, in [0,2Pi]
|
---|
| 1042 | // jp = (jpll[face_num+1]*nr + jpt + 1 + kshift)/2;// ! 'phi' number in the ring in {1,4*nr}
|
---|
| 1043 | jp = (jpll[face_num]*nr + jpt + 1 + kshift)/2;
|
---|
| 1044 | if( jp>nl4 ) jp = jp - nl4;
|
---|
| 1045 | if( jp<1 ) jp = jp + nl4;
|
---|
| 1046 | phi = (jp - (kshift+1)*0.5) * (piover2 / nr);
|
---|
| 1047 | }
|
---|
[228] | 1048 |
|
---|
| 1049 |
|
---|
| 1050 |
|
---|
[470] | 1051 | template <class T>
|
---|
| 1052 | void SphereGorski<T>::print(ostream& os) const
|
---|
| 1053 | {
|
---|
| 1054 | if(mInfo_) os << " DVList Info= " << *mInfo_ << endl;
|
---|
| 1055 | //
|
---|
| 1056 | os << " nSide_ = " << nSide_ << endl;
|
---|
| 1057 | os << " nPix_ = " << nPix_ << endl;
|
---|
| 1058 | os << " omeg_ = " << omeg_ << endl;
|
---|
[228] | 1059 |
|
---|
[487] | 1060 | os << " content of pixels : ";
|
---|
[470] | 1061 | for(int i=0; i < nPix_; i++)
|
---|
| 1062 | {
|
---|
| 1063 | if(i%5 == 0) os << endl;
|
---|
| 1064 | os << pixels_(i) <<", ";
|
---|
| 1065 | }
|
---|
| 1066 | os << endl;
|
---|
[228] | 1067 |
|
---|
[470] | 1068 | os << endl;
|
---|
[487] | 1069 | //const PIXELS_XY& PXY= PIXELS_XY::instance();
|
---|
[228] | 1070 |
|
---|
[487] | 1071 | //os << endl; os << " contenu des tableaux conversions "<<endl;
|
---|
| 1072 | //for(int i=0; i < 5; i++)
|
---|
| 1073 | // {
|
---|
| 1074 | // os<<PXY.pix2x_(i)<<", "<<PXY.pix2y_(i)<<", "<<PXY.x2pix_(i)<<", "<<PXY.y2pix_(i)<<endl;
|
---|
| 1075 | // }
|
---|
[470] | 1076 | os << endl;
|
---|
[228] | 1077 |
|
---|
| 1078 | }
|
---|
| 1079 |
|
---|
[470] | 1080 | //*******************************************************************
|
---|
| 1081 | // Class FIO_SphereGorski<T>
|
---|
| 1082 | // Les objets delegues pour la gestion de persistance
|
---|
| 1083 | //*******************************************************************
|
---|
[228] | 1084 |
|
---|
[470] | 1085 | template <class T>
|
---|
| 1086 | FIO_SphereGorski<T>::FIO_SphereGorski()
|
---|
| 1087 | {
|
---|
| 1088 | dobj= new SphereGorski<T>;
|
---|
| 1089 | ownobj= true;
|
---|
| 1090 | }
|
---|
[228] | 1091 |
|
---|
[470] | 1092 | template <class T>
|
---|
| 1093 | FIO_SphereGorski<T>::FIO_SphereGorski(string const& filename)
|
---|
| 1094 | {
|
---|
| 1095 | dobj= new SphereGorski<T>;
|
---|
| 1096 | ownobj= true;
|
---|
| 1097 | Read(filename);
|
---|
| 1098 | }
|
---|
[228] | 1099 |
|
---|
[470] | 1100 | template <class T>
|
---|
| 1101 | FIO_SphereGorski<T>::FIO_SphereGorski(const SphereGorski<T>& obj)
|
---|
| 1102 | {
|
---|
| 1103 | dobj= new SphereGorski<T>(obj);
|
---|
| 1104 | ownobj= true;
|
---|
| 1105 | }
|
---|
[228] | 1106 |
|
---|
[470] | 1107 | template <class T>
|
---|
| 1108 | FIO_SphereGorski<T>::FIO_SphereGorski(SphereGorski<T>* obj)
|
---|
| 1109 | {
|
---|
| 1110 | dobj= obj;
|
---|
| 1111 | ownobj= false;
|
---|
| 1112 | }
|
---|
[228] | 1113 |
|
---|
[470] | 1114 | template <class T>
|
---|
| 1115 | FIO_SphereGorski<T>::~FIO_SphereGorski()
|
---|
| 1116 | {
|
---|
| 1117 | if (ownobj && dobj) delete dobj;
|
---|
| 1118 | }
|
---|
[228] | 1119 |
|
---|
[470] | 1120 | template <class T>
|
---|
| 1121 | AnyDataObj* FIO_SphereGorski<T>::DataObj()
|
---|
| 1122 | {
|
---|
| 1123 | return(dobj);
|
---|
| 1124 | }
|
---|
[228] | 1125 |
|
---|
[470] | 1126 | template <class T>
|
---|
| 1127 | void FIO_SphereGorski<T>::ReadSelf(PInPersist& is)
|
---|
| 1128 | {
|
---|
| 1129 | cout << " FIO_SphereGorski:: ReadSelf " << endl;
|
---|
[228] | 1130 |
|
---|
[470] | 1131 | if(dobj == NULL)
|
---|
| 1132 | {
|
---|
| 1133 | dobj= new SphereGorski<T>;
|
---|
| 1134 | }
|
---|
[228] | 1135 |
|
---|
[470] | 1136 | // Pour savoir s'il y avait un DVList Info associe
|
---|
| 1137 | char strg[256];
|
---|
| 1138 | is.GetLine(strg, 255);
|
---|
| 1139 | bool hadinfo= false;
|
---|
| 1140 | if(strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0) hadinfo= true;
|
---|
| 1141 | if(hadinfo)
|
---|
| 1142 | { // Lecture eventuelle du DVList Info
|
---|
| 1143 | is >> dobj->Info();
|
---|
| 1144 | }
|
---|
[228] | 1145 |
|
---|
[473] | 1146 | int nSide;
|
---|
[470] | 1147 | is.GetI4(nSide);
|
---|
| 1148 | dobj->setSizeIndex(nSide);
|
---|
| 1149 |
|
---|
[473] | 1150 | int nPix;
|
---|
[470] | 1151 | is.GetI4(nPix);
|
---|
| 1152 | dobj->setNbPixels(nPix);
|
---|
| 1153 |
|
---|
[473] | 1154 | double Omega;
|
---|
[470] | 1155 | is.GetR8(Omega);
|
---|
| 1156 | dobj->setPixSolAngle(Omega);
|
---|
| 1157 |
|
---|
| 1158 | T* pixels= new T[nPix];
|
---|
| 1159 | PIOSReadArray(is, pixels, nPix);
|
---|
| 1160 | dobj->setDataBlock(pixels, nPix);
|
---|
| 1161 | delete [] pixels;
|
---|
| 1162 |
|
---|
[228] | 1163 | }
|
---|
| 1164 |
|
---|
[470] | 1165 | template <class T>
|
---|
| 1166 | void FIO_SphereGorski<T>::WriteSelf(POutPersist& os) const
|
---|
| 1167 | {
|
---|
| 1168 | cout << " FIO_SphereGorski:: WriteSelf " << endl;
|
---|
[228] | 1169 |
|
---|
[470] | 1170 | if(dobj == NULL)
|
---|
| 1171 | {
|
---|
| 1172 | cout << " WriteSelf:: dobj= null " << endl;
|
---|
| 1173 | return;
|
---|
| 1174 | }
|
---|
[228] | 1175 |
|
---|
[470] | 1176 | char strg[256];
|
---|
[473] | 1177 | int nSide= dobj->SizeIndex();
|
---|
| 1178 | int nPix = dobj->NbPixels();
|
---|
[470] | 1179 |
|
---|
| 1180 | if(dobj->ptrInfo())
|
---|
| 1181 | {
|
---|
| 1182 | sprintf(strg,"SphereGorski: NSide=%6d NPix=%9d HasInfo",nSide,nPix);
|
---|
| 1183 | os.PutLine(strg);
|
---|
| 1184 | os << dobj->Info();
|
---|
| 1185 | }
|
---|
| 1186 | else
|
---|
| 1187 | {
|
---|
| 1188 | sprintf(strg,"SphereGorski: NSide=%6d NPix=%9d ",nSide,nPix);
|
---|
| 1189 | os.PutLine(strg);
|
---|
| 1190 | }
|
---|
| 1191 |
|
---|
| 1192 | os.PutI4(nSide);
|
---|
| 1193 | os.PutI4(nPix);
|
---|
| 1194 | os.PutR8(dobj->PixSolAngle(0));
|
---|
| 1195 |
|
---|
| 1196 | PIOSWriteArray(os,(dobj->getDataBlock())->Data(), nPix);
|
---|
| 1197 |
|
---|
| 1198 |
|
---|
| 1199 | }
|
---|
| 1200 |
|
---|
| 1201 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 1202 | #pragma define_template SphereGorski<double>
|
---|
| 1203 | #pragma define_template SphereGorski<float>
|
---|
| 1204 | #pragma define_template SphereGorski< complex<float> >
|
---|
| 1205 | #pragma define_template SphereGorski< complex<double> >
|
---|
| 1206 | #pragma define_template FIO_SphereGorski<double>
|
---|
| 1207 | #pragma define_template FIO_SphereGorski<float>
|
---|
| 1208 | #pragma define_template FIO_SphereGorski< complex<float> >
|
---|
| 1209 | #pragma define_template FIO_SphereGorski< complex<double> >
|
---|
| 1210 | #endif
|
---|
| 1211 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 1212 | template class SphereGorski<double>;
|
---|
| 1213 | template class SphereGorski<float>;
|
---|
| 1214 | template class SphereGorski< complex<float> >;
|
---|
| 1215 | template class SphereGorski< complex<double> >;
|
---|
| 1216 | template class FIO_SphereGorski<double>;
|
---|
| 1217 | template class FIO_SphereGorski<float>;
|
---|
| 1218 | template class FIO_SphereGorski< complex<float> >;
|
---|
| 1219 | template class FIO_SphereGorski< complex<double> >;
|
---|
| 1220 | #endif
|
---|
| 1221 |
|
---|