Commit c7d8b33c1753b6d7c71b4c0d12695fdb60bb81c3

Authored by Jürgen Knödlseder
1 parent 3ffc2688

Clean up scripts

cscripts/cslightcrv.py
... ... @@ -457,12 +457,14 @@ class cslightcrv(ctools.csobservation):
457 457  
458 458 # Deal with stacked and On/Off Observations
459 459 if self._stacked or self._onoff:
  460 +
460 461 # If a stacked analysis is requested bin the events
461 462 # and compute the stacked response functions and setup
462 463 # an observation container with a single stacked observation.
463 464 if self._stacked:
464 465 new_obs = obsutils.get_stacked_obs(self, obs)
465   - # Otherwise if On/Off analysis is requested generate
  466 +
  467 + # ... otherwise if On/Off analysis is requested generate
466 468 # the On/Off observations and response
467 469 elif self._onoff:
468 470 new_obs = obsutils.get_onoff_obs(self, obs)
... ...
cscripts/csphasecrv.py
... ... @@ -363,31 +363,36 @@ class csphasecrv(ctools.csobservation):
363 363 select['dec'] = 'UNDEFINED'
364 364 select['expr'] = 'PHASE>'+str(phbin[0])+' && PHASE<'+str(phbin[1])
365 365 select.run()
366   -
  366 +
  367 + # Set phase string
  368 + phstr = str(phbin[0]) + '-' + str(phbin[1])
  369 +
367 370 # Add phase to observation id
368 371 for i in range(0,select.obs().size()):
369 372 oldid = select.obs()[i].id()
370   - select.obs()[i].id(oldid+'_'+str(phbin[0])+'-'+str(phbin[1]))
  373 + select.obs()[i].id(oldid+'_'+phstr)
371 374 obs = select.obs()
372 375  
373 376 # If an On/Off analysis is requested generate the On/Off observations
374 377 if self._onoff:
375 378 obs = obsutils.get_onoff_obs(self, select.obs())
376   - # Otherwise, if stacked analysis is requested then bin the events
377   - # and compute the stacked response functions and setup
  379 +
  380 + # ... otherwise, if stacked analysis is requested then bin the
  381 + # events and compute the stacked response functions and setup
378 382 # an observation container with a single stacked observation.
379 383 elif self._stacked:
380 384 obs = obsutils.get_stacked_obs(self, select.obs())
381   -
  385 +
382 386 # Header
383 387 self._log_header3(gammalib.EXPLICIT, 'Fitting the data')
384   -
385   - # Do maximum likelihood model fitting
  388 +
386 389 # The On/Off analysis can produce empty observation containers,
387 390 # e.g., when on-axis observations are used. To avoid ctlike asking
388   - # for a new observations contained (or hang, in on interactive mode)
  391 + # for a new observation container (or hang, if in interactive mode)
389 392 # we'll run ctlike only if the size is >0
390 393 if obs.size() > 0:
  394 +
  395 + # Do maximum likelihood model fitting
391 396 like = ctools.ctlike(obs)
392 397 like['edisp'] = self['edisp'].boolean()
393 398 like.run()
... ... @@ -397,16 +402,18 @@ class csphasecrv(ctools.csobservation):
397 402 for model in like.obs().models():
398 403 scaled_norm = model['Normalization'].value()/(phbin[1]-phbin[0])
399 404 model['Normalization'].value(scaled_norm)
  405 +
400 406 # Store fit model
401   - self._fitmodels[str(phbin[0])+'-'+str(phbin[1])] = \
402   - like.obs().models().copy()
  407 + self._fitmodels[phstr] = like.obs().models().copy()
  408 +
  409 + # ... otherwise we set an empty model container
403 410 else:
404 411 self._log_string(gammalib.TERSE,
405 412 'PHASE %f - %f: no observations available'
406 413 ' for fitting' %(phbin[0], phbin[1]))
407   - # empty models container
408   - self._fitmodels[str(phbin[0]) + '-' + str(phbin[1])] = \
409   - gammalib.GModels()
  414 +
  415 + # Set empty models container
  416 + self._fitmodels[phstr] = gammalib.GModels()
410 417  
411 418 # Create FITS file
412 419 self._create_fits()
... ...