Commit d0bfcda6b7667f0042ee230ddf6a7b9a85949011

Authored by Jürgen Knödlseder
1 parent b2297ef0

Add GSkyMap comparison operators (#4209)

ChangeLog
1   -2023-01-20
  1 +2023-02-10
2 2  
3 3 * Version 2.1.0 released
4 4 ========================
5 5  
  6 + Add GSkyMap comparison operators (#4209)
6 7 Add GIntegral::adaptive_gauss_kronrod() method (#4204)
7 8 Add optional unit parameter to GApplication::log_value() methods (#4202)
8 9 Fix segfault on saving empty GModelSpectralTable (#4198)
... ...
1 1 New Features and Important Changes in GammaLib 2.1.0
2 2  
3   -20 January 2023
  3 +10 February 2023
4 4  
5 5  
6 6 1. Introduction
... ... @@ -23,6 +23,8 @@ The following classes have been renamed:
23 23 The following methods have been added:
24 24 - GNdarray::index(int&)
25 25 - GIntegral::adaptive_gauss_kronrod()
  26 +- GSkyMap::operator==()
  27 +- GSkyMap::operator!=()
26 28 - GModelSpectralTable::nspectra()
27 29 - GModelSpectralTable::scale_energy()
28 30 - GModelSpectralTable::has_energy_scale()
... ... @@ -113,7 +115,9 @@ None
113 115  
114 116 13. Sky module
115 117 --------------
116   -None
  118 +Added comparison operators for sky map. Sky maps are considered identical if their
  119 +projections are identical, their coordinate definition and their number if pixels.
  120 +The actual content of the map is not relevant (#4209).
117 121  
118 122  
119 123 14. Support module
... ...
README.md
1 1 GammaLib information
2 2 ====================
3   -* Version: 2.1.0.dev (20 January 2023)
  3 +* Version: 2.1.0.dev (10 February 2023)
4 4  
5 5 [![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 6  
... ...
doc/source/admin/release_history/2.1.rst
... ... @@ -23,6 +23,8 @@ Bug fixes
23 23 Improvements
24 24 ------------
25 25  
  26 +* [`4209 <https://cta-redmine.irap.omp.eu/issues/4209>`_] -
  27 + Add ``GSkyMap`` comparison operators (#4209)
26 28 * [`4204 <https://cta-redmine.irap.omp.eu/issues/4204>`_] -
27 29 Add ``GIntegral::adaptive_gauss_kronrod()`` method
28 30 * [`4202 <https://cta-redmine.irap.omp.eu/issues/4202>`_] -
... ...
include/GSkyMap.hpp
1 1 /***************************************************************************
2 2 * GSkyMap.hpp - Sky map class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2021 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2023 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -88,12 +88,14 @@ class GSkyRegions;
88 88 ***************************************************************************/
89 89 class GSkyMap : public GBase {
90 90  
91   - friend GSkyMap sqrt(const GSkyMap& map);
92   - friend GSkyMap log(const GSkyMap& map);
93   - friend GSkyMap log10(const GSkyMap& map);
94   - friend GSkyMap abs(const GSkyMap& map);
95   - friend GSkyMap sign(const GSkyMap& map);
  91 + friend GSkyMap sqrt(const GSkyMap& map);
  92 + friend GSkyMap log(const GSkyMap& map);
  93 + friend GSkyMap log10(const GSkyMap& map);
  94 + friend GSkyMap abs(const GSkyMap& map);
  95 + friend GSkyMap sign(const GSkyMap& map);
96 96 friend GSkyMap clip(const GSkyMap& map, const double& thresh);
  97 + friend bool operator==(const GSkyMap &a, const GSkyMap &b);
  98 + friend bool operator!=(const GSkyMap &a, const GSkyMap &b);
97 99  
98 100 public:
99 101 // Constructors and destructors
... ...
pyext/GSkyMap.i
1 1 /***************************************************************************
2 2 * GSkyMap.i - Sky map class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2021 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2023 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -236,6 +236,10 @@ public:
236 236 self->operator/=(factor);
237 237 return (*self);
238 238 }
  239 + // Equality operator
  240 + bool __is__(const GSkyMap &map) {
  241 + return (*self) == map;
  242 + }
239 243 // Add pixel access operator as Python array
240 244 PyObject* array(const int& imap = 0) {
241 245 if (imap < 0 || imap >= self->nmaps()) {
... ...
src/sky/GSkyMap.cpp
1 1 /***************************************************************************
2 2 * GSkyMap.cpp - Sky map class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2022 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2023 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -4156,3 +4156,45 @@ GSkyMap clip(const GSkyMap&amp; map, const double&amp; thresh)
4156 4156 // Return sky map
4157 4157 return result;
4158 4158 }
  4159 +
  4160 +
  4161 +/*==========================================================================
  4162 + = =
  4163 + = Friends =
  4164 + = =
  4165 + ==========================================================================*/
  4166 +
  4167 +/***********************************************************************//**
  4168 + * @brief Equality operator
  4169 + *
  4170 + * @param[in] a First sky map.
  4171 + * @param[in] b Second sky map.
  4172 + * @return True if @p a and @p b are identical.
  4173 + *
  4174 + * Two sky maps are considered identical if they have the same projections,
  4175 + * coordinate definiton and number of pixels. The actual content of the map
  4176 + * does not need to be identical.
  4177 + ***************************************************************************/
  4178 +bool operator==(const GSkyMap &a, const GSkyMap &b)
  4179 +{
  4180 + // Return result
  4181 + return a.is_same(b);
  4182 +}
  4183 +
  4184 +
  4185 +/***********************************************************************//**
  4186 + * @brief Non-equality operator
  4187 + *
  4188 + * @param[in] a First sky map.
  4189 + * @param[in] b Second sky map.
  4190 + * @return True if @p a and @p b are not identical.
  4191 + *
  4192 + * Two sky maps are considered different if they either differ in projections,
  4193 + * coordinate definiton or number of pixels. The actual content of the map
  4194 + * does is not relevant.
  4195 + ***************************************************************************/
  4196 +bool operator!=(const GSkyMap &a, const GSkyMap &b)
  4197 +{
  4198 + // Return result
  4199 + return !(a == b);
  4200 +}
... ...
test/test_GSky.cpp
1 1 /***************************************************************************
2 2 * test_GSky.cpp - Test sky module *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2022 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2023 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -1125,13 +1125,13 @@ void TestGSky::test_GSkyMap(void)
1125 1125 GSkyMap empty_map;
1126 1126  
1127 1127 // Test that empty map is indeed empty
1128   - test_assert(empty_map.is_empty(), "Check for empty sky map");
1129   - test_value(empty_map.nmaps(), 0, "Check for no sky maps");
1130   - test_value(empty_map.npix(), 0, "Check number of empty sky map pixels");
1131   - test_value(empty_map.nx(), 0, "Check number of empty sky map X pixels");
1132   - test_value(empty_map.ny(), 0, "Check number of empty sky map X pixels");
1133   - test_value(empty_map.ndim(), 0, "Check empty sky map dimension");
1134   - test_value(empty_map.shape().size(), 0, "Check empty sky map shape");
  1128 + test_assert(empty_map.is_empty(), "Check for empty sky map");
  1129 + test_value(empty_map.nmaps(), 0, "Check for no sky maps");
  1130 + test_value(empty_map.npix(), 0, "Check number of empty sky map pixels");
  1131 + test_value(empty_map.nx(), 0, "Check number of empty sky map X pixels");
  1132 + test_value(empty_map.ny(), 0, "Check number of empty sky map X pixels");
  1133 + test_value(empty_map.ndim(), 0, "Check empty sky map dimension");
  1134 + test_value(empty_map.shape().size(), 0, "Check empty sky map shape");
1135 1135  
1136 1136 // Test that writing, publishing and printing of empty sky map does not
1137 1137 // lead to a segmentation fault
... ... @@ -1145,10 +1145,10 @@ void TestGSky::test_GSkyMap(void)
1145 1145 GSkyMap map_new("CAR", "GAL", 0.0, 0.0, -0.1, 0.1, 100, 100, 2);
1146 1146  
1147 1147 // Test map dimensions and shape
1148   - test_value(map_src.nmaps(), 2, "Check that sky map contains 2 maps");
1149   - test_value(map_src.ndim(), 1, "Check that sky map has one dimension");
1150   - test_value(map_src.shape().size(), 1, "Check that sky map has a shape size of 1");
1151   - test_value(map_src.shape()[0], 2, "Check that sky map has 2 maps");
  1148 + test_value(map_src.nmaps(), 2, "Check that sky map contains 2 maps");
  1149 + test_value(map_src.ndim(), 1, "Check that sky map has one dimension");
  1150 + test_value(map_src.shape().size(), 1, "Check that sky map has a shape size of 1");
  1151 + test_value(map_src.shape()[0], 2, "Check that sky map has 2 maps");
1152 1152  
1153 1153 // Fill map pixels
1154 1154 double total_src = 0.0;
... ... @@ -1179,8 +1179,8 @@ void TestGSky::test_GSkyMap(void)
1179 1179 total_dst /= 100.0;
1180 1180 total_new /= 100.0;
1181 1181 total_ref /= 100.0;
1182   - test_value(total_dst, total_ref, 1.0e-3, "Test operator+=(GSkyMap)");
1183   - test_value(total_new, total_ref, 1.0e-3, "Test operator+(GSkyMap)");
  1182 + test_value(total_dst, total_ref, 1.0e-3, "Test operator+=(GSkyMap)");
  1183 + test_value(total_new, total_ref, 1.0e-3, "Test operator+(GSkyMap)");
1184 1184  
1185 1185 // Subtract pixels from destination map
1186 1186 map_new = map_dst - map_src;
... ... @@ -1196,8 +1196,8 @@ void TestGSky::test_GSkyMap(void)
1196 1196 total_new += map_dst(pix,k);
1197 1197 }
1198 1198 }
1199   - test_value(total_dst, 0.0, 1.0e-3, "Test operator-=(GSkyMap)");
1200   - test_value(total_new, 0.0, 1.0e-3, "Test operator-(GSkyMap)");
  1199 + test_value(total_dst, 0.0, 1.0e-3, "Test operator-=(GSkyMap)");
  1200 + test_value(total_new, 0.0, 1.0e-3, "Test operator-(GSkyMap)");
1201 1201  
1202 1202 // Check map multiplication
1203 1203 GSkyMap test_map = map_src;
... ... @@ -1213,8 +1213,8 @@ void TestGSky::test_GSkyMap(void)
1213 1213 total_ref += map_src(pix,k) * map_src(pix,k);
1214 1214 }
1215 1215 }
1216   - test_value(total_test, total_ref, 1.0e-3, "Test operator*=(GSkyMap)");
1217   - test_value(total_new, total_ref, 1.0e-3, "Test operator*(GSkyMap)");
  1216 + test_value(total_test, total_ref, 1.0e-3, "Test operator*=(GSkyMap)");
  1217 + test_value(total_new, total_ref, 1.0e-3, "Test operator*(GSkyMap)");
1218 1218  
1219 1219 // Check map division
1220 1220 test_map = map_src;
... ... @@ -1230,8 +1230,8 @@ void TestGSky::test_GSkyMap(void)
1230 1230 total_ref += map_src(pix,k) / map_src(pix,k);
1231 1231 }
1232 1232 }
1233   - test_value(total_test, total_ref, 1.0e-3, "Test operator/=(GSkyMap)");
1234   - test_value(total_new, total_ref, 1.0e-3, "Test operator/(GSkyMap)");
  1233 + test_value(total_test, total_ref, 1.0e-3, "Test operator/=(GSkyMap)");
  1234 + test_value(total_new, total_ref, 1.0e-3, "Test operator/(GSkyMap)");
1235 1235  
1236 1236 // Check map scaling
1237 1237 test_map = map_src;
... ... @@ -1242,7 +1242,7 @@ void TestGSky::test_GSkyMap(void)
1242 1242 total_test += test_map(pix,k);
1243 1243 }
1244 1244 }
1245   - test_value(total_test, total_src*3.3, 1.0e-3, "Test operator*=(double)");
  1245 + test_value(total_test, total_src*3.3, 1.0e-3, "Test operator*=(double)");
1246 1246  
1247 1247 // Check map division
1248 1248 test_map = map_src;
... ... @@ -1253,7 +1253,7 @@ void TestGSky::test_GSkyMap(void)
1253 1253 total_test += test_map(pix,k);
1254 1254 }
1255 1255 }
1256   - test_value(total_test, total_src/3.3, 1.0e-3, "Test operator/=(double)");
  1256 + test_value(total_test, total_src/3.3, 1.0e-3, "Test operator/=(double)");
1257 1257  
1258 1258 // Check map value addition
1259 1259 test_map = map_src;
... ... @@ -1265,7 +1265,7 @@ void TestGSky::test_GSkyMap(void)
1265 1265 total_test += test_map(pix,k);
1266 1266 }
1267 1267 }
1268   - test_value(total_test, ref, 1.0e-3, "Test operator+=(double)");
  1268 + test_value(total_test, ref, 1.0e-3, "Test operator+=(double)");
1269 1269  
1270 1270 // Check map value subtraction
1271 1271 test_map = map_src;
... ... @@ -1277,7 +1277,11 @@ void TestGSky::test_GSkyMap(void)
1277 1277 total_test += test_map(pix,k);
1278 1278 }
1279 1279 }
1280   - test_value(total_test, ref, 1.0e-3, "Test operator-=(double)");
  1280 + test_value(total_test, ref, 1.0e-3, "Test operator-=(double)");
  1281 +
  1282 + // Test equality opeators
  1283 + test_assert(map_src == map_src, "Check map equality");
  1284 + test_assert(map_src != map_dst, "Check map inequality");
1281 1285  
1282 1286 // Save maps
1283 1287 map_src.save("test_map_src.fits", true);
... ... @@ -1290,8 +1294,8 @@ void TestGSky::test_GSkyMap(void)
1290 1294 for (int pix = 0; pix < map_stacked.npix(); ++pix) {
1291 1295 total_stacked += map_stacked(pix);
1292 1296 }
1293   - test_value(total_stacked, total_src, 1.0e-3, "Test stack_maps() method");
1294   - test_value(map_stacked.nmaps(), 1, "Test stack_maps() method");
  1297 + test_value(total_stacked, total_src, 1.0e-3, "Test stack_maps() method");
  1298 + test_value(map_stacked.nmaps(), 1, "Test stack_maps() method");
1295 1299  
1296 1300 // Test total counts computation
1297 1301 GNdarray counts_spectrum = map_src.counts();
... ... @@ -1299,12 +1303,12 @@ void TestGSky::test_GSkyMap(void)
1299 1303 for (int i = 0; i < counts_spectrum.size(); ++i) {
1300 1304 total_counts += counts_spectrum(i);
1301 1305 }
1302   - test_value(total_counts, total_src, 1.0e-3, "Test counts() method");
1303   - test_value(counts_spectrum.size(), map_src.nmaps(), "Test counts() method");
  1306 + test_value(total_counts, total_src, 1.0e-3, "Test counts() method");
  1307 + test_value(counts_spectrum.size(), map_src.nmaps(), "Test counts() method");
1304 1308  
1305 1309 // Test total flux computation
1306 1310 GNdarray flux_spectrum = map_src.flux();
1307   - test_value(flux_spectrum.size(), map_src.nmaps(), "Test flux() method");
  1311 + test_value(flux_spectrum.size(), map_src.nmaps(), "Test flux() method");
1308 1312  
1309 1313 // Test flux in region methods
1310 1314 GSkyRegionCircle gc_circle(266.40499, -28.93617, 3.0);
... ... @@ -1333,8 +1337,8 @@ void TestGSky::test_GSkyMap(void)
1333 1337 total_more += map_more(pix,k);
1334 1338 }
1335 1339 }
1336   - test_value(total_more, total_src, 1.0e-3, "Test nmaps() method with more maps");
1337   - test_value(map_more.nmaps(), 4, "Test nmaps() method with more maps");
  1340 + test_value(total_more, total_src, 1.0e-3, "Test nmaps() method with more maps");
  1341 + test_value(map_more.nmaps(), 4, "Test nmaps() method with more maps");
1338 1342 GSkyMap map_less = map_src;
1339 1343 map_less.nmaps(1);
1340 1344 double total_less = 0.0;
... ... @@ -1343,8 +1347,8 @@ void TestGSky::test_GSkyMap(void)
1343 1347 total_less += map_less(pix,k);
1344 1348 }
1345 1349 }
1346   - test_value(total_less, 0.5*total_src, 1.0e-3, "Test nmaps() method with less maps");
1347   - test_value(map_less.nmaps(), 1, "Test nmaps() method with less maps");
  1350 + test_value(total_less, 0.5*total_src, 1.0e-3, "Test nmaps() method with less maps");
  1351 + test_value(map_less.nmaps(), 1, "Test nmaps() method with less maps");
1348 1352  
1349 1353 // Test map extraction
1350 1354 GSkyMap map_extract = map_src.extract(0);
... ... @@ -1354,8 +1358,8 @@ void TestGSky::test_GSkyMap(void)
1354 1358 total_extract += map_extract(pix,k);
1355 1359 }
1356 1360 }
1357   - test_value(total_extract, 0.5*total_src, 1.0e-3, "Test extract() method with 1 map");
1358   - test_value(map_extract.nmaps(), 1, "Test extract() method with 1 map");
  1361 + test_value(total_extract, 0.5*total_src, 1.0e-3, "Test extract() method with 1 map");
  1362 + test_value(map_extract.nmaps(), 1, "Test extract() method with 1 map");
1359 1363 map_extract = map_src.extract(0,2);
1360 1364 total_extract = 0.0;
1361 1365 for (int k = 0; k < map_extract.nmaps(); ++k) {
... ... @@ -1363,17 +1367,17 @@ void TestGSky::test_GSkyMap(void)
1363 1367 total_extract += map_extract(pix,k);
1364 1368 }
1365 1369 }
1366   - test_value(total_extract, total_src, 1.0e-3, "Test extract() method with 2 maps");
1367   - test_value(map_extract.nmaps(), 2, "Test extract() method with 2 maps");
  1370 + test_value(total_extract, total_src, 1.0e-3, "Test extract() method with 2 maps");
  1371 + test_value(map_extract.nmaps(), 2, "Test extract() method with 2 maps");
1368 1372  
1369 1373 // Define one more map for shaping manipulation
1370 1374 GSkyMap map_shape0("CAR", "GAL", 0.0, 0.0, -1.0, 1.0, 10, 10);
1371 1375  
1372 1376 // Test map dimensions and shape
1373   - test_value(map_shape0.nmaps(), 1, "Check that sky map contains one map");
1374   - test_value(map_shape0.ndim(), 1, "Check that sky map has one dimension");
1375   - test_value(map_shape0.shape().size(), 1, "Check that sky map has a shape size of 1");
1376   - test_value(map_shape0.shape()[0], 1, "Check that sky map has one map");
  1377 + test_value(map_shape0.nmaps(), 1, "Check that sky map contains one map");
  1378 + test_value(map_shape0.ndim(), 1, "Check that sky map has one dimension");
  1379 + test_value(map_shape0.shape().size(), 1, "Check that sky map has a shape size of 1");
  1380 + test_value(map_shape0.shape()[0], 1, "Check that sky map has one map");
1377 1381  
1378 1382 // Save map
1379 1383 map_shape0.save("test_map_shape0.fits", true);
... ... @@ -1382,19 +1386,19 @@ void TestGSky::test_GSkyMap(void)
1382 1386 GSkyMap map_load_shape0("test_map_shape0.fits");
1383 1387  
1384 1388 // Test map dimensions and shape
1385   - test_value(map_load_shape0.nmaps(), 1, "Check that sky map contains one map");
1386   - test_value(map_load_shape0.ndim(), 1, "Check that sky map has one dimension");
1387   - test_value(map_load_shape0.shape().size(), 1, "Check that sky map has a shape size of 1");
1388   - test_value(map_load_shape0.shape()[0], 1, "Check that sky map has one map");
  1389 + test_value(map_load_shape0.nmaps(), 1, "Check that sky map contains one map");
  1390 + test_value(map_load_shape0.ndim(), 1, "Check that sky map has one dimension");
  1391 + test_value(map_load_shape0.shape().size(), 1, "Check that sky map has a shape size of 1");
  1392 + test_value(map_load_shape0.shape()[0], 1, "Check that sky map has one map");
1389 1393  
1390 1394 // Define one more map for shaping manipulation
1391 1395 GSkyMap map_shape("CAR", "GAL", 0.0, 0.0, -1.0, 1.0, 10, 10, 12);
1392 1396  
1393 1397 // Test initial map dimensions and shape
1394   - test_value(map_shape.nmaps(), 12, "Check that sky map contains 12 maps");
1395   - test_value(map_shape.ndim(), 1, "Check that sky map has one dimension");
1396   - test_value(map_shape.shape().size(), 1, "Check that sky map has a shape size of 1");
1397   - test_value(map_shape.shape()[0], 12, "Check that sky map has 12 maps");
  1398 + test_value(map_shape.nmaps(), 12, "Check that sky map contains 12 maps");
  1399 + test_value(map_shape.ndim(), 1, "Check that sky map has one dimension");
  1400 + test_value(map_shape.shape().size(), 1, "Check that sky map has a shape size of 1");
  1401 + test_value(map_shape.shape()[0], 12, "Check that sky map has 12 maps");
1398 1402  
1399 1403 // Save map
1400 1404 map_shape.save("test_map_shape1.fits", true);
... ... @@ -1403,20 +1407,20 @@ void TestGSky::test_GSkyMap(void)
1403 1407 GSkyMap map_load_shape1("test_map_shape1.fits");
1404 1408  
1405 1409 // Test loaded map dimensions and shape
1406   - test_value(map_load_shape1.nmaps(), 12, "Check that sky map contains 12 maps");
1407   - test_value(map_load_shape1.ndim(), 1, "Check that sky map has one dimension");
1408   - test_value(map_load_shape1.shape().size(), 1, "Check that sky map has a shape size of 1");
1409   - test_value(map_load_shape1.shape()[0], 12, "Check that sky map has 12 maps");
  1410 + test_value(map_load_shape1.nmaps(), 12, "Check that sky map contains 12 maps");
  1411 + test_value(map_load_shape1.ndim(), 1, "Check that sky map has one dimension");
  1412 + test_value(map_load_shape1.shape().size(), 1, "Check that sky map has a shape size of 1");
  1413 + test_value(map_load_shape1.shape()[0], 12, "Check that sky map has 12 maps");
1410 1414  
1411 1415 // Set new map shape
1412 1416 map_shape.shape(3,4);
1413 1417  
1414 1418 // Test map dimensions and shape
1415   - test_value(map_shape.nmaps(), 12, "Check that sky map contains 12 maps");
1416   - test_value(map_shape.ndim(), 2, "Check that sky map has two dimensions");
1417   - test_value(map_shape.shape().size(), 2, "Check that sky map has a shape size of 2");
1418   - test_value(map_shape.shape()[0], 3, "Check that sky map has 3 maps in first dimension");
1419   - test_value(map_shape.shape()[1], 4, "Check that sky map has 4 maps in second dimension");
  1419 + test_value(map_shape.nmaps(), 12, "Check that sky map contains 12 maps");
  1420 + test_value(map_shape.ndim(), 2, "Check that sky map has two dimensions");
  1421 + test_value(map_shape.shape().size(), 2, "Check that sky map has a shape size of 2");
  1422 + test_value(map_shape.shape()[0], 3, "Check that sky map has 3 maps in first dimension");
  1423 + test_value(map_shape.shape()[1], 4, "Check that sky map has 4 maps in second dimension");
1420 1424  
1421 1425 // Save map
1422 1426 map_shape.save("test_map_shape2.fits", true);
... ... @@ -1425,22 +1429,22 @@ void TestGSky::test_GSkyMap(void)
1425 1429 GSkyMap map_load_shape2("test_map_shape2.fits");
1426 1430  
1427 1431 // Test map dimensions and shape
1428   - test_value(map_load_shape2.nmaps(), 12, "Check that sky map contains 12 maps");
1429   - test_value(map_load_shape2.ndim(), 2, "Check that sky map has two dimensions");
1430   - test_value(map_load_shape2.shape().size(), 2, "Check that sky map has a shape size of 2");
1431   - test_value(map_load_shape2.shape()[0], 3, "Check that sky map has 3 maps in first dimension");
1432   - test_value(map_load_shape2.shape()[1], 4, "Check that sky map has 4 maps in second dimension");
  1432 + test_value(map_load_shape2.nmaps(), 12, "Check that sky map contains 12 maps");
  1433 + test_value(map_load_shape2.ndim(), 2, "Check that sky map has two dimensions");
  1434 + test_value(map_load_shape2.shape().size(), 2, "Check that sky map has a shape size of 2");
  1435 + test_value(map_load_shape2.shape()[0], 3, "Check that sky map has 3 maps in first dimension");
  1436 + test_value(map_load_shape2.shape()[1], 4, "Check that sky map has 4 maps in second dimension");
1433 1437  
1434 1438 // Set new map shape
1435 1439 map_shape.shape(2,3,2);
1436 1440  
1437 1441 // Test map dimensions and shape
1438   - test_value(map_shape.nmaps(), 12, "Check that sky map contains 12 maps");
1439   - test_value(map_shape.ndim(), 3, "Check that sky map has three dimensions");
1440   - test_value(map_shape.shape().size(), 3, "Check that sky map has a shape size of 3");
1441   - test_value(map_shape.shape()[0], 2, "Check that sky map has 2 maps in first dimension");
1442   - test_value(map_shape.shape()[1], 3, "Check that sky map has 3 maps in second dimension");
1443   - test_value(map_shape.shape()[2], 2, "Check that sky map has 2 maps in third dimension");
  1442 + test_value(map_shape.nmaps(), 12, "Check that sky map contains 12 maps");
  1443 + test_value(map_shape.ndim(), 3, "Check that sky map has three dimensions");
  1444 + test_value(map_shape.shape().size(), 3, "Check that sky map has a shape size of 3");
  1445 + test_value(map_shape.shape()[0], 2, "Check that sky map has 2 maps in first dimension");
  1446 + test_value(map_shape.shape()[1], 3, "Check that sky map has 3 maps in second dimension");
  1447 + test_value(map_shape.shape()[2], 2, "Check that sky map has 2 maps in third dimension");
1444 1448  
1445 1449 // Save map
1446 1450 map_shape.save("test_map_shape3.fits", true);
... ... @@ -1449,12 +1453,12 @@ void TestGSky::test_GSkyMap(void)
1449 1453 GSkyMap map_load_shape3("test_map_shape3.fits");
1450 1454  
1451 1455 // Test map dimensions and shape
1452   - test_value(map_load_shape3.nmaps(), 12, "Check that sky map contains 12 maps");
1453   - test_value(map_load_shape3.ndim(), 3, "Check that sky map has three dimensions");
1454   - test_value(map_load_shape3.shape().size(), 3, "Check that sky map has a shape size of 3");
1455   - test_value(map_load_shape3.shape()[0], 2, "Check that sky map has 2 maps in first dimension");
1456   - test_value(map_load_shape3.shape()[1], 3, "Check that sky map has 3 maps in second dimension");
1457   - test_value(map_load_shape3.shape()[2], 2, "Check that sky map has 2 maps in third dimension");
  1456 + test_value(map_load_shape3.nmaps(), 12, "Check that sky map contains 12 maps");
  1457 + test_value(map_load_shape3.ndim(), 3, "Check that sky map has three dimensions");
  1458 + test_value(map_load_shape3.shape().size(), 3, "Check that sky map has a shape size of 3");
  1459 + test_value(map_load_shape3.shape()[0], 2, "Check that sky map has 2 maps in first dimension");
  1460 + test_value(map_load_shape3.shape()[1], 3, "Check that sky map has 3 maps in second dimension");
  1461 + test_value(map_load_shape3.shape()[2], 2, "Check that sky map has 2 maps in third dimension");
1458 1462  
1459 1463 // Load map for smoothing
1460 1464 GSkyMap map_smooth(sky_map);
... ... @@ -1475,7 +1479,7 @@ void TestGSky::test_GSkyMap(void)
1475 1479 for (int pix = 0; pix < map_smooth1.npix(); ++pix) {
1476 1480 sum_smooth1 += map_smooth1(pix);
1477 1481 }
1478   - test_value(sum_smooth1, ref_smooth, "Check DISK smoothing");
  1482 + test_value(sum_smooth1, ref_smooth, "Check DISK smoothing");
1479 1483  
1480 1484 // Smooth map using GAUSSIAN kernel
1481 1485 GSkyMap map_smooth2 = map_smooth;
... ...
test/test_GSky.py
1 1 # ==========================================================================
2 2 # This module performs unit tests for the GammaLib sky module.
3 3 #
4   -# Copyright (C) 2012-2021 Juergen Knoedlseder
  4 +# Copyright (C) 2012-2023 Juergen Knoedlseder
5 5 #
6 6 # This program is free software: you can redistribute it and/or modify
7 7 # it under the terms of the GNU General Public License as published by
... ... @@ -211,7 +211,7 @@ class Test(gammalib.GPythonTestSuite):
211 211 sum = 0.0
212 212 for pix in map:
213 213 sum += pix
214   - self.test_value(sum, 16.0)
  214 + self.test_value(sum, 16.0)
215 215  
216 216 # Addition operator
217 217 map_res = map + map_b
... ... @@ -241,6 +241,17 @@ class Test(gammalib.GPythonTestSuite):
241 241 self.test_value(map_res[2], 5.0/3.0)
242 242 self.test_value(map_res[3], 7.0/4.0)
243 243  
  244 + # Equality operator
  245 + self.test_assert(map == map, 'Check map equality')
  246 +
  247 + # Inequality operator
  248 + map_ineq1 = gammalib.GSkyMap('TAN', 'CEL', 83.6331, 22.0145, -3.7, 2.6, 2, 2)
  249 + map_ineq2 = gammalib.GSkyMap('CAR', 'CEL', 0.0, 0.0, -3.7, 2.6, 2, 2)
  250 + map_ineq3 = gammalib.GSkyMap('CAR', 'CEL', 83.6331, 22.0145, -3.7, 2.6, 2, 3)
  251 + self.test_assert(map != map_ineq1, 'Check map inequality (projection)')
  252 + self.test_assert(map != map_ineq2, 'Check map inequality (centre)')
  253 + self.test_assert(map != map_ineq3, 'Check map inequality (pixels)')
  254 +
244 255 # Return
245 256 return
246 257  
... ...