Commit 717bee7d2614ddf1c1f04814e3eb37cc8ef87c9e

Authored by Jürgen Knödlseder
1 parent e13c97b5

Add margin to maximum light and phase curve values (#2149)

ChangeLog
... ... @@ -3,6 +3,7 @@
3 3 * Bug fix version 1.3.1 released
4 4 ================================
5 5  
  6 + Add margin to maximum light and phase curve values (#2149)
6 7 Improve caching in GSkyDir (#2148)
7 8 Make GCTAPsfKing save against invalid values (#2133)
8 9  
... ...
... ... @@ -63,7 +63,11 @@ None
63 63  
64 64 8. Model module
65 65 ---------------
66   -None
  66 +The normalisation values of light and phase curves shall not exceed values of 1
  67 +but due to rounding problems when reading the FITS file it can happen that
  68 +slightly larger value occur. To circumvent the issue a small margin of 1e-8 has
  69 +been added to the maximum value of 1, well below the required precision for
  70 +flux normalisations (#2149).
67 71  
68 72  
69 73 9. Numerics module
... ...
doc/source/admin/release_history/1.3.1.rst
... ... @@ -10,6 +10,8 @@ GammaLib 1.3.1 is a bug fix for GammaLib release 1.3.
10 10  
11 11 The following bugs have been fixed:
12 12  
  13 +* [`2149 <https://cta-redmine.irap.omp.eu/issues/2149>`_] -
  14 + Add margin to maximum light and phase curve values
13 15 * [`2133 <https://cta-redmine.irap.omp.eu/issues/2133>`_] -
14 16 Make GCTAPsfKing save against invalid values
15 17  
... ...
src/model/GModelTemporalLightCurve.cpp
... ... @@ -587,6 +587,9 @@ void GModelTemporalLightCurve::free_members(void)
587 587 ***************************************************************************/
588 588 void GModelTemporalLightCurve::load_nodes(const GFilename& filename)
589 589 {
  590 + // Set maximum light curve normalization value, including a small margin
  591 + const double max_norm = 1.0 + 1.0e-8;
  592 +
590 593 // Clear nodes and values
591 594 m_nodes.clear();
592 595 m_values.clear();
... ... @@ -630,7 +633,7 @@ void GModelTemporalLightCurve::load_nodes(const GFilename&amp; filename)
630 633 int nodes = time_col->nrows();
631 634  
632 635 // Check that time values are in ascending order and that no node is
633   - // larger than one
  636 + // larger than 1
634 637 double last_time = -1.0;
635 638 for (int i = 0; i < nodes; ++i) {
636 639  
... ... @@ -644,12 +647,12 @@ void GModelTemporalLightCurve::load_nodes(const GFilename&amp; filename)
644 647 throw GException::invalid_value(G_LOAD_NODES, msg);
645 648 }
646 649  
647   - // Check if value is <= 1
648   - if (norm_col->real(i) > 1.0) {
  650 + // Check if value is smaller than maximum allowed normalisation
  651 + if (norm_col->real(i) > max_norm) {
649 652 std::string msg = "Value "+gammalib::str(norm_col->real(i))+" at "
650 653 "time "+gammalib::str(time_col->real(i))+" is "
651   - "above 1. Please provide a light curve file with "
652   - "normalizations not exceeding 1.";
  654 + "larger than 1. Please provide a light curve file "
  655 + "with normalizations not exceeding 1.";
653 656 throw GException::invalid_value(G_LOAD_NODES, msg);
654 657 }
655 658  
... ... @@ -661,6 +664,13 @@ void GModelTemporalLightCurve::load_nodes(const GFilename&amp; filename)
661 664 m_values.push_back(norm_col->real(i));
662 665 }
663 666  
  667 + // Make sure that no node exceeds 1
  668 + for (int i = 0; i < m_values.size(); ++i) {
  669 + if (m_values[i] > 1.0) {
  670 + m_values[i] = 1.0;
  671 + }
  672 + }
  673 +
664 674 // Set minimum and maximum times (assumes that times are ordered)
665 675 m_tmin.set(time_col->real(0), m_timeref);
666 676 m_tmax.set(time_col->real(time_col->nrows()-1), m_timeref);
... ...
src/model/GModelTemporalPhaseCurve.cpp
... ... @@ -688,6 +688,9 @@ void GModelTemporalPhaseCurve::free_members(void)
688 688 ***************************************************************************/
689 689 void GModelTemporalPhaseCurve::load_nodes(const GFilename& filename)
690 690 {
  691 + // Set maximum phase curve normalization value, including a small margin
  692 + const double max_norm = 1.0 + 1.0e-8;
  693 +
691 694 // Clear nodes and values
692 695 m_nodes.clear();
693 696 m_values.clear();
... ... @@ -728,7 +731,7 @@ void GModelTemporalPhaseCurve::load_nodes(const GFilename&amp; filename)
728 731 int nodes = phase_col->nrows();
729 732  
730 733 // Check that phase values are in ascending order and comprised between
731   - // 0 and 1, and that no node is larger than one
  734 + // 0 and 1, and that no node is larger than 1
732 735 double last_phase = -1.0;
733 736 for (int i = 0; i < nodes; ++i) {
734 737  
... ... @@ -751,12 +754,12 @@ void GModelTemporalPhaseCurve::load_nodes(const GFilename&amp; filename)
751 754 throw GException::invalid_value(G_LOAD_NODES, msg);
752 755 }
753 756  
754   - // Check if value is <= 1
755   - if (norm_col->real(i) > 1.0) {
  757 + // Check if value is smaller than maximum allowed normalisation
  758 + if (norm_col->real(i) > max_norm) {
756 759 std::string msg = "Value "+gammalib::str(norm_col->real(i))+" at "
757 760 "phase "+gammalib::str(phase_col->real(i))+" is "
758   - "above 1. Please provide a phase curve file with "
759   - "normalizations not exceeding 1.";
  761 + "larger than 1. Please provide a phase curve file "
  762 + "with normalizations not exceeding 1.";
760 763 throw GException::invalid_value(G_LOAD_NODES, msg);
761 764 }
762 765  
... ... @@ -784,6 +787,13 @@ void GModelTemporalPhaseCurve::load_nodes(const GFilename&amp; filename)
784 787 m_values.push_back(norm_col->real(0));
785 788 }
786 789  
  790 + // Make sure that no node exceeds 1
  791 + for (int i = 0; i < m_values.size(); ++i) {
  792 + if (m_values[i] > 1.0) {
  793 + m_values[i] = 1.0;
  794 + }
  795 + }
  796 +
787 797 // Close FITS file
788 798 fits.close();
789 799  
... ...