GSkymap.hpp
11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/***************************************************************************
* GSkymap.hpp - Sky map class *
* ----------------------------------------------------------------------- *
* copyright (C) 2010-2014 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
/**
* @file GSkymap.hpp
* @brief Sky map class definition
* @author Juergen Knoedlseder
*/
#ifndef GSKYMAP_HPP
#define GSKYMAP_HPP
/* __ Includes ___________________________________________________________ */
#include <string>
#include "GBase.hpp"
#include "GSkyDir.hpp"
#include "GSkyPixel.hpp"
#include "GSkyProjection.hpp"
#include "GFits.hpp"
#include "GFitsTable.hpp"
#include "GFitsBinTable.hpp"
#include "GFitsImage.hpp"
#include "GFitsImageDouble.hpp"
#include "GMatrix.hpp"
#include "GVector.hpp"
/***********************************************************************//**
* @class GSkymap
*
* @brief Sky map class
*
* This class implements a sky maps. Sky maps are collections of pixels that
* define a quantity as function of pixel location. Typical quantities are
* gamma-ray intensities, but may also be the number of measured counts.
*
* Sky map pixels may be arranged in a 2-dimensional grid or in a linear
* 1-dimensional sequence. The link between pixel index and sky direction
* on the celestial sphere is established using a projection, implemented
* by the GSkyProjection class. 2-dimensional grids are represented by
* World Coordinate Systems. All World Coordinate Systems derive from GWcs
* and are registered in GWcsRegistry. The Healpix pixelisation, implemented
* by the GHealpix class, is the only 1-dimensional grid that is so far
* available.
*
* Sky map pixels may be accessed by their linear index, by pixel or by
* sky direction. While the index and pixel access return the sky map value
* at the pixel centre, the sky direction access operator performs an
* interpolation to the exact sky direction.
*
* Conversion methods exist to convert between the linear index, the pixel
* and the sky direction:
*
* GSkyPixel pixel = map.inx2pix(index); // Index to pixel
* GSkyDir dir = map.inx2dir(index); // Index to sky direction
* GSkyDir dir = map.pix2dir(pixel); // Pixel to sky direction
* int index = map.pix2inx(pixel); // Pixel to index
* int index = map.dir2inx(dir); // Sky direction to index
* GSkyPixel pixel = map.dir2pix(dir); // Sky direction to pixel
*
***************************************************************************/
class GSkymap : public GBase {
friend GSkymap sqrt(const GSkymap& map);
public:
// Constructors and destructors
GSkymap(void);
explicit GSkymap(const std::string& filename);
explicit GSkymap(const std::string& coords,
const int& nside,
const std::string& order,
const int& nmaps = 1);
explicit GSkymap(const std::string& wcs,
const std::string& coords,
const double& x,
const double& y,
const double& dx,
const double& dy,
const int& nx,
const int& ny,
const int& nmaps = 1);
GSkymap(const GSkymap& map);
virtual ~GSkymap(void);
// Operators
GSkymap& operator=(const GSkymap& map);
GSkymap& operator=(const double& value);
GSkymap& operator+=(const GSkymap& map);
GSkymap& operator-=(const GSkymap& map);
GSkymap& operator*=(const GSkymap& map);
GSkymap& operator/=(const GSkymap& map);
double& operator()(const int& index, const int& map = 0);
const double& operator()(const int& index, const int& map = 0) const;
double& operator()(const GSkyPixel& pixel, const int& map = 0);
const double& operator()(const GSkyPixel& pixel, const int& map = 0) const;
double operator()(const GSkyDir& dir, const int& map = 0) const;
// Methods
void clear(void);
GSkymap* clone(void) const;
std::string classname(void) const;
const int& npix(void) const;
const int& nx(void) const;
const int& ny(void) const;
const int& nmaps(void) const;
GSkyPixel inx2pix(const int& index) const;
GSkyDir inx2dir(const int& index) const;
GSkyDir pix2dir(const GSkyPixel& pixel) const;
int pix2inx(const GSkyPixel& pixel) const;
int dir2inx(const GSkyDir& dir) const;
GSkyPixel dir2pix(const GSkyDir& dir) const;
double solidangle(const int& index) const;
double solidangle(const GSkyPixel& pixel) const;
bool contains(const GSkyDir& dir) const;
bool contains(const GSkyPixel& pixel) const;
const GSkyProjection* projection(void) const;
void projection(const GSkyProjection& proj);
const double* pixels(void) const;
void stack_maps(void);
void load(const std::string& filename);
void save(const std::string& filename, bool clobber = false) const;
void read(const GFitsHDU& hdu);
void write(GFits& file) const;
std::string print(const GChatter& chatter = NORMAL) const;
private:
// Private methods
void init_members(void);
void alloc_pixels(void);
void copy_members(const GSkymap& map);
void free_members(void);
void set_wcs(const std::string& wcs, const std::string& coords,
const double& crval1, const double& crval2,
const double& crpix1, const double& crpix2,
const double& cdelt1, const double& cdelt2,
const GMatrix& cd, const GVector& pv2);
void read_healpix(const GFitsTable& table);
void read_wcs(const GFitsImage& image);
void alloc_wcs(const GFitsImage& image);
GFitsBinTable* create_healpix_hdu(void) const;
GFitsImageDouble* create_wcs_hdu(void) const;
// Private data area
int m_num_pixels; //!< Number of pixels (used for pixel allocation)
int m_num_maps; //!< Number of maps (used for pixel allocation)
int m_num_x; //!< Number of pixels in x direction (only 2D)
int m_num_y; //!< Number of pixels in y direction (only 2D)
GSkyProjection* m_proj; //!< Pointer to sky projection
double* m_pixels; //!< Pointer to skymap pixels
// Computation cache
mutable bool m_hascache; //!< Cache is valid
mutable bool m_contained; //!< Direction contained in map
mutable GSkyDir m_last_dir; //!< Last sky direction
mutable int m_inx1; //!< Interpolation index 1
mutable int m_inx2; //!< Interpolation index 2
mutable int m_inx3; //!< Interpolation index 3
mutable int m_inx4; //!< Interpolation index 4
mutable double m_wgt1; //!< Interpolation weight 1
mutable double m_wgt2; //!< Interpolation weight 2
mutable double m_wgt3; //!< Interpolation weight 3
mutable double m_wgt4; //!< Interpolation weight 4
};
/***********************************************************************//**
* @brief Return class name
*
* @return String containing the class name ("GSkymap").
***************************************************************************/
inline
std::string GSkymap::classname(void) const
{
return ("GSkymap");
}
/***********************************************************************//**
* @brief Returns number of pixels
*
* @return Number of pixels in one sky map.
*
* Returns the number of pixels in one sky map.
***************************************************************************/
inline
const int& GSkymap::npix(void) const
{
return m_num_pixels;
}
/***********************************************************************//**
* @brief Returns number of pixels in x coordinate
*
* @return Number of pixels in the X direction.
*
* Returns the number of pixels in the X direction. If the sky map is a
* one dimensional array (which is the case for the Healpix projection),
* the method returns 0.
***************************************************************************/
inline
const int& GSkymap::nx(void) const
{
return m_num_x;
}
/***********************************************************************//**
* @brief Returns number of pixels in y coordinate
*
* @return Number of pixels in the Y direction.
*
* Returns the number of pixels in the Y direction. If the sky map is a
* one dimensional array (which is the case for the Healpix projection),
* the method returns 0.
***************************************************************************/
inline
const int& GSkymap::ny(void) const
{
return m_num_y;
}
/***********************************************************************//**
* @brief Returns number of maps
*
* @return Number of maps in the sky map object.
***************************************************************************/
inline
const int& GSkymap::nmaps(void) const
{
return m_num_maps;
}
/***********************************************************************//**
* @brief Returns pointer to sky projection
*
* @return Pointer to sky projection (NULL if no projection is defined).
***************************************************************************/
inline
const GSkyProjection* GSkymap::projection(void) const
{
return m_proj;
}
/***********************************************************************//**
* @brief Returns pointer to pixel data
*
* @return Pointer to pixel data.
***************************************************************************/
inline
const double* GSkymap::pixels(void) const
{
return m_pixels;
}
#endif /* GSKYMAP_HPP */