Skip to content

Commit

Permalink
aeff table evaluate accepts arbitrary ndarray for offset
Browse files Browse the repository at this point in the history
  • Loading branch information
tibaldo committed Dec 7, 2015
1 parent 72e5951 commit 8fd14ce
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions gammapy/irf/effective_area_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,12 @@ def evaluate(self, offset=None, energy=None):
"""Evaluate effective area for a given energy and offset.
If a parameter is not given, the nodes from the FITS table are used.
2D input arrays are not supported yet.
Parameters
----------
offset : `~astropy.coordinates.Angle`
offset : `~astropy.coordinates.Angle`, generic ndarray
offset
energy : `~astropy.units.Quantity`
energy : `~astropy.units.Quantity`, only 1D array supported
energy
Returns
Expand All @@ -535,13 +534,19 @@ def evaluate(self, offset=None, energy=None):
offset = offset.to('deg')
energy = energy.to('TeV')

offset_shape = np.shape(offset)
energy_shape = np.shape(energy)
offset = offset.flatten()

method = self.interpolation_method
if method == 'linear':
val = self._eval_linear(offset.value, np.log10(energy.value))
elif method == 'spline':
val = self._eval_spline(offset.value, np.log10(energy.value))
else:
raise ValueError('Invalid interpolation method: {}'.format(method))

val = np.reshape(val, np.append(offset_shape, energy_shape))
return Quantity(val, self.eff_area.unit)

def _eval_linear(self, offset=None, energy=None):
Expand All @@ -561,7 +566,7 @@ def _eval_linear(self, offset=None, energy=None):
"""
off = np.atleast_1d(offset)
ener = np.atleast_1d(energy)
points = [(x,y) for x in off for y in ener]
points = [(x, y) for x in off for y in ener]
shape = (off.size, ener.size)
val = self._linear(points)
val = np.reshape(val, shape).squeeze()
Expand Down Expand Up @@ -691,7 +696,6 @@ def info(self):

return ss


def _prepare_linear_interpolator(self):
"""Setup `~scipy.interpolate.RegularGridInterpolator`
"""
Expand All @@ -702,7 +706,7 @@ def _prepare_linear_interpolator(self):
y = np.log10(self.energy.value)
vals = self.eff_area.value

self._linear = RegularGridInterpolator((x,y),vals, bounds_error = True)
self._linear = RegularGridInterpolator((x, y), vals, bounds_error=True)

def _prepare_spline_interpolator(self):
"""Only works for radial symmetric input files (N=2)
Expand Down

0 comments on commit 8fd14ce

Please sign in to comment.