update tests and plotting

This commit is contained in:
Pim Nelissen
2026-03-20 09:26:10 +01:00
parent b1d781714b
commit a1a18c6a35
4 changed files with 140 additions and 51 deletions

View File

@ -3,20 +3,20 @@ import pytest
from pg_rad.inputparser.parser import ConfigParser
from pg_rad.landscape.director import LandscapeDirector
from pg_rad.physics import calculate_fluence_at
from pg_rad.physics.fluence import phi
@pytest.fixture
def isotropic_detector():
from pg_rad.detector.detectors import IsotropicDetector
return IsotropicDetector(name="test_detector", eff=1.0)
from pg_rad.detector.detector import load_detector
return load_detector('dummy')
@pytest.fixture
def phi_ref(test_landscape, isotropic_detector):
source = test_landscape.point_sources[0]
r = np.linalg.norm(np.array([10, 10, 0]) - np.array(source.pos))
r = np.linalg.norm(np.array([0, 0, 0]) - np.array(source.pos))
A = source.activity * 1E6
b = source.isotope.b
@ -43,12 +43,11 @@ def test_landscape():
sources:
test_source:
activity_MBq: 100
position: [0, 0, 0]
isotope: CS137
position: [0, 100, 0]
isotope: Cs137
gamma_energy_keV: 661
detector:
name: dummy
is_isotropic: True
detector: dummy
"""
cp = ConfigParser(test_yaml).parse()
@ -57,10 +56,15 @@ def test_landscape():
def test_single_source_fluence(phi_ref, test_landscape, isotropic_detector):
phi = calculate_fluence_at(
test_landscape,
np.array([10, 10, 0]),
isotropic_detector,
tangent_vectors=None,
s = test_landscape.point_sources[0]
r = np.linalg.norm(np.array([0, 0, 0]) - np.array(s.pos))
phi_calc = phi(
r,
s.activity*1E6,
s.isotope.b,
s.isotope.mu_mass_air,
test_landscape.air_density,
isotropic_detector.get_efficiency(s.isotope.E)
)
assert pytest.approx(phi[0], rel=1E-3) == phi_ref
assert pytest.approx(phi_calc, rel=1E-6) == phi_ref