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