diff --git a/src/ctapipe/image/psf_model.py b/src/ctapipe/image/psf_model.py index 9f6f97ffeb2..cba6fc2098a 100644 --- a/src/ctapipe/image/psf_model.py +++ b/src/ctapipe/image/psf_model.py @@ -82,11 +82,16 @@ def __init__( az_scale_params=[0.24271557, 7.5511501, 0.02037972], ): """ - PSF model, describing pure coma aberrations PSF effect + PSF model, describing purely the effect of coma aberration on the PSF - param list asymmetry_params Parameters describing the dependency of the asymmetry of the psf on the distance to the center of the camera - param list radial_scale_params Parameters describing the dependency of the radial scale on the distance to the center of the camera - param list radial_scale_params Parameters describing the dependency of the azimuthal scale scale on the distance to the center of the camera + Parameters + ---------- + asymmetry_params: list + Parameters describing the dependency of the asymmetry of the psf on the distance to the center of the camera + radial_scale_params : list + Parameters describing the dependency of the radial scale on the distance to the center of the camera + radial_scale_params : list + Parameters describing the dependency of the azimuthal scale scale on the distance to the center of the camera """ self.asymmetry_params = asymmetry_params @@ -116,11 +121,36 @@ def sf_func(self, x): ) + self.az_scale_params[2] / (self.az_scale_params[2] + x) def pdf(self, r, f): + """ + Calculates the value of the psf at a given location + + Parameters + ---------- + r : float + distance to the center of the camera in meters + f : float + polar angle in radians + + Returns + ---------- + psf : float + value of the PSF at the specified location + """ return laplace_asymmetric.pdf(r, *self.radial_pdf_params) * laplace.pdf( f, *self.azimuthal_pdf_params ) def update_model_parameters(self, model_params): + """ + Updates the model parameters for the psf + + Parameters + ---------- + model_params : dict + dictionary with the model parameters + needs to have the keys `asymmetry_params`, `radial_scale_params` and `az_scale_params` + The values need to be lists of length 3, 4 and 3 respectively + """ if not ( len(model_params["asymmetry_params"]) == 3 and len(model_params["radial_scale_params"]) == 4 @@ -140,6 +170,15 @@ def update_model_parameters(self, model_params): self.azimuthal_pdf_params = (self.azimuthal_pdf_params[0], sf) def update_location(self, r, f): + """ + Updates the location on the camera focal plane from where the psf is calculated + Parameters + ---------- + r : float + distance to the center of the camera in meters + f : float + polar angle in radians + """ k = self.k_func(r) sr = self.sr_func(r) sf = self.sf_func(r) diff --git a/src/ctapipe/image/tests/test_psf_model.py b/src/ctapipe/image/tests/test_psf_model.py new file mode 100644 index 00000000000..21ecd22fe34 --- /dev/null +++ b/src/ctapipe/image/tests/test_psf_model.py @@ -0,0 +1,27 @@ +""" +This module contains the ctapipe.image.psf_model unit tests +""" +import numpy as np +import pytest + +from ctapipe.image.psf_model import PSFModel + + +def test_psf(): + psf = PSFModel.from_name("ComaModel") + wrong_parameters = { + "asymmetry_params": [0.49244797, 9.23573115, 0.15216096], + "radial_scale_params": [0.01409259, 0.02947208, 0.06000271, -0.02969355], + "az_scale_params": [0.24271557, 7.5511501], + } + with pytest.raises( + ValueError, + match="asymmetry_params and az_scale_params needs to have length 3 and radial_scale_params length 4", + ): + psf.update_model_parameters(wrong_parameters) + + +def test_asymptotic_behavior(): + psf_coma = PSFModel.from_name("ComaModel") + psf_coma.update_location(1.0, 0.0) + assert np.isclose(psf_coma.psf(10.0, 0.0), 0.0)