Commit 7a14eaae3c21796789d28a18980ea612e9528dde
1 parent
2659914b
Add GSkyMap::flux(GRegion(s)) and GSkyMap::solidangle(GRegion(s)) methods (#1785)
Showing
8 changed files
with
171 additions
and
15 deletions
ChangeLog
| 1 | -2021-03-04 | |
| 1 | +2021-03-08 | |
| 2 | 2 | |
| 3 | 3 | * Version 2.0.0 released |
| 4 | 4 | ======================== |
| ... | ... | @@ -40,7 +40,8 @@ |
| 40 | 40 | Implement analytical gradients for the radial Gaussian model in a |
| 41 | 41 | stacked analysis (#3203) |
| 42 | 42 | Add GSkyModel flux_error() and eflux_error() methods (#3074) |
| 43 | - Remove COMPTEL internal response caching (#2973). | |
| 43 | + Remove COMPTEL internal response caching (#2973) | |
| 44 | + Add GSkyMap::flux(GRegion(s)) and GSkyMap::solidangle(GRegion(s)) methods (#1785) | |
| 44 | 45 | Implement pre-computation cache in GModelSpatialGauss (#1300) |
| 45 | 46 | |
| 46 | 47 | ... | ... |
NEWS
| 1 | 1 | New Features and Important Changes in GammaLib 2.0.0 |
| 2 | 2 | |
| 3 | -4 March 2021 | |
| 3 | +8 March 2021 | |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | 1. Introduction |
| ... | ... | @@ -60,6 +60,10 @@ The following methods have been added: |
| 60 | 60 | - GModelSpectralFunc::intensity() |
| 61 | 61 | - GModelSpectralFunc::save() |
| 62 | 62 | - GSkyMap::correlate() |
| 63 | +- GSkyMap::flux(GSkyRegion&, int&) | |
| 64 | +- GSkyMap::flux(GSkyRegions&, int&) | |
| 65 | +- GSkyMap::solidangle(GSkyRegion&) | |
| 66 | +- GSkyMap::solidangle(GSkyRegions&) | |
| 63 | 67 | - GOptimizerLM::npars() |
| 64 | 68 | - GOptimizerLM::nfree() |
| 65 | 69 | - GXmlElement(std::string&, int&) |
| ... | ... | @@ -223,6 +227,13 @@ method now returns an instance of GSkyDirs (#3324). |
| 223 | 227 | |
| 224 | 228 | Added GSkyRegionRect class to implement a rectangular region on the sky (#3248). |
| 225 | 229 | |
| 230 | +Added GSkyMap::flux(GSkyRegion&, int&) and GSkyMap::flux(GSkyRegions&, int&) methods | |
| 231 | +to compute the total flux within a given sky region or a list of sky regions. The flux | |
| 232 | +returns the sum of the intensity times the solidangle for all pixels that are contained | |
| 233 | +within the sky region(s). Containment is tested using the GSkyMap::contains() methods. | |
| 234 | +Equivalent methods GSkyMap::solidangle(GSkyRegion&) and GSkyMap::solidangle(GSkyRegions&) | |
| 235 | +were added to compute the total solid angle within specified sky region(s) (#1785). | |
| 236 | + | |
| 226 | 237 | |
| 227 | 238 | 13. Support module |
| 228 | 239 | ------------------ | ... | ... |
README.md
| 1 | 1 | GammaLib information |
| 2 | 2 | ==================== |
| 3 | -* Version: 2.0.0.dev (4 March 2021) | |
| 3 | +* Version: 2.0.0.dev (8 March 2021) | |
| 4 | 4 | |
| 5 | 5 | [](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/) |
| 6 | 6 | ... | ... |
doc/source/admin/release_history/2.0.rst
| 1 | 1 | .. _2.0: |
| 2 | 2 | |
| 3 | -GammaLib 2.0 release (3 March 2021) | |
| 3 | +GammaLib 2.0 release (8 March 2021) | |
| 4 | 4 | =================================== |
| 5 | 5 | |
| 6 | 6 | Overview |
| ... | ... | @@ -56,6 +56,8 @@ Improvements |
| 56 | 56 | * [`3203 <https://cta-redmine.irap.omp.eu/issues/3203>`_] - |
| 57 | 57 | Implement vectorised response computation and analytical gradients for |
| 58 | 58 | the radial Gaussian model in a stacked analysis |
| 59 | +* [`1785 <https://cta-redmine.irap.omp.eu/issues/1785>`_] - | |
| 60 | + Add ``GSkyMap::flux(GRegion)``, ``GSkyMap::flux(GRegions)``, ``GSkyMap::solidangle(GRegion)`` and ``GSkyMap::solidangle(GRegions)`` methods | |
| 59 | 61 | * [`1300 <https://cta-redmine.irap.omp.eu/issues/1300>`_] - |
| 60 | 62 | Implement pre-computation cache in GModelSpatialGauss |
| 61 | 63 | ... | ... |
include/GSkyMap.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GSkyMap.hpp - Sky map class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2020 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -162,9 +162,13 @@ public: |
| 162 | 162 | GNdarray counts(void) const; |
| 163 | 163 | double flux(const int& index, const int& map = 0) const; |
| 164 | 164 | double flux(const GSkyPixel& pixel, const int& map = 0) const; |
| 165 | + double flux(const GSkyRegion& region, const int& map = 0) const; | |
| 166 | + double flux(const GSkyRegions& regions, const int& map = 0) const; | |
| 165 | 167 | GNdarray flux(void) const; |
| 166 | 168 | double solidangle(const int& index) const; |
| 167 | 169 | double solidangle(const GSkyPixel& pixel) const; |
| 170 | + double solidangle(const GSkyRegion& region) const; | |
| 171 | + double solidangle(const GSkyRegions& regions) const; | |
| 168 | 172 | bool contains(const GSkyDir& dir) const; |
| 169 | 173 | bool contains(const GSkyPixel& pixel) const; |
| 170 | 174 | bool overlaps(const GSkyRegion& region) const; | ... | ... |
pyext/GSkyMap.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GSkyMap.i - Sky map class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2020 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -97,9 +97,13 @@ public: |
| 97 | 97 | GNdarray counts(void); |
| 98 | 98 | double flux(const int& index, const int& map = 0) const; |
| 99 | 99 | double flux(const GSkyPixel& pixel, const int& map = 0) const; |
| 100 | + double flux(const GSkyRegion& region, const int& map = 0) const; | |
| 101 | + double flux(const GSkyRegions& regions, const int& map = 0) const; | |
| 100 | 102 | GNdarray flux(void); |
| 101 | 103 | double solidangle(const int& index) const; |
| 102 | 104 | double solidangle(const GSkyPixel& pixel) const; |
| 105 | + double solidangle(const GSkyRegion& region) const; | |
| 106 | + double solidangle(const GSkyRegions& regions) const; | |
| 103 | 107 | bool contains(const GSkyDir& dir) const; |
| 104 | 108 | bool contains(const GSkyPixel& pixel) const; |
| 105 | 109 | bool overlaps(const GSkyRegion& region) const; | ... | ... |
src/sky/GSkyMap.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GSkyMap.cpp - Sky map class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2020 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -417,7 +417,7 @@ GSkyMap& GSkyMap::operator+=(const GSkyMap& map) |
| 417 | 417 | } // endfor: looped over all layers |
| 418 | 418 | |
| 419 | 419 | } // endfor: looped over all pixels |
| 420 | - | |
| 420 | + | |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | // ... otherwise use interpolation method and add map |
| ... | ... | @@ -507,7 +507,7 @@ GSkyMap& GSkyMap::operator-=(const GSkyMap& map) |
| 507 | 507 | } // endfor: looped over all layers |
| 508 | 508 | |
| 509 | 509 | } // endfor: looped over all pixels |
| 510 | - | |
| 510 | + | |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | // ... otherwise use interpolation method and subtract map |
| ... | ... | @@ -597,7 +597,7 @@ GSkyMap& GSkyMap::operator*=(const GSkyMap& map) |
| 597 | 597 | } // endfor: looped over all layers |
| 598 | 598 | |
| 599 | 599 | } // endfor: looped over all pixels |
| 600 | - | |
| 600 | + | |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | // ... otherwise use interpolation method and multiply map |
| ... | ... | @@ -701,7 +701,7 @@ GSkyMap& GSkyMap::operator/=(const GSkyMap& map) |
| 701 | 701 | } // endfor: looped over all layers |
| 702 | 702 | |
| 703 | 703 | } // endfor: looped over all pixels |
| 704 | - | |
| 704 | + | |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | // ... otherwise use interpolation method and divide map |
| ... | ... | @@ -1724,6 +1724,66 @@ double GSkyMap::flux(const GSkyPixel& pixel, const int& map) const |
| 1724 | 1724 | |
| 1725 | 1725 | |
| 1726 | 1726 | /***********************************************************************//** |
| 1727 | + * @brief Returns flux within sky region | |
| 1728 | + * | |
| 1729 | + * @param[in] region Sky region. | |
| 1730 | + * @param[in] map Map index [0,...,nmaps()-1]. | |
| 1731 | + * @return Flux in sky region. | |
| 1732 | + * | |
| 1733 | + * The method returns the total flux in all sky map pixels that fall within | |
| 1734 | + * the specified region. Containment is tested using the | |
| 1735 | + * GSkyRegion::contains() method. Sky map values are multiplied by the solid | |
| 1736 | + * angle of the pixel. | |
| 1737 | + ***************************************************************************/ | |
| 1738 | +double GSkyMap::flux(const GSkyRegion& region, const int& map) const | |
| 1739 | +{ | |
| 1740 | + // Initialise flux | |
| 1741 | + double flux = 0.0; | |
| 1742 | + | |
| 1743 | + // Loop over all sky pixels and sum flux of all pixels that fall within | |
| 1744 | + // the sky region | |
| 1745 | + for (int i = 0; i < m_num_pixels; ++i) { | |
| 1746 | + if (region.contains(inx2dir(i))) { | |
| 1747 | + flux += (*this)(i,map) * solidangle(i); | |
| 1748 | + } | |
| 1749 | + } | |
| 1750 | + | |
| 1751 | + // Return flux | |
| 1752 | + return flux; | |
| 1753 | +} | |
| 1754 | + | |
| 1755 | + | |
| 1756 | +/***********************************************************************//** | |
| 1757 | + * @brief Returns flux within sky regions | |
| 1758 | + * | |
| 1759 | + * @param[in] regions Sky regions. | |
| 1760 | + * @param[in] map Map index [0,...,nmaps()-1]. | |
| 1761 | + * @return Flux in sky region. | |
| 1762 | + * | |
| 1763 | + * The method returns the total flux in all sky map pixels that fall within | |
| 1764 | + * the specified regions. Containment is tested using the | |
| 1765 | + * GSkyRegions::contains() method. Sky map values are multiplied by the solid | |
| 1766 | + * angle of the pixel. | |
| 1767 | + ***************************************************************************/ | |
| 1768 | +double GSkyMap::flux(const GSkyRegions& regions, const int& map) const | |
| 1769 | +{ | |
| 1770 | + // Initialise flux | |
| 1771 | + double flux = 0.0; | |
| 1772 | + | |
| 1773 | + // Loop over all sky pixels and sum flux of all pixels that fall within | |
| 1774 | + // the sky region | |
| 1775 | + for (int i = 0; i < m_num_pixels; ++i) { | |
| 1776 | + if (regions.contains(inx2dir(i))) { | |
| 1777 | + flux += (*this)(i,map) * solidangle(i); | |
| 1778 | + } | |
| 1779 | + } | |
| 1780 | + | |
| 1781 | + // Return flux | |
| 1782 | + return flux; | |
| 1783 | +} | |
| 1784 | + | |
| 1785 | + | |
| 1786 | +/***********************************************************************//** | |
| 1727 | 1787 | * @brief Returns array with total flux for sky maps |
| 1728 | 1788 | * |
| 1729 | 1789 | * @return Array of pixel flux sums. |
| ... | ... | @@ -1734,7 +1794,7 @@ double GSkyMap::flux(const GSkyPixel& pixel, const int& map) const |
| 1734 | 1794 | GNdarray GSkyMap::flux(void) const |
| 1735 | 1795 | { |
| 1736 | 1796 | // Initialise output array |
| 1737 | - GNdarray flux_array = GNdarray(m_num_maps); | |
| 1797 | + GNdarray flux_array = GNdarray(m_num_maps); | |
| 1738 | 1798 | |
| 1739 | 1799 | // Loop over maps and store sums in output array |
| 1740 | 1800 | for (int i = 0; i < m_num_maps; ++i) { |
| ... | ... | @@ -1836,6 +1896,62 @@ double GSkyMap::solidangle(const GSkyPixel& pixel) const |
| 1836 | 1896 | |
| 1837 | 1897 | |
| 1838 | 1898 | /***********************************************************************//** |
| 1899 | + * @brief Returns solid angle within sky region | |
| 1900 | + * | |
| 1901 | + * @param[in] region Sky region. | |
| 1902 | + * @return Solid angle within sky region. | |
| 1903 | + * | |
| 1904 | + * The method returns the total solid angle of all sky map pixels that fall | |
| 1905 | + * within the specified region. Containment is tested using the | |
| 1906 | + * GSkyRegion::contains() method. | |
| 1907 | + ***************************************************************************/ | |
| 1908 | +double GSkyMap::solidangle(const GSkyRegion& region) const | |
| 1909 | +{ | |
| 1910 | + // Initialise flux | |
| 1911 | + double solidangle = 0.0; | |
| 1912 | + | |
| 1913 | + // Loop over all sky pixels and sum solid angle of all pixels that fall | |
| 1914 | + // within the sky region | |
| 1915 | + for (int i = 0; i < m_num_pixels; ++i) { | |
| 1916 | + if (region.contains(inx2dir(i))) { | |
| 1917 | + solidangle += this->solidangle(i); | |
| 1918 | + } | |
| 1919 | + } | |
| 1920 | + | |
| 1921 | + // Return solidangle | |
| 1922 | + return solidangle; | |
| 1923 | +} | |
| 1924 | + | |
| 1925 | + | |
| 1926 | +/***********************************************************************//** | |
| 1927 | + * @brief Returns flux within sky regions | |
| 1928 | + * | |
| 1929 | + * @param[in] region Sky region. | |
| 1930 | + * @return Solid angle within sky region. | |
| 1931 | + * | |
| 1932 | + * The method returns the total solid angle of all sky map pixels that fall | |
| 1933 | + * within the specified region. Containment is tested using the | |
| 1934 | + * GSkyRegions::contains() method. | |
| 1935 | + ***************************************************************************/ | |
| 1936 | +double GSkyMap::solidangle(const GSkyRegions& regions) const | |
| 1937 | +{ | |
| 1938 | + // Initialise flux | |
| 1939 | + double solidangle = 0.0; | |
| 1940 | + | |
| 1941 | + // Loop over all sky pixels and sum solid angle of all pixels that fall | |
| 1942 | + // within the sky regions | |
| 1943 | + for (int i = 0; i < m_num_pixels; ++i) { | |
| 1944 | + if (regions.contains(inx2dir(i))) { | |
| 1945 | + solidangle += this->solidangle(i); | |
| 1946 | + } | |
| 1947 | + } | |
| 1948 | + | |
| 1949 | + // Return solidangle | |
| 1950 | + return solidangle; | |
| 1951 | +} | |
| 1952 | + | |
| 1953 | + | |
| 1954 | +/***********************************************************************//** | |
| 1839 | 1955 | * @brief Set sky projection |
| 1840 | 1956 | * |
| 1841 | 1957 | * @param[in] proj Sky projection. |
| ... | ... | @@ -2266,7 +2382,7 @@ GSkyRegionCircle GSkyMap::region_circle(void) const |
| 2266 | 2382 | |
| 2267 | 2383 | // Consider edges of pixel with maximum distance |
| 2268 | 2384 | if (max_index != -1) { |
| 2269 | - | |
| 2385 | + | |
| 2270 | 2386 | // Set upper pixel edge just beyond the upper boundary since the |
| 2271 | 2387 | // upper boundary is excluded |
| 2272 | 2388 | const double up = 0.4999999; | ... | ... |
test/test_GSky.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * test_GSky.cpp - Test sky module * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2020 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -1284,6 +1284,24 @@ void TestGSky::test_GSkyMap(void) |
| 1284 | 1284 | GNdarray flux_spectrum = map_src.flux(); |
| 1285 | 1285 | test_value(flux_spectrum.size(), map_src.nmaps(), "Test flux() method"); |
| 1286 | 1286 | |
| 1287 | + // Test flux in region methods | |
| 1288 | + GSkyRegionCircle gc_circle(266.40499, -28.93617, 3.0); | |
| 1289 | + GSkyRegionRectangle gc_box(266.40499, -28.93617, 4.0, 2.0, -58.59867); | |
| 1290 | + GSkyRegionMap gc_map(&gc_box); | |
| 1291 | + GSkyRegions gc_regions; | |
| 1292 | + gc_regions.append(gc_circle); | |
| 1293 | + gc_regions.append(gc_box); | |
| 1294 | + test_value(map_src.flux(gc_circle), 0.49208055, "Test flux(GSkyRegionCircle) method"); | |
| 1295 | + test_value(map_src.flux(gc_box), 0.12306231, "Test flux(GSkyRegionRectangle) method"); | |
| 1296 | + test_value(map_src.flux(gc_map), 0.12306231, "Test flux(GSkyRegionMap) method"); | |
| 1297 | + test_value(map_src.flux(gc_regions), 0.49208055, "Test flux(GSkyRegions) method"); | |
| 1298 | + | |
| 1299 | + // Test solidangle in region methods | |
| 1300 | + test_value(map_src.solidangle(gc_circle), 0.0097441693, "Test solidangle(GSkyRegionCircle) method"); | |
| 1301 | + test_value(map_src.solidangle(gc_box), 0.0024368775, "Test solidangle(GSkyRegionRectangle) method"); | |
| 1302 | + test_value(map_src.solidangle(gc_map), 0.0024368775, "Test solidangle(GSkyRegionMap) method"); | |
| 1303 | + test_value(map_src.solidangle(gc_regions), 0.0097441693, "Test solidangle(GSkyRegions) method"); | |
| 1304 | + | |
| 1287 | 1305 | // Test map number changing |
| 1288 | 1306 | GSkyMap map_more = map_src; |
| 1289 | 1307 | map_more.nmaps(4); | ... | ... |