mirror of
https://github.com/pim-n/pg-rad
synced 2026-03-11 19:58:11 +01:00
Add LandscapeDirector with a test case to build landscape using LandscapeBuilder
This commit is contained in:
@ -1,8 +1,11 @@
|
|||||||
# do not expose internal logger when running mkinit
|
# do not expose internal logger when running mkinit
|
||||||
__ignore__ = ["logger"]
|
__ignore__ = ["logger"]
|
||||||
|
|
||||||
|
from pg_rad.landscape import director
|
||||||
from pg_rad.landscape import landscape
|
from pg_rad.landscape import landscape
|
||||||
|
|
||||||
|
from pg_rad.landscape.director import (LandscapeDirector,)
|
||||||
from pg_rad.landscape.landscape import (Landscape, LandscapeBuilder,)
|
from pg_rad.landscape.landscape import (Landscape, LandscapeBuilder,)
|
||||||
|
|
||||||
__all__ = ['Landscape', 'LandscapeBuilder', 'landscape']
|
__all__ = ['Landscape', 'LandscapeBuilder', 'LandscapeDirector', 'director',
|
||||||
|
'landscape']
|
||||||
|
|||||||
23
src/pg_rad/landscape/director.py
Normal file
23
src/pg_rad/landscape/director.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from importlib.resources import files
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from pg_rad.configs.filepaths import TEST_EXP_DATA
|
||||||
|
from pg_rad.isotopes import CS137
|
||||||
|
from pg_rad.landscape.landscape import LandscapeBuilder
|
||||||
|
from pg_rad.objects import PointSource
|
||||||
|
|
||||||
|
|
||||||
|
class LandscapeDirector:
|
||||||
|
def __init__(self):
|
||||||
|
self.logger = logging.getLogger(__name__)
|
||||||
|
self.logger.debug("LandscapeDirector initialized.")
|
||||||
|
|
||||||
|
def build_test_landscape(self):
|
||||||
|
fp = files('pg_rad.data').joinpath(TEST_EXP_DATA)
|
||||||
|
source = PointSource(activity=100, isotope=CS137(), pos=(0, 0, 0))
|
||||||
|
lb = LandscapeBuilder("Test landscape")
|
||||||
|
lb.set_air_density(1.243)
|
||||||
|
lb.set_path_from_experimental_data(fp, z=0)
|
||||||
|
lb.set_point_sources(source)
|
||||||
|
landscape = lb.build()
|
||||||
|
return landscape
|
||||||
@ -16,6 +16,7 @@ class Landscape:
|
|||||||
"""
|
"""
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
name: str,
|
||||||
path: Path,
|
path: Path,
|
||||||
point_sources: list[PointSource] = [],
|
point_sources: list[PointSource] = [],
|
||||||
size: tuple[int, int, int] = [500, 500, 50],
|
size: tuple[int, int, int] = [500, 500, 50],
|
||||||
@ -35,12 +36,13 @@ class Landscape:
|
|||||||
TypeError: _description_
|
TypeError: _description_
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
self.name = name
|
||||||
self.path = path
|
self.path = path
|
||||||
self.point_sources = point_sources
|
self.point_sources = point_sources
|
||||||
self.size = size
|
self.size = size
|
||||||
self.air_density = air_density
|
self.air_density = air_density
|
||||||
|
|
||||||
logger.debug("Landscape initialized.")
|
logger.debug(f"Landscape created: {self.name}")
|
||||||
|
|
||||||
def calculate_fluence_at(self, pos: tuple):
|
def calculate_fluence_at(self, pos: tuple):
|
||||||
total_phi = 0.
|
total_phi = 0.
|
||||||
@ -61,12 +63,15 @@ class Landscape:
|
|||||||
|
|
||||||
|
|
||||||
class LandscapeBuilder:
|
class LandscapeBuilder:
|
||||||
def __init__(self):
|
def __init__(self, name: str = "Unnamed landscape"):
|
||||||
|
self.name = name
|
||||||
self._path = None
|
self._path = None
|
||||||
self._point_sources = []
|
self._point_sources = []
|
||||||
self._size = None
|
self._size = None
|
||||||
self._air_density = None
|
self._air_density = None
|
||||||
|
|
||||||
|
logger.debug(f"LandscapeBuilder initialized: {self.name}")
|
||||||
|
|
||||||
def set_air_density(self, air_density) -> Self:
|
def set_air_density(self, air_density) -> Self:
|
||||||
"""Set the air density of the world."""
|
"""Set the air density of the world."""
|
||||||
self._air_density = air_density
|
self._air_density = air_density
|
||||||
@ -95,7 +100,8 @@ class LandscapeBuilder:
|
|||||||
self._path = path_from_RT90(
|
self._path = path_from_RT90(
|
||||||
df=df,
|
df=df,
|
||||||
east_col=east_col,
|
east_col=east_col,
|
||||||
north_col=north_col
|
north_col=north_col,
|
||||||
|
z=z
|
||||||
)
|
)
|
||||||
|
|
||||||
# The size of the landscape will be updated if
|
# The size of the landscape will be updated if
|
||||||
@ -108,11 +114,12 @@ class LandscapeBuilder:
|
|||||||
|
|
||||||
if needs_resize:
|
if needs_resize:
|
||||||
if not self._size:
|
if not self._size:
|
||||||
logger.info("Landscape size set to path dimensions.")
|
logger.debug("Because no Landscape size was set, "
|
||||||
|
"it will now set to path dimensions.")
|
||||||
else:
|
else:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Path exceeds current landscape size. "
|
"Path exceeds current landscape size. "
|
||||||
"Expanding landscape to accommodate it."
|
"Landscape size will be expanded to accommodate path."
|
||||||
)
|
)
|
||||||
|
|
||||||
self.set_landscape_size(self._path.size)
|
self.set_landscape_size(self._path.size)
|
||||||
@ -142,9 +149,13 @@ class LandscapeBuilder:
|
|||||||
self._point_sources = sources
|
self._point_sources = sources
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
return Landscape(
|
landscape = Landscape(
|
||||||
|
name=self.name,
|
||||||
path=self._path,
|
path=self._path,
|
||||||
point_sources=self._point_sources,
|
point_sources=self._point_sources,
|
||||||
size=self._size,
|
size=self._size,
|
||||||
air_density=self._air_density
|
air_density=self._air_density
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logger.info(f"Landscape built successfully: {landscape.name}")
|
||||||
|
return landscape
|
||||||
|
|||||||
Reference in New Issue
Block a user