Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBeiske committed Oct 21, 2024
1 parent 162db3f commit 22ac2a3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion docs/changes/290.feature.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Make it possible to pass multiple quantiles to ``pyirf.benchmarks.angular_resolution``, calculating all of them.
If only one quantile is passed, the output is the same as before.
2 changes: 1 addition & 1 deletion examples/comparison_with_EventDisplay.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@
"\n",
"plt.errorbar(\n",
" 0.5 * (ang_res['reco_energy_low'] + ang_res['reco_energy_high']).to_value(u.TeV),\n",
" ang_res['containment_quantile_68'].to_value(u.deg),\n",
" ang_res['angular_resolution_68'].to_value(u.deg),\n",
" xerr=0.5 * (ang_res['reco_energy_high'] - ang_res['reco_energy_low']).to_value(u.TeV),\n",
" ls='',\n",
" label='pyirf'\n",
Expand Down
2 changes: 1 addition & 1 deletion pyirf/benchmarks/angular_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def angular_resolution(
if not isinstance(quantile, Sequence):
quantile = [quantile]

keys = [f"containment_quantile_{value * 100:.0f}" for value in quantile]
keys = [f"angular_resolution_{value * 100:.0f}" for value in quantile]

for key in keys:
result[key] = u.Quantity(np.nan, table["theta"].unit)
Expand Down
12 changes: 6 additions & 6 deletions pyirf/benchmarks/tests/test_angular_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_empty_angular_resolution():

table = angular_resolution(events, [1, 10, 100] * u.TeV)

assert np.all(np.isnan(table["containment_quantile_68"]))
assert np.all(np.isnan(table["angular_resolution_68"]))


@pytest.mark.parametrize("unit", (u.deg, u.rad))
Expand Down Expand Up @@ -57,7 +57,7 @@ def test_angular_resolution(unit):

bins = [1, 10, 100] * u.TeV
table = angular_resolution(events, bins)
ang_res = table["containment_quantile_68"].to(u.deg)
ang_res = table["angular_resolution_68"].to(u.deg)
assert len(ang_res) == 2
assert u.isclose(ang_res[0], TRUE_RES_1 * u.deg, rtol=0.05)
assert u.isclose(ang_res[1], TRUE_RES_2 * u.deg, rtol=0.05)
Expand All @@ -68,14 +68,14 @@ def test_angular_resolution(unit):
# 2 sigma coverage interval
quantile = norm(0, 1).cdf(2) - norm(0, 1).cdf(-2)
table = angular_resolution(events, bins, quantile=quantile)
ang_res = table["containment_quantile_95"].to(u.deg)
ang_res = table["angular_resolution_95"].to(u.deg)
assert len(ang_res) == 2
assert u.isclose(ang_res[0], 2 * TRUE_RES_1 * u.deg, rtol=0.05)
assert u.isclose(ang_res[1], 2 * TRUE_RES_2 * u.deg, rtol=0.05)

# 25%, 50%, 90% coverage interval
table = angular_resolution(events, bins, quantile=[0.25, 0.5, 0.9])
cov_25 = table["containment_quantile_25"].to(u.deg)
cov_25 = table["angular_resolution_25"].to(u.deg)
assert len(cov_25) == 2
assert u.isclose(
cov_25[0], norm(0, TRUE_RES_1).interval(0.25)[1] * u.deg, rtol=0.05
Expand All @@ -84,10 +84,10 @@ def test_angular_resolution(unit):
cov_25[1], norm(0, TRUE_RES_2).interval(0.25)[1] * u.deg, rtol=0.05
)

cov_50 = table["containment_quantile_50"].to(u.deg)
cov_50 = table["angular_resolution_50"].to(u.deg)
assert u.isclose(cov_50[0], norm(0, TRUE_RES_1).interval(0.5)[1] * u.deg, rtol=0.05)
assert u.isclose(cov_50[1], norm(0, TRUE_RES_2).interval(0.5)[1] * u.deg, rtol=0.05)

cov_90 = table["containment_quantile_90"].to(u.deg)
cov_90 = table["angular_resolution_90"].to(u.deg)
assert u.isclose(cov_90[0], norm(0, TRUE_RES_1).interval(0.9)[1] * u.deg, rtol=0.05)
assert u.isclose(cov_90[1], norm(0, TRUE_RES_2).interval(0.9)[1] * u.deg, rtol=0.05)

0 comments on commit 22ac2a3

Please sign in to comment.