Commit ca3bbac7de01a2624d08c2aec40b0fc9c7f06ed4

Authored by Jürgen Knödlseder
1 parent 17d59710

Add GSkyMap::is_empty() method (#1828)

ChangeLog
1 -2016-08-09 1 +2016-08-10
2 2
3 * Version 1.2.0 released 3 * Version 1.2.0 released
4 ========================= 4 =========================
5 5
  6 + Add GSkyMap::is_empty() method (#1828)
6 Add GApplication access by index operator (#1838) 7 Add GApplication access by index operator (#1838)
7 Add GApplication::pars() and GApplicationPar::current_value() methods (#1838) 8 Add GApplication::pars() and GApplicationPar::current_value() methods (#1838)
8 Add GLog is_open(), is_empty() and written_size() methods (#1837) 9 Add GLog is_open(), is_empty() and written_size() methods (#1837)
1 New Features and Important Changes in GammaLib 1.2.0 1 New Features and Important Changes in GammaLib 1.2.0
2 2
3 -9 August 2016 3 +10 August 2016
4 4
5 5
6 1. Introduction 6 1. Introduction
@@ -33,6 +33,7 @@ The following methods have been added: @@ -33,6 +33,7 @@ The following methods have been added:
33 - GLog::is_open() 33 - GLog::is_open()
34 - GLog::is_empty() 34 - GLog::is_empty()
35 - GLog::written_size() 35 - GLog::written_size()
  36 +- GSkyMap::is_empty()
36 37
37 The following methods have been removed: 38 The following methods have been removed:
38 - ... 39 - ...
@@ -146,6 +147,9 @@ object. In case that no sky map is written, for example because none has been @@ -146,6 +147,9 @@ object. In case that no sky map is written, for example because none has been
146 defined so far, the method returns NONE. The GSkyMap::publish() method will 147 defined so far, the method returns NONE. The GSkyMap::publish() method will
147 detect the NONE value and will do nothing if no sky map exists (#1835). 148 detect the NONE value and will do nothing if no sky map exists (#1835).
148 149
  150 +The GSkyMap::is_empty() method signals whether a sky map contains no pixels
  151 +or no maps (#1828).
  152 +
149 153
150 13. Support module 154 13. Support module
151 ------------------ 155 ------------------
README.md
1 GammaLib information 1 GammaLib information
2 ==================== 2 ====================
3 -* Version: 1.2.0.dev1 (9 August 2016) 3 +* Version: 1.2.0.dev1 (10 August 2016)
4 * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu) 4 * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu)
5 5
6 [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=gammalib-integrate-os)](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/) 6 [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=gammalib-integrate-os)](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/)
include/GSkyMap.hpp
@@ -131,6 +131,7 @@ public: @@ -131,6 +131,7 @@ public:
131 void clear(void); 131 void clear(void);
132 GSkyMap* clone(void) const; 132 GSkyMap* clone(void) const;
133 std::string classname(void) const; 133 std::string classname(void) const;
  134 + bool is_empty(void) const;
134 const int& npix(void) const; 135 const int& npix(void) const;
135 const int& nx(void) const; 136 const int& nx(void) const;
136 const int& ny(void) const; 137 const int& ny(void) const;
@@ -289,6 +290,20 @@ std::string GSkyMap::classname(void) const @@ -289,6 +290,20 @@ std::string GSkyMap::classname(void) const
289 290
290 291
291 /***********************************************************************//** 292 /***********************************************************************//**
  293 + * @brief Signals if sky map is empty
  294 + *
  295 + * @return True if sky map is empty, false otherwise.
  296 + *
  297 + * Signals if a sky map has no pixels or maps.
  298 + ***************************************************************************/
  299 +inline
  300 +bool GSkyMap::is_empty(void) const
  301 +{
  302 + return ((m_num_pixels == 0) || (m_num_maps == 0));
  303 +}
  304 +
  305 +
  306 +/***********************************************************************//**
292 * @brief Returns number of pixels 307 * @brief Returns number of pixels
293 * 308 *
294 * @return Number of pixels in one sky map. 309 * @return Number of pixels in one sky map.
pyext/GSkyMap.i
@@ -146,6 +146,7 @@ public: @@ -146,6 +146,7 @@ public:
146 void clear(void); 146 void clear(void);
147 GSkyMap* clone(void) const; 147 GSkyMap* clone(void) const;
148 std::string classname(void) const; 148 std::string classname(void) const;
  149 + bool is_empty(void) const;
149 const int& npix(void) const; 150 const int& npix(void) const;
150 const int& nx(void) const; 151 const int& nx(void) const;
151 const int& ny(void) const; 152 const int& ny(void) const;
test/test_GSky.cpp
@@ -876,6 +876,24 @@ void TestGSky::test_GSkyMap(void) @@ -876,6 +876,24 @@ void TestGSky::test_GSkyMap(void)
876 system("rm -rf test_map_src.fits"); 876 system("rm -rf test_map_src.fits");
877 system("rm -rf test_map_dst.fits"); 877 system("rm -rf test_map_dst.fits");
878 system("rm -rf test_map_shape*.fits"); 878 system("rm -rf test_map_shape*.fits");
  879 +
  880 + // Define empty sky map
  881 + GSkyMap empty_map;
  882 +
  883 + // Test that empty map is indeed empty
  884 + test_assert(empty_map.is_empty(), "Check for empty sky map");
  885 + test_value(empty_map.nmaps(), 0, "Check for no sky maps");
  886 + test_value(empty_map.npix(), 0, "Check number of empty sky map pixels");
  887 + test_value(empty_map.nx(), 0, "Check number of empty sky map X pixels");
  888 + test_value(empty_map.ny(), 0, "Check number of empty sky map X pixels");
  889 + test_value(empty_map.ndim(), 0, "Check empty sky map dimension");
  890 + test_value(empty_map.shape().size(), 0, "Check empty sky map shape");
  891 +
  892 + // Test that writing, publishing and printing of empty sky map does not
  893 + // lead to a segmentation fault
  894 + empty_map.save("test_empty_map.fits", true);
  895 + empty_map.publish("Empty sky map");
  896 + empty_map.print();
879 897
880 // Define several maps for comparison 898 // Define several maps for comparison
881 GSkyMap map_src("CAR", "GAL", 0.0, 0.0, -1.0, 1.0, 10, 10, 2); 899 GSkyMap map_src("CAR", "GAL", 0.0, 0.0, -1.0, 1.0, 10, 10, 2);