Commit a19472b80a8d0c019c88d24caca4e5cfa9596e29

Authored by Josh Cardenzana
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.
src/ctphase/ctphase.cpp
... ... @@ -633,16 +633,30 @@ void ctphase::phase_events(GCTAObservation* obs,
633 633 const std::string& evtname,
634 634 const std::string& gtiname)
635 635 {
636   - // Write header into logger
637   - log_header3(NORMAL, "Events phasing");
638   -
639 636 // Get CTA event list pointer
640 637 GCTAEventList* list =
641 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 657 for (int evnt=0; evnt<list->size(); evnt++) {
644 658 // Get the next event
645   - GCTAEventAtom* event = (*list)[evnt];
  659 + event = (*list)[evnt];
646 660  
647 661 // Get the event time
648 662 GTime time = event->time();
... ...
src/ctphase/ctphase.par
... ... @@ -24,11 +24,11 @@ prefix, s, h, &quot;phased_&quot;,,, &quot;Prefix for event lists in observation definition XML
24 24 #
25 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 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 34 # Standard parameters
... ...
test/test_ctphase.py
... ... @@ -71,7 +71,7 @@ class Test(test):
71 71 # Setup ctphase command
72 72 cmd = ctphase+' inobs="'+self._events+'"'+ \
73 73 ' outobs="ctphase_cmd1.fits"'+ \
74   - ' p0=0.1 mjd=52400'+ \
  74 + ' p0=0.1 mjd=51544.5'+ \
75 75 ' f0=0.1 f1=0. f2=0.'+ \
76 76 ' logfile="ctphase_cmd1.log" chatter=1'
77 77  
... ... @@ -89,7 +89,7 @@ class Test(test):
89 89 # Setup ctphase command
90 90 cmd = ctphase+' inobs="event_file_that_does_not_exist.fits"'+ \
91 91 ' outobs="ctphase_cmd2.fits"'+ \
92   - ' p0=0.1 mjd=52400'+ \
  92 + ' p0=0.1 mjd=51544.5'+ \
93 93 ' f0=0.1 f1=0. f2=0.'+ \
94 94 ' logfile="ctphase_cmd2.log" chatter=1'
95 95  
... ... @@ -137,9 +137,9 @@ class Test(test):
137 137 # Now set ctphase parameters
138 138 phase['inobs'] = self._events
139 139 phase['p0'] = 0.
140   - phase['mjd'] = 52400
  140 + phase['mjd'] = 51544.5
141 141 phase['f0'] = 1.
142   - phase['f1'] = -0.2
  142 + phase['f1'] = 0.0
143 143 phase['f2'] = 0.
144 144 phase['outobs'] = 'ctphase_py1.fits'
145 145 phase['logfile'] = 'ctphase_py1.log'
... ... @@ -158,18 +158,18 @@ class Test(test):
158 158  
159 159 # Execute copy of ctphase tool again, now with a negative value
160 160 # of initial phase to test for invalid parameter value
  161 + self.test_try('Test invalid parameter value')
161 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 164 cpy_phase['f0'] = 1.
166   - cpy_phase['f1'] = -0.2
  165 + cpy_phase['f1'] = 0.2
167 166 cpy_phase['f2'] = 0.
168 167 cpy_phase['outobs'] = 'ctphase_py2.fits'
169 168 cpy_phase['logfile'] = 'ctphase_py2.log'
170 169 cpy_phase['chatter'] = 3
171 170 cpy_phase['publish'] = True
172 171 cpy_phase.logFileOpen() # Needed to get a new log file
  172 + cpy_phase['p0'] = -0.5
173 173 cpy_phase.execute()
174 174 self.test_try_failure('Exception not thrown')
175 175 except ValueError:
... ...