Commit 9a32c2d423b477f2bca45e769f2afe1c6e32fff8

Authored by Josh Cardenzana
1 parent 59b21f3f

Add tests for ctskymap RING subtraction (#2207)

Added test to make sure ctskymap is able to run when RING background subtraction is requested.
Observation responses are now checked regardless of what type of background subtraction is requested.
Fixed origin for exceptions thrown in 'ctskymap::map_background_ring()'
Added log message to update user during run averaged alpha computation.
src/ctskymap/ctskymap.cpp
... ... @@ -442,7 +442,7 @@ void ctskymap::get_parameters(void)
442 442  
443 443 // If IRF background subtraction is requested then make sure that the
444 444 // CTA observations in the observation container have response information
445   - if (m_bkgsubtract == "IRF") {
  445 + if (m_bkgsubtract != "NONE") {
446 446 set_response(m_obs);
447 447 }
448 448  
... ... @@ -746,7 +746,7 @@ void ctskymap::map_background_ring(GCTAObservation* obs)
746 746 get_obs_header(obs)+" to compute IRF background. "
747 747 "Please specify response information or use "
748 748 "another background subtraction method.";
749   - throw GException::invalid_value(G_BKG_SUBTRACT_IRF, msg);
  749 + throw GException::invalid_value(G_BKG_SUBTRACT_RING, msg);
750 750 }
751 751  
752 752 // Get IRF background template
... ... @@ -758,7 +758,7 @@ void ctskymap::map_background_ring(GCTAObservation* obs)
758 758 "response function for "+
759 759 get_obs_header(obs)+". Please specify an instrument "
760 760 "response function containing a background template.";
761   - throw GException::invalid_value(G_BKG_SUBTRACT_IRF, msg);
  761 + throw GException::invalid_value(G_BKG_SUBTRACT_RING, msg);
762 762 }
763 763  
764 764 // Compute natural logarithm of energy range in MeV
... ... @@ -836,9 +836,7 @@ void ctskymap::map_background_ring(GCTAObservation* obs)
836 836 else {
837 837  
838 838 // Compute the on, off and alpha parameters
839   - double n_on(0);
840   - double n_off(0);
841   - double alpha(0);
  839 + double n_on(0.0), n_off(0.0), alpha(0.0);
842 840 compute_ring_values(m_skymap, sens, m_dirs[ibin],
843 841 n_on, n_off, alpha);
844 842  
... ... @@ -886,6 +884,12 @@ void ctskymap::map_significance(void)
886 884 // Loop through each bin in the on-counts map
887 885 for (int i = 0; i < m_onmap.npix(); ++i) {
888 886  
  887 + // Since this can take a long time, keep the user updated on
  888 + // the progress when another 10% of pixels is processed
  889 + if (i%(m_onmap.npix()/10)==0) {
  890 + log_value(NORMAL, "Pixels remaining", m_onmap.npix()-i);
  891 + }
  892 +
889 893 // Get bin coordinate
890 894 GSkyDir& skydir = m_dirs[i];
891 895  
... ...
test/test_ctskymap.py
... ... @@ -206,6 +206,10 @@ class Test(test):
206 206 # Publish with name
207 207 skymap.publish('My sky map')
208 208  
  209 + # ================================
  210 + # TEST IRF BACKGROUND SUBTRACTION
  211 + # ================================
  212 +
209 213 # Allocate ctskymap tool from observation container
210 214 skymap = ctools.ctskymap(obs)
211 215 skymap['emin'] = 0.1
... ... @@ -229,7 +233,41 @@ class Test(test):
229 233 skymap.execute()
230 234  
231 235 # Check result file
232   - self._check_result_file('ctskymap_py3.fits')
  236 + self._check_result_file('ctskymap_py4.fits')
  237 +
  238 + # ================================
  239 + # TEST RING BACKGROUND SUBTRACTION
  240 + # ================================
  241 +
  242 + # Allocate ctskymap tool from observation container
  243 + skymap = ctools.ctskymap(obs)
  244 + skymap['emin'] = 0.1
  245 + skymap['emax'] = 100
  246 + skymap['nxpix'] = 100 # Make region smaller since the 'RING'
  247 + skymap['nypix'] = 100 # method takes longer to run than 'IRF'
  248 + skymap['binsz'] = 0.02
  249 + skymap['coordsys'] = 'CEL'
  250 + skymap['proj'] = 'CAR'
  251 + skymap['xref'] = 83.63
  252 + skymap['yref'] = 22.01
  253 + skymap['bkgsubtract'] = 'RING'
  254 + skymap['caldb'] = self._caldb
  255 + skymap['irf'] = self._irf
  256 + skymap['outmap'] = 'ctskymap_py5.fits'
  257 + skymap['logfile'] = 'ctskymap_py5.log'
  258 + skymap['chatter'] = 4
  259 + skymap['roiradius'] = 0.1
  260 + skymap['inradius'] = 0.6
  261 + skymap['outradius'] = 0.8
  262 + skymap['regfile'] = 'NONE'
  263 + skymap['runavgalpha'] = True
  264 +
  265 + # Execute tool
  266 + skymap.logFileOpen() # Needed to get a new log file
  267 + skymap.execute()
  268 +
  269 + # Check result file
  270 + self._check_result_file('ctskymap_py5.fits', 100, 100)
233 271  
234 272 # Return
235 273 return
... ...