GammaLib 2.0.0
Loading...
Searching...
No Matches
GHealpix.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GHealpix.hpp - Healpix projection class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2010-2020 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GHealpix.hpp
23 * @brief HealPix projection class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GHEALPIX_HPP
28#define GHEALPIX_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include "GSkyProjection.hpp"
32#include "GFitsHDU.hpp"
33#include "GSkyDir.hpp"
34#include "GSkyPixel.hpp"
35#include "GBilinear.hpp"
36
37/* __ Forward declarations _______________________________________________ */
38class GSkyDirs;
39
40
41/***********************************************************************//**
42 * @class GHealpix
43 *
44 * @brief HealPix projection class interface definition
45 *
46 * The HealPix projection class has been implemented by adapting code from
47 * the HealPix library (version 2.1). For more information about HEALPix, see
48 * http://healpix.jpl.nasa.gov
49 ***************************************************************************/
50class GHealpix : public GSkyProjection {
51
52public:
53 // Constructors and destructors
54 GHealpix(void);
55 GHealpix(const int& nside,
56 const std::string& ordering = "NESTED",
57 const std::string& coordsys = "CEL");
58 explicit GHealpix(const GFitsHDU& hdu);
59 GHealpix(const GHealpix& wcs);
60 virtual ~GHealpix(void);
61
62 // Operators
63 GHealpix& operator=(const GHealpix& wcs);
64
65 // Implemented pure virtual base class methods
66 virtual void clear(void);
67 virtual GHealpix* clone(void) const;
68 virtual std::string classname(void) const;
69 virtual int size(void) const;
70 virtual std::string code(void) const;
71 virtual std::string name(void) const;
72 virtual void read(const GFitsHDU& hdu);
73 virtual void write(GFitsHDU& hdu) const;
74 virtual double solidangle(const GSkyPixel& pixel) const;
75 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const;
76 virtual GSkyPixel dir2pix(const GSkyDir& dir) const;
77 virtual GBilinear interpolator(const GSkyDir& dir) const;
78 virtual std::string print(const GChatter& chatter = NORMAL) const;
79
80 // Other methods
81 const int& npix(void) const;
82 const int& nside(void) const;
83 std::string ordering(void) const;
84 void ordering(const std::string& ordering);
85 std::vector<int> neighbours(const GSkyPixel& pixel) const;
86 GSkyDirs boundaries(const GSkyPixel& pixel, const int& step = 1) const;
87 double max_pixrad(void) const;
88
89private:
90 // Private methods
91 void init_members(void);
92 void copy_members(const GHealpix& wcs);
93 void free_members(void);
94 virtual bool compare(const GSkyProjection& proj) const;
95
96 // Low-level HealPix methods
97 int compress_bits(const int& value) const;
98 int spread_bits(const int& value) const;
99 void pix2xyf(const int& pix, int* ix, int* iy, int* face) const;
100 void nest2xyf(const int& pix, int* ix, int* iy, int* face) const;
101 void ring2xyf(const int& pix, int* ix, int* iy, int* face) const;
102 int xyf2nest(const int& ix, const int& iy, const int& face) const;
103 int xyf2ring(const int& ix, const int& iy, const int& face) const;
104 void xyf2loc(const double& x, const double& y, const int& face,
105 double* z, double* phi) const;
106 int nside2order(const int& nside) const;
107 int nest2ring(const int& pix) const;
108 int ring2nest(const int& pix) const;
109 void pix2xy(const int& ipix, int* x, int* y) const;
110 int xy2pix(int x, int y) const;
111 void pix2ang_ring(int ipix, double* theta, double* phi) const;
112 void pix2ang_nest(int ipix, double* theta, double* phi) const;
113 int ang2pix_z_phi_ring(double z, double phi) const;
114 int ang2pix_z_phi_nest(double z, double phi) const;
115 int ring_above(const double& z) const;
116 void get_ring_info(const int& ring, int* startpix, int* ringpix,
117 bool* shifted) const;
118 void get_ring_info(const int& ring, int* startpix, int* ringpix,
119 double* theta, bool* shifted) const;
120 GBilinear interpolator(const double& theta, const double& phi) const;
121 unsigned int isqrt(unsigned int arg) const;
122 GVector set_z_phi(const double& z, const double& phi) const;
123 GSkyDir loc2dir(const double& z, const double& phi) const;
124
125 // Private data area
126 int m_nside; //!< Number of divisions of each base pixel (1-8192)
127 int m_npface; //!<
128 int m_ncap; //!< Number of pixels in polar cap
129 int m_order; //!< Order
130 int m_ordering; //!< Pixel ordering (0=ring, 1=nested, -1=?)
131 int m_num_pixels; //!< Number of pixels in projection
132 double m_fact1; //!<
133 double m_fact2; //!<
134 double m_solidangle; //!< Solid angle of pixel
135};
136
137
138/***********************************************************************//**
139 * @brief Return class name
140 *
141 * @return String containing the class name ("GHealpix").
142 ***************************************************************************/
143inline
144std::string GHealpix::classname(void) const
145{
146 return ("GHealpix");
147}
148
149
150/***********************************************************************//**
151 * @brief Return dimension of projection
152 *
153 * @return Dimension of projection.
154 *
155 * Returns the dimension of the projection.
156 ***************************************************************************/
157inline
158int GHealpix::size(void) const
159{
160 return 1;
161}
162
163
164/***********************************************************************//**
165 * @brief Return projection code
166 *
167 * @return Projection code.
168 *
169 * Returns the projection code "HPX".
170 ***************************************************************************/
171inline
172std::string GHealpix::code(void) const
173{
174 return "HPX";
175}
176
177
178/***********************************************************************//**
179 * @brief Return projection name
180 *
181 * @return Projection name.
182 *
183 * Returns the projection name.
184 ***************************************************************************/
185inline
186std::string GHealpix::name(void) const
187{
188 return "HealPix";
189}
190
191
192/***********************************************************************//**
193 * @brief Returns number of pixels
194 ***************************************************************************/
195inline
196const int& GHealpix::npix(void) const
197{
198 // Return number of pixels
199 return m_num_pixels;
200}
201
202
203/***********************************************************************//**
204 * @brief Returns number of divisions of the side of each base pixel.
205 ***************************************************************************/
206inline
207const int& GHealpix::nside(void) const
208{
209 return m_nside;
210}
211
212
213/***********************************************************************//**
214 * @brief Returns solid angle of pixel
215 *
216 * @param[in] pixel Sky pixel.
217 * @return Solid angle of pixel.
218 *
219 * Returns the solid angle of the specified @p pixel. Note that HEALPix
220 * pixels have all the same solid angle, hence the @p pixel argument is in
221 * fact not used by the method.
222 ***************************************************************************/
223inline
224double GHealpix::solidangle(const GSkyPixel& pixel) const
225{
226 return m_solidangle;
227}
228
229#endif /* GHEALPIX_HPP */
Bilinear interpolator class interface definition.
Abstract FITS extension base class definition.
Sky direction class interface definition.
Sky map pixel class definition.
Abstract sky projection base class definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Bilinear interpolator class.
Definition GBilinear.hpp:40
Abstract FITS extension base class.
Definition GFitsHDU.hpp:51
HealPix projection class interface definition.
Definition GHealpix.hpp:50
int nside2order(const int &nside) const
Convert nside to order.
virtual int size(void) const
Return dimension of projection.
Definition GHealpix.hpp:158
double m_solidangle
Solid angle of pixel.
Definition GHealpix.hpp:134
virtual std::string classname(void) const
Return class name.
Definition GHealpix.hpp:144
int xyf2ring(const int &ix, const int &iy, const int &face) const
Convert (x,y,face) tuple to pixel number in ring scheme.
void copy_members(const GHealpix &wcs)
Copy class members.
Definition GHealpix.cpp:879
void nest2xyf(const int &pix, int *ix, int *iy, int *face) const
Convert pixel number in nested scheme to (x,y,face) tuple.
int xyf2nest(const int &ix, const int &iy, const int &face) const
Convert (x,y,face) tuple to pixel number in nested scheme.
virtual ~GHealpix(void)
Destructor.
Definition GHealpix.cpp:198
GHealpix & operator=(const GHealpix &wcs)
Assignment operator.
Definition GHealpix.cpp:220
GHealpix(void)
Void constructor.
Definition GHealpix.cpp:103
virtual std::string name(void) const
Return projection name.
Definition GHealpix.hpp:186
void free_members(void)
Delete class members.
Definition GHealpix.cpp:900
double m_fact1
Definition GHealpix.hpp:132
int m_ordering
Pixel ordering (0=ring, 1=nested, -1=?)
Definition GHealpix.hpp:130
virtual GSkyPixel dir2pix(const GSkyDir &dir) const
Returns sky map pixel of sky coordinate.
Definition GHealpix.cpp:433
std::vector< int > neighbours(const GSkyPixel &pixel) const
Return neighbouring pixels of a pixel.
Definition GHealpix.cpp:579
int ang2pix_z_phi_ring(double z, double phi) const
Returns pixel which contains angular coordinates (z,phi)
int m_num_pixels
Number of pixels in projection.
Definition GHealpix.hpp:131
int ang2pix_z_phi_nest(double z, double phi) const
Returns pixel which contains angular coordinates (z,phi)
int m_order
Order.
Definition GHealpix.hpp:129
GSkyDirs boundaries(const GSkyPixel &pixel, const int &step=1) const
Return pixel boundaries.
Definition GHealpix.cpp:711
virtual GBilinear interpolator(const GSkyDir &dir) const
Return interpolator for given sky direction.
Definition GHealpix.cpp:474
virtual void clear(void)
Clear object.
Definition GHealpix.cpp:255
virtual double solidangle(const GSkyPixel &pixel) const
Returns solid angle of pixel.
Definition GHealpix.hpp:224
virtual void write(GFitsHDU &hdu) const
Write Healpix definition into FITS HDU.
Definition GHealpix.cpp:356
int xy2pix(int x, int y) const
Convert (x,y) coordinate to pixel.
int ring_above(const double &z) const
Get ring index north of cos(theta)
virtual std::string code(void) const
Return projection code.
Definition GHealpix.hpp:172
int compress_bits(const int &value) const
Compress Bits.
Definition GHealpix.cpp:952
int spread_bits(const int &value) const
Spread Bits.
Definition GHealpix.cpp:972
int m_ncap
Number of pixels in polar cap.
Definition GHealpix.hpp:128
void pix2xyf(const int &pix, int *ix, int *iy, int *face) const
Convert pixel number in to (x,y,face) tuple.
Definition GHealpix.cpp:993
std::string ordering(void) const
Returns ordering parameter.
Definition GHealpix.cpp:511
int ring2nest(const int &pix) const
Converts pixel number in ring indexing scheme to nested scheme.
virtual bool compare(const GSkyProjection &proj) const
Returns true if argument is identical.
Definition GHealpix.cpp:914
const int & nside(void) const
Returns number of divisions of the side of each base pixel.
Definition GHealpix.hpp:207
GVector set_z_phi(const double &z, const double &phi) const
Return 3D vector.
GSkyDir loc2dir(const double &z, const double &phi) const
Convert local coordinate into sky direction.
void pix2ang_nest(int ipix, double *theta, double *phi) const
Convert pixel index to (theta,phi) angles for nested ordering.
double max_pixrad(void) const
Return maximum angular distance between pixel centre and corners.
Definition GHealpix.cpp:778
int m_npface
Definition GHealpix.hpp:127
void init_members(void)
Initialise class members.
Definition GHealpix.cpp:846
virtual std::string print(const GChatter &chatter=NORMAL) const
Print WCS information.
Definition GHealpix.cpp:802
virtual GHealpix * clone(void) const
Clone instance.
Definition GHealpix.cpp:273
void xyf2loc(const double &x, const double &y, const int &face, double *z, double *phi) const
Convert (x,y,f) tuple into local coordinates.
const int & npix(void) const
Returns number of pixels.
Definition GHealpix.hpp:196
virtual void read(const GFitsHDU &hdu)
Read Healpix definition from FITS header.
Definition GHealpix.cpp:287
virtual GSkyDir pix2dir(const GSkyPixel &pixel) const
Returns sky direction of pixel.
Definition GHealpix.cpp:384
unsigned int isqrt(unsigned int arg) const
Integer n that fulfills n*n <= arg < (n+1)*(n+1)
double m_fact2
Definition GHealpix.hpp:133
void pix2xy(const int &ipix, int *x, int *y) const
Convert pixel index to (x,y) coordinate.
int nest2ring(const int &pix) const
Converts pixel number in nested indexing scheme to ring scheme.
int m_nside
Number of divisions of each base pixel (1-8192)
Definition GHealpix.hpp:126
void get_ring_info(const int &ring, int *startpix, int *ringpix, bool *shifted) const
Returns useful information about a given ring of the projection.
void ring2xyf(const int &pix, int *ix, int *iy, int *face) const
Convert pixel number in ring scheme to (x,y,face) tuple.
void pix2ang_ring(int ipix, double *theta, double *phi) const
Convert pixel index to (theta,phi) angles for ring ordering.
Sky direction class.
Definition GSkyDir.hpp:62
Sky directions container class.
Definition GSkyDirs.hpp:49
Sky map pixel class.
Definition GSkyPixel.hpp:74
Abstract sky projection base class.
virtual std::string coordsys(void) const
Returns coordinate system.
Vector class.
Definition GVector.hpp:46