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