Add RegionGeom.is_allclose
@@ -578,17 +578,39 @@ class RegionGeom(Geom):
f"\tcenter : {lon:.1f} deg, {lat:.1f} deg\n"
)
- def __eq__(self, other):
- # check overall shape and axes compatibility
+ def is_allclose(self, other, rtol_axes=1e-6, atol_axes=1e-6):
+ """Compare two data IRFs for equivalency
+
+ Parameters
+ ----------
+ other : the irf to compare against
+ `gammapy.irfs.IRF`
+ rtol_axes : float
+ Relative tolerance for the axes comparison.
+ atol_axes : float
+ Relative tolerance for the axes comparison.
+
+ Returns
+ -------
+ is_allclose : bool
+ Whether the IRF is all close.
+ """
+ if not isinstance(other, self.__class__):
+ return TypeError(f"Cannot compare {type(self)} and {type(other)}")
+
if self.data_shape != other.data_shape:
return False
- for axis, otheraxis in zip(self.axes, other.axes):
- if axis != otheraxis:
+ axes_eq = self.axes.is_allclose(other.axes, rtol=rtol_axes, atol=atol_axes)
+ # TODO: compare regions based on masks...
+ regions_eq = True
+ return axes_eq and regions_eq
+
+ def __eq__(self, other):
+ if not isinstance(other, self.__class__):
return False
- # TODO: compare regions
- return True
+ return self.is_allclose(other=other)
def _to_region_table(self):
"""Export region to a FITS region table."""
