From 8f652875dcff281164b74d4febe081a77c17abe8 Mon Sep 17 00:00:00 2001 From: Pim Nelissen Date: Fri, 20 Feb 2026 11:45:21 +0100 Subject: [PATCH] update LandscapeDirector to be able to build from config. --- src/pg_rad/landscape/director.py | 51 +++++++++++++++++++++++++++---- src/pg_rad/landscape/landscape.py | 6 ++-- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/pg_rad/landscape/director.py b/src/pg_rad/landscape/director.py index 4484092..54b354b 100644 --- a/src/pg_rad/landscape/director.py +++ b/src/pg_rad/landscape/director.py @@ -2,22 +2,61 @@ from importlib.resources import files import logging from pg_rad.configs.filepaths import TEST_EXP_DATA -from pg_rad.isotopes.presets import CS137 -from pg_rad.landscape.landscape import LandscapeBuilder +from .landscape import LandscapeBuilder +from .config_parser import ConfigParser from pg_rad.objects.sources import PointSource +from pg_rad.utils.positional import rel_to_abs_source_position + + +logger = logging.getLogger(__name__) class LandscapeDirector: def __init__(self): - self.logger = logging.getLogger(__name__) - self.logger.debug("LandscapeDirector initialized.") + logger.debug("LandscapeDirector initialized.") - def build_test_landscape(self): + @staticmethod + def build_test_landscape(): fp = files('pg_rad.data').joinpath(TEST_EXP_DATA) - source = PointSource(activity=100E9, isotope=CS137(), pos=(0, 0, 0)) + source = PointSource(activity=100E9, 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 + + @staticmethod + def build_from_config(path_to_config): + conf = ConfigParser(path_to_config) + conf.parse() + + lb = LandscapeBuilder(conf.name) + + if conf.path_type == 'csv': + lb.set_path_from_experimental_data(**conf.path) + elif conf.path_type == 'procedural': + lb.set_path_from_segments( + speed=conf.speed, + acquisition_time=conf.acquisition_time, + **conf.path + ) + + sources = [] + for s_name, s_params in conf.sources.items(): + if isinstance(s_params['position'], dict): + path = lb.get_path() + x_abs, y_abs, z_abs = rel_to_abs_source_position( + x_list=path.x_list, + y_list=path.y_list, + path_z=path.z, + **s_params['position'] + ) + + s_params['position'] = [x_abs, y_abs, z_abs] + + sources.append(PointSource(name=s_name, **s_params)) + + lb.set_point_sources(*sources) + landscape = lb.build() + return landscape diff --git a/src/pg_rad/landscape/landscape.py b/src/pg_rad/landscape/landscape.py index 8df0226..0f7f0fa 100644 --- a/src/pg_rad/landscape/landscape.py +++ b/src/pg_rad/landscape/landscape.py @@ -91,11 +91,11 @@ class LandscapeBuilder: ds=speed*acquisition_time, velocity=speed ) - + x, y = sg.generate( segments=segments ) - + self._path = Path(list(zip(x, y))) self._fit_landscape_to_path() return self @@ -114,7 +114,7 @@ class LandscapeBuilder: north_col=north_col_name, z=z ) - + self._fit_landscape_to_path() return self