Repository: cta-observatory/pyirf

Issue:
angular resolution function does not respect units of theta in input
Due to how astropy tables work, the input is assumed to be degrees.

Discussion:

Patch:
diff --git a/pyirf/benchmarks/angular_resolution.py b/pyirf/benchmarks/angular_resolution.py
index a5c120d..c1bcb1b 100644
--- a/pyirf/benchmarks/angular_resolution.py
+++ b/pyirf/benchmarks/angular_resolution.py
@@ -51,7 +51,7 @@ def angular_resolution(
     result[f"{energy_type}_energy_high"] = energy_bins[1:]
     result[f"{energy_type}_energy_center"] = 0.5 * (energy_bins[:-1] + energy_bins[1:])
 
-    result["angular_resolution"] = np.nan * u.deg
+    result["angular_resolution"] = u.Quantity(np.nan, table["theta"].unit)
 
     if not len(events):
         # if we get an empty input (no selected events available)


Test patch:
diff --git a/pyirf/benchmarks/tests/test_angular_resolution.py b/pyirf/benchmarks/tests/test_angular_resolution.py
index 5ae0044..c3aa192 100644
--- a/pyirf/benchmarks/tests/test_angular_resolution.py
+++ b/pyirf/benchmarks/tests/test_angular_resolution.py
@@ -1,6 +1,7 @@
 from astropy.table import QTable
 import astropy.units as u
 import numpy as np
+import pytest
 
 
 def test_empty_angular_resolution():
@@ -18,7 +19,8 @@ def test_empty_angular_resolution():
 
     assert np.all(np.isnan(table["angular_resolution"]))
 
-def test_angular_resolution():
+@pytest.mark.parametrize("unit", (u.deg, u.rad))
+def test_angular_resolution(unit):
     from pyirf.benchmarks import angular_resolution
 
     np.random.seed(1337)
@@ -37,6 +39,8 @@ def test_angular_resolution():
         'theta': np.abs(np.random.normal(0, true_resolution)) * u.deg
     })
 
+    events['theta'] = events['theta'].to(unit)
+
     ang_res = angular_resolution(
         events,
         [1, 10, 100] * u.TeV,