add fluence function to landscape and update to new position system

This commit is contained in:
Pim Nelissen
2026-02-10 13:53:57 +01:00
parent 0971c2bab9
commit 3f7395ed70

View File

@ -3,9 +3,11 @@ import logging
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from matplotlib.patches import Circle from matplotlib.patches import Circle
import numpy as np import numpy as np
from numpy.typing import ArrayLike
from pg_rad.path import Path from pg_rad.path import Path
from pg_rad.objects import PointSource from pg_rad.objects import PointSource
from pg_rad.physics.fluence import phi_single_source
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -35,7 +37,6 @@ class Landscape:
self.air_density = air_density self.air_density = air_density
self.scale = scale self.scale = scale
self.path: Path = None self.path: Path = None
self.sources: list[PointSource] = [] self.sources: list[PointSource] = []
logger.debug("Landscape initialized.") logger.debug("Landscape initialized.")
@ -94,12 +95,10 @@ class Landscape:
ValueError: If the source is outside the boundaries of the ValueError: If the source is outside the boundaries of the
landscape. landscape.
""" """
max_x, max_y, max_z = self.world.shape[:3] if not any(
(0 <= source.pos[0] <= self.world.shape[0] or
if any( 0 <= source.pos[1] <= self.world.shape[1] or
not (0 <= source.x < max_x and 0 <= source.pos[2] <= self.world.shape[2])
0 <= source.y < max_y and
0 <= source.z < max_z)
for source in sources for source in sources
): ):
raise ValueError("One or more sources are outside the landscape!") raise ValueError("One or more sources are outside the landscape!")
@ -110,8 +109,28 @@ class Landscape:
""" """
Set the path in the landscape. Set the path in the landscape.
""" """
if not isinstance(path, Path):
raise TypeError("path must be of type Path.")
self.path = path self.path = path
def calculate_fluence_at(self, pos: tuple):
total_phi = 0.
for source in self.sources:
r = source.distance_to(pos)
phi_source = phi_single_source(
r=r,
activity=source.activity,
branching_ratio=source.isotope.b,
mu_mass_air=source.isotope.mu_mass_air,
air_density=self.air_density
)
total_phi += phi_source
return total_phi
def calculate_fluence_along_path(self):
if self.path is None:
raise ValueError("Path is not set!")
def create_landscape_from_path(path: Path, max_z: float | int = 50): def create_landscape_from_path(path: Path, max_z: float | int = 50):
"""Generate a landscape from a path, using its dimensions to determine """Generate a landscape from a path, using its dimensions to determine