@@ 1740-1767 (lines=28) @@ | ||
1737 | data = self.quantity.to_value(unit) |
|
1738 | return self.from_geom(self.geom, data=data, unit=unit) |
|
1739 | ||
1740 | def is_allclose(self, other, rtol_axes=1e-3, atol_axes=1e-6, **kwargs): |
|
1741 | """Compare two Maps for close equivalency |
|
1742 | ||
1743 | Parameters |
|
1744 | ---------- |
|
1745 | other : `gammapy.maps.Map` |
|
1746 | The Map to compare against |
|
1747 | rtol_axes : float |
|
1748 | Relative tolerance for the axes comparison. |
|
1749 | atol_axes : float |
|
1750 | Relative tolerance for the axes comparison. |
|
1751 | **kwargs : dict |
|
1752 | keywords passed to `numpy.allclose` |
|
1753 | ||
1754 | Returns |
|
1755 | ------- |
|
1756 | is_allclose : bool |
|
1757 | Whether the Map is all close. |
|
1758 | """ |
|
1759 | if not isinstance(other, self.__class__): |
|
1760 | return TypeError(f"Cannot compare {type(self)} and {type(other)}") |
|
1761 | ||
1762 | if self.data.shape != other.data.shape: |
|
1763 | return False |
|
1764 | ||
1765 | axes_eq = self.axes.is_allclose(other.axes, rtol=rtol_axes, atol=atol_axes) |
|
1766 | data_eq = np.allclose(self.quantity, other.quantity, **kwargs) |
|
1767 | return axes_eq and data_eq |
|
1768 | ||
1769 | def __repr__(self): |
|
1770 | geom = self.geom.__class__.__name__ |
@@ 586-613 (lines=28) @@ | ||
583 | data = self.data[slices] |
|
584 | return self.__class__(axes=axes, data=data, unit=self.unit, meta=self.meta) |
|
585 | ||
586 | def is_allclose(self, other, rtol_axes=1e-3, atol_axes=1e-6, **kwargs): |
|
587 | """Compare two data IRFs for equivalency |
|
588 | ||
589 | Parameters |
|
590 | ---------- |
|
591 | other : `gammapy.irfs.IRF` |
|
592 | The irf to compare against |
|
593 | rtol_axes : float |
|
594 | Relative tolerance for the axes comparison. |
|
595 | atol_axes : float |
|
596 | Relative tolerance for the axes comparison. |
|
597 | **kwargs : dict |
|
598 | keywords passed to `numpy.allclose` |
|
599 | ||
600 | Returns |
|
601 | ------- |
|
602 | is_allclose : bool |
|
603 | Whether the IRF is all close. |
|
604 | """ |
|
605 | if not isinstance(other, self.__class__): |
|
606 | return TypeError(f"Cannot compare {type(self)} and {type(other)}") |
|
607 | ||
608 | if self.data.shape != other.data.shape: |
|
609 | return False |
|
610 | ||
611 | axes_eq = self.axes.is_allclose(other.axes, rtol=rtol_axes, atol=atol_axes) |
|
612 | data_eq = np.allclose(self.quantity, other.quantity, **kwargs) |
|
613 | return axes_eq and data_eq |
|
614 | ||
615 | def __eq__(self, other): |
|
616 | if not isinstance(other, self.__class__): |