Commit a19472b80a8d0c019c88d24caca4e5cfa9596e29
1 parent
a1db5073
Added warning and updated test cases for ctphase (#1982)
Added a warning in ctphase that is written into the log file when either the first or second derivative term in the phase computation is above 1e8, as at this point precision issues can manifest in the computed phase values. Updated test cases and fixed some bugs that allow the tests of ctphase to pass.
Showing
3 changed files
with
30 additions
and
16 deletions
src/ctphase/ctphase.cpp
| @@ -633,16 +633,30 @@ void ctphase::phase_events(GCTAObservation* obs, | @@ -633,16 +633,30 @@ void ctphase::phase_events(GCTAObservation* obs, | ||
| 633 | const std::string& evtname, | 633 | const std::string& evtname, |
| 634 | const std::string& gtiname) | 634 | const std::string& gtiname) |
| 635 | { | 635 | { |
| 636 | - // Write header into logger | ||
| 637 | - log_header3(NORMAL, "Events phasing"); | ||
| 638 | - | ||
| 639 | // Get CTA event list pointer | 636 | // Get CTA event list pointer |
| 640 | GCTAEventList* list = | 637 | GCTAEventList* list = |
| 641 | static_cast<GCTAEventList*>(const_cast<GEvents*>(obs->events())); | 638 | static_cast<GCTAEventList*>(const_cast<GEvents*>(obs->events())); |
| 642 | 639 | ||
| 640 | + GCTAEventAtom* event = (*list)[0]; | ||
| 641 | + | ||
| 642 | + // Print a warning into the log file if there are some precision concerns | ||
| 643 | + double dt = std::abs(event->time() - m_phase.mjd()); | ||
| 644 | + if (((m_phase.f1() * dt) > 1.0e8) || | ||
| 645 | + (m_phase.f2() * dt * dt) > 1.0e8) { | ||
| 646 | + log_string(NORMAL,"*** WARNING ***"); | ||
| 647 | + log_string(NORMAL," Values supplied for reference MJD and/or f1 and/or f2"); | ||
| 648 | + log_string(NORMAL," are large and may result in numerical precision issues."); | ||
| 649 | + log_string(NORMAL," Consider using an ephemeris derived from a date closer"); | ||
| 650 | + log_string(NORMAL," to the data being analyzed."); | ||
| 651 | + log_value(NORMAL, " Observation ID", obs->obs_id()); | ||
| 652 | + log_value(NORMAL, " Reference MJD", m_phase.mjd().mjd()); | ||
| 653 | + log_value(NORMAL, " First event MJD", event->time().mjd()); | ||
| 654 | + log_string(NORMAL,"*** WARNING ***"); | ||
| 655 | + } | ||
| 656 | + | ||
| 643 | for (int evnt=0; evnt<list->size(); evnt++) { | 657 | for (int evnt=0; evnt<list->size(); evnt++) { |
| 644 | // Get the next event | 658 | // Get the next event |
| 645 | - GCTAEventAtom* event = (*list)[evnt]; | 659 | + event = (*list)[evnt]; |
| 646 | 660 | ||
| 647 | // Get the event time | 661 | // Get the event time |
| 648 | GTime time = event->time(); | 662 | GTime time = event->time(); |
src/ctphase/ctphase.par
| @@ -24,11 +24,11 @@ prefix, s, h, "phased_",,, "Prefix for event lists in observation definition XML | @@ -24,11 +24,11 @@ prefix, s, h, "phased_",,, "Prefix for event lists in observation definition XML | ||
| 24 | # | 24 | # |
| 25 | # Phase information parameters | 25 | # Phase information parameters |
| 26 | #===================== | 26 | #===================== |
| 27 | -mjd, r, a, 52400,,, "Reference MJD for phase information" | ||
| 28 | -f0, r, a, 1,,, "Frequency at reference MJD [Hz]" | ||
| 29 | -f1, r, a, -0.2,,, "First freq. derivative at reference MJD [s^-1]" | ||
| 30 | -f2, r, a, 0,,, "Second freq. derivative at reference MJD [s^-2]" | 27 | +mjd, r, a, 51544.5,,, "Reference MJD for phase information" |
| 31 | p0, r, a, 0.1,0.0,1.0, "Phase at reference MJD" | 28 | p0, r, a, 0.1,0.0,1.0, "Phase at reference MJD" |
| 29 | +f0, r, a, 1,,, "Frequency at reference MJD [Hz]" | ||
| 30 | +f1, r, a, 0.0,,, "First freq. derivative at reference MJD [s^-1]" | ||
| 31 | +f2, r, a, 0.0,,, "Second freq. derivative at reference MJD [s^-2]" | ||
| 32 | 32 | ||
| 33 | # | 33 | # |
| 34 | # Standard parameters | 34 | # Standard parameters |
test/test_ctphase.py
| @@ -71,7 +71,7 @@ class Test(test): | @@ -71,7 +71,7 @@ class Test(test): | ||
| 71 | # Setup ctphase command | 71 | # Setup ctphase command |
| 72 | cmd = ctphase+' inobs="'+self._events+'"'+ \ | 72 | cmd = ctphase+' inobs="'+self._events+'"'+ \ |
| 73 | ' outobs="ctphase_cmd1.fits"'+ \ | 73 | ' outobs="ctphase_cmd1.fits"'+ \ |
| 74 | - ' p0=0.1 mjd=52400'+ \ | 74 | + ' p0=0.1 mjd=51544.5'+ \ |
| 75 | ' f0=0.1 f1=0. f2=0.'+ \ | 75 | ' f0=0.1 f1=0. f2=0.'+ \ |
| 76 | ' logfile="ctphase_cmd1.log" chatter=1' | 76 | ' logfile="ctphase_cmd1.log" chatter=1' |
| 77 | 77 | ||
| @@ -89,7 +89,7 @@ class Test(test): | @@ -89,7 +89,7 @@ class Test(test): | ||
| 89 | # Setup ctphase command | 89 | # Setup ctphase command |
| 90 | cmd = ctphase+' inobs="event_file_that_does_not_exist.fits"'+ \ | 90 | cmd = ctphase+' inobs="event_file_that_does_not_exist.fits"'+ \ |
| 91 | ' outobs="ctphase_cmd2.fits"'+ \ | 91 | ' outobs="ctphase_cmd2.fits"'+ \ |
| 92 | - ' p0=0.1 mjd=52400'+ \ | 92 | + ' p0=0.1 mjd=51544.5'+ \ |
| 93 | ' f0=0.1 f1=0. f2=0.'+ \ | 93 | ' f0=0.1 f1=0. f2=0.'+ \ |
| 94 | ' logfile="ctphase_cmd2.log" chatter=1' | 94 | ' logfile="ctphase_cmd2.log" chatter=1' |
| 95 | 95 | ||
| @@ -137,9 +137,9 @@ class Test(test): | @@ -137,9 +137,9 @@ class Test(test): | ||
| 137 | # Now set ctphase parameters | 137 | # Now set ctphase parameters |
| 138 | phase['inobs'] = self._events | 138 | phase['inobs'] = self._events |
| 139 | phase['p0'] = 0. | 139 | phase['p0'] = 0. |
| 140 | - phase['mjd'] = 52400 | 140 | + phase['mjd'] = 51544.5 |
| 141 | phase['f0'] = 1. | 141 | phase['f0'] = 1. |
| 142 | - phase['f1'] = -0.2 | 142 | + phase['f1'] = 0.0 |
| 143 | phase['f2'] = 0. | 143 | phase['f2'] = 0. |
| 144 | phase['outobs'] = 'ctphase_py1.fits' | 144 | phase['outobs'] = 'ctphase_py1.fits' |
| 145 | phase['logfile'] = 'ctphase_py1.log' | 145 | phase['logfile'] = 'ctphase_py1.log' |
| @@ -158,18 +158,18 @@ class Test(test): | @@ -158,18 +158,18 @@ class Test(test): | ||
| 158 | 158 | ||
| 159 | # Execute copy of ctphase tool again, now with a negative value | 159 | # Execute copy of ctphase tool again, now with a negative value |
| 160 | # of initial phase to test for invalid parameter value | 160 | # of initial phase to test for invalid parameter value |
| 161 | + self.test_try('Test invalid parameter value') | ||
| 161 | try: | 162 | try: |
| 162 | - self.test_try('Test invalid parameter value') | ||
| 163 | - cpy_phase['p0'] = -0.5 | ||
| 164 | - cpy_phase['mjd'] = 52400 | 163 | + cpy_phase['mjd'] = 51544.5 |
| 165 | cpy_phase['f0'] = 1. | 164 | cpy_phase['f0'] = 1. |
| 166 | - cpy_phase['f1'] = -0.2 | 165 | + cpy_phase['f1'] = 0.2 |
| 167 | cpy_phase['f2'] = 0. | 166 | cpy_phase['f2'] = 0. |
| 168 | cpy_phase['outobs'] = 'ctphase_py2.fits' | 167 | cpy_phase['outobs'] = 'ctphase_py2.fits' |
| 169 | cpy_phase['logfile'] = 'ctphase_py2.log' | 168 | cpy_phase['logfile'] = 'ctphase_py2.log' |
| 170 | cpy_phase['chatter'] = 3 | 169 | cpy_phase['chatter'] = 3 |
| 171 | cpy_phase['publish'] = True | 170 | cpy_phase['publish'] = True |
| 172 | cpy_phase.logFileOpen() # Needed to get a new log file | 171 | cpy_phase.logFileOpen() # Needed to get a new log file |
| 172 | + cpy_phase['p0'] = -0.5 | ||
| 173 | cpy_phase.execute() | 173 | cpy_phase.execute() |
| 174 | self.test_try_failure('Exception not thrown') | 174 | self.test_try_failure('Exception not thrown') |
| 175 | except ValueError: | 175 | except ValueError: |