Commit bf39a08a569317292f60fbae23241fa32a9fc871
1 parent
cb5748f8
Add equality and non-equality operators to GSkyRegionCircle class
Showing
9 changed files
with
203 additions
and
162 deletions
ChangeLog
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | * Version 1.7.0 released |
| 4 | 4 | ======================== |
| 5 | 5 | |
| 6 | + Add equality and non-equality operators to GSkyRegionCircle class | |
| 6 | 7 | Add GModelSpatialRadialRing class (#3253) |
| 7 | 8 | Fix ambiguity problem in GSkyDir::posang() and posang_deg() (#3199) |
| 8 | 9 | Avoid rounding errors in GSkyMap operators (#3126) | ... | ... |
NEWS
| ... | ... | @@ -44,7 +44,10 @@ The following methods have been added: |
| 44 | 44 | - GSkyDir::rotate() - Rotate sky direction (radians variant) |
| 45 | 45 | - GSkyDir::GSkyDir(GVector&) - Sky direction vector constructor |
| 46 | 46 | - GSkyMap::extract() - Extract section of sky map |
| 47 | +- GSkyRegionCircle::operator==() - Equality operator | |
| 48 | +- GSkyRegionCircle::operator!=() - Non-equality operator | |
| 47 | 49 | - GModelSpatial::flux() - Extract flux from sky region |
| 50 | +- GModelSpatialDiffuseCube::mc_cone() - Return MC simulation cone | |
| 48 | 51 | - GCTAObservation::remove_response_cache(string&) - Remove response cache for model |
| 49 | 52 | - GCTAResponse::remove_response_cache(string&) - Remove response cache for model |
| 50 | 53 | - GCTAResponseCache::remove(string&) - Remove response cache for model |
| ... | ... | @@ -58,6 +61,7 @@ The following methods have been removed: |
| 58 | 61 | - none |
| 59 | 62 | |
| 60 | 63 | The following methods have been renamed: |
| 64 | +- GModelSpatialDiffuseCube::set_mc_cone() to GModelSpatialDiffuseCube::mc_cone() | |
| 61 | 65 | - GResponse::irf(GEvent&, GSource&, GObservation&) to GResponse::irf_spatial() |
| 62 | 66 | - GLATResponse::irf(GLATEventAtom&, GSource&, GObservation&) to GLATResponse::irf_spatial_atom() |
| 63 | 67 | - GLATResponse::irf(GLATEventBin&, GSource&, GObservation&) to GLATResponse::irf_spatial_bin() |
| ... | ... | @@ -161,6 +165,8 @@ None |
| 161 | 165 | |
| 162 | 166 | 12. Sky module |
| 163 | 167 | -------------- |
| 168 | +Added equality and non-equality operators to the GSkyRegionCircle class. | |
| 169 | + | |
| 164 | 170 | The position angle is now computed by GSkyDir::posang() and GSkyDir::posang_deg() |
| 165 | 171 | for the coordinate system that is specified by the coordsys argument. By default |
| 166 | 172 | this argument is set to "CEL", hence by default the methods return the position | ... | ... |
doc/source/admin/release_history/1.7.rst
| ... | ... | @@ -30,6 +30,7 @@ Bug fixes |
| 30 | 30 | Improvements |
| 31 | 31 | ------------ |
| 32 | 32 | |
| 33 | +* Add equality and non-equality operators to ``GSkyRegionCircle`` class. | |
| 33 | 34 | * [`3202 <https://cta-redmine.irap.omp.eu/issues/3202>`_] - |
| 34 | 35 | Replace ``GCTAResponseCache`` class by ``GResponseCache`` class. |
| 35 | 36 | * [`3062 <https://cta-redmine.irap.omp.eu/issues/3062>`_] - | ... | ... |
include/GSkyRegionCircle.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GSkyRegionCircle.hpp - circular sky region class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2015 by Michael Mayer * | |
| 4 | + * copyright (C) 2013-2020 by Michael Mayer * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -57,6 +57,10 @@ |
| 57 | 57 | ***************************************************************************/ |
| 58 | 58 | class GSkyRegionCircle : public GSkyRegion { |
| 59 | 59 | |
| 60 | + // Operator friends | |
| 61 | + friend bool operator==(const GSkyRegionCircle &a, const GSkyRegionCircle &b); | |
| 62 | + friend bool operator!=(const GSkyRegionCircle &a, const GSkyRegionCircle &b); | |
| 63 | + | |
| 60 | 64 | public: |
| 61 | 65 | // Constructors and destructors |
| 62 | 66 | GSkyRegionCircle(void); |
| ... | ... | @@ -96,7 +100,7 @@ protected: |
| 96 | 100 | |
| 97 | 101 | // Protected members |
| 98 | 102 | GSkyDir m_centre; //!< Centre or reference point of the region |
| 99 | - double m_radius; //!< Radius of circular the region [deg] | |
| 103 | + double m_radius; //!< Radius of circular the region (degrees) | |
| 100 | 104 | }; |
| 101 | 105 | |
| 102 | 106 | ... | ... |
pyext/GSkyRegionCircle.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GSkyRegionCircle.i - Sky region class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2019 by Michael Mayer * | |
| 4 | + * copyright (C) 2013-2020 by Michael Mayer * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -67,6 +67,12 @@ public: |
| 67 | 67 | * @brief GSkyRegionCircle class extension |
| 68 | 68 | ***************************************************************************/ |
| 69 | 69 | %extend GSkyRegionCircle { |
| 70 | + bool __eq__(const GSkyRegionCircle& region) const { | |
| 71 | + return ((*self) == region); | |
| 72 | + } | |
| 73 | + bool __ne__(const GSkyRegionCircle& region) const { | |
| 74 | + return ((*self) != region); | |
| 75 | + } | |
| 70 | 76 | GSkyRegionCircle copy() { |
| 71 | 77 | return (*self); |
| 72 | 78 | } | ... | ... |
src/sky/GSkyRegionCircle.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GSkyRegionCircle.cpp - Circular sky region class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2016 by Michael Mayer * | |
| 4 | + * copyright (C) 2013-2020 by Michael Mayer * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -609,3 +609,33 @@ void GSkyRegionCircle::compute_solid_angle(void) |
| 609 | 609 | // Return |
| 610 | 610 | return; |
| 611 | 611 | } |
| 612 | + | |
| 613 | + | |
| 614 | +/***********************************************************************//** | |
| 615 | + * @brief Equality operator | |
| 616 | + * | |
| 617 | + * @param[in] a First sky region circle. | |
| 618 | + * @param[in] b Second sky region circle. | |
| 619 | + * @return True if both sky region circles are identical. | |
| 620 | + * | |
| 621 | + * Returns true if two sky region circles and identical. | |
| 622 | + ***************************************************************************/ | |
| 623 | +bool operator==(const GSkyRegionCircle &a, const GSkyRegionCircle &b) | |
| 624 | +{ | |
| 625 | + // Return equality | |
| 626 | + return ((a.m_centre == b.m_centre) && (a.m_radius == b.m_radius)); | |
| 627 | +} | |
| 628 | + | |
| 629 | + | |
| 630 | +/***********************************************************************//** | |
| 631 | + * @brief Non equality operator | |
| 632 | + * | |
| 633 | + * @param[in] a First sky region circle. | |
| 634 | + * @param[in] b Second sky region circle. | |
| 635 | + * @return True if both sky region circles are different. | |
| 636 | + ***************************************************************************/ | |
| 637 | +bool operator!=(const GSkyRegionCircle &a, const GSkyRegionCircle &b) | |
| 638 | +{ | |
| 639 | + // Return non equality | |
| 640 | + return ((a.m_centre != b.m_centre) || (a.m_radius != b.m_radius)); | |
| 641 | +} | ... | ... |
test/test_GSky.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * test_GSky.cpp - Test sky module * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2019 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2020 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -54,10 +54,10 @@ const std::string sky_map = datadir + "/cena_lobes_parkes.fits"; |
| 54 | 54 | * @brief Set parameters and tests |
| 55 | 55 | ***************************************************************************/ |
| 56 | 56 | void TestGSky::set(void){ |
| 57 | - | |
| 57 | + | |
| 58 | 58 | // Test name |
| 59 | 59 | name("GSky"); |
| 60 | - | |
| 60 | + | |
| 61 | 61 | // Append tests |
| 62 | 62 | append(static_cast<pfunction>(&TestGSky::test_GWcs), |
| 63 | 63 | "Test GWcs"); |
| ... | ... | @@ -77,16 +77,12 @@ void TestGSky::set(void){ |
| 77 | 77 | "Test GSkyMap"); |
| 78 | 78 | append(static_cast<pfunction>(&TestGSky::test_GSkyMap_io), |
| 79 | 79 | "Test GSkyMap I/O"); |
| 80 | - append(static_cast<pfunction>(&TestGSky::test_GSkyRegions_io), | |
| 80 | + append(static_cast<pfunction>(&TestGSky::test_GSkyRegions), | |
| 81 | 81 | "Test GSkyRegions"); |
| 82 | - append(static_cast<pfunction>(&TestGSky::test_GSkyRegionCircle_construct), | |
| 83 | - "Test GSkyRegionCircle constructors"); | |
| 84 | - append(static_cast<pfunction>(&TestGSky::test_GSkyRegionCircle_logic), | |
| 85 | - "Test GSkyRegionCircle logic"); | |
| 86 | - append(static_cast<pfunction>(&TestGSky::test_GSkyRegionMap_construct), | |
| 87 | - "Test GSkyRegionMap constructors"); | |
| 88 | - append(static_cast<pfunction>(&TestGSky::test_GSkyRegionMap_logic), | |
| 89 | - "Test GSkyRegionMap logic"); | |
| 82 | + append(static_cast<pfunction>(&TestGSky::test_GSkyRegionCircle), | |
| 83 | + "Test GSkyRegionCircle"); | |
| 84 | + append(static_cast<pfunction>(&TestGSky::test_GSkyRegionMap), | |
| 85 | + "Test GSkyRegionMap"); | |
| 90 | 86 | append(static_cast<pfunction>(&TestGSky::test_GHorizDir), |
| 91 | 87 | "Test GHorizDir"); |
| 92 | 88 | |
| ... | ... | @@ -124,10 +120,10 @@ double TestGSky::wcs_forth_back_pixel(GWcs* wcs, |
| 124 | 120 | { |
| 125 | 121 | // Initialise maximal distance |
| 126 | 122 | double dist_max = 0.0; |
| 127 | - | |
| 123 | + | |
| 128 | 124 | // Loop over x pixels |
| 129 | 125 | for (int ix = -nx; ix <= nx; ++ix) { |
| 130 | - | |
| 126 | + | |
| 131 | 127 | // Set x value |
| 132 | 128 | double x = double(ix) + crpix1; |
| 133 | 129 | |
| ... | ... | @@ -357,7 +353,7 @@ void TestGSky::test_GSkyDir(void) |
| 357 | 353 | |
| 358 | 354 | // Return |
| 359 | 355 | return; |
| 360 | -} | |
| 356 | +} | |
| 361 | 357 | |
| 362 | 358 | |
| 363 | 359 | /***********************************************************************//** |
| ... | ... | @@ -913,7 +909,7 @@ void TestGSky::test_GSkyMap(void) |
| 913 | 909 | |
| 914 | 910 | // Define empty sky map |
| 915 | 911 | GSkyMap empty_map; |
| 916 | - | |
| 912 | + | |
| 917 | 913 | // Test that empty map is indeed empty |
| 918 | 914 | test_assert(empty_map.is_empty(), "Check for empty sky map"); |
| 919 | 915 | test_value(empty_map.nmaps(), 0, "Check for no sky maps"); |
| ... | ... | @@ -922,13 +918,13 @@ void TestGSky::test_GSkyMap(void) |
| 922 | 918 | test_value(empty_map.ny(), 0, "Check number of empty sky map X pixels"); |
| 923 | 919 | test_value(empty_map.ndim(), 0, "Check empty sky map dimension"); |
| 924 | 920 | test_value(empty_map.shape().size(), 0, "Check empty sky map shape"); |
| 925 | - | |
| 921 | + | |
| 926 | 922 | // Test that writing, publishing and printing of empty sky map does not |
| 927 | 923 | // lead to a segmentation fault |
| 928 | 924 | empty_map.save("test_empty_map.fits", true); |
| 929 | 925 | empty_map.publish("Empty sky map"); |
| 930 | 926 | empty_map.print(); |
| 931 | - | |
| 927 | + | |
| 932 | 928 | // Define several maps for comparison |
| 933 | 929 | GSkyMap map_src("CAR", "GAL", 0.0, 0.0, -1.0, 1.0, 10, 10, 2); |
| 934 | 930 | GSkyMap map_dst("CAR", "GAL", 0.0, 0.0, -0.1, 0.1, 100, 100, 2); |
| ... | ... | @@ -1230,7 +1226,7 @@ void TestGSky::test_GSkyMap(void) |
| 1230 | 1226 | |
| 1231 | 1227 | // Load map for smoothing |
| 1232 | 1228 | GSkyMap map_smooth(sky_map); |
| 1233 | - | |
| 1229 | + | |
| 1234 | 1230 | // Compute sum of sky map for reference |
| 1235 | 1231 | double ref_smooth = 0.0; |
| 1236 | 1232 | for (int pix = 0; pix < map_smooth.npix(); ++pix) { |
| ... | ... | @@ -1296,7 +1292,7 @@ void TestGSky::test_GSkyMap(void) |
| 1296 | 1292 | test_map = map_src.extract(inclusions); |
| 1297 | 1293 | test_value(test_map.npix(), 36, "Check trimmed map pixel count (region)"); |
| 1298 | 1294 | test_value(test_map.nmaps(), map_src.nmaps(), "Check total maps in trimmed map (region)"); |
| 1299 | - | |
| 1295 | + | |
| 1300 | 1296 | // Check the pixel values |
| 1301 | 1297 | total_test = 0.0; |
| 1302 | 1298 | total_src = 0.0; |
| ... | ... | @@ -1408,7 +1404,7 @@ void TestGSky::test_GSkyMap_io(void) |
| 1408 | 1404 | wcs3.shape(2,2,3); |
| 1409 | 1405 | wcs3.write(fits, "WCS3"); |
| 1410 | 1406 | fits.save(true); |
| 1411 | - | |
| 1407 | + | |
| 1412 | 1408 | // Load HEALPix map and check content |
| 1413 | 1409 | GSkyMap map1(filename+"[HEALPIX1]"); |
| 1414 | 1410 | test_value(map1.npix(), healpix1.npix(), "Check number of HEALPix pixels"); |
| ... | ... | @@ -1452,12 +1448,69 @@ void TestGSky::test_GSkyMap_io(void) |
| 1452 | 1448 | |
| 1453 | 1449 | |
| 1454 | 1450 | /*************************************************************************** |
| 1455 | - * @brief GSkyRegionCircle_construct | |
| 1451 | + * @brief Test GSkyRegions class | |
| 1452 | + ***************************************************************************/ | |
| 1453 | + void TestGSky::test_GSkyRegions(void) | |
| 1454 | +{ | |
| 1455 | + // Allocate regions | |
| 1456 | + GSkyRegions regions; | |
| 1457 | + | |
| 1458 | + // Test regions loading | |
| 1459 | + test_try("Test regions loading"); | |
| 1460 | + try { | |
| 1461 | + regions.load(sky_region); | |
| 1462 | + test_try_success(); | |
| 1463 | + } | |
| 1464 | + catch (std::exception &e) { | |
| 1465 | + test_try_failure(e); | |
| 1466 | + } | |
| 1467 | + | |
| 1468 | + // Check if region was loaded correctly | |
| 1469 | + GSkyRegionCircle* circle = dynamic_cast<GSkyRegionCircle*>(regions[0]); | |
| 1470 | + test_assert(circle->type() == "Circle", "Region is not a circle"); | |
| 1471 | + test_value(circle->radius(), 10.0, 1.0e-10); | |
| 1472 | + test_value(circle->ra(), 0.1, 1.0e-10); | |
| 1473 | + test_value(circle->dec(), -35.6, 1.0e-10); | |
| 1474 | + | |
| 1475 | + // Test regions saving | |
| 1476 | + test_try("Test regions saving"); | |
| 1477 | + try { | |
| 1478 | + regions.save("region.reg"); | |
| 1479 | + test_try_success(); | |
| 1480 | + } | |
| 1481 | + catch (std::exception &e) { | |
| 1482 | + test_try_failure(e); | |
| 1483 | + } | |
| 1484 | + | |
| 1485 | + // Test regions reloading | |
| 1486 | + test_try("Test regions reloading"); | |
| 1487 | + try { | |
| 1488 | + regions.load("region.reg"); | |
| 1489 | + test_try_success(); | |
| 1490 | + } | |
| 1491 | + catch (std::exception &e) { | |
| 1492 | + test_try_failure(e); | |
| 1493 | + } | |
| 1494 | + | |
| 1495 | + // Check if region was loaded correctly | |
| 1496 | + circle = dynamic_cast<GSkyRegionCircle*>(regions[0]); | |
| 1497 | + test_assert(circle->type() == "Circle", "Region is not a circle"); | |
| 1498 | + test_value(circle->radius(), 10.0, 1.0e-10); | |
| 1499 | + test_value(circle->ra(), 0.1, 1.0e-10); | |
| 1500 | + test_value(circle->dec(), -35.6, 1.0e-10); | |
| 1501 | + | |
| 1502 | + // Exit test | |
| 1503 | + return; | |
| 1504 | +} | |
| 1505 | + | |
| 1506 | + | |
| 1507 | +/*************************************************************************** | |
| 1508 | + * @brief Test GSkyRegionCircle | |
| 1456 | 1509 | ***************************************************************************/ |
| 1457 | -void TestGSky::test_GSkyRegionCircle_construct(void) | |
| 1510 | +void TestGSky::test_GSkyRegionCircle(void) | |
| 1458 | 1511 | { |
| 1459 | 1512 | // Define region for comparison |
| 1460 | - GSkyDir refdir_radeczerozero = GSkyDir(); | |
| 1513 | + GSkyDir refdir_radeczerozero; | |
| 1461 | 1514 | refdir_radeczerozero.radec_deg(0,0); |
| 1462 | 1515 | double refradius = 10.; |
| 1463 | 1516 | |
| ... | ... | @@ -1471,7 +1524,7 @@ void TestGSky::test_GSkyRegionCircle_construct(void) |
| 1471 | 1524 | test_try_failure(e); |
| 1472 | 1525 | } |
| 1473 | 1526 | |
| 1474 | - // Test constructing with radius 0 | |
| 1527 | + // Test constructing with radius -1 | |
| 1475 | 1528 | test_try("Test constructor2"); |
| 1476 | 1529 | try { |
| 1477 | 1530 | GSkyRegionCircle circle(refdir_radeczerozero,-1); |
| ... | ... | @@ -1508,70 +1561,55 @@ void TestGSky::test_GSkyRegionCircle_construct(void) |
| 1508 | 1561 | double solidangle = 2*gammalib::pi*(1- std::cos(refradius /180 * gammalib::pi)); |
| 1509 | 1562 | test_value(solidangle_check,solidangle,1.0e-10, "Test solid angle assignment"); |
| 1510 | 1563 | |
| 1511 | - //exit test | |
| 1512 | - return; | |
| 1513 | -} | |
| 1514 | - | |
| 1515 | -/*************************************************************************** | |
| 1516 | - * @brief GSkyRegions_logic | |
| 1517 | - ***************************************************************************/ | |
| 1518 | -void TestGSky::test_GSkyRegionCircle_logic(void) | |
| 1519 | -{ | |
| 1520 | - | |
| 1521 | - // set input files /filenames | |
| 1522 | -// const std::string file1 = "test_GSkyRegionCircle1.reg"; | |
| 1523 | -// const std::string file2 = "test_GSkyRegionCircle2.reg"; | |
| 1524 | - | |
| 1525 | - //set reference values | |
| 1526 | - | |
| 1527 | - GSkyDir refdir_radeczerozero = GSkyDir(); | |
| 1564 | + // Set reference sky directions | |
| 1565 | + //GSkyDir refdir_radeczerozero; | |
| 1566 | + GSkyDir refdir_lbzerozero; | |
| 1567 | + GSkyDir refdir_outside_refregion; | |
| 1568 | + GSkyDir refdir_raoffset; | |
| 1569 | + GSkyDir refdir_decpole; | |
| 1570 | + GSkyDir refdir_ndecpole; | |
| 1571 | + GSkyDir refdir_rapole; | |
| 1528 | 1572 | refdir_radeczerozero.radec_deg(0,0); |
| 1529 | - | |
| 1530 | - GSkyDir refdir_lbzerozero = GSkyDir(); | |
| 1531 | 1573 | refdir_lbzerozero.lb_deg(0,0); |
| 1532 | - | |
| 1533 | - GSkyDir refdir_outside_refregion = GSkyDir(); | |
| 1534 | 1574 | refdir_outside_refregion.radec_deg(100,80); |
| 1535 | - | |
| 1536 | - GSkyDir refdir_raoffset = GSkyDir(); | |
| 1537 | 1575 | refdir_raoffset.radec_deg(5,0); |
| 1538 | - | |
| 1539 | - GSkyDir refdir_decpole = GSkyDir(); | |
| 1540 | 1576 | refdir_decpole.radec_deg(0,89); |
| 1541 | - | |
| 1542 | - GSkyDir refdir_ndecpole = GSkyDir(); | |
| 1543 | 1577 | refdir_ndecpole.radec_deg(100,89); |
| 1544 | - | |
| 1545 | - GSkyDir refdir_rapole = GSkyDir(); | |
| 1546 | 1578 | refdir_rapole.radec_deg(359,0); |
| 1547 | 1579 | |
| 1548 | - GSkyRegionCircle refregion(refdir_radeczerozero,10); | |
| 1549 | - GSkyDir centre = refregion.centre(); | |
| 1550 | - | |
| 1551 | - GSkyRegionCircle refregion_smaller(refdir_radeczerozero,5); | |
| 1552 | - GSkyRegionCircle refregion_larger(refdir_radeczerozero,20); | |
| 1553 | - GSkyRegionCircle refregion_raoffset(refdir_raoffset,10); | |
| 1554 | - GSkyRegionCircle refregion_rapole(refdir_rapole,3); | |
| 1555 | - GSkyRegionCircle refregion_decpole(refdir_decpole,3); | |
| 1580 | + // Set reference sky regions | |
| 1581 | + refregion = GSkyRegionCircle(refdir_radeczerozero, 10.0); | |
| 1582 | + GSkyDir centre = refregion.centre(); | |
| 1583 | + GSkyRegionCircle refregion_smaller(refdir_radeczerozero, 5.0); | |
| 1584 | + GSkyRegionCircle refregion_larger(refdir_radeczerozero, 20.0); | |
| 1585 | + GSkyRegionCircle refregion_raoffset(refdir_raoffset, 10.0); | |
| 1586 | + GSkyRegionCircle refregion_rapole(refdir_rapole, 3.0); | |
| 1587 | + GSkyRegionCircle refregion_decpole(refdir_decpole, 3.0); | |
| 1556 | 1588 | |
| 1557 | 1589 | // Test contain dirs |
| 1558 | - test_assert(refregion.contains(refdir_radeczerozero),"test for containment"); | |
| 1559 | - test_assert(refregion.contains(centre), "test if centre in circle"); | |
| 1560 | - test_assert(!refregion.contains(refdir_outside_refregion), "test2 for containment"); | |
| 1590 | + test_assert(refregion.contains(refdir_radeczerozero),"Test for containment"); | |
| 1591 | + test_assert(refregion.contains(centre), "Test if centre in circle"); | |
| 1592 | + test_assert(!refregion.contains(refdir_outside_refregion), "Test2 for containment"); | |
| 1561 | 1593 | |
| 1562 | 1594 | // Test contain regions |
| 1563 | - test_assert(refregion.contains(refregion_smaller),"test for containment region"); | |
| 1564 | - test_assert(!refregion.contains(refregion_larger), "test for containment region2 "); | |
| 1565 | - test_assert(refregion.contains(refregion), "test3 for containment region"); | |
| 1595 | + test_assert(refregion.contains(refregion_smaller),"Test for containment region"); | |
| 1596 | + test_assert(!refregion.contains(refregion_larger), "Test for containment region2 "); | |
| 1597 | + test_assert(refregion.contains(refregion), "Test3 for containment region"); | |
| 1566 | 1598 | |
| 1567 | - test_assert(refregion.contains(refdir_rapole), "rapole for containment region"); | |
| 1568 | - test_assert(refregion_decpole.contains(refdir_ndecpole), "rapole for containment region"); | |
| 1599 | + test_assert(refregion.contains(refdir_rapole), "Test rapole for containment region"); | |
| 1600 | + test_assert(refregion_decpole.contains(refdir_ndecpole), "Test rapole for containment region"); | |
| 1569 | 1601 | |
| 1570 | 1602 | // Test overlaps |
| 1571 | - test_assert(refregion.overlaps(refregion_smaller),"test for overlap"); | |
| 1572 | - test_assert(refregion.overlaps(refregion_larger),"test2 for overlap"); | |
| 1573 | - test_assert(refregion.overlaps(refregion_raoffset),"test3 for overlap"); | |
| 1574 | - test_assert(!refregion.overlaps(refregion_decpole),"test4 for overlap"); | |
| 1603 | + test_assert(refregion.overlaps(refregion_smaller),"Test for overlap"); | |
| 1604 | + test_assert(refregion.overlaps(refregion_larger),"Test2 for overlap"); | |
| 1605 | + test_assert(refregion.overlaps(refregion_raoffset),"Test3 for overlap"); | |
| 1606 | + test_assert(!refregion.overlaps(refregion_decpole),"Test4 for overlap"); | |
| 1607 | + | |
| 1608 | + // Test equality and non-equality operators | |
| 1609 | + test_assert(refregion_smaller == refregion_smaller,"Test for equality"); | |
| 1610 | + test_assert(!(refregion_smaller == refregion_larger),"Test for equality"); | |
| 1611 | + test_assert(!(refregion_smaller != refregion_smaller),"Test for non-equality"); | |
| 1612 | + test_assert(refregion_smaller != refregion_larger,"Test for non-equality"); | |
| 1575 | 1613 | |
| 1576 | 1614 | // Exit test |
| 1577 | 1615 | return; |
| ... | ... | @@ -1579,9 +1617,9 @@ void TestGSky::test_GSkyRegionCircle_logic(void) |
| 1579 | 1617 | |
| 1580 | 1618 | |
| 1581 | 1619 | /*************************************************************************** |
| 1582 | - * @brief GSkyRegionMap_construct | |
| 1620 | + * @brief Test GSkyRegionMap | |
| 1583 | 1621 | ***************************************************************************/ |
| 1584 | -void TestGSky::test_GSkyRegionMap_construct(void) | |
| 1622 | +void TestGSky::test_GSkyRegionMap(void) | |
| 1585 | 1623 | { |
| 1586 | 1624 | // Test file constructor: |
| 1587 | 1625 | test_try("Test file constructor"); |
| ... | ... | @@ -1603,26 +1641,16 @@ void TestGSky::test_GSkyRegionMap_construct(void) |
| 1603 | 1641 | catch (std::exception &e) { |
| 1604 | 1642 | test_try_failure(e); |
| 1605 | 1643 | } |
| 1606 | - | |
| 1607 | - // Exit test | |
| 1608 | - return; | |
| 1609 | -} | |
| 1610 | 1644 | |
| 1611 | - | |
| 1612 | -/*************************************************************************** | |
| 1613 | - * @brief GSkyRegionMap_logic | |
| 1614 | - ***************************************************************************/ | |
| 1615 | -void TestGSky::test_GSkyRegionMap_logic(void) | |
| 1616 | -{ | |
| 1617 | 1645 | // Load reference region map (a mask centred on (RA,Dec)=(0,0) with radius 0.3deg) |
| 1618 | 1646 | GSkyRegionMap regmap(sky_region_map); |
| 1619 | 1647 | |
| 1620 | 1648 | // Set reference directions and regions |
| 1621 | 1649 | GSkyDir refdir_radeczerozero = GSkyDir(); |
| 1622 | - refdir_radeczerozero.radec_deg(0.0,0.0); | |
| 1623 | 1650 | GSkyDir refdir_radeclargeshift = GSkyDir(); |
| 1624 | - refdir_radeclargeshift.radec_deg(2.0,0.0); | |
| 1625 | 1651 | GSkyDir refdir_radecsmallshift = GSkyDir(); |
| 1652 | + refdir_radeczerozero.radec_deg(0.0,0.0); | |
| 1653 | + refdir_radeclargeshift.radec_deg(2.0,0.0); | |
| 1626 | 1654 | refdir_radecsmallshift.radec_deg(0.3,0.0); |
| 1627 | 1655 | GSkyRegionCircle inregion(refdir_radeczerozero,0.2); |
| 1628 | 1656 | GSkyRegionCircle outregion(refdir_radeclargeshift,0.2); |
| ... | ... | @@ -1646,64 +1674,6 @@ void TestGSky::test_GSkyRegionMap_logic(void) |
| 1646 | 1674 | |
| 1647 | 1675 | |
| 1648 | 1676 | /*************************************************************************** |
| 1649 | - * @brief Test GSkyRegions input and output | |
| 1650 | - ***************************************************************************/ | |
| 1651 | - void TestGSky::test_GSkyRegions_io(void) | |
| 1652 | -{ | |
| 1653 | - // Allocate regions | |
| 1654 | - GSkyRegions regions; | |
| 1655 | - | |
| 1656 | - // Test regions loading | |
| 1657 | - test_try("Test regions loading"); | |
| 1658 | - try { | |
| 1659 | - regions.load(sky_region); | |
| 1660 | - test_try_success(); | |
| 1661 | - } | |
| 1662 | - catch (std::exception &e) { | |
| 1663 | - test_try_failure(e); | |
| 1664 | - } | |
| 1665 | - | |
| 1666 | - // Check if region was loaded correctly | |
| 1667 | - GSkyRegionCircle* circle = dynamic_cast<GSkyRegionCircle*>(regions[0]); | |
| 1668 | - test_assert(circle->type() == "Circle", "Region is not a circle"); | |
| 1669 | - test_value(circle->radius(), 10.0, 1.0e-10); | |
| 1670 | - test_value(circle->ra(), 0.1, 1.0e-10); | |
| 1671 | - test_value(circle->dec(), -35.6, 1.0e-10); | |
| 1672 | - | |
| 1673 | - // Test regions saving | |
| 1674 | - test_try("Test regions saving"); | |
| 1675 | - try { | |
| 1676 | - regions.save("region.reg"); | |
| 1677 | - test_try_success(); | |
| 1678 | - } | |
| 1679 | - catch (std::exception &e) { | |
| 1680 | - test_try_failure(e); | |
| 1681 | - } | |
| 1682 | - | |
| 1683 | - // Test regions reloading | |
| 1684 | - test_try("Test regions reloading"); | |
| 1685 | - try { | |
| 1686 | - regions.load("region.reg"); | |
| 1687 | - test_try_success(); | |
| 1688 | - } | |
| 1689 | - catch (std::exception &e) { | |
| 1690 | - test_try_failure(e); | |
| 1691 | - } | |
| 1692 | - | |
| 1693 | - // Check if region was loaded correctly | |
| 1694 | - circle = dynamic_cast<GSkyRegionCircle*>(regions[0]); | |
| 1695 | - test_assert(circle->type() == "Circle", "Region is not a circle"); | |
| 1696 | - test_value(circle->radius(), 10.0, 1.0e-10); | |
| 1697 | - test_value(circle->ra(), 0.1, 1.0e-10); | |
| 1698 | - test_value(circle->dec(), -35.6, 1.0e-10); | |
| 1699 | - | |
| 1700 | - // Exit test | |
| 1701 | - return; | |
| 1702 | - | |
| 1703 | -} | |
| 1704 | - | |
| 1705 | - | |
| 1706 | -/*************************************************************************** | |
| 1707 | 1677 | * @brief Test GHorizDir class |
| 1708 | 1678 | ***************************************************************************/ |
| 1709 | 1679 | void TestGSky::test_GHorizDir(void) |
| ... | ... | @@ -1729,7 +1699,7 @@ void TestGSky::test_GHorizDir(void) |
| 1729 | 1699 | |
| 1730 | 1700 | // Return |
| 1731 | 1701 | return; |
| 1732 | -} | |
| 1702 | +} | |
| 1733 | 1703 | |
| 1734 | 1704 | |
| 1735 | 1705 | /*************************************************************************** |
| ... | ... | @@ -1738,12 +1708,12 @@ void TestGSky::test_GHorizDir(void) |
| 1738 | 1708 | int main(void) |
| 1739 | 1709 | { |
| 1740 | 1710 | GTestSuites testsuites("GSky"); |
| 1741 | - | |
| 1711 | + | |
| 1742 | 1712 | bool was_successful = true; |
| 1743 | - | |
| 1713 | + | |
| 1744 | 1714 | // Create a test suite |
| 1745 | 1715 | TestGSky test; |
| 1746 | - | |
| 1716 | + | |
| 1747 | 1717 | // Append to the container |
| 1748 | 1718 | testsuites.append(test); |
| 1749 | 1719 | ... | ... |
test/test_GSky.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * test_GSky.hpp - Test sky module * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2019 by Jean-Baptiste Cayrou * | |
| 4 | + * copyright (C) 2012-2020 by Jean-Baptiste Cayrou * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -50,11 +50,9 @@ public: |
| 50 | 50 | void test_GSkyMap_wcs_io(void); |
| 51 | 51 | void test_GSkyMap(void); |
| 52 | 52 | void test_GSkyMap_io(void); |
| 53 | - void test_GSkyRegions_io(void); | |
| 54 | - void test_GSkyRegionCircle_construct(void); | |
| 55 | - void test_GSkyRegionCircle_logic(void); | |
| 56 | - void test_GSkyRegionMap_construct(void); | |
| 57 | - void test_GSkyRegionMap_logic(void); | |
| 53 | + void test_GSkyRegions(void); | |
| 54 | + void test_GSkyRegionCircle(void); | |
| 55 | + void test_GSkyRegionMap(void); | |
| 58 | 56 | void test_GHorizDir(void); |
| 59 | 57 | |
| 60 | 58 | // Private methods | ... | ... |
test/test_GSky.py
| 1 | 1 | # ========================================================================== |
| 2 | 2 | # This module performs unit tests for the GammaLib sky module. |
| 3 | 3 | # |
| 4 | -# Copyright (C) 2012-2018 Juergen Knoedlseder | |
| 4 | +# Copyright (C) 2012-2020 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 |
| ... | ... | @@ -164,7 +164,7 @@ class Test(gammalib.GPythonTestSuite): |
| 164 | 164 | map[2] = 3.0 |
| 165 | 165 | map[3] = 4.0 |
| 166 | 166 | map_b = map.copy() |
| 167 | - | |
| 167 | + | |
| 168 | 168 | # Addition operator |
| 169 | 169 | map += map_b |
| 170 | 170 | self.test_value(map[0], 2.0) |
| ... | ... | @@ -561,6 +561,30 @@ class Test(gammalib.GPythonTestSuite): |
| 561 | 561 | # Return |
| 562 | 562 | return |
| 563 | 563 | |
| 564 | + # Test GSkyRegionCircle class | |
| 565 | + def _test_region_circle(self): | |
| 566 | + """ | |
| 567 | + Test GSkyRegionCircle class | |
| 568 | + """ | |
| 569 | + # Setup sky region circles | |
| 570 | + circle1 = gammalib.GSkyRegionCircle(0.0, 0.0, 180.0) | |
| 571 | + circle2 = gammalib.GSkyRegionCircle(0.0, 0.0, 90.0) | |
| 572 | + circle3 = gammalib.GSkyRegionCircle(10.0, 10.0, 180.0) | |
| 573 | + circle4 = gammalib.GSkyRegionCircle(10.0, 10.0, 180.0) | |
| 574 | + | |
| 575 | + # Test equality and non-equality operators | |
| 576 | + self.test_assert(circle1 == circle1, 'Test equality operator (1)') | |
| 577 | + self.test_assert(not(circle1 == circle2), 'Test equality operator (2)') | |
| 578 | + self.test_assert(not(circle1 == circle3), 'Test equality operator (3)') | |
| 579 | + self.test_assert(not(circle1 == circle4), 'Test equality operator (4)') | |
| 580 | + self.test_assert(not(circle1 != circle1), 'Test non-equality operator (1)') | |
| 581 | + self.test_assert(circle1 != circle2, 'Test non-equality operator (2)') | |
| 582 | + self.test_assert(circle1 != circle3, 'Test non-equality operator (3)') | |
| 583 | + self.test_assert(circle1 != circle4, 'Test non-equality operator (4)') | |
| 584 | + | |
| 585 | + # Return | |
| 586 | + return | |
| 587 | + | |
| 564 | 588 | # Test class pickeling |
| 565 | 589 | def _test_pickeling(self): |
| 566 | 590 | """ |
| ... | ... | @@ -651,6 +675,7 @@ class Test(gammalib.GPythonTestSuite): |
| 651 | 675 | self.append(self._test_skymap_tan, 'Test TAN projection map') |
| 652 | 676 | self.append(self._test_regions_access, 'Test GSkyRegions region access') |
| 653 | 677 | self.append(self._test_regions_slicing, 'Test GSkyRegions slicing') |
| 678 | + self.append(self._test_region_circle, 'Test GSkyRegionCircle class') | |
| 654 | 679 | self.append(self._test_pickeling, 'Test sky class pickeling') |
| 655 | 680 | |
| 656 | 681 | # Return | ... | ... |