Commit f418ba9a90dc3ccfba233bc83f78c7d0bfce2ba3

Authored by Jürgen Knödlseder
1 parent 0f0fab79

Improve logging of csphagen

Showing 1 changed file with 53 additions and 31 deletions
cscripts/csphagen.py
@@ -317,29 +317,51 @@ class csphagen(ctools.csobservation): @@ -317,29 +317,51 @@ class csphagen(ctools.csobservation):
317 pnt_dir = obs.pointing().dir() 317 pnt_dir = obs.pointing().dir()
318 offset = pnt_dir.dist_deg(self._src_dir) 318 offset = pnt_dir.dist_deg(self._src_dir)
319 319
320 - # If ...  
321 - if offset <= self._rad or offset >= self['maxoffset'].real():  
322 - self._log_string(gammalib.EXPLICIT, 'Observation %s pointed at %.3f '  
323 - 'deg from source' % ((obs.id(), offset))) 320 + # Skip observation if it is too close to source
  321 + if offset <= self._rad:
  322 + msg = ' Skip because observation is pointed at %.3f deg <= '\
  323 + '"rad=%.3f" from source.' \
  324 + % (offset, self._rad)
  325 + self._log_string(gammalib.NORMAL, msg)
  326 +
  327 + # Skip observation if it is pointed too far from the source
  328 + elif offset >= self['maxoffset'].real():
  329 + msg = ' Skip because observation is pointed at %.3f deg >= '\
  330 + '"maxoffset=%.3f" from source.' \
  331 + % (offset, self['maxoffset'].real())
  332 + self._log_string(gammalib.NORMAL, msg)
324 333
325 # ... otherwise 334 # ... otherwise
326 else: 335 else:
327 posang = pnt_dir.posang_deg(self._src_dir) 336 posang = pnt_dir.posang_deg(self._src_dir)
328 if self._srcshape == 'CIRCLE': 337 if self._srcshape == 'CIRCLE':
329 - # angular separation of reflected regions wrt camera center  
330 - # and number 338 +
  339 + # Compute the angular separation of reflected regions wrt
  340 + # camera center. The factor 1.05 ensures background regions
  341 + # do not overlap due to numerical precision issues
331 alpha = 1.05 * 2.0 * self._rad / offset 342 alpha = 1.05 * 2.0 * self._rad / offset
332 - # 1.05 ensures background regions do not overlap due to  
333 - # numerical precision issues 343 +
  344 + # Compute number of reflected regions by dividing the angular
  345 + # separation by 2 pi.
334 N = int(2.0 * math.pi / alpha) 346 N = int(2.0 * math.pi / alpha)
  347 +
  348 + # If there are not enough reflected regions then skip the
  349 + # observation ...
335 if N < self['bkgregmin'].integer() + 3: 350 if N < self['bkgregmin'].integer() + 3:
336 - self._log_string(gammalib.EXPLICIT, 'Observation %s: '  
337 - 'insufficient regions for background '  
338 - 'estimation' % (obs.id())) 351 + msg = ' Skip because the number %d of reflected regions '\
  352 + 'for background estimation is smaller than '\
  353 + '"bkgregmin"=%d.' % (N-3, self['bkgregmin'].integer())
  354 + self._log_string(gammalib.NORMAL, msg)
339 355
340 - # Otherwise loop over position angle to create reflected 356 + # ... otherwise loop over position angle to create reflected
341 # regions 357 # regions
342 else: 358 else:
  359 +
  360 + # Log appending of reflected regions
  361 + msg = ' Use %d reflected regions.' % (N-3)
  362 + self._log_string(gammalib.NORMAL, msg)
  363 +
  364 + # Append reflected regions
343 alpha = 360.0 / N 365 alpha = 360.0 / N
344 for s in range(2, N - 1): 366 for s in range(2, N - 1):
345 dphi = s * alpha 367 dphi = s * alpha
@@ -348,10 +370,9 @@ class csphagen(ctools.csobservation): @@ -348,10 +370,9 @@ class csphagen(ctools.csobservation):
348 region = gammalib.GSkyRegionCircle(ctr_dir, self._rad) 370 region = gammalib.GSkyRegionCircle(ctr_dir, self._rad)
349 if self._has_exclusion: 371 if self._has_exclusion:
350 if self._excl_reg.overlaps(region): 372 if self._excl_reg.overlaps(region):
351 - self._log_string(gammalib.VERBOSE, 'Observation '  
352 - '%s: reflected region overlaps '  
353 - 'with exclusion region' %  
354 - (obs.id())) 373 + msg = ' Reflected region overlaps with '\
  374 + 'exclusion region.'
  375 + self._log_string(gammalib.EXPLICIT, msg)
355 else: 376 else:
356 regions.append(region) 377 regions.append(region)
357 else: 378 else:
@@ -553,29 +574,32 @@ class csphagen(ctools.csobservation): @@ -553,29 +574,32 @@ class csphagen(ctools.csobservation):
553 bkg_reg = None 574 bkg_reg = None
554 obs = self.obs()[i] 575 obs = self.obs()[i]
555 576
  577 + # Log header
  578 + self._log_header3(gammalib.NORMAL,'%s observation "%s"' % \
  579 + (obs.instrument(), obs.id()))
  580 +
556 # Skip non CTA observations 581 # Skip non CTA observations
557 if obs.classname() != 'GCTAObservation': 582 if obs.classname() != 'GCTAObservation':
558 - self._log_string(gammalib.NORMAL, 'Skip %s observation "%s"' % \  
559 - (obs.instrument(), obs.id())) 583 + self._log_string(gammalib.NORMAL, ' Skip because not a "GCTAObservation"')
560 584
561 # Otherwise calculate On/Off spectra 585 # Otherwise calculate On/Off spectra
562 else: 586 else:
563 - # Log current observation  
564 - self._log_string(gammalib.NORMAL, ' Process observation "%s"' % \  
565 - (obs.id())) 587 + # Get background model usage flag and log flag
  588 + use_model_bkg = self['use_model_bkg'].boolean()
  589 + if use_model_bkg:
  590 + msg = ' Use background model.'
  591 + else:
  592 + msg = ' Background model not used, assume constant backround rate.'
  593 + self._log_string(gammalib.NORMAL, msg)
566 594
567 # Set background regions for this observation 595 # Set background regions for this observation
568 bkg_reg = self._set_background_regions(obs) 596 bkg_reg = self._set_background_regions(obs)
569 597
570 - # Get IRF background template usage flag  
571 - use_model_bkg = self['use_model_bkg'].boolean()  
572 - if not use_model_bkg:  
573 - self._log_string(gammalib.NORMAL, ' Background model not used, '  
574 - 'assume constant backround rate.')  
575 -  
576 # If there are background regions then create On/Off observation 598 # If there are background regions then create On/Off observation
577 # and append it to the output container 599 # and append it to the output container
578 if bkg_reg.size() >= self['bkgregmin'].integer(): 600 if bkg_reg.size() >= self['bkgregmin'].integer():
  601 +
  602 + # Create On/Off observation
579 onoff = gammalib.GCTAOnOffObservation(obs, 603 onoff = gammalib.GCTAOnOffObservation(obs,
580 self._models, 604 self._models,
581 self._srcname, 605 self._srcname,
@@ -584,11 +608,9 @@ class csphagen(ctools.csobservation): @@ -584,11 +608,9 @@ class csphagen(ctools.csobservation):
584 self._src_reg, 608 self._src_reg,
585 bkg_reg, 609 bkg_reg,
586 use_model_bkg) 610 use_model_bkg)
587 - onoff.id(obs.id())  
588 611
589 - else:  
590 - self._log_string(gammalib.NORMAL, ' Observation %s not included '  
591 - 'in spectra generation' % (obs.id())) 612 + # Set On/Off observation ID
  613 + onoff.id(obs.id())
592 614
593 # Construct dictionary with results 615 # Construct dictionary with results
594 result = {'onoff' : onoff, 616 result = {'onoff' : onoff,