mirror of
https://github.com/pim-n/pg-rad
synced 2026-03-23 21:58:12 +01:00
update tests to follow new architecture
This commit is contained in:
@ -42,7 +42,7 @@ def phi(
|
|||||||
return phi_r
|
return phi_r
|
||||||
|
|
||||||
|
|
||||||
def calculate_fluence_at(landscape: "Landscape", pos: np.ndarray):
|
def calculate_fluence_at(landscape: "Landscape", pos: np.ndarray, scaling=1E6):
|
||||||
"""Compute fluence at an arbitrary position in the landscape.
|
"""Compute fluence at an arbitrary position in the landscape.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -52,15 +52,16 @@ def calculate_fluence_at(landscape: "Landscape", pos: np.ndarray):
|
|||||||
Returns:
|
Returns:
|
||||||
total_phi (np.ndarray): (N,) array of fluences.
|
total_phi (np.ndarray): (N,) array of fluences.
|
||||||
"""
|
"""
|
||||||
|
pos = np.atleast_2d(pos)
|
||||||
total_phi = np.zeros(pos.shape[0])
|
total_phi = np.zeros(pos.shape[0])
|
||||||
|
|
||||||
for source in landscape.point_sources:
|
for source in landscape.point_sources:
|
||||||
r = np.linalg.norm(pos - np.array(source.pos), axis=1)
|
r = np.linalg.norm(pos - np.array(source.pos), axis=1)
|
||||||
r = np.maximum(r, 1e-3) # enforce minimum distance of 1cm
|
r = np.maximum(r, 1E-3) # enforce minimum distance of 1cm
|
||||||
|
|
||||||
phi_source = phi(
|
phi_source = phi(
|
||||||
r=r,
|
r=r,
|
||||||
activity=source.activity,
|
activity=source.activity * scaling,
|
||||||
branching_ratio=source.isotope.b,
|
branching_ratio=source.isotope.b,
|
||||||
mu_mass_air=source.isotope.mu_mass_air,
|
mu_mass_air=source.isotope.mu_mass_air,
|
||||||
air_density=landscape.air_density
|
air_density=landscape.air_density
|
||||||
|
|||||||
@ -1,34 +1,53 @@
|
|||||||
from math import dist, exp, pi
|
import numpy as np
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pg_rad.landscape import LandscapeDirector
|
from pg_rad.inputparser.parser import ConfigParser
|
||||||
|
from pg_rad.landscape.director import LandscapeDirector
|
||||||
|
from pg_rad.physics import calculate_fluence_at
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def phi_ref():
|
def phi_ref(test_landscape):
|
||||||
A = 100 # MBq
|
source = test_landscape.point_sources[0]
|
||||||
b = 0.851
|
|
||||||
mu_mass_air = 0.0778 # cm^2/g
|
|
||||||
air_density = 1.243 # kg/m^3
|
|
||||||
r = dist((0, 0, 0), (10, 10, 0)) # m
|
|
||||||
|
|
||||||
A *= 1E9 # Convert to Bq
|
r = np.linalg.norm(np.array([10, 10, 0]) - np.array(source.pos))
|
||||||
mu_mass_air *= 0.1 # Convert to m^2/kg
|
|
||||||
|
|
||||||
mu_air = mu_mass_air * air_density # [m^2/kg] x [kg/m^3] = [m^-1]
|
A = source.activity * 1E6
|
||||||
|
b = source.isotope.b
|
||||||
|
mu_air = source.isotope.mu_mass_air * test_landscape.air_density
|
||||||
|
mu_air *= 0.1
|
||||||
|
|
||||||
# [s^-1] x exp([m^-1] x [m]) / [m^-2] = [s^-1 m^-2]
|
return A * b * np.exp(-mu_air * r) / (4 * np.pi * r**2)
|
||||||
phi = A * b * exp(-mu_air * r) / (4 * pi * r**2)
|
|
||||||
return phi
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def test_landscape():
|
def test_landscape():
|
||||||
landscape = LandscapeDirector().build_test_landscape()
|
|
||||||
|
test_yaml = """
|
||||||
|
name: Test landscape
|
||||||
|
speed: 8.33
|
||||||
|
acquisition_time: 1
|
||||||
|
|
||||||
|
path:
|
||||||
|
length: 1000
|
||||||
|
segments:
|
||||||
|
- straight
|
||||||
|
|
||||||
|
sources:
|
||||||
|
test_source:
|
||||||
|
activity_MBq: 100
|
||||||
|
position: [0, 0, 0]
|
||||||
|
isotope: CS137
|
||||||
|
"""
|
||||||
|
|
||||||
|
cp = ConfigParser(test_yaml).parse()
|
||||||
|
landscape = LandscapeDirector.build_from_config(cp)
|
||||||
return landscape
|
return landscape
|
||||||
|
|
||||||
|
|
||||||
def test_single_source_fluence(phi_ref, test_landscape):
|
def test_single_source_fluence(phi_ref, test_landscape):
|
||||||
phi = test_landscape.calculate_fluence_at((10, 10, 0))
|
phi = calculate_fluence_at(
|
||||||
assert pytest.approx(phi, rel=1E-3) == phi_ref
|
test_landscape,
|
||||||
|
np.array([10, 10, 0]),
|
||||||
|
)
|
||||||
|
assert pytest.approx(phi[0], rel=1E-3) == phi_ref
|
||||||
|
|||||||
@ -2,17 +2,16 @@ import numpy as np
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pg_rad.objects import PointSource
|
from pg_rad.objects import PointSource
|
||||||
from pg_rad.isotopes import CS137
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def test_sources():
|
def test_sources():
|
||||||
iso = CS137()
|
iso = "CS137"
|
||||||
pos_a = np.random.rand(3)
|
pos_a = np.random.rand(3)
|
||||||
pos_b = np.random.rand(3)
|
pos_b = np.random.rand(3)
|
||||||
|
|
||||||
a = PointSource(pos=pos_a, activity=None, isotope=iso)
|
a = PointSource(position=pos_a, activity_MBq=None, isotope=iso)
|
||||||
b = PointSource(pos=pos_b, activity=None, isotope=iso)
|
b = PointSource(position=pos_b, activity_MBq=None, isotope=iso)
|
||||||
|
|
||||||
return pos_a, pos_b, a, b
|
return pos_a, pos_b, a, b
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user