Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exposure and flux units in IACTBasicImageEstimator #1305

Merged
merged 2 commits into from
Feb 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gammapy/image/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def flux(images):

with np.errstate(invalid='ignore', divide='ignore'):
flux.data = (excess / images['exposure'].data)
flux.unit = (1 / images['exposure'].unit).unit

is_zero = images['exposure'].data == 0
flux.data[is_zero] = 0
Expand Down Expand Up @@ -193,6 +194,7 @@ def _exposure(self, observation):
exposure = exposure_cube.sky_image_integral(emin=p['emin'], emax=p['emax'])

exposure.name = 'exposure'
exposure.unit = exposure.data.unit
exposure.data = np.nan_to_num(exposure.data.value)
return exposure

Expand Down Expand Up @@ -304,6 +306,9 @@ def run(self, observations, which='all'):
if 'exposure' in which:
exposure = self._exposure(observation)
result['exposure'].paste(exposure)
# TODO: improve SkyImage.paste() so that it enforces compatibility
# of units when doing the sum. The fix below can then be removed.
result['exposure'].unit = exposure.unit

if 'counts' in which:
counts = self._counts(observation)
Expand All @@ -327,6 +332,9 @@ def run(self, observations, which='all'):
if 'flux' in which:
flux = self.flux(SkyImageList([counts, background, exposure]))
result['flux'].paste(flux)
# TODO: improve SkyImage.paste() so that it enforces compatibility
# of units when doing the sum. The fix below can then be removed.
result['flux'].unit = flux.unit

if 'psf' in which:
result['psf'] = self.psf(observations)
Expand Down