diff --git a/ChangeLog b/ChangeLog index 682d69a..4a39df1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2016-08-09 +2016-08-10 * Version 1.2.0 released ========================= + Add GSkyMap::is_empty() method (#1828) Add GApplication access by index operator (#1838) Add GApplication::pars() and GApplicationPar::current_value() methods (#1838) Add GLog is_open(), is_empty() and written_size() methods (#1837) diff --git a/NEWS b/NEWS index 93f024a..e6184ff 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in GammaLib 1.2.0 -9 August 2016 +10 August 2016 1. Introduction @@ -33,6 +33,7 @@ The following methods have been added: - GLog::is_open() - GLog::is_empty() - GLog::written_size() +- GSkyMap::is_empty() The following methods have been removed: - ... @@ -146,6 +147,9 @@ object. In case that no sky map is written, for example because none has been defined so far, the method returns NONE. The GSkyMap::publish() method will detect the NONE value and will do nothing if no sky map exists (#1835). +The GSkyMap::is_empty() method signals whether a sky map contains no pixels +or no maps (#1828). + 13. Support module ------------------ diff --git a/README.md b/README.md index 2006261..9ee3665 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ GammaLib information ==================== -* Version: 1.2.0.dev1 (9 August 2016) +* Version: 1.2.0.dev1 (10 August 2016) * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu) [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=gammalib-integrate-os)](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/) diff --git a/include/GSkyMap.hpp b/include/GSkyMap.hpp index 0298d49..30f72a6 100644 --- a/include/GSkyMap.hpp +++ b/include/GSkyMap.hpp @@ -131,6 +131,7 @@ public: void clear(void); GSkyMap* clone(void) const; std::string classname(void) const; + bool is_empty(void) const; const int& npix(void) const; const int& nx(void) const; const int& ny(void) const; @@ -289,6 +290,20 @@ std::string GSkyMap::classname(void) const /***********************************************************************//** + * @brief Signals if sky map is empty + * + * @return True if sky map is empty, false otherwise. + * + * Signals if a sky map has no pixels or maps. + ***************************************************************************/ +inline +bool GSkyMap::is_empty(void) const +{ + return ((m_num_pixels == 0) || (m_num_maps == 0)); +} + + +/***********************************************************************//** * @brief Returns number of pixels * * @return Number of pixels in one sky map. diff --git a/pyext/GSkyMap.i b/pyext/GSkyMap.i index a7c12c1..3cb6a6d 100644 --- a/pyext/GSkyMap.i +++ b/pyext/GSkyMap.i @@ -146,6 +146,7 @@ public: void clear(void); GSkyMap* clone(void) const; std::string classname(void) const; + bool is_empty(void) const; const int& npix(void) const; const int& nx(void) const; const int& ny(void) const; diff --git a/test/test_GSky.cpp b/test/test_GSky.cpp index 281dbca..7526131 100644 --- a/test/test_GSky.cpp +++ b/test/test_GSky.cpp @@ -876,6 +876,24 @@ void TestGSky::test_GSkyMap(void) system("rm -rf test_map_src.fits"); system("rm -rf test_map_dst.fits"); system("rm -rf test_map_shape*.fits"); + + // Define empty sky map + GSkyMap empty_map; + + // Test that empty map is indeed empty + test_assert(empty_map.is_empty(), "Check for empty sky map"); + test_value(empty_map.nmaps(), 0, "Check for no sky maps"); + test_value(empty_map.npix(), 0, "Check number of empty sky map pixels"); + test_value(empty_map.nx(), 0, "Check number of empty sky map X pixels"); + test_value(empty_map.ny(), 0, "Check number of empty sky map X pixels"); + test_value(empty_map.ndim(), 0, "Check empty sky map dimension"); + test_value(empty_map.shape().size(), 0, "Check empty sky map shape"); + + // Test that writing, publishing and printing of empty sky map does not + // lead to a segmentation fault + empty_map.save("test_empty_map.fits", true); + empty_map.publish("Empty sky map"); + empty_map.print(); // Define several maps for comparison GSkyMap map_src("CAR", "GAL", 0.0, 0.0, -1.0, 1.0, 10, 10, 2);