Commit 4485a86ff847bf6db41e451387bb12de804d145f
1 parent
1d494a96
Integrate code
Showing
13 changed files
with
305 additions
and
377 deletions
ChangeLog
NEWS
| 1 | -New Features and Important Changes in GammaLib 1.3.0 | 1 | +New Features and Important Changes in GammaLib 1.4.0 |
| 2 | 2 | ||
| 3 | -6 June 2017 | 3 | +6 July 2017 |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 1. Introduction | 6 | 1. Introduction |
| @@ -12,15 +12,7 @@ made since the last release of GammaLib. | @@ -12,15 +12,7 @@ made since the last release of GammaLib. | ||
| 12 | 2. Public interface modifications | 12 | 2. Public interface modifications |
| 13 | --------------------------------- | 13 | --------------------------------- |
| 14 | The following classes have been added: | 14 | The following classes have been added: |
| 15 | -- GPhases | ||
| 16 | -- GWcsGLS | ||
| 17 | -- GWcsSFL | ||
| 18 | -- GModelSpectralSmoothBrokenPlaw | ||
| 19 | -- GModelSpatialRadialProfile | ||
| 20 | -- GModelSpatialRadialProfileGauss | ||
| 21 | -- GModelSpatialRadialProfileDMBurkert | ||
| 22 | -- GModelSpatialRadialProfileDMEinasto | ||
| 23 | -- GModelSpatialRadialProfileDMZhao | 15 | +- n.a. |
| 24 | 16 | ||
| 25 | The following classes have been removed: | 17 | The following classes have been removed: |
| 26 | - n.a. | 18 | - n.a. |
| @@ -29,48 +21,14 @@ The following classes have been renamed: | @@ -29,48 +21,14 @@ The following classes have been renamed: | ||
| 29 | - n.a. | 21 | - n.a. |
| 30 | 22 | ||
| 31 | The following methods have been added: | 23 | The following methods have been added: |
| 32 | -- GEbounds::set(GEnergies&) | ||
| 33 | -- GEbounds::emin(int&, GEnergy&) | ||
| 34 | -- GEbounds::emax(int&, GEnergy&) | ||
| 35 | -- GEnergies::set(GEbounds&) | ||
| 36 | -- GFilename::type() | ||
| 37 | -- GMatrix::operator+(double&) | ||
| 38 | -- GMatrix::operator-(double&) | ||
| 39 | -- GMatrix::operator+=(double&) | ||
| 40 | -- GMatrix::operator-=(double&) | ||
| 41 | -- GMatrixSymmetric::operator+(double&) | ||
| 42 | -- GMatrixSymmetric::operator-(double&) | ||
| 43 | -- GMatrixSymmetric::operator+=(double&) | ||
| 44 | -- GMatrixSymmetric::operator-=(double&) | ||
| 45 | -- GMatrixSparse::operator+(double&) | ||
| 46 | -- GMatrixSparse::operator-(double&) | ||
| 47 | -- GMatrixSparse::operator+=(double&) | ||
| 48 | -- GMatrixSparse::operator-=(double&) | ||
| 49 | -- GCTAResponseIrf::rspname() | ||
| 50 | -- GCTARoi::contains(GCTAInstDir&) | ||
| 51 | -- GCTAEdisp2D::fetch() | ||
| 52 | -- GCTAAeff::ebounds() | ||
| 53 | -- GCTAAeff2D::ebounds() | ||
| 54 | -- GCTAAeffArf::ebounds() | ||
| 55 | -- GCTAAeffPerfTable::ebounds() | ||
| 56 | -- GCTAEventList::append_column(GFitsTableCol&) | ||
| 57 | -- GCTAEventList::has_phase(bool&) | ||
| 58 | -- GCTAEventList::has_phase() | ||
| 59 | -- GCTAEventList::has_detxy(bool&) | ||
| 60 | -- GCTAEventList::has_detxy() | ||
| 61 | -- GCTAEventList::has_mc_id(bool&) | ||
| 62 | -- GCTAEventList::has_mc_id() | ||
| 63 | -- GCTAEventList::set_mc_id_names(std::vector<int>&, std::vector<std::string>&) | ||
| 64 | -- GCTAEventAtom::mc_id(int&) | ||
| 65 | -- GCTAEventAtom::mc_id() | 24 | +- GSkyRegion::overlaps(GSkyRegions&) |
| 25 | +- GSkyMap::overlaps(GSkyRegion&) | ||
| 66 | 26 | ||
| 67 | The following methods have been removed: | 27 | The following methods have been removed: |
| 68 | -- GFitsTable::size() | 28 | +- n.a. |
| 69 | 29 | ||
| 70 | The following methods have been renamed: | 30 | The following methods have been renamed: |
| 71 | -- GFitsImage::size() => GFitsImage::npix() | ||
| 72 | -- GFitsHDU::size() => GFitsHDU::cards() | ||
| 73 | -- GFitsTableCol::length() => GFitsTableCol::nrows() | 31 | +- n.a. |
| 74 | 32 | ||
| 75 | The arguments for the following methods have been changed: | 33 | The arguments for the following methods have been changed: |
| 76 | - n.a. | 34 | - n.a. |
| @@ -81,19 +39,7 @@ The return value of the following methods has been changed: | @@ -81,19 +39,7 @@ The return value of the following methods has been changed: | ||
| 81 | 39 | ||
| 82 | 3. Configuration | 40 | 3. Configuration |
| 83 | ----------------- | 41 | ----------------- |
| 84 | -The Python unit tests now raise exceptions instead of exiting with a non- | ||
| 85 | -zero return code so that the user is not thrown out of Python after calling | ||
| 86 | -gammalib.test() (#1983). | ||
| 87 | - | ||
| 88 | -If the code originates from the Git repository the configuration now switches | ||
| 89 | -to developer mode which implies that the Python bindings are always built. | ||
| 90 | -This solves the problem that occured for developers that could not get rid | ||
| 91 | -of existing Python wrappers, even if they modified the Python interface | ||
| 92 | -(#1985). | ||
| 93 | - | ||
| 94 | -The shared libraries needed by the Python wrappers are now copied into a | ||
| 95 | -build/gammalib directory for unit testing instead of creating a symbolic | ||
| 96 | -link since on shared VM file systems symbolic links may not work (#1987). | 42 | +None |
| 97 | 43 | ||
| 98 | 44 | ||
| 99 | 4. Application module | 45 | 4. Application module |
| @@ -108,57 +54,17 @@ None | @@ -108,57 +54,17 @@ None | ||
| 108 | 54 | ||
| 109 | 6. FITS I/O Interface | 55 | 6. FITS I/O Interface |
| 110 | --------------------- | 56 | --------------------- |
| 111 | -FITS image type conversion constructors have been added to convert a FITS | ||
| 112 | -image of any type into a specific storage class (#1986). | ||
| 113 | - | ||
| 114 | -A map between header card keywords and header card pointers was added to | ||
| 115 | -GFitsHeader to speed up the access of FITS header cards (#2120). | ||
| 116 | - | ||
| 117 | -The GFitsImage::size() method has been renamed to GFitsImage::npix() since | ||
| 118 | -the size() method overloaded the GFitsHDU::size() method (#1858). | ||
| 119 | - | ||
| 120 | -The GFitsTable::size() method has been removed since the meaning of the | ||
| 121 | -method was ambiguous. It returned the number of table columns, but the | ||
| 122 | -GFitsTable::ncols() does exactly the same thing, hence the method was | ||
| 123 | -redundant (#1857). | ||
| 124 | - | ||
| 125 | -The GFitsHDU::size() method has been renamed to GFitsHDU::cards() since the | ||
| 126 | -meaning of the size() method was not clear (#1859). | ||
| 127 | - | ||
| 128 | -The GFitsTableCol::length() method was renamed to GFitsTableCol::nrows() | ||
| 129 | -to clarify the meaning of thie method (#1860). | 57 | +None |
| 130 | 58 | ||
| 131 | 59 | ||
| 132 | 7. Linear algebra module | 60 | 7. Linear algebra module |
| 133 | ------------------------ | 61 | ------------------------ |
| 134 | -Add operators for addition and subtraction of scalars to all matrix classes | ||
| 135 | -(#1990). | 62 | +None |
| 136 | 63 | ||
| 137 | 64 | ||
| 138 | 8. Model module | 65 | 8. Model module |
| 139 | --------------- | 66 | --------------- |
| 140 | -The GModelSpectralNodes class now throws an exception if the energy or | ||
| 141 | -intensity of a node is set to a non-positive value (#990). | ||
| 142 | - | ||
| 143 | -The GModelSpectralSmoothBrokenPlaw class that implements a smoothly broken | ||
| 144 | -power law spectrum has been added (#1948). | ||
| 145 | - | ||
| 146 | -The scale of the composite spatial models can now be fitted by adding the | ||
| 147 | -free_scale="1" attribute to the XML file (#1992). | ||
| 148 | - | ||
| 149 | -Add GModelSpatialRadialProfile class to handle arbitrary radial profiles. | ||
| 150 | -The method deals with pre-computation and normalization of the profiles, | ||
| 151 | -and implements the eval() and mc() methods. The following derived classes | ||
| 152 | -have been implemented: | ||
| 153 | -- GModelSpatialRadialProfileGauss: radial Gaussian profile | ||
| 154 | -- GModelSpatialRadialProfileDMBurkert: Burkert Dark Matter profile | ||
| 155 | -- GModelSpatialRadialProfileDMEinasto: Einasto Dark Matter profile | ||
| 156 | -- GModelSpatialRadialProfileDMZhao: Zhao Dark matter profile | ||
| 157 | -Please note that these models are not deeply tested so far and the code | ||
| 158 | -and interface is still subject to change (#1520). | ||
| 159 | - | ||
| 160 | -The names of spatial model parameters are now always set to RA/DEC even if | ||
| 161 | -the input parameters were GLON/GLAT (#2113). | 67 | +None |
| 162 | 68 | ||
| 163 | 69 | ||
| 164 | 9. Numerics module | 70 | 9. Numerics module |
| @@ -168,39 +74,27 @@ None | @@ -168,39 +74,27 @@ None | ||
| 168 | 74 | ||
| 169 | 10. Observation module | 75 | 10. Observation module |
| 170 | ---------------------- | 76 | ---------------------- |
| 171 | -A set() method has been added to GEbounds and GEnergies to allow converting | ||
| 172 | -energy boundaries into an energy container and vice versa. In addition, | ||
| 173 | -conversion constructors have been added (#1977). | ||
| 174 | - | ||
| 175 | -The GEbounds::set_lin() and GEbounds::set_log() method now throw exceptions | ||
| 176 | -if the minimum energy is larger than the maximum energy. In addition, the | ||
| 177 | -GEbounds::set_log() method throws an exception if either the minimum or | ||
| 178 | -maximum energy are zero. Furthermore, the methods clear the energy boundaries | ||
| 179 | -if the requested number of intervals is non-zero (#1989). | ||
| 180 | - | ||
| 181 | -The GPhases class has been added to handle phase selections of events (#1996). | 77 | +None |
| 182 | 78 | ||
| 183 | 79 | ||
| 184 | 11. Optimization module | 80 | 11. Optimization module |
| 185 | ----------------------- | 81 | ----------------------- |
| 186 | -The Levenberg-Marquardt optimiser convergence criterion is now scaled with the | ||
| 187 | -step size so that a small step size does no longer lead to a stop of the | ||
| 188 | -iterative process (#2022). | 82 | +None |
| 189 | 83 | ||
| 190 | 84 | ||
| 191 | 12. Sky module | 85 | 12. Sky module |
| 192 | -------------- | 86 | -------------- |
| 193 | -The GWcsGLS and GWcsSFL classes have been added to support the GLS and SFL | ||
| 194 | -World Coordinate System projections (#1851). | 87 | +A GSkyRegions::overlaps(GSkyRegions&) method has been added to check the |
| 88 | +overlap of any region in a given container with any region in another | ||
| 89 | +container (#1980). | ||
| 195 | 90 | ||
| 196 | -The GWcs base class now also supports CD keywords instead of CDELT keywords | ||
| 197 | -(#1951). | 91 | +A GSkyMap::overlaps(GSkyRegions&) method has been added to check the overlap |
| 92 | +of a sky region with a sky map (#1980). | ||
| 198 | 93 | ||
| 199 | 94 | ||
| 200 | 13. Support module | 95 | 13. Support module |
| 201 | ------------------ | 96 | ------------------ |
| 202 | -A GFilename::type() method has been added that returns the type of the file | ||
| 203 | -based on the file type extension (e.g. ".fits") (#1863). | 97 | +None |
| 204 | 98 | ||
| 205 | 99 | ||
| 206 | 14. XML module | 100 | 14. XML module |
| @@ -235,62 +129,10 @@ None | @@ -235,62 +129,10 @@ None | ||
| 235 | 129 | ||
| 236 | 20. CTA interface | 130 | 20. CTA interface |
| 237 | ----------------- | 131 | ----------------- |
| 238 | -Correct the containment radius computation in GCTAPsf2D (#1876). | ||
| 239 | - | ||
| 240 | -The GCTAResponseIrf::rspname() method has been added that returns the name | ||
| 241 | -of the response function (attribute m_rspname). | ||
| 242 | - | ||
| 243 | -Do no longer interpret a CTA calibration database as a file path in the | ||
| 244 | -GCTAResponseIrf::read() method (#1969). | ||
| 245 | - | ||
| 246 | -Add GCTARoi::contains() method that checks whether an instrument direction | ||
| 247 | -is contained within the region of interest. | ||
| 248 | - | ||
| 249 | -Lazy loading of the energy dispersion in GCTAEdisp2D has been implemented by | ||
| 250 | -adding a fetch() method to the class. Now the energy dispersion is only loaded | ||
| 251 | -when needed, for example for function evaluation or Monte Carlo sampling (#1940). | ||
| 252 | - | ||
| 253 | -The GCTAEdisp2D::compute_ebounds_src() method now loops over the migration to | ||
| 254 | -enhance the precision in the true energy boundaries that are returned by this | ||
| 255 | -method. In addition, the validity range of the table is now stored in members | ||
| 256 | -of the class, and a non-zero energy dispersion is only returned for valid | ||
| 257 | -elements of the response table. | ||
| 258 | - | ||
| 259 | -An GCTAAeff::ebounds() method has been added to the abstract interface for | ||
| 260 | -effective area responses to return the valid energy range of the effective | ||
| 261 | -area (#1989). | ||
| 262 | - | ||
| 263 | -The GCTAModelAeffBackground::mc() could get stuck in the rejection loop if the | ||
| 264 | -effective area returned is always zero. A counter has been added that leads to | ||
| 265 | -the exit of the loop in case that 1000 subsequent zero values are returned | ||
| 266 | -(#1988). | ||
| 267 | - | ||
| 268 | -A GCTAEventList::append_column() method has been added to allow appending of | ||
| 269 | -FITS columns to an event list. The method checks whether the length of the | ||
| 270 | -FITS column is compatible with the number of events that are present in the | ||
| 271 | -event list (#1991). | ||
| 272 | - | ||
| 273 | -Add GCTAEventList::has_phase() and GCTAEventList::has_detxy() getter and setter | ||
| 274 | -methods to manipulate the event list information flags (#1982). | ||
| 275 | - | ||
| 276 | -Add GCTAEventList::has_mc_id() and GCTAEventAtom::mc_id() getter and setter methods | ||
| 277 | -to set the Monte Carlo identifier of a given event. This allows to attribute a | ||
| 278 | -Monte Carlo simulated event to a specific model (#1483). | ||
| 279 | - | ||
| 280 | -Add GCTAEventList::set_mc_id_names() method to store Monte Carlo metadata into an | ||
| 281 | -event list and to write this information into the FITS header. Furthermore, the | ||
| 282 | -information is read back when loading an event list (#1483). | ||
| 283 | - | ||
| 284 | -The loading and saving of CTA response cubes was put into an OpenMP critial zone to | ||
| 285 | -avoid FITS file pointer exceptions (#2021). | ||
| 286 | - | ||
| 287 | -The CTA background template HDUCLAS2 was changed from "BGD" to "BKG". Both strings | ||
| 288 | -are supported by GammaLib. | ||
| 289 | - | ||
| 290 | -The maximum radius of the King PSF has been increased from 0.7 to 2 degrees to cope | ||
| 291 | -with some extreme cases. Now also the maximum PSF radius is computed for a given | ||
| 292 | -energy so that if the PSF is smaller than the maximum radius of 2 degrees a smaller | ||
| 293 | -region of interest will be used for the computation (#2112). | 132 | +The GCTACubeExposure::fill_cube(), GCTACubePsf::fill_cube(), |
| 133 | +GCTACubeEdisp::fill_cube(), and GCTACubeBackground::fill() methods now | ||
| 134 | +exclude any observations from the filling for which the RoI does not | ||
| 135 | +overlap with the cube definition (#1980). | ||
| 294 | 136 | ||
| 295 | 137 | ||
| 296 | 21. COMPTEL interface | 138 | 21. COMPTEL interface |
include/GSkyMap.hpp
| @@ -35,7 +35,6 @@ | @@ -35,7 +35,6 @@ | ||
| 35 | #include "GSkyPixel.hpp" | 35 | #include "GSkyPixel.hpp" |
| 36 | #include "GSkyProjection.hpp" | 36 | #include "GSkyProjection.hpp" |
| 37 | #include "GBilinear.hpp" | 37 | #include "GBilinear.hpp" |
| 38 | -#include "GSkyRegionCircle.hpp" | ||
| 39 | 38 | ||
| 40 | /* __ Forward declarations _______________________________________________ */ | 39 | /* __ Forward declarations _______________________________________________ */ |
| 41 | class GFilename; | 40 | class GFilename; |
| @@ -47,6 +46,8 @@ class GFitsImage; | @@ -47,6 +46,8 @@ class GFitsImage; | ||
| 47 | class GFitsImageDouble; | 46 | class GFitsImageDouble; |
| 48 | class GMatrix; | 47 | class GMatrix; |
| 49 | class GVector; | 48 | class GVector; |
| 49 | +class GSkyRegion; | ||
| 50 | +class GSkyRegionCircle; | ||
| 50 | 51 | ||
| 51 | 52 | ||
| 52 | /***********************************************************************//** | 53 | /***********************************************************************//** |
| @@ -159,9 +160,9 @@ public: | @@ -159,9 +160,9 @@ public: | ||
| 159 | double flux(const GSkyPixel& pixel, const int& map = 0) const; | 160 | double flux(const GSkyPixel& pixel, const int& map = 0) const; |
| 160 | double solidangle(const int& index) const; | 161 | double solidangle(const int& index) const; |
| 161 | double solidangle(const GSkyPixel& pixel) const; | 162 | double solidangle(const GSkyPixel& pixel) const; |
| 162 | - bool overlaps(const GSkyRegionCircle& reg) const; | ||
| 163 | bool contains(const GSkyDir& dir) const; | 163 | bool contains(const GSkyDir& dir) const; |
| 164 | bool contains(const GSkyPixel& pixel) const; | 164 | bool contains(const GSkyPixel& pixel) const; |
| 165 | + bool overlaps(const GSkyRegion& region) const; | ||
| 165 | const GSkyProjection* projection(void) const; | 166 | const GSkyProjection* projection(void) const; |
| 166 | void projection(const GSkyProjection& proj); | 167 | void projection(const GSkyProjection& proj); |
| 167 | const double* pixels(void) const; | 168 | const double* pixels(void) const; |
| @@ -196,6 +197,7 @@ private: | @@ -196,6 +197,7 @@ private: | ||
| 196 | const GSkyDir& dir3) const; | 197 | const GSkyDir& dir3) const; |
| 197 | double solidangle(const GSkyDir& dir1, const GSkyDir& dir2, | 198 | double solidangle(const GSkyDir& dir1, const GSkyDir& dir2, |
| 198 | const GSkyDir& dir3, const GSkyDir& dir4) const; | 199 | const GSkyDir& dir3, const GSkyDir& dir4) const; |
| 200 | + bool overlaps_circle(const GSkyRegionCircle& region) const; | ||
| 199 | bool is_healpix(const GFitsHDU& hdu) const; | 201 | bool is_healpix(const GFitsHDU& hdu) const; |
| 200 | bool is_wcs(const GFitsHDU& hdu) const; | 202 | bool is_wcs(const GFitsHDU& hdu) const; |
| 201 | 203 |
include/GSkyRegions.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GSkyRegions.hpp - Sky region container class * | 2 | * GSkyRegions.hpp - Sky region container class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2016 by Pierrick Martin * | 4 | + * copyright (C) 2013-2017 by Pierrick Martin * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -83,7 +83,7 @@ public: | @@ -83,7 +83,7 @@ public: | ||
| 83 | void reserve(const int& num); | 83 | void reserve(const int& num); |
| 84 | void extend(const GSkyRegions& regions); | 84 | void extend(const GSkyRegions& regions); |
| 85 | bool contains(const GSkyDir& dir) const; | 85 | bool contains(const GSkyDir& dir) const; |
| 86 | - bool overlaps(const GSkyRegion& reg) const; | 86 | + bool overlaps(const GSkyRegion& region) const; |
| 87 | bool overlaps(const GSkyRegions& regions) const; | 87 | bool overlaps(const GSkyRegions& regions) const; |
| 88 | void load(const GFilename& filename); | 88 | void load(const GFilename& filename); |
| 89 | void save(const GFilename& filename) const; | 89 | void save(const GFilename& filename) const; |
inst/cta/src/GCTACubeBackground.cpp
| @@ -32,15 +32,16 @@ | @@ -32,15 +32,16 @@ | ||
| 32 | #include "GException.hpp" | 32 | #include "GException.hpp" |
| 33 | #include "GMath.hpp" | 33 | #include "GMath.hpp" |
| 34 | #include "GRan.hpp" | 34 | #include "GRan.hpp" |
| 35 | +#include "GLog.hpp" | ||
| 35 | #include "GFits.hpp" | 36 | #include "GFits.hpp" |
| 36 | #include "GFitsBinTable.hpp" | 37 | #include "GFitsBinTable.hpp" |
| 37 | #include "GObservations.hpp" | 38 | #include "GObservations.hpp" |
| 39 | +#include "GSkyRegionCircle.hpp" | ||
| 38 | #include "GCTAEventCube.hpp" | 40 | #include "GCTAEventCube.hpp" |
| 39 | #include "GCTAObservation.hpp" | 41 | #include "GCTAObservation.hpp" |
| 40 | #include "GCTARoi.hpp" | 42 | #include "GCTARoi.hpp" |
| 41 | #include "GCTAInstDir.hpp" | 43 | #include "GCTAInstDir.hpp" |
| 42 | #include "GCTACubeBackground.hpp" | 44 | #include "GCTACubeBackground.hpp" |
| 43 | -#include "GLog.hpp" | ||
| 44 | 45 | ||
| 45 | /* __ Method name definitions ____________________________________________ */ | 46 | /* __ Method name definitions ____________________________________________ */ |
| 46 | #define G_READ "GCTACubeBackground::read(GFits&)" | 47 | #define G_READ "GCTACubeBackground::read(GFits&)" |
| @@ -405,16 +406,17 @@ void GCTACubeBackground::fill(const GObservations& obs, GLog* log) | @@ -405,16 +406,17 @@ void GCTACubeBackground::fill(const GObservations& obs, GLog* log) | ||
| 405 | GSkyRegionCircle obs_reg(roi.centre().dir(), roi.radius()); | 406 | GSkyRegionCircle obs_reg(roi.centre().dir(), roi.radius()); |
| 406 | if (!m_cube.overlaps(obs_reg)) { | 407 | if (!m_cube.overlaps(obs_reg)) { |
| 407 | if (log != NULL) { | 408 | if (log != NULL) { |
| 408 | - *log << "Skipping "; | 409 | + *log << "Skipping unbinned "; |
| 409 | *log << cta->instrument(); | 410 | *log << cta->instrument(); |
| 410 | *log << " observation "; | 411 | *log << " observation "; |
| 411 | *log << "\"" << cta->name() << "\""; | 412 | *log << "\"" << cta->name() << "\""; |
| 412 | - *log << " (id=" << cta->id() << ") as it lies outside the cube"; | 413 | + *log << " (id=" << cta->id() << ") since it does not overlap "; |
| 414 | + *log << "with the background cube."; | ||
| 413 | *log << std::endl; | 415 | *log << std::endl; |
| 414 | } | 416 | } |
| 415 | continue; | 417 | continue; |
| 416 | } // endif: m_cube overlaps observation | 418 | } // endif: m_cube overlaps observation |
| 417 | - | 419 | + |
| 418 | // Announce observation usage | 420 | // Announce observation usage |
| 419 | if (log != NULL) { | 421 | if (log != NULL) { |
| 420 | *log << "Including "; | 422 | *log << "Including "; |
| @@ -423,7 +425,7 @@ void GCTACubeBackground::fill(const GObservations& obs, GLog* log) | @@ -423,7 +425,7 @@ void GCTACubeBackground::fill(const GObservations& obs, GLog* log) | ||
| 423 | *log << "\" (id=" << cta->id() << ")"; | 425 | *log << "\" (id=" << cta->id() << ")"; |
| 424 | *log << " in background cube computation." << std::endl; | 426 | *log << " in background cube computation." << std::endl; |
| 425 | } | 427 | } |
| 426 | - | 428 | + |
| 427 | // Set GTI of actual observations as the GTI of the event cube | 429 | // Set GTI of actual observations as the GTI of the event cube |
| 428 | eventcube.gti(cta->gti()); | 430 | eventcube.gti(cta->gti()); |
| 429 | 431 |
inst/cta/src/GCTACubeEdisp.cpp
| @@ -35,6 +35,7 @@ | @@ -35,6 +35,7 @@ | ||
| 35 | #include "GFitsImage.hpp" | 35 | #include "GFitsImage.hpp" |
| 36 | #include "GFitsTable.hpp" | 36 | #include "GFitsTable.hpp" |
| 37 | #include "GObservations.hpp" | 37 | #include "GObservations.hpp" |
| 38 | +#include "GSkyRegionCircle.hpp" | ||
| 38 | #include "GCTACubeEdisp.hpp" | 39 | #include "GCTACubeEdisp.hpp" |
| 39 | #include "GCTAObservation.hpp" | 40 | #include "GCTAObservation.hpp" |
| 40 | #include "GCTAResponseIrf.hpp" | 41 | #include "GCTAResponseIrf.hpp" |
| @@ -866,20 +867,9 @@ void GCTACubeEdisp::fill_cube(const GCTAObservation& obs, | @@ -866,20 +867,9 @@ void GCTACubeEdisp::fill_cube(const GCTAObservation& obs, | ||
| 866 | "to specify an RoI for this observation."; | 867 | "to specify an RoI for this observation."; |
| 867 | throw GException::invalid_value(G_FILL_CUBE, msg); | 868 | throw GException::invalid_value(G_FILL_CUBE, msg); |
| 868 | } | 869 | } |
| 869 | - | ||
| 870 | - // Make sure the observation falls within the bounds of the cube | ||
| 871 | - GSkyRegionCircle obs_reg(roi.centre().dir(), roi.radius()); | ||
| 872 | - if (!m_cube.overlaps(obs_reg)) { | ||
| 873 | - if (log != NULL) { | ||
| 874 | - *log << "Skipping unbinned "; | ||
| 875 | - *log << obs.instrument(); | ||
| 876 | - *log << " observation "; | ||
| 877 | - *log << "\"" << obs.name() << "\""; | ||
| 878 | - *log << " (id=" << obs.id() << ") which does not overlap Edisp cube."; | ||
| 879 | - *log << std::endl; | ||
| 880 | - } | ||
| 881 | - return; | ||
| 882 | - } | 870 | + |
| 871 | + // Convert RoI into a circular region for overlap checking | ||
| 872 | + GSkyRegionCircle roi_reg(roi.centre().dir(), roi.radius()); | ||
| 883 | 873 | ||
| 884 | // Extract response from observation | 874 | // Extract response from observation |
| 885 | const GCTAResponseIrf* rsp = dynamic_cast<const GCTAResponseIrf*> | 875 | const GCTAResponseIrf* rsp = dynamic_cast<const GCTAResponseIrf*> |
| @@ -915,6 +905,19 @@ void GCTACubeEdisp::fill_cube(const GCTAObservation& obs, | @@ -915,6 +905,19 @@ void GCTACubeEdisp::fill_cube(const GCTAObservation& obs, | ||
| 915 | } | 905 | } |
| 916 | } | 906 | } |
| 917 | 907 | ||
| 908 | + // Skip observation if observation is outside the bounds of the cube | ||
| 909 | + else if (!m_cube.overlaps(roi_reg)) { | ||
| 910 | + if (log != NULL) { | ||
| 911 | + *log << "Skipping unbinned "; | ||
| 912 | + *log << obs.instrument(); | ||
| 913 | + *log << " observation "; | ||
| 914 | + *log << "\"" << obs.name() << "\""; | ||
| 915 | + *log << " (id=" << obs.id() << ") since it does not overlap "; | ||
| 916 | + *log << "with the energy dispersion cube."; | ||
| 917 | + *log << std::endl; | ||
| 918 | + } | ||
| 919 | + } | ||
| 920 | + | ||
| 918 | // ... otherwise continue | 921 | // ... otherwise continue |
| 919 | else { | 922 | else { |
| 920 | 923 |
inst/cta/src/GCTACubeExposure.cpp
| @@ -32,6 +32,7 @@ | @@ -32,6 +32,7 @@ | ||
| 32 | #include "GMath.hpp" | 32 | #include "GMath.hpp" |
| 33 | #include "GLog.hpp" | 33 | #include "GLog.hpp" |
| 34 | #include "GObservations.hpp" | 34 | #include "GObservations.hpp" |
| 35 | +#include "GSkyRegionCircle.hpp" | ||
| 35 | #include "GCTACubeExposure.hpp" | 36 | #include "GCTACubeExposure.hpp" |
| 36 | #include "GCTAObservation.hpp" | 37 | #include "GCTAObservation.hpp" |
| 37 | #include "GCTAResponseIrf.hpp" | 38 | #include "GCTAResponseIrf.hpp" |
| @@ -655,20 +656,9 @@ void GCTACubeExposure::fill_cube(const GCTAObservation& obs, GLog* log) | @@ -655,20 +656,9 @@ void GCTACubeExposure::fill_cube(const GCTAObservation& obs, GLog* log) | ||
| 655 | "to specify an RoI for this observation."; | 656 | "to specify an RoI for this observation."; |
| 656 | throw GException::invalid_value(G_FILL_CUBE, msg); | 657 | throw GException::invalid_value(G_FILL_CUBE, msg); |
| 657 | } | 658 | } |
| 658 | - | ||
| 659 | - // Check that the observation overlaps with the cube | ||
| 660 | - GSkyRegionCircle obs_reg(roi.centre().dir(), roi.radius()); | ||
| 661 | - if (!m_cube.overlaps(obs_reg)) { | ||
| 662 | - if (log != NULL) { | ||
| 663 | - *log << "Skipping unbinned "; | ||
| 664 | - *log << obs.instrument(); | ||
| 665 | - *log << " observation "; | ||
| 666 | - *log << "\"" << obs.name() << "\""; | ||
| 667 | - *log << " (id=" << obs.id() << ") "; | ||
| 668 | - *log << "which lies outside exposure cube"; | ||
| 669 | - *log << std::endl; | ||
| 670 | - } | ||
| 671 | - } | 659 | + |
| 660 | + // Convert RoI into a circular region for overlap checking | ||
| 661 | + GSkyRegionCircle roi_reg(roi.centre().dir(), roi.radius()); | ||
| 672 | 662 | ||
| 673 | // Extract response from observation | 663 | // Extract response from observation |
| 674 | const GCTAResponseIrf* rsp = dynamic_cast<const GCTAResponseIrf*> | 664 | const GCTAResponseIrf* rsp = dynamic_cast<const GCTAResponseIrf*> |
| @@ -693,6 +683,19 @@ void GCTACubeExposure::fill_cube(const GCTAObservation& obs, GLog* log) | @@ -693,6 +683,19 @@ void GCTACubeExposure::fill_cube(const GCTAObservation& obs, GLog* log) | ||
| 693 | } | 683 | } |
| 694 | } | 684 | } |
| 695 | 685 | ||
| 686 | + // Skip observation if observation is outside the bounds of the cube | ||
| 687 | + else if (!m_cube.overlaps(roi_reg)) { | ||
| 688 | + if (log != NULL) { | ||
| 689 | + *log << "Skipping unbinned "; | ||
| 690 | + *log << obs.instrument(); | ||
| 691 | + *log << " observation "; | ||
| 692 | + *log << "\"" << obs.name() << "\""; | ||
| 693 | + *log << " (id=" << obs.id() << ") since it does not overlap "; | ||
| 694 | + *log << "with the exposure cube."; | ||
| 695 | + *log << std::endl; | ||
| 696 | + } | ||
| 697 | + } | ||
| 698 | + | ||
| 696 | // ... otherwise continue | 699 | // ... otherwise continue |
| 697 | else { | 700 | else { |
| 698 | 701 |
inst/cta/src/GCTACubePsf.cpp
| @@ -32,6 +32,7 @@ | @@ -32,6 +32,7 @@ | ||
| 32 | #include "GMath.hpp" | 32 | #include "GMath.hpp" |
| 33 | #include "GLog.hpp" | 33 | #include "GLog.hpp" |
| 34 | #include "GObservations.hpp" | 34 | #include "GObservations.hpp" |
| 35 | +#include "GSkyRegionCircle.hpp" | ||
| 35 | #include "GCTACubePsf.hpp" | 36 | #include "GCTACubePsf.hpp" |
| 36 | #include "GCTAObservation.hpp" | 37 | #include "GCTAObservation.hpp" |
| 37 | #include "GCTAResponseIrf.hpp" | 38 | #include "GCTAResponseIrf.hpp" |
| @@ -787,20 +788,9 @@ void GCTACubePsf::fill_cube(const GCTAObservation& obs, | @@ -787,20 +788,9 @@ void GCTACubePsf::fill_cube(const GCTAObservation& obs, | ||
| 787 | throw GException::invalid_value(G_FILL_CUBE, msg); | 788 | throw GException::invalid_value(G_FILL_CUBE, msg); |
| 788 | } | 789 | } |
| 789 | 790 | ||
| 790 | - // Make sure the observation falls within the bounds of the cube | ||
| 791 | - GSkyRegionCircle obs_reg(roi.centre().dir(), roi.radius()); | ||
| 792 | - if (!m_cube.overlaps(obs_reg)) { | ||
| 793 | - if (log != NULL) { | ||
| 794 | - *log << "Skipping unbinned "; | ||
| 795 | - *log << obs.instrument(); | ||
| 796 | - *log << " observation "; | ||
| 797 | - *log << "\"" << obs.name() << "\""; | ||
| 798 | - *log << " (id=" << obs.id() << ") which does not overlap PSF cube."; | ||
| 799 | - *log << std::endl; | ||
| 800 | - } | ||
| 801 | - return; | ||
| 802 | - } | ||
| 803 | - | 791 | + // Convert RoI into a circular region for overlap checking |
| 792 | + GSkyRegionCircle roi_reg(roi.centre().dir(), roi.radius()); | ||
| 793 | + | ||
| 804 | // Extract response from observation | 794 | // Extract response from observation |
| 805 | const GCTAResponseIrf* rsp = dynamic_cast<const GCTAResponseIrf*> | 795 | const GCTAResponseIrf* rsp = dynamic_cast<const GCTAResponseIrf*> |
| 806 | (obs.response()); | 796 | (obs.response()); |
| @@ -824,6 +814,19 @@ void GCTACubePsf::fill_cube(const GCTAObservation& obs, | @@ -824,6 +814,19 @@ void GCTACubePsf::fill_cube(const GCTAObservation& obs, | ||
| 824 | } | 814 | } |
| 825 | } | 815 | } |
| 826 | 816 | ||
| 817 | + // Skip observation if observation is outside the bounds of the cube | ||
| 818 | + else if (!m_cube.overlaps(roi_reg)) { | ||
| 819 | + if (log != NULL) { | ||
| 820 | + *log << "Skipping unbinned "; | ||
| 821 | + *log << obs.instrument(); | ||
| 822 | + *log << " observation "; | ||
| 823 | + *log << "\"" << obs.name() << "\""; | ||
| 824 | + *log << " (id=" << obs.id() << ") since it does not overlap "; | ||
| 825 | + *log << "with the point spread function cube."; | ||
| 826 | + *log << std::endl; | ||
| 827 | + } | ||
| 828 | + } | ||
| 829 | + | ||
| 827 | // ... otherwise continue | 830 | // ... otherwise continue |
| 828 | else { | 831 | else { |
| 829 | 832 |
inst/cta/src/GCTAEventList.cpp
| @@ -797,11 +797,13 @@ void GCTAEventList::dispose(void) const | @@ -797,11 +797,13 @@ void GCTAEventList::dispose(void) const | ||
| 797 | // Clear events and additional columns | 797 | // Clear events and additional columns |
| 798 | m_events.clear(); | 798 | m_events.clear(); |
| 799 | m_columns.clear(); | 799 | m_columns.clear(); |
| 800 | - | ||
| 801 | - // Now actually remove the memory reserved for these objects | 800 | + |
| 801 | + // Now actually remove the memory reserved for these objects. See | ||
| 802 | + // https://prateekvjoshi.com/2013/10/20/c-vector-memory-release/ | ||
| 803 | + // for an explanation of this code. | ||
| 802 | std::vector<GCTAEventAtom>(m_events).swap(m_events); | 804 | std::vector<GCTAEventAtom>(m_events).swap(m_events); |
| 803 | std::vector<GFitsTableCol*>(m_columns).swap(m_columns); | 805 | std::vector<GFitsTableCol*>(m_columns).swap(m_columns); |
| 804 | - | 806 | + |
| 805 | // Return | 807 | // Return |
| 806 | return; | 808 | return; |
| 807 | } | 809 | } |
pyext/GSkyMap.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GSkyMap.i - Sky map class * | 2 | * GSkyMap.i - Sky map class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2010-2017 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -171,6 +171,7 @@ public: | @@ -171,6 +171,7 @@ public: | ||
| 171 | double solidangle(const GSkyPixel& pixel) const; | 171 | double solidangle(const GSkyPixel& pixel) const; |
| 172 | bool contains(const GSkyDir& dir) const; | 172 | bool contains(const GSkyDir& dir) const; |
| 173 | bool contains(const GSkyPixel& pixel) const; | 173 | bool contains(const GSkyPixel& pixel) const; |
| 174 | + bool overlaps(const GSkyRegion& region) const; | ||
| 174 | const GSkyProjection* projection(void) const; | 175 | const GSkyProjection* projection(void) const; |
| 175 | void projection(const GSkyProjection& proj); | 176 | void projection(const GSkyProjection& proj); |
| 176 | const double* pixels(void) const; | 177 | const double* pixels(void) const; |
pyext/GSkyRegions.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GSkyRegions.i - Sky region container class * | 2 | * GSkyRegions.i - Sky region container class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2016 by Pierrick Martin * | 4 | + * copyright (C) 2013-2017 by Pierrick Martin * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -56,7 +56,8 @@ public: | @@ -56,7 +56,8 @@ public: | ||
| 56 | void reserve(const int& num); | 56 | void reserve(const int& num); |
| 57 | void extend(const GSkyRegions& regions); | 57 | void extend(const GSkyRegions& regions); |
| 58 | bool contains(const GSkyDir& dir) const; | 58 | bool contains(const GSkyDir& dir) const; |
| 59 | - bool overlaps(const GSkyRegion& reg) const; | 59 | + bool overlaps(const GSkyRegion& region) const; |
| 60 | + bool overlaps(const GSkyRegions& regions) const; | ||
| 60 | void load(const GFilename& filename); | 61 | void load(const GFilename& filename); |
| 61 | void save(const GFilename& filename) const; | 62 | void save(const GFilename& filename) const; |
| 62 | const GFilename& filename(void) const; | 63 | const GFilename& filename(void) const; |
src/sky/GSkyMap.cpp
| @@ -44,6 +44,8 @@ | @@ -44,6 +44,8 @@ | ||
| 44 | #include "GMatrix.hpp" | 44 | #include "GMatrix.hpp" |
| 45 | #include "GVector.hpp" | 45 | #include "GVector.hpp" |
| 46 | #include "GVOClient.hpp" | 46 | #include "GVOClient.hpp" |
| 47 | +#include "GSkyRegion.hpp" | ||
| 48 | +#include "GSkyRegionCircle.hpp" | ||
| 47 | 49 | ||
| 48 | /* __ Method name definitions ____________________________________________ */ | 50 | /* __ Method name definitions ____________________________________________ */ |
| 49 | #define G_CONSTRUCT_HPX "GSkyMap::GSkyMap(std::string&, int&,"\ | 51 | #define G_CONSTRUCT_HPX "GSkyMap::GSkyMap(std::string&, int&,"\ |
| @@ -68,6 +70,7 @@ | @@ -68,6 +70,7 @@ | ||
| 68 | #define G_FLUX2 "GSkyMap::flux(GSkyPixel&)" | 70 | #define G_FLUX2 "GSkyMap::flux(GSkyPixel&)" |
| 69 | #define G_SOLIDANGLE1 "GSkyMap::solidangle(int&)" | 71 | #define G_SOLIDANGLE1 "GSkyMap::solidangle(int&)" |
| 70 | #define G_SOLIDANGLE2 "GSkyMap::solidangle(GSkyPixel&)" | 72 | #define G_SOLIDANGLE2 "GSkyMap::solidangle(GSkyPixel&)" |
| 73 | +#define G_OVERLAPS "GSkyMap::overlaps(GSkyRegion&)" | ||
| 71 | #define G_EXTRACT "GSkyMap::extract(int&, int&)" | 74 | #define G_EXTRACT "GSkyMap::extract(int&, int&)" |
| 72 | #define G_READ "GSkyMap::read(GFitsHDU&)" | 75 | #define G_READ "GSkyMap::read(GFitsHDU&)" |
| 73 | #define G_SET_WCS "GSkyMap::set_wcs(std::string&, std::string&, double&,"\ | 76 | #define G_SET_WCS "GSkyMap::set_wcs(std::string&, std::string&, double&,"\ |
| @@ -1716,72 +1719,11 @@ void GSkyMap::projection(const GSkyProjection& proj) | @@ -1716,72 +1719,11 @@ void GSkyMap::projection(const GSkyProjection& proj) | ||
| 1716 | } | 1719 | } |
| 1717 | 1720 | ||
| 1718 | 1721 | ||
| 1719 | -/*********************************************************************** | ||
| 1720 | - * @brief Checks whether or not a circular region overlaps with this map | ||
| 1721 | - * | ||
| 1722 | - * @param[in] reg Circular region | ||
| 1723 | - * @return True or False | ||
| 1724 | - * | ||
| 1725 | - * The check is done by first testing whether the central pointing | ||
| 1726 | - * position of the observation falls into the sky map. If this is false, | ||
| 1727 | - * then pixel positions that border the sky map are tested for whether or | ||
| 1728 | - * not they fall into the observation region. The positions tested can be | ||
| 1729 | - * visualized as follows, where '*' marks the positions tested. | ||
| 1730 | - * | ||
| 1731 | - * * * * * * * | ||
| 1732 | - * +---+---+---+---+ | ||
| 1733 | - * * |0,2|1,2|2,2|3,2| * | ||
| 1734 | - * +---+---+---+---+ | ||
| 1735 | - * * |0,1|1,1|2,1|3,1| * | ||
| 1736 | - * +---+---+---+---+ | ||
| 1737 | - * * |0,0|1,0|2,0|3,0| * | ||
| 1738 | - * +---+---+---+---+ | ||
| 1739 | - * * * * * * * | ||
| 1740 | - * | ||
| 1741 | - ***************************************************************************/ | ||
| 1742 | -bool GSkyMap::overlaps(const GSkyRegionCircle& reg) const | ||
| 1743 | -{ | ||
| 1744 | - // Check if the center of the region is inside the map | ||
| 1745 | - if (contains(reg.centre())) { | ||
| 1746 | - return true; | ||
| 1747 | - } else { | ||
| 1748 | - // Loop through each of the outer bins and check if the map | ||
| 1749 | - // overlaps with them (within some delta) | ||
| 1750 | - GSkyPixel pix1(0.0,0.0); | ||
| 1751 | - GSkyPixel pix2(0.0,0.0); | ||
| 1752 | - | ||
| 1753 | - // Check the bottom and top bins | ||
| 1754 | - pix1.y(-1); | ||
| 1755 | - pix2.y(ny()); | ||
| 1756 | - for (int xbin=-1; xbin <= nx(); xbin+=1.0) { | ||
| 1757 | - pix1.x(xbin); | ||
| 1758 | - pix2.x(xbin); | ||
| 1759 | - if ((reg.contains(pix2dir(pix1))) || (reg.contains(pix2dir(pix2)))) { | ||
| 1760 | - return true; | ||
| 1761 | - } | ||
| 1762 | - } // endfor: loop on xbin | ||
| 1763 | - | ||
| 1764 | - // Check the left and right bins | ||
| 1765 | - // Check the bottom and top bins | ||
| 1766 | - pix1.x(-1); | ||
| 1767 | - pix2.x(nx()); | ||
| 1768 | - for (double ybin=0; ybin < ny(); ybin+=1.0) { | ||
| 1769 | - pix1.y(ybin); | ||
| 1770 | - pix2.y(ybin); | ||
| 1771 | - if ((reg.contains(pix2dir(pix1))) || (reg.contains(pix2dir(pix2)))) { | ||
| 1772 | - return true; | ||
| 1773 | - } | ||
| 1774 | - } // endfor: loop on ybin | ||
| 1775 | - | ||
| 1776 | - } | ||
| 1777 | - return false; | ||
| 1778 | -} | ||
| 1779 | - | ||
| 1780 | - | ||
| 1781 | /***********************************************************************//** | 1722 | /***********************************************************************//** |
| 1782 | - * @brief Verifies if sky direction falls in map | 1723 | + * @brief Checks if sky direction falls in map |
| 1783 | * | 1724 | * |
| 1784 | * @param[in] dir Sky direction. | 1725 | * @param[in] dir Sky direction. |
| 1726 | + * @return True if sky direction falls into map, false otherwise. | ||
| 1785 | * | 1727 | * |
| 1786 | * This method checks if the specified sky direction falls within the pixels | 1728 | * This method checks if the specified sky direction falls within the pixels |
| 1787 | * covered by the skymap. The method uses the dir2xy method to convert the | 1729 | * covered by the skymap. The method uses the dir2xy method to convert the |
| @@ -1837,6 +1779,38 @@ bool GSkyMap::contains(const GSkyPixel& pixel) const | @@ -1837,6 +1779,38 @@ bool GSkyMap::contains(const GSkyPixel& pixel) const | ||
| 1837 | 1779 | ||
| 1838 | 1780 | ||
| 1839 | /***********************************************************************//** | 1781 | /***********************************************************************//** |
| 1782 | + * @brief Checks whether a region overlaps with this map | ||
| 1783 | + * | ||
| 1784 | + * @param[in] region Region | ||
| 1785 | + * @return True if region overlaps with map, false otherwise | ||
| 1786 | + * | ||
| 1787 | + * @exception GException::feature_not_implemented | ||
| 1788 | + * Region is not a circular sky region | ||
| 1789 | + ***************************************************************************/ | ||
| 1790 | +bool GSkyMap::overlaps(const GSkyRegion& region) const | ||
| 1791 | +{ | ||
| 1792 | + // Initialise overlap | ||
| 1793 | + bool overlap = false; | ||
| 1794 | + | ||
| 1795 | + // If the region is a circular region than test on overlap | ||
| 1796 | + if (region.type() == "Circle") { | ||
| 1797 | + const GSkyRegionCircle* circle = | ||
| 1798 | + static_cast<const GSkyRegionCircle*>(®ion); | ||
| 1799 | + overlap = overlaps_circle(*circle); | ||
| 1800 | + } | ||
| 1801 | + | ||
| 1802 | + // ... otherwise signal that method is not implemented | ||
| 1803 | + else { | ||
| 1804 | + std::string msg = "Method not implemented for non-circular regions."; | ||
| 1805 | + throw GException::feature_not_implemented(G_OVERLAPS, msg); | ||
| 1806 | + } | ||
| 1807 | + | ||
| 1808 | + // Return overlap flag | ||
| 1809 | + return overlap; | ||
| 1810 | +} | ||
| 1811 | + | ||
| 1812 | + | ||
| 1813 | +/***********************************************************************//** | ||
| 1840 | * @brief Extract maps into a new sky map object | 1814 | * @brief Extract maps into a new sky map object |
| 1841 | * | 1815 | * |
| 1842 | * @param[in] map First map to extract | 1816 | * @param[in] map First map to extract |
| @@ -3033,6 +3007,83 @@ double GSkyMap::solidangle(const GSkyDir& dir1, const GSkyDir& dir2, | @@ -3033,6 +3007,83 @@ double GSkyMap::solidangle(const GSkyDir& dir1, const GSkyDir& dir2, | ||
| 3033 | 3007 | ||
| 3034 | 3008 | ||
| 3035 | /***********************************************************************//** | 3009 | /***********************************************************************//** |
| 3010 | + * @brief Checks whether a circular region overlaps with this map | ||
| 3011 | + * | ||
| 3012 | + * @param[in] region Circular region | ||
| 3013 | + * @return True if circular region overlaps with map, false otherwise | ||
| 3014 | + * | ||
| 3015 | + * The check is done by first testing whether the central pointing | ||
| 3016 | + * position of the observation falls into the sky map. If this is false, | ||
| 3017 | + * then pixel positions that border the sky map are tested for whether or | ||
| 3018 | + * not they fall into the observation region. The positions tested can be | ||
| 3019 | + * visualized as follows, where '*' marks the positions tested. | ||
| 3020 | + * | ||
| 3021 | + * * * * * * * | ||
| 3022 | + * +---+---+---+---+ | ||
| 3023 | + * * |0,2|1,2|2,2|3,2| * | ||
| 3024 | + * +---+---+---+---+ | ||
| 3025 | + * * |0,1|1,1|2,1|3,1| * | ||
| 3026 | + * +---+---+---+---+ | ||
| 3027 | + * * |0,0|1,0|2,0|3,0| * | ||
| 3028 | + * +---+---+---+---+ | ||
| 3029 | + * * * * * * * | ||
| 3030 | + * | ||
| 3031 | + ***************************************************************************/ | ||
| 3032 | +bool GSkyMap::overlaps_circle(const GSkyRegionCircle& region) const | ||
| 3033 | +{ | ||
| 3034 | + // Initialise overlap with true | ||
| 3035 | + bool overlap = false; | ||
| 3036 | + | ||
| 3037 | + // If the centre of the region is inside the map then signal overlap ... | ||
| 3038 | + if (contains(region.centre())) { | ||
| 3039 | + overlap = true; | ||
| 3040 | + } | ||
| 3041 | + | ||
| 3042 | + // ... otherwise loop through each of the outer bins and check if the | ||
| 3043 | + // region overlaps with them (within some delta) | ||
| 3044 | + else { | ||
| 3045 | + | ||
| 3046 | + // Initialise test pixels | ||
| 3047 | + GSkyPixel pix1(0.0,0.0); | ||
| 3048 | + GSkyPixel pix2(0.0,0.0); | ||
| 3049 | + | ||
| 3050 | + // Check the bottom and top bins | ||
| 3051 | + pix1.y(-1.0); | ||
| 3052 | + pix2.y(double(ny())); | ||
| 3053 | + for (double xbin = -1.0; xbin <= nx(); xbin += 1.0) { | ||
| 3054 | + pix1.x(xbin); | ||
| 3055 | + pix2.x(xbin); | ||
| 3056 | + if ((region.contains(pix2dir(pix1))) || | ||
| 3057 | + (region.contains(pix2dir(pix2)))) { | ||
| 3058 | + overlap = true; | ||
| 3059 | + break; | ||
| 3060 | + } | ||
| 3061 | + } // endfor: loop on xbin | ||
| 3062 | + | ||
| 3063 | + // If no overlap has been found then check now the left and right | ||
| 3064 | + // bins | ||
| 3065 | + if (!overlap) { | ||
| 3066 | + pix1.x(-1.0); | ||
| 3067 | + pix2.x(double(nx())); | ||
| 3068 | + for (double ybin = 0.0; ybin < ny(); ybin += 1.0) { | ||
| 3069 | + pix1.y(ybin); | ||
| 3070 | + pix2.y(ybin); | ||
| 3071 | + if ((region.contains(pix2dir(pix1))) || | ||
| 3072 | + (region.contains(pix2dir(pix2)))) { | ||
| 3073 | + overlap = true; | ||
| 3074 | + break; | ||
| 3075 | + } | ||
| 3076 | + } // endfor: loop on ybin | ||
| 3077 | + } | ||
| 3078 | + | ||
| 3079 | + } // endelse: check border bins | ||
| 3080 | + | ||
| 3081 | + // Return overlap flag | ||
| 3082 | + return overlap; | ||
| 3083 | +} | ||
| 3084 | + | ||
| 3085 | + | ||
| 3086 | +/***********************************************************************//** | ||
| 3036 | * @brief Check if HDU contains HEALPix data | 3087 | * @brief Check if HDU contains HEALPix data |
| 3037 | * | 3088 | * |
| 3038 | * @param[in] hdu FITS Header Data Unit. | 3089 | * @param[in] hdu FITS Header Data Unit. |
src/sky/GSkyRegions.cpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GSkyRegions.cpp - Sky region container class * | 2 | * GSkyRegions.cpp - Sky region container class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2016 by Pierrick Martin * | 4 | + * copyright (C) 2013-2017 by Pierrick Martin * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -408,6 +408,90 @@ void GSkyRegions::extend(const GSkyRegions& regions) | @@ -408,6 +408,90 @@ void GSkyRegions::extend(const GSkyRegions& regions) | ||
| 408 | 408 | ||
| 409 | 409 | ||
| 410 | /***********************************************************************//** | 410 | /***********************************************************************//** |
| 411 | + * @brief Check if direction is contained in one of the regions | ||
| 412 | + * | ||
| 413 | + * @param[in] dir Sky direction. | ||
| 414 | + * @return True if the sky direction is container in one of the regions, | ||
| 415 | + * falls otherwise. | ||
| 416 | + * | ||
| 417 | + * Checks if a sky direction is contained in one of the regions of the | ||
| 418 | + * container. | ||
| 419 | + ***************************************************************************/ | ||
| 420 | +bool GSkyRegions::contains(const GSkyDir& dir) const | ||
| 421 | +{ | ||
| 422 | + // Initialise return value | ||
| 423 | + bool overlap = false; | ||
| 424 | + | ||
| 425 | + // Loop over regions | ||
| 426 | + for (int i = 0; i < size(); ++i) { | ||
| 427 | + overlap = m_regions[i]->contains(dir); | ||
| 428 | + if (overlap) { | ||
| 429 | + break; | ||
| 430 | + } | ||
| 431 | + } | ||
| 432 | + | ||
| 433 | + // Return result | ||
| 434 | + return overlap; | ||
| 435 | +} | ||
| 436 | + | ||
| 437 | + | ||
| 438 | +/***********************************************************************//** | ||
| 439 | + * @brief Check if region overlaps one of the regions | ||
| 440 | + * | ||
| 441 | + * @param[in] region Sky region. | ||
| 442 | + * @return True if @p region overlaps with one of the regions in the region | ||
| 443 | + * container, false otherwise | ||
| 444 | + * | ||
| 445 | + * Tells if region overlaps one of the regions | ||
| 446 | + ***************************************************************************/ | ||
| 447 | +bool GSkyRegions::overlaps(const GSkyRegion& region) const | ||
| 448 | +{ | ||
| 449 | + // Initialise return value | ||
| 450 | + bool overlap = false; | ||
| 451 | + | ||
| 452 | + // Loop over regions | ||
| 453 | + for (int i = 0; i < size(); ++i) { | ||
| 454 | + overlap = m_regions[i]->overlaps(region); | ||
| 455 | + if (overlap) { | ||
| 456 | + break; | ||
| 457 | + } | ||
| 458 | + } | ||
| 459 | + | ||
| 460 | + // Return result | ||
| 461 | + return overlap; | ||
| 462 | +} | ||
| 463 | + | ||
| 464 | + | ||
| 465 | +/***********************************************************************//** | ||
| 466 | + * @brief Check if any of the regions in two containers overlap | ||
| 467 | + * | ||
| 468 | + * @param[in] regions Sky region container. | ||
| 469 | + * @return True if one of the regions in the @p regions container overlaps | ||
| 470 | + * with one of the regions in the container, false otherwise | ||
| 471 | + * | ||
| 472 | + * Tells if all regions in overlaps one of the regions. Note, this method | ||
| 473 | + * returns true if ANY of the regions in the two containers overlap with | ||
| 474 | + * each other | ||
| 475 | + ***************************************************************************/ | ||
| 476 | +bool GSkyRegions::overlaps(const GSkyRegions& regions) const | ||
| 477 | +{ | ||
| 478 | + // Initialize return value | ||
| 479 | + bool overlap = false; | ||
| 480 | + | ||
| 481 | + // Loop over each region in the container | ||
| 482 | + for (int i = 0; i < size(); ++i) { | ||
| 483 | + overlap = regions.overlaps(*m_regions[i]); | ||
| 484 | + if (overlap) { | ||
| 485 | + break; | ||
| 486 | + } | ||
| 487 | + } | ||
| 488 | + | ||
| 489 | + // Return result | ||
| 490 | + return overlap; | ||
| 491 | +} | ||
| 492 | + | ||
| 493 | + | ||
| 494 | +/***********************************************************************//** | ||
| 411 | * @brief Load regions from DS9 region file | 495 | * @brief Load regions from DS9 region file |
| 412 | * | 496 | * |
| 413 | * @param[in] filename DS9 region filename. | 497 | * @param[in] filename DS9 region filename. |
| @@ -545,7 +629,7 @@ void GSkyRegions::save(const GFilename& filename) const | @@ -545,7 +629,7 @@ void GSkyRegions::save(const GFilename& filename) const | ||
| 545 | /***********************************************************************//** | 629 | /***********************************************************************//** |
| 546 | * @brief Print regions | 630 | * @brief Print regions |
| 547 | * | 631 | * |
| 548 | - * @param[in] chatter Chattiness | 632 | + * @param[in] chatter Chattiness. |
| 549 | * @return String containing region container information. | 633 | * @return String containing region container information. |
| 550 | * | 634 | * |
| 551 | * Prints all regions into a string. | 635 | * Prints all regions into a string. |
| @@ -577,79 +661,6 @@ std::string GSkyRegions::print(const GChatter& chatter) const | @@ -577,79 +661,6 @@ std::string GSkyRegions::print(const GChatter& chatter) const | ||
| 577 | } | 661 | } |
| 578 | 662 | ||
| 579 | 663 | ||
| 580 | -/***********************************************************************//** | ||
| 581 | - * @brief Tells if direction is contained in one of the regions | ||
| 582 | - * | ||
| 583 | - * @param[in] dir A sky direction | ||
| 584 | - * @return True or False | ||
| 585 | - * | ||
| 586 | - * Tells if direction is contained in one of the regions | ||
| 587 | - ***************************************************************************/ | ||
| 588 | - bool GSkyRegions::contains(const GSkyDir& dir) const | ||
| 589 | - { | ||
| 590 | - // Initialise return value | ||
| 591 | - bool dir_is_in = false; | ||
| 592 | - | ||
| 593 | - // Loop over regions | ||
| 594 | - for (int i = 0; i < size(); ++i) { | ||
| 595 | - dir_is_in=m_regions[i]->contains(dir); | ||
| 596 | - if (dir_is_in) break; | ||
| 597 | - } | ||
| 598 | - | ||
| 599 | - // Return result | ||
| 600 | - return dir_is_in; | ||
| 601 | - } | ||
| 602 | - | ||
| 603 | - | ||
| 604 | -/***********************************************************************//** | ||
| 605 | - * @brief Tells if region overlaps one of the regions | ||
| 606 | - * | ||
| 607 | - * @param[in] reg A sky region | ||
| 608 | - * @return True or False | ||
| 609 | - * | ||
| 610 | - * Tells if region overlaps one of the regions | ||
| 611 | - ***************************************************************************/ | ||
| 612 | -bool GSkyRegions::overlaps(const GSkyRegion& reg) const | ||
| 613 | -{ | ||
| 614 | - // Initialise return value | ||
| 615 | - bool reg_is_in = false; | ||
| 616 | - | ||
| 617 | - // Loop over regions | ||
| 618 | - for (int i = 0; i < size(); ++i) { | ||
| 619 | - reg_is_in=m_regions[i]->overlaps(reg); | ||
| 620 | - if (reg_is_in) break; | ||
| 621 | - } | ||
| 622 | - | ||
| 623 | - // Return result | ||
| 624 | - return reg_is_in; | ||
| 625 | -} | ||
| 626 | - | ||
| 627 | - | ||
| 628 | -/*********************************************************************** | ||
| 629 | - * @brief Tells if any of the regions in two containers overlap | ||
| 630 | - * | ||
| 631 | - * @param[in] regions GSkyRegions object containing a list of sky regions | ||
| 632 | - * @return True or False | ||
| 633 | - * | ||
| 634 | - * Tells if all regions in overlaps one of the regions. Note, this method | ||
| 635 | - * returns true if ANY of the regions in the two containers overlap with | ||
| 636 | - * each other | ||
| 637 | - ***************************************************************************/ | ||
| 638 | -bool GSkyRegions::overlaps(const GSkyRegions& regions) const | ||
| 639 | -{ | ||
| 640 | - // Initialize return value | ||
| 641 | - bool reg_is_in = false; | ||
| 642 | - | ||
| 643 | - // Loop over each region in the container | ||
| 644 | - for (int i=0; i < size(); i++) { | ||
| 645 | - reg_is_in = regions.overlaps( *m_regions[i] ); | ||
| 646 | - if (reg_is_in) break; | ||
| 647 | - } | ||
| 648 | - | ||
| 649 | - // Return result | ||
| 650 | - return reg_is_in; | ||
| 651 | -} | ||
| 652 | - | ||
| 653 | /*========================================================================== | 664 | /*========================================================================== |
| 654 | = = | 665 | = = |
| 655 | = Private methods = | 666 | = Private methods = |
| @@ -712,4 +723,3 @@ void GSkyRegions::free_members(void) | @@ -712,4 +723,3 @@ void GSkyRegions::free_members(void) | ||
| 712 | // Return | 723 | // Return |
| 713 | return; | 724 | return; |
| 714 | } | 725 | } |
| 715 | - |