Commit 4f199898170cf8bc0c21bf11cb44e9a3cf859ce7
1 parent
f5618c95
Add sky map example code.
Showing
2 changed files
with
77 additions
and
0 deletions
examples/cpp/createskymap/Makefile
0 → 100644
examples/cpp/createskymap/createskymap.cpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * createskymap.cpp - Create sky map * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2013 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 createskymap.cpp | |
| 23 | + * @brief Create sky map | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | + */ | |
| 26 | + | |
| 27 | +/* __ Includes ___________________________________________________________ */ | |
| 28 | +#include "GammaLib.hpp" | |
| 29 | + | |
| 30 | + | |
| 31 | +/***********************************************************************//** | |
| 32 | + * @brief Create sky map | |
| 33 | + * | |
| 34 | + * This code illustrates the creation of a sky map. | |
| 35 | + ***************************************************************************/ | |
| 36 | +int main(void) { | |
| 37 | + | |
| 38 | + // Create a SNR shell model. The shell is centred on RA=0.3 deg and | |
| 39 | + // Dec=0.1 deg. The shell has an inner radius of 0.5 deg and a width | |
| 40 | + // of 0.1 deg. | |
| 41 | + GSkyDir centre; | |
| 42 | + centre.radec_deg(0.3, 0.1); | |
| 43 | + GModelSpatialRadialShell model(centre, 0.5, 0.1); | |
| 44 | + | |
| 45 | + // Create an empty sky map in celestial coordinates using a cartesian | |
| 46 | + // projection. The image is centred on RA=Dec=0, has a bin size of | |
| 47 | + // 0.01 degrees and 300 pixels in RA and Dec | |
| 48 | + double ra(0.0); | |
| 49 | + double dec(0.0); | |
| 50 | + double binsz(0.01); | |
| 51 | + int npix(300); | |
| 52 | + GSkymap image("CAR", "CEL", ra, dec, -binsz, binsz, npix, npix, 1); | |
| 53 | + | |
| 54 | + // Fill the sky map with the model image | |
| 55 | + GEnergy energy; // Dummy (not relevant as model is not energy dependent) | |
| 56 | + GTime time; // Dummy (not relevant as model is not time dependent) | |
| 57 | + for (int index = 0; index < image.npix(); ++index) { | |
| 58 | + GSkyDir dir = image.inx2dir(index); // sky coordinate of pixel | |
| 59 | + double theta = centre.dist(dir); // distance in radians | |
| 60 | + image(index) = model.eval(theta, energy, time); | |
| 61 | + } | |
| 62 | + | |
| 63 | + // Save the image to a FITS file | |
| 64 | + image.save("my_sky_map.fits", true); | |
| 65 | + | |
| 66 | + // Exit | |
| 67 | + return 0; | |
| 68 | +} | |
| 69 | + | ... | ... |