Commit e8b5c1bddbe1f980d65b7c8144e5818c943548f5
1 parent
1d7e58a3
implement only HPX specific methods (base class overloading)
Showing
2 changed files
with
118 additions
and
157 deletions
include/GWcsHPX.hpp
| ... | ... | @@ -20,6 +20,9 @@ |
| 20 | 20 | #define GWCSHPX_HPP |
| 21 | 21 | |
| 22 | 22 | /* __ Includes ___________________________________________________________ */ |
| 23 | +#ifdef HAVE_CONFIG_H | |
| 24 | +#include <config.h> | |
| 25 | +#endif | |
| 23 | 26 | #include "GWcs.hpp" |
| 24 | 27 | #include "GSkyDir.hpp" |
| 25 | 28 | #include "GSkyPixel.hpp" |
| ... | ... | @@ -40,7 +43,7 @@ public: |
| 40 | 43 | GWcsHPX(void); |
| 41 | 44 | GWcsHPX(const int& nside, const std::string& ordering = "NESTED", |
| 42 | 45 | const std::string& coordsys = "GAL"); |
| 43 | - GWcsHPX(const GFitsHDU* hdu); | |
| 46 | + explicit GWcsHPX(const GFitsHDU* hdu); | |
| 44 | 47 | GWcsHPX(const GWcsHPX& wcs); |
| 45 | 48 | virtual ~GWcsHPX(void); |
| 46 | 49 | |
| ... | ... | @@ -49,16 +52,15 @@ public: |
| 49 | 52 | |
| 50 | 53 | // Implemented pure virtual methods |
| 51 | 54 | std::string type(void) const; |
| 55 | + | |
| 56 | + // Overloaded base class methods | |
| 57 | + void read(const GFitsHDU* hdu); | |
| 58 | + void write(GFitsHDU* hdu); | |
| 59 | + double omega(const int& pix) const; | |
| 52 | 60 | GSkyDir pix2dir(const int& pix); |
| 53 | - GSkyDir xy2dir(const GSkyPixel& pix); | |
| 54 | 61 | int dir2pix(GSkyDir dir) const; |
| 55 | - GSkyPixel dir2xy(GSkyDir dir) const; | |
| 56 | - double omega(const int& pix) const; | |
| 57 | - double omega(const GSkyPixel& pix) const; | |
| 58 | 62 | |
| 59 | 63 | // Class specific methods |
| 60 | - void read(const GFitsHDU* hdu); // overwrites base class method | |
| 61 | - void write(GFitsHDU* hdu); // overwrites base class method | |
| 62 | 64 | int npix(void) const; |
| 63 | 65 | int nside(void) const; |
| 64 | 66 | std::string ordering(void) const; | ... | ... |
src/sky/GWcsHPX.cpp
| ... | ... | @@ -18,6 +18,9 @@ |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | /* __ Includes ___________________________________________________________ */ |
| 21 | +#ifdef HAVE_CONFIG_H | |
| 22 | +#include <config.h> | |
| 23 | +#endif | |
| 21 | 24 | #include <iostream> |
| 22 | 25 | #include <cmath> |
| 23 | 26 | #include "GException.hpp" |
| ... | ... | @@ -218,144 +221,6 @@ std::string GWcsHPX::type(void) const |
| 218 | 221 | |
| 219 | 222 | |
| 220 | 223 | /***********************************************************************//** |
| 221 | - * @brief Returns sky direction of pixel | |
| 222 | - * | |
| 223 | - * @param[in] pix Pixel number (0,1,...,m_num_pixels). | |
| 224 | - ***************************************************************************/ | |
| 225 | -GSkyDir GWcsHPX::pix2dir(const int& pix) | |
| 226 | -{ | |
| 227 | - // Declare result | |
| 228 | - GSkyDir result; | |
| 229 | - double theta = 0.0; | |
| 230 | - double phi = 0.0; | |
| 231 | - | |
| 232 | - // Perform ordering dependent conversion | |
| 233 | - switch (m_ordering) { | |
| 234 | - case 0: | |
| 235 | - pix2ang_ring(pix, &theta, &phi); | |
| 236 | - break; | |
| 237 | - case 1: | |
| 238 | - pix2ang_nest(pix, &theta, &phi); | |
| 239 | - break; | |
| 240 | - default: | |
| 241 | - break; | |
| 242 | - } | |
| 243 | - | |
| 244 | - // Store coordinate system dependent result | |
| 245 | - switch (m_coordsys) { | |
| 246 | - case 0: | |
| 247 | - result.radec(phi, pihalf-theta); | |
| 248 | - break; | |
| 249 | - case 1: | |
| 250 | - result.lb(phi, pihalf-theta); | |
| 251 | - break; | |
| 252 | - default: | |
| 253 | - break; | |
| 254 | - } | |
| 255 | - | |
| 256 | - // Return result | |
| 257 | - return result; | |
| 258 | -} | |
| 259 | - | |
| 260 | - | |
| 261 | -/***********************************************************************//** | |
| 262 | - * @brief Returns sky direction of pixel (method should never be called) | |
| 263 | - * | |
| 264 | - * @param[in] pix Sky pixel. | |
| 265 | - ***************************************************************************/ | |
| 266 | -GSkyDir GWcsHPX::xy2dir(const GSkyPixel& pix) | |
| 267 | -{ | |
| 268 | - // Throw error | |
| 269 | - throw GException::wcs(G_XY2DIR, "WCS method not defined for HPX type."); | |
| 270 | -} | |
| 271 | - | |
| 272 | - | |
| 273 | -/***********************************************************************//** | |
| 274 | - * @brief Returns pixel for a given sky direction | |
| 275 | - * | |
| 276 | - * @param[in] dir Sky direction. | |
| 277 | - ***************************************************************************/ | |
| 278 | -int GWcsHPX::dir2pix(GSkyDir dir) const | |
| 279 | -{ | |
| 280 | - // Declare result | |
| 281 | - int pix; | |
| 282 | - double z; | |
| 283 | - double phi; | |
| 284 | - | |
| 285 | - // Compute coordinate system dependent (z,phi) | |
| 286 | - switch (m_coordsys) { | |
| 287 | - case 0: | |
| 288 | - z = cos(pihalf-dir.dec()); | |
| 289 | - phi = dir.ra(); | |
| 290 | - break; | |
| 291 | - case 1: | |
| 292 | - z = cos(pihalf-dir.b()); | |
| 293 | - phi = dir.l(); | |
| 294 | - break; | |
| 295 | - default: | |
| 296 | - break; | |
| 297 | - } | |
| 298 | - | |
| 299 | - // Perform ordering dependent conversion | |
| 300 | - switch (m_ordering) { | |
| 301 | - case 0: | |
| 302 | - pix = ang2pix_z_phi_ring(z, phi); | |
| 303 | - break; | |
| 304 | - case 1: | |
| 305 | - pix = ang2pix_z_phi_nest(z, phi); | |
| 306 | - break; | |
| 307 | - default: | |
| 308 | - break; | |
| 309 | - } | |
| 310 | - | |
| 311 | - // Return pixel index | |
| 312 | - return pix; | |
| 313 | -} | |
| 314 | - | |
| 315 | - | |
| 316 | -/***********************************************************************//** | |
| 317 | - * @brief Returns pixel of sky direction (method should never be called) | |
| 318 | - * | |
| 319 | - * @param[in] dir Sky direction. | |
| 320 | - ***************************************************************************/ | |
| 321 | -GSkyPixel GWcsHPX::dir2xy(GSkyDir dir) const | |
| 322 | -{ | |
| 323 | - // Throw error | |
| 324 | - throw GException::wcs(G_DIR2XY, "WCS method not defined for HPX type."); | |
| 325 | -} | |
| 326 | - | |
| 327 | - | |
| 328 | -/***********************************************************************//** | |
| 329 | - * @brief Returns solid angle of pixel | |
| 330 | - * | |
| 331 | - * @param[in] pix Pixel number (0,1,...,num_pixels). | |
| 332 | - * | |
| 333 | - * HEALPix pixels have all the same solid angle, hence the pix argument is | |
| 334 | - * not used. | |
| 335 | - ***************************************************************************/ | |
| 336 | -double GWcsHPX::omega(const int& pix) const | |
| 337 | -{ | |
| 338 | - // Return solid angle | |
| 339 | - return m_omega; | |
| 340 | -} | |
| 341 | - | |
| 342 | - | |
| 343 | -/***********************************************************************//** | |
| 344 | - * @brief Returns solid angle of pixel | |
| 345 | - * | |
| 346 | - * @param[in] pix Pixel index (x,y). | |
| 347 | - * | |
| 348 | - * HEALPix pixels have all the same solid angle, hence the pix argument is | |
| 349 | - * not used. | |
| 350 | - ***************************************************************************/ | |
| 351 | -double GWcsHPX::omega(const GSkyPixel& pix) const | |
| 352 | -{ | |
| 353 | - // Return solid angle | |
| 354 | - return m_omega; | |
| 355 | -} | |
| 356 | - | |
| 357 | - | |
| 358 | -/***********************************************************************//** | |
| 359 | 224 | * @brief Read Healpix definiton from FITS header. |
| 360 | 225 | * |
| 361 | 226 | * @param[in] hdu FITS HDU containing the Healpix definition. |
| ... | ... | @@ -440,8 +305,10 @@ void GWcsHPX::write(GFitsHDU* hdu) |
| 440 | 305 | hdu->card("NSIDE", nside(), "HEALPix resolution parameter"); |
| 441 | 306 | hdu->card("FIRSTPIX", 0, "Index of first pixel"); |
| 442 | 307 | hdu->card("LASTPIX", npix()-1, "Index of last pixel"); |
| 443 | - hdu->card("ORDERING", ordering(), "Pixel ordering scheme, either RING or NESTED"); | |
| 444 | - hdu->card("COORDSYS", coordsys(), "Coordinate system, either EQU or GAL"); | |
| 308 | + hdu->card("ORDERING", ordering(), | |
| 309 | + "Pixel ordering scheme, either RING or NESTED"); | |
| 310 | + hdu->card("COORDSYS", coordsys(), | |
| 311 | + "Coordinate system, either EQU or GAL"); | |
| 445 | 312 | |
| 446 | 313 | } // endif: HDU was valid |
| 447 | 314 | |
| ... | ... | @@ -451,6 +318,105 @@ void GWcsHPX::write(GFitsHDU* hdu) |
| 451 | 318 | |
| 452 | 319 | |
| 453 | 320 | /***********************************************************************//** |
| 321 | + * @brief Returns solid angle of pixel | |
| 322 | + * | |
| 323 | + * @param[in] pix Pixel number (0,1,...,num_pixels). | |
| 324 | + * | |
| 325 | + * HEALPix pixels have all the same solid angle, hence the pix argument is | |
| 326 | + * not used. | |
| 327 | + ***************************************************************************/ | |
| 328 | +double GWcsHPX::omega(const int& pix) const | |
| 329 | +{ | |
| 330 | + // Return solid angle | |
| 331 | + return m_omega; | |
| 332 | +} | |
| 333 | + | |
| 334 | + | |
| 335 | +/***********************************************************************//** | |
| 336 | + * @brief Returns sky direction of pixel | |
| 337 | + * | |
| 338 | + * @param[in] pix Pixel number (0,1,...,m_num_pixels). | |
| 339 | + ***************************************************************************/ | |
| 340 | +GSkyDir GWcsHPX::pix2dir(const int& pix) | |
| 341 | +{ | |
| 342 | + // Declare result | |
| 343 | + GSkyDir result; | |
| 344 | + double theta = 0.0; | |
| 345 | + double phi = 0.0; | |
| 346 | + | |
| 347 | + // Perform ordering dependent conversion | |
| 348 | + switch (m_ordering) { | |
| 349 | + case 0: | |
| 350 | + pix2ang_ring(pix, &theta, &phi); | |
| 351 | + break; | |
| 352 | + case 1: | |
| 353 | + pix2ang_nest(pix, &theta, &phi); | |
| 354 | + break; | |
| 355 | + default: | |
| 356 | + break; | |
| 357 | + } | |
| 358 | + | |
| 359 | + // Store coordinate system dependent result | |
| 360 | + switch (m_coordsys) { | |
| 361 | + case 0: | |
| 362 | + result.radec(phi, pihalf-theta); | |
| 363 | + break; | |
| 364 | + case 1: | |
| 365 | + result.lb(phi, pihalf-theta); | |
| 366 | + break; | |
| 367 | + default: | |
| 368 | + break; | |
| 369 | + } | |
| 370 | + | |
| 371 | + // Return result | |
| 372 | + return result; | |
| 373 | +} | |
| 374 | + | |
| 375 | + | |
| 376 | +/***********************************************************************//** | |
| 377 | + * @brief Returns pixel for a given sky direction | |
| 378 | + * | |
| 379 | + * @param[in] dir Sky direction. | |
| 380 | + ***************************************************************************/ | |
| 381 | +int GWcsHPX::dir2pix(GSkyDir dir) const | |
| 382 | +{ | |
| 383 | + // Declare result | |
| 384 | + int pix; | |
| 385 | + double z; | |
| 386 | + double phi; | |
| 387 | + | |
| 388 | + // Compute coordinate system dependent (z,phi) | |
| 389 | + switch (m_coordsys) { | |
| 390 | + case 0: | |
| 391 | + z = cos(pihalf-dir.dec()); | |
| 392 | + phi = dir.ra(); | |
| 393 | + break; | |
| 394 | + case 1: | |
| 395 | + z = cos(pihalf-dir.b()); | |
| 396 | + phi = dir.l(); | |
| 397 | + break; | |
| 398 | + default: | |
| 399 | + break; | |
| 400 | + } | |
| 401 | + | |
| 402 | + // Perform ordering dependent conversion | |
| 403 | + switch (m_ordering) { | |
| 404 | + case 0: | |
| 405 | + pix = ang2pix_z_phi_ring(z, phi); | |
| 406 | + break; | |
| 407 | + case 1: | |
| 408 | + pix = ang2pix_z_phi_nest(z, phi); | |
| 409 | + break; | |
| 410 | + default: | |
| 411 | + break; | |
| 412 | + } | |
| 413 | + | |
| 414 | + // Return pixel index | |
| 415 | + return pix; | |
| 416 | +} | |
| 417 | + | |
| 418 | + | |
| 419 | +/***********************************************************************//** | |
| 454 | 420 | * @brief Returns number of pixels |
| 455 | 421 | ***************************************************************************/ |
| 456 | 422 | int GWcsHPX::npix(void) const |
| ... | ... | @@ -499,7 +465,7 @@ std::string GWcsHPX::ordering(void) const |
| 499 | 465 | * |
| 500 | 466 | * @param[in] ordering Pixel ordering (RING or NEST/NESTED). |
| 501 | 467 | * |
| 502 | - * @exception GException::wcs_hpx_bad_ordering | |
| 468 | + * @exception GException::wcs_hpx_bad_ordering | |
| 503 | 469 | * Invalid ordering parameter. |
| 504 | 470 | ***************************************************************************/ |
| 505 | 471 | void GWcsHPX::ordering(const std::string& ordering) |
| ... | ... | @@ -667,7 +633,7 @@ int GWcsHPX::xy2pix(int x, int y) const |
| 667 | 633 | * @param[out] theta Pointer to result zenith angle in radians. |
| 668 | 634 | * @param[out] phi Pointer to result azimuth angle in radians. |
| 669 | 635 | * |
| 670 | - * @exception GException::out_of_range | |
| 636 | + * @exception GException::out_of_range | |
| 671 | 637 | * Pixel index is out of range. |
| 672 | 638 | ***************************************************************************/ |
| 673 | 639 | void GWcsHPX::pix2ang_ring(int ipix, double* theta, double* phi) |
| ... | ... | @@ -716,7 +682,7 @@ void GWcsHPX::pix2ang_ring(int ipix, double* theta, double* phi) |
| 716 | 682 | * @param[out] theta Pointer to result zenith angle in radians. |
| 717 | 683 | * @param[out] phi Pointer to result azimuth angle in radians. |
| 718 | 684 | * |
| 719 | - * @exception GException::out_of_range | |
| 685 | + * @exception GException::out_of_range | |
| 720 | 686 | * Pixel index is out of range. |
| 721 | 687 | ***************************************************************************/ |
| 722 | 688 | void GWcsHPX::pix2ang_nest(int ipix, double* theta, double* phi) |
| ... | ... | @@ -932,10 +898,3 @@ std::ostream& operator<< (std::ostream& os, const GWcsHPX& wcs) |
| 932 | 898 | // Return output stream |
| 933 | 899 | return os; |
| 934 | 900 | } |
| 935 | - | |
| 936 | - | |
| 937 | -/*========================================================================== | |
| 938 | - = = | |
| 939 | - = Other functions used by GWcsHPX = | |
| 940 | - = = | |
| 941 | - ==========================================================================*/ | ... | ... |