Commit 581a934b78c97cd4bd4a740c90a3624180a4f17e
1 parent
00e1b0bb
Response cubes computed by get_stacked_response() have at least 30 energy bins per decade
Showing
2 changed files
with
24 additions
and
23 deletions
cscripts/cspull.py
| ... | ... | @@ -180,29 +180,19 @@ class cspull(ctools.cscript): |
| 180 | 180 | self._log.header2('Trial '+str(seed-self._seed+1)) |
| 181 | 181 | |
| 182 | 182 | # If we have a binned obeservation then specify the lower and |
| 183 | - # upper energy limit | |
| 183 | + # upper energy limit in TeV | |
| 184 | 184 | if self._enumbins > 0: |
| 185 | - | |
| 186 | - # Get energy range in TeV | |
| 187 | 185 | emin = self['emin'].real() |
| 188 | 186 | emax = self['emax'].real() |
| 189 | - | |
| 190 | - # Set number of energy bins to at least 30 per energy decade | |
| 191 | - enumbins = int((math.log10(self['emax'].real()) - | |
| 192 | - math.log10(self['emin'].real())) * 30.0) | |
| 193 | - if self._enumbins > enumbins: | |
| 194 | - enumbins = self._enumbins | |
| 195 | - | |
| 196 | 187 | else: |
| 197 | - emin = None | |
| 198 | - emax = None | |
| 199 | - enumbins = 0 | |
| 188 | + emin = None | |
| 189 | + emax = None | |
| 200 | 190 | |
| 201 | 191 | # Simulate events |
| 202 | 192 | obs = obsutils.sim(self._obs, |
| 203 | 193 | emin=emin, |
| 204 | 194 | emax=emax, |
| 205 | - nbins=enumbins, | |
| 195 | + nbins=self._enumbins, | |
| 206 | 196 | addbounds=True, |
| 207 | 197 | seed=seed, |
| 208 | 198 | binsz=self._binsz, | ... | ... |
cscripts/obsutils.py
| ... | ... | @@ -17,6 +17,7 @@ |
| 17 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | 18 | # |
| 19 | 19 | # ========================================================================== |
| 20 | +import math | |
| 20 | 21 | import gammalib |
| 21 | 22 | import ctools |
| 22 | 23 | |
| ... | ... | @@ -468,8 +469,12 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, |
| 468 | 469 | """ |
| 469 | 470 | Get stacked response cubes |
| 470 | 471 | |
| 471 | - If no xref and yref arguments have been specified then use the pointing | |
| 472 | - information to determine the map centre | |
| 472 | + The number of energies bins are set to at least 30 bins per decade, and | |
| 473 | + the "enumbins" parameter is only used if the number of bins is larger | |
| 474 | + than 30 bins per decade. | |
| 475 | + | |
| 476 | + If the xref or yref arguments are "None" the response cube centre will be | |
| 477 | + determined from the pointing information in the observation container. | |
| 473 | 478 | |
| 474 | 479 | Parameters |
| 475 | 480 | ---------- |
| ... | ... | @@ -518,11 +523,17 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, |
| 518 | 523 | else: |
| 519 | 524 | usepnt = False |
| 520 | 525 | |
| 526 | + # Set number of energy bins to at least 30 per energy decade | |
| 527 | + _enumbins = int((math.log10(emax) - math.log10(emin)) * 30.0) | |
| 528 | + if enumbins > _enumbins: | |
| 529 | + _enumbins = enumbins | |
| 530 | + | |
| 521 | 531 | # Compute spatial binning for point spread function and energy dispersion |
| 522 | - # cubes | |
| 532 | + # cubes. The spatial binning is 10 times coarser than the spatial binning | |
| 533 | + # of the exposure and background cubes. At least 2 spatial are required. | |
| 523 | 534 | psf_binsz = 10.0 * binsz |
| 524 | - psf_nxpix = min(nxpix // 10, 2) # Make sure result is int | |
| 525 | - psf_nypix = min(nypix // 10, 2) # Make sure result is int | |
| 535 | + psf_nxpix = max(nxpix // 10, 2) # Make sure result is int | |
| 536 | + psf_nypix = max(nypix // 10, 2) # Make sure result is int | |
| 526 | 537 | |
| 527 | 538 | # Create exposure cube |
| 528 | 539 | expcube = ctools.ctexpcube(obs) |
| ... | ... | @@ -532,7 +543,7 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, |
| 532 | 543 | expcube['binsz'] = binsz |
| 533 | 544 | expcube['nxpix'] = nxpix |
| 534 | 545 | expcube['nypix'] = nypix |
| 535 | - expcube['enumbins'] = enumbins | |
| 546 | + expcube['enumbins'] = _enumbins | |
| 536 | 547 | expcube['emin'] = emin |
| 537 | 548 | expcube['emax'] = emax |
| 538 | 549 | expcube['coordsys'] = coordsys |
| ... | ... | @@ -555,7 +566,7 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, |
| 555 | 566 | psfcube['binsz'] = psf_binsz |
| 556 | 567 | psfcube['nxpix'] = psf_nxpix |
| 557 | 568 | psfcube['nypix'] = psf_nypix |
| 558 | - psfcube['enumbins'] = enumbins | |
| 569 | + psfcube['enumbins'] = _enumbins | |
| 559 | 570 | psfcube['emin'] = emin |
| 560 | 571 | psfcube['emax'] = emax |
| 561 | 572 | psfcube['coordsys'] = coordsys |
| ... | ... | @@ -578,7 +589,7 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, |
| 578 | 589 | bkgcube['binsz'] = binsz |
| 579 | 590 | bkgcube['nxpix'] = nxpix |
| 580 | 591 | bkgcube['nypix'] = nypix |
| 581 | - bkgcube['enumbins'] = enumbins | |
| 592 | + bkgcube['enumbins'] = _enumbins | |
| 582 | 593 | bkgcube['emin'] = emin |
| 583 | 594 | bkgcube['emax'] = emax |
| 584 | 595 | bkgcube['coordsys'] = coordsys |
| ... | ... | @@ -602,7 +613,7 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, |
| 602 | 613 | edispcube['binsz'] = psf_binsz |
| 603 | 614 | edispcube['nxpix'] = psf_nxpix |
| 604 | 615 | edispcube['nypix'] = psf_nypix |
| 605 | - edispcube['enumbins'] = enumbins | |
| 616 | + edispcube['enumbins'] = _enumbins | |
| 606 | 617 | edispcube['emin'] = emin |
| 607 | 618 | edispcube['emax'] = emax |
| 608 | 619 | edispcube['coordsys'] = coordsys | ... | ... |