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 317 pnt_dir = obs.pointing().dir()
318 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 334 # ... otherwise
326 335 else:
327 336 posang = pnt_dir.posang_deg(self._src_dir)
328 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 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 346 N = int(2.0 * math.pi / alpha)
  347 +
  348 + # If there are not enough reflected regions then skip the
  349 + # observation ...
335 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 357 # regions
342 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 365 alpha = 360.0 / N
344 366 for s in range(2, N - 1):
345 367 dphi = s * alpha
... ... @@ -348,10 +370,9 @@ class csphagen(ctools.csobservation):
348 370 region = gammalib.GSkyRegionCircle(ctr_dir, self._rad)
349 371 if self._has_exclusion:
350 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 376 else:
356 377 regions.append(region)
357 378 else:
... ... @@ -553,29 +574,32 @@ class csphagen(ctools.csobservation):
553 574 bkg_reg = None
554 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 581 # Skip non CTA observations
557 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 585 # Otherwise calculate On/Off spectra
562 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 595 # Set background regions for this observation
568 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 598 # If there are background regions then create On/Off observation
577 599 # and append it to the output container
578 600 if bkg_reg.size() >= self['bkgregmin'].integer():
  601 +
  602 + # Create On/Off observation
579 603 onoff = gammalib.GCTAOnOffObservation(obs,
580 604 self._models,
581 605 self._srcname,
... ... @@ -584,11 +608,9 @@ class csphagen(ctools.csobservation):
584 608 self._src_reg,
585 609 bkg_reg,
586 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 615 # Construct dictionary with results
594 616 result = {'onoff' : onoff,
... ...