From b61c2fbc09dfed35bf5905d23a894895d043127d Mon Sep 17 00:00:00 2001 From: Alison Mitchell Date: Tue, 23 Mar 2021 15:38:47 +0100 Subject: [PATCH] add validation function for psf norm --- pyirf/validation.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 pyirf/validation.py diff --git a/pyirf/validation.py b/pyirf/validation.py new file mode 100644 index 000000000..1ffc7c248 --- /dev/null +++ b/pyirf/validation.py @@ -0,0 +1,18 @@ +import numpy as np +from .utils import cone_solid_angle + +class InvalidIRF(Exception): + pass + +class InvalidNormalisation(InvalidIRF): + pass + +def validate_psf(psf,source_offset_bins): + + radbin_solidangle = np.diff(cone_solid_angle(source_offset_bins)) + integral = np.sum(psf*radbin_solidangle,axis=2) + + if not np.allclose(integral,1): + nbad = np.count_nonzero(~np.isclose(integral,1)) + raise InvalidNormalisation(f"PSF not correctly normalised: {nbad} affected bins") + \ No newline at end of file