Skip to content

Commit

Permalink
adding tests and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Toennis committed Nov 1, 2024
1 parent 4aeaa05 commit 295dd24
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
47 changes: 43 additions & 4 deletions src/ctapipe/image/psf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions src/ctapipe/image/tests/test_psf_model.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 295dd24

Please sign in to comment.