diff --git a/src/pg_rad/landscape/__init__.py b/src/pg_rad/landscape/__init__.py index 5bfc4d7..9dda6f9 100644 --- a/src/pg_rad/landscape/__init__.py +++ b/src/pg_rad/landscape/__init__.py @@ -1,8 +1,11 @@ # do not expose internal logger when running mkinit __ignore__ = ["logger"] +from pg_rad.landscape import director from pg_rad.landscape import landscape +from pg_rad.landscape.director import (LandscapeDirector,) from pg_rad.landscape.landscape import (Landscape, LandscapeBuilder,) -__all__ = ['Landscape', 'LandscapeBuilder', 'landscape'] +__all__ = ['Landscape', 'LandscapeBuilder', 'LandscapeDirector', 'director', + 'landscape'] diff --git a/src/pg_rad/landscape/director.py b/src/pg_rad/landscape/director.py new file mode 100644 index 0000000..e1fd9f4 --- /dev/null +++ b/src/pg_rad/landscape/director.py @@ -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 diff --git a/src/pg_rad/landscape/landscape.py b/src/pg_rad/landscape/landscape.py index 861f9f2..a0e58d5 100644 --- a/src/pg_rad/landscape/landscape.py +++ b/src/pg_rad/landscape/landscape.py @@ -16,6 +16,7 @@ class Landscape: """ def __init__( self, + name: str, path: Path, point_sources: list[PointSource] = [], size: tuple[int, int, int] = [500, 500, 50], @@ -35,12 +36,13 @@ class Landscape: TypeError: _description_ """ + self.name = name self.path = path self.point_sources = point_sources self.size = size self.air_density = air_density - logger.debug("Landscape initialized.") + logger.debug(f"Landscape created: {self.name}") def calculate_fluence_at(self, pos: tuple): total_phi = 0. @@ -61,12 +63,15 @@ class Landscape: class LandscapeBuilder: - def __init__(self): + def __init__(self, name: str = "Unnamed landscape"): + self.name = name self._path = None self._point_sources = [] self._size = None self._air_density = None + logger.debug(f"LandscapeBuilder initialized: {self.name}") + def set_air_density(self, air_density) -> Self: """Set the air density of the world.""" self._air_density = air_density @@ -95,7 +100,8 @@ class LandscapeBuilder: self._path = path_from_RT90( df=df, east_col=east_col, - north_col=north_col + north_col=north_col, + z=z ) # The size of the landscape will be updated if @@ -108,11 +114,12 @@ class LandscapeBuilder: if needs_resize: 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: logger.warning( "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) @@ -142,9 +149,13 @@ class LandscapeBuilder: self._point_sources = sources def build(self): - return Landscape( + landscape = Landscape( + name=self.name, path=self._path, point_sources=self._point_sources, size=self._size, air_density=self._air_density ) + + logger.info(f"Landscape built successfully: {landscape.name}") + return landscape