Skip to content

Commit

Permalink
Merge pull request #4722 from Astro-Kirsty/fix_get_overlap_fraction
Browse files Browse the repository at this point in the history
Fix get_overlap_fraction for different energies
  • Loading branch information
Astro-Kirsty committed Aug 25, 2023
2 parents 2be59e6 + 3d003b0 commit eb87310
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gammapy/irf/edisp/map.py
Expand Up @@ -17,7 +17,7 @@ def get_overlap_fraction(energy_axis, energy_axis_true):

xmin = np.fmin(a_max, b_max)
xmax = np.fmax(a_min, b_min)
return np.clip(xmin - xmax, 0, np.inf) / (b_max - b_min)
return (np.clip(xmin - xmax, 0, np.inf) / (b_max - b_min)).to("")


class EDispMap(IRFMap):
Expand Down
6 changes: 6 additions & 0 deletions gammapy/irf/edisp/tests/test_kernel.py
Expand Up @@ -35,6 +35,12 @@ def test_from_diagonal_response(self):

assert_equal(edisp.pdf_matrix, expected)

# Test with different energy units
energy_axis = MapAxis.from_energy_edges([2000, 4000, 6000] * u.GeV)
edisp = EDispKernel.from_diagonal_response(energy_axis_true, energy_axis)
assert edisp.pdf_matrix.shape == (4, 2)
assert_allclose(edisp.pdf_matrix, expected, atol=1e-5)

# Test square matrix
edisp = EDispKernel.from_diagonal_response(energy_axis_true)
assert_allclose(edisp.axes["energy"].edges, edisp.axes["energy_true"].edges)
Expand Down
2 changes: 1 addition & 1 deletion gammapy/irf/edisp/tests/test_map.py
Expand Up @@ -224,7 +224,7 @@ def test_edisp_kernel_map_stack():
assert_allclose(exposure, 3.0)


def test__incorrect_edisp_kernel_map_stack():
def test_incorrect_edisp_kernel_map_stack():
energy_axis = MapAxis.from_energy_bounds("1 TeV", "10 TeV", nbin=5)

energy_axis_true = MapAxis.from_energy_bounds(
Expand Down

0 comments on commit eb87310

Please sign in to comment.