Commit e8d96bfeb52bd1b9f9d275a3003c1e54fa5c6b46
1 parent
7fc53dcf
clean code to support new GWcs interface
Showing
2 changed files
with
42 additions
and
10 deletions
include/GSkymap.hpp
| ... | ... | @@ -70,6 +70,7 @@ public: |
| 70 | 70 | const double& operator() (const GSkyPixel& pixel, const int map = 0) const; |
| 71 | 71 | GSkyDir xy2dir(const GSkyPixel& pix); |
| 72 | 72 | GSkyPixel dir2xy(GSkyDir dir) const; |
| 73 | + double omega(const GSkyPixel& pix) const; | |
| 73 | 74 | |
| 74 | 75 | // Methods |
| 75 | 76 | void load(const std::string& filename); | ... | ... |
src/sky/GSkymap.cpp
| ... | ... | @@ -41,7 +41,8 @@ |
| 41 | 41 | #define G_DIR2PIX "GSkymap::dir2pix(GSkyDir)" |
| 42 | 42 | #define G_XY2DIR "GSkymap::xy2dir(GSkyPixel)" |
| 43 | 43 | #define G_DIR2XY "GSkymap::dir2xy(GSkyDir)" |
| 44 | -#define G_OMEGA "GSkymap::omega(int)" | |
| 44 | +#define G_OMEGA1 "GSkymap::omega(int)" | |
| 45 | +#define G_OMEGA2 "GSkymap::omega(GSkyPixel)" | |
| 45 | 46 | #define G_SET_WCS "GSkymap::set_wcs(std::string,std::string,double,double," \ |
| 46 | 47 | "double,double,double,double,GMatrix,GVector)" |
| 47 | 48 | #define G_READ_HEALPIX "GSkymap::read_healpix(GFitsHDU*)" |
| ... | ... | @@ -51,7 +52,7 @@ |
| 51 | 52 | /* __ Coding definitions _________________________________________________ */ |
| 52 | 53 | |
| 53 | 54 | /* __ Debug definitions __________________________________________________ */ |
| 54 | -#define G_READ_HEALPIX_DEBUG 0 // Debug read_healpix | |
| 55 | +//#define G_READ_HEALPIX_DEBUG // Debug read_healpix | |
| 55 | 56 | |
| 56 | 57 | /* __ Prototype __________________________________________________________ */ |
| 57 | 58 | |
| ... | ... | @@ -653,10 +654,39 @@ double GSkymap::omega(const int& pix) const |
| 653 | 654 | { |
| 654 | 655 | // Throw error if WCS is not valid |
| 655 | 656 | if (m_wcs == NULL) |
| 656 | - throw GException::wcs(G_OMEGA, "No valid WCS found."); | |
| 657 | + throw GException::wcs(G_OMEGA1, "No valid WCS found."); | |
| 658 | + | |
| 659 | + // Determine solid angle from pixel. Use 2D version if sky map is | |
| 660 | + // 2D, otherwise use 1D version. | |
| 661 | + double omega = (m_num_x == 0) ? m_wcs->omega(pix) | |
| 662 | + : m_wcs->omega(pix2xy(pix)); | |
| 663 | + | |
| 664 | + // Return solid angle | |
| 665 | + return omega; | |
| 666 | +} | |
| 667 | + | |
| 668 | + | |
| 669 | +/***********************************************************************//** | |
| 670 | + * @brief Returns solid angle of pixel | |
| 671 | + * | |
| 672 | + * @param[in] pix Sky map pixel. | |
| 673 | + * | |
| 674 | + * @exception GException::wcs | |
| 675 | + * No valid WCS found. | |
| 676 | + ***************************************************************************/ | |
| 677 | +double GSkymap::omega(const GSkyPixel& pix) const | |
| 678 | +{ | |
| 679 | + // Throw error if WCS is not valid | |
| 680 | + if (m_wcs == NULL) | |
| 681 | + throw GException::wcs(G_OMEGA2, "No valid WCS found."); | |
| 682 | + | |
| 683 | + // Determine solid angle from pixel. Use 2D version if sky map is | |
| 684 | + // 2D, otherwise use 1D version. | |
| 685 | + double omega = (m_num_x == 0) ? m_wcs->omega(xy2pix(pix)) | |
| 686 | + : m_wcs->omega(pix); | |
| 657 | 687 | |
| 658 | 688 | // Return solid angle |
| 659 | - return (m_wcs->omega(pix)); | |
| 689 | + return omega; | |
| 660 | 690 | } |
| 661 | 691 | |
| 662 | 692 | |
| ... | ... | @@ -929,7 +959,7 @@ void GSkymap::read_healpix(const GFitsHDU* hdu) |
| 929 | 959 | // Determine number of rows and columns in table |
| 930 | 960 | int nrows = ((GFitsTable*)hdu->data())->nrows(); |
| 931 | 961 | int ncols = ((GFitsTable*)hdu->data())->ncols(); |
| 932 | - #if G_READ_HEALPIX_DEBUG | |
| 962 | + #if defined(G_READ_HEALPIX_DEBUG) | |
| 933 | 963 | std::cout << "nrows=" << nrows << " ncols=" << ncols << std::endl; |
| 934 | 964 | #endif |
| 935 | 965 | |
| ... | ... | @@ -941,7 +971,7 @@ void GSkymap::read_healpix(const GFitsHDU* hdu) |
| 941 | 971 | |
| 942 | 972 | // Set number of pixels based on NSIDE parameter |
| 943 | 973 | m_num_pixels = ((GWcsHPX*)m_wcs)->npix(); |
| 944 | - #if G_READ_HEALPIX_DEBUG | |
| 974 | + #if defined(G_READ_HEALPIX_DEBUG) | |
| 945 | 975 | std::cout << "m_num_pixels=" << m_num_pixels << std::endl; |
| 946 | 976 | #endif |
| 947 | 977 | |
| ... | ... | @@ -953,7 +983,7 @@ void GSkymap::read_healpix(const GFitsHDU* hdu) |
| 953 | 983 | |
| 954 | 984 | // Determine vector length for HEALPix data storage |
| 955 | 985 | int nentry = m_num_pixels / nrows; |
| 956 | - #if G_READ_HEALPIX_DEBUG | |
| 986 | + #if defined(G_READ_HEALPIX_DEBUG) | |
| 957 | 987 | std::cout << "nentry=" << nentry << std::endl; |
| 958 | 988 | #endif |
| 959 | 989 | |
| ... | ... | @@ -971,7 +1001,7 @@ void GSkymap::read_healpix(const GFitsHDU* hdu) |
| 971 | 1001 | m_num_maps += col->number() / nentry; |
| 972 | 1002 | } |
| 973 | 1003 | } |
| 974 | - #if G_READ_HEALPIX_DEBUG | |
| 1004 | + #if defined(G_READ_HEALPIX_DEBUG) | |
| 975 | 1005 | std::cout << "m_num_maps=" << m_num_maps << std::endl; |
| 976 | 1006 | #endif |
| 977 | 1007 | |
| ... | ... | @@ -1001,10 +1031,11 @@ void GSkymap::read_healpix(const GFitsHDU* hdu) |
| 1001 | 1031 | // Load map |
| 1002 | 1032 | double *ptr = m_pixels + imap; |
| 1003 | 1033 | for (int row = 0; row < col->length(); ++row) { |
| 1004 | - for (int inx = inx_start; inx < inx_end; ++inx, ptr+=m_num_maps) | |
| 1034 | + for (int inx = inx_start; inx < inx_end; | |
| 1035 | + ++inx, ptr+=m_num_maps) | |
| 1005 | 1036 | *ptr = col->real(row,inx); |
| 1006 | 1037 | } |
| 1007 | - #if G_READ_HEALPIX_DEBUG | |
| 1038 | + #if defined(G_READ_HEALPIX_DEBUG) | |
| 1008 | 1039 | std::cout << "Load map=" << imap << " index=" |
| 1009 | 1040 | << inx_start << "-" << inx_end << std::endl; |
| 1010 | 1041 | #endif | ... | ... |