Commit e8d96bfeb52bd1b9f9d275a3003c1e54fa5c6b46

Authored by knodlseder
1 parent 7fc53dcf

clean code to support new GWcs interface

include/GSkymap.hpp
@@ -70,6 +70,7 @@ public: @@ -70,6 +70,7 @@ public:
70 const double& operator() (const GSkyPixel& pixel, const int map = 0) const; 70 const double& operator() (const GSkyPixel& pixel, const int map = 0) const;
71 GSkyDir xy2dir(const GSkyPixel& pix); 71 GSkyDir xy2dir(const GSkyPixel& pix);
72 GSkyPixel dir2xy(GSkyDir dir) const; 72 GSkyPixel dir2xy(GSkyDir dir) const;
  73 + double omega(const GSkyPixel& pix) const;
73 74
74 // Methods 75 // Methods
75 void load(const std::string& filename); 76 void load(const std::string& filename);
src/sky/GSkymap.cpp
@@ -41,7 +41,8 @@ @@ -41,7 +41,8 @@
41 #define G_DIR2PIX "GSkymap::dir2pix(GSkyDir)" 41 #define G_DIR2PIX "GSkymap::dir2pix(GSkyDir)"
42 #define G_XY2DIR "GSkymap::xy2dir(GSkyPixel)" 42 #define G_XY2DIR "GSkymap::xy2dir(GSkyPixel)"
43 #define G_DIR2XY "GSkymap::dir2xy(GSkyDir)" 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 #define G_SET_WCS "GSkymap::set_wcs(std::string,std::string,double,double," \ 46 #define G_SET_WCS "GSkymap::set_wcs(std::string,std::string,double,double," \
46 "double,double,double,double,GMatrix,GVector)" 47 "double,double,double,double,GMatrix,GVector)"
47 #define G_READ_HEALPIX "GSkymap::read_healpix(GFitsHDU*)" 48 #define G_READ_HEALPIX "GSkymap::read_healpix(GFitsHDU*)"
@@ -51,7 +52,7 @@ @@ -51,7 +52,7 @@
51 /* __ Coding definitions _________________________________________________ */ 52 /* __ Coding definitions _________________________________________________ */
52 53
53 /* __ Debug definitions __________________________________________________ */ 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 /* __ Prototype __________________________________________________________ */ 57 /* __ Prototype __________________________________________________________ */
57 58
@@ -653,10 +654,39 @@ double GSkymap::omega(const int& pix) const @@ -653,10 +654,39 @@ double GSkymap::omega(const int& pix) const
653 { 654 {
654 // Throw error if WCS is not valid 655 // Throw error if WCS is not valid
655 if (m_wcs == NULL) 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 // Return solid angle 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,7 +959,7 @@ void GSkymap::read_healpix(const GFitsHDU* hdu)
929 // Determine number of rows and columns in table 959 // Determine number of rows and columns in table
930 int nrows = ((GFitsTable*)hdu->data())->nrows(); 960 int nrows = ((GFitsTable*)hdu->data())->nrows();
931 int ncols = ((GFitsTable*)hdu->data())->ncols(); 961 int ncols = ((GFitsTable*)hdu->data())->ncols();
932 - #if G_READ_HEALPIX_DEBUG 962 + #if defined(G_READ_HEALPIX_DEBUG)
933 std::cout << "nrows=" << nrows << " ncols=" << ncols << std::endl; 963 std::cout << "nrows=" << nrows << " ncols=" << ncols << std::endl;
934 #endif 964 #endif
935 965
@@ -941,7 +971,7 @@ void GSkymap::read_healpix(const GFitsHDU* hdu) @@ -941,7 +971,7 @@ void GSkymap::read_healpix(const GFitsHDU* hdu)
941 971
942 // Set number of pixels based on NSIDE parameter 972 // Set number of pixels based on NSIDE parameter
943 m_num_pixels = ((GWcsHPX*)m_wcs)->npix(); 973 m_num_pixels = ((GWcsHPX*)m_wcs)->npix();
944 - #if G_READ_HEALPIX_DEBUG 974 + #if defined(G_READ_HEALPIX_DEBUG)
945 std::cout << "m_num_pixels=" << m_num_pixels << std::endl; 975 std::cout << "m_num_pixels=" << m_num_pixels << std::endl;
946 #endif 976 #endif
947 977
@@ -953,7 +983,7 @@ void GSkymap::read_healpix(const GFitsHDU* hdu) @@ -953,7 +983,7 @@ void GSkymap::read_healpix(const GFitsHDU* hdu)
953 983
954 // Determine vector length for HEALPix data storage 984 // Determine vector length for HEALPix data storage
955 int nentry = m_num_pixels / nrows; 985 int nentry = m_num_pixels / nrows;
956 - #if G_READ_HEALPIX_DEBUG 986 + #if defined(G_READ_HEALPIX_DEBUG)
957 std::cout << "nentry=" << nentry << std::endl; 987 std::cout << "nentry=" << nentry << std::endl;
958 #endif 988 #endif
959 989
@@ -971,7 +1001,7 @@ void GSkymap::read_healpix(const GFitsHDU* hdu) @@ -971,7 +1001,7 @@ void GSkymap::read_healpix(const GFitsHDU* hdu)
971 m_num_maps += col->number() / nentry; 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 std::cout << "m_num_maps=" << m_num_maps << std::endl; 1005 std::cout << "m_num_maps=" << m_num_maps << std::endl;
976 #endif 1006 #endif
977 1007
@@ -1001,10 +1031,11 @@ void GSkymap::read_healpix(const GFitsHDU* hdu) @@ -1001,10 +1031,11 @@ void GSkymap::read_healpix(const GFitsHDU* hdu)
1001 // Load map 1031 // Load map
1002 double *ptr = m_pixels + imap; 1032 double *ptr = m_pixels + imap;
1003 for (int row = 0; row < col->length(); ++row) { 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 *ptr = col->real(row,inx); 1036 *ptr = col->real(row,inx);
1006 } 1037 }
1007 - #if G_READ_HEALPIX_DEBUG 1038 + #if defined(G_READ_HEALPIX_DEBUG)
1008 std::cout << "Load map=" << imap << " index=" 1039 std::cout << "Load map=" << imap << " index="
1009 << inx_start << "-" << inx_end << std::endl; 1040 << inx_start << "-" << inx_end << std::endl;
1010 #endif 1041 #endif