implement mapevaluator.peek
import logging
import numpy as np
import astropy.units as u
+import matplotlib.pyplot as plt
from astropy.coordinates.angle_utilities import angular_separation
from astropy.utils import lazyproperty
from regions import CircleSkyRegion
@@ -487,3 +488,71 @@ class MapEvaluator:
if not self.model.apply_irf["edisp"]:
methods.remove(self.apply_edisp)
return methods
+
+ def peek(self, figsize=(12, 15)):
+ """Quick-look summary plots.
+ Parameters
+ ----------
+ figsize : tuple
+ Size of the figure.
+ """
+ if self.needs_update:
+ raise AttributeError(
+ "The evaluator needs to be updated first. Execute "
+ "`MapDataset.npred_signal(model_name=...)` before calling this method."
+ )
+
+ nrows = 1
+ if self.psf:
+ nrows += 1
+ if self.edisp:
+ nrows += 1
+
+ fig, axes = plt.subplots(
+ ncols=2,
+ nrows=nrows,
+ subplot_kw={"projection": self.exposure.geom.wcs},
+ figsize=figsize,
+ gridspec_kw={"hspace": 0.2, "wspace": 0.3},
+ )
+
+ axes = axes.flat
+
+ exposure = self.exposure
+ if isinstance(exposure, WcsNDMap) or isinstance(exposure, HpxNDMap):
+ axes[0].set_title("Predicted counts")
+ self.compute_npred().sum_over_axes().plot(ax=axes[0], add_cbar=True)
+
+ axes[1].set_title("Exposure")
+ self.exposure.sum_over_axes().plot(ax=axes[1], add_cbar=True)
+ elif isinstance(exposure, RegionNDMap):
+ axes[0].remove()
+ ax0 = fig.add_subplot(nrows, 2, 1)
+ ax0.set_title("Predicted counts")
+ self.compute_npred().plot(ax=ax0)
+
+ axes[1].remove()
+ ax1 = fig.add_subplot(nrows, 2, 2)
+ ax1.set_title("Exposure")
+ self.exposure.plot(ax=ax1)
+
+ idx = 3
+ if self.psf:
+ axes[2].set_title("Energy-integrated PSF kernel")
+ self.psf.plot_kernel(ax=axes[2], add_cbar=True)
+
+ axes[3].set_title("PSF kernel at 1 TeV")
+ self.psf.plot_kernel(ax=axes[3], add_cbar=True, energy=1 * u.TeV)
+
+ idx += 2
+
+ if self.edisp:
+ axes[idx - 1].remove()
+ ax = fig.add_subplot(nrows, 2, idx)
+ ax.set_title("Energy bias")
+ self.edisp.plot_bias(ax=ax)
+
+ axes[idx].remove()
+ ax = fig.add_subplot(nrows, 2, idx + 1)
+ ax.set_title("Energy dispersion matrix")
+ self.edisp.plot_matrix(ax=ax)
\ No newline at end of file
