mirror of
https://github.com/pim-n/pg-rad
synced 2026-03-11 19:58:11 +01:00
update LandscapeDirector to be able to build from config.
This commit is contained in:
@ -2,22 +2,61 @@ from importlib.resources import files
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pg_rad.configs.filepaths import TEST_EXP_DATA
|
from pg_rad.configs.filepaths import TEST_EXP_DATA
|
||||||
from pg_rad.isotopes.presets import CS137
|
from .landscape import LandscapeBuilder
|
||||||
from pg_rad.landscape.landscape import LandscapeBuilder
|
from .config_parser import ConfigParser
|
||||||
from pg_rad.objects.sources import PointSource
|
from pg_rad.objects.sources import PointSource
|
||||||
|
from pg_rad.utils.positional import rel_to_abs_source_position
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LandscapeDirector:
|
class LandscapeDirector:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.logger = logging.getLogger(__name__)
|
logger.debug("LandscapeDirector initialized.")
|
||||||
self.logger.debug("LandscapeDirector initialized.")
|
|
||||||
|
|
||||||
def build_test_landscape(self):
|
@staticmethod
|
||||||
|
def build_test_landscape():
|
||||||
fp = files('pg_rad.data').joinpath(TEST_EXP_DATA)
|
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 = LandscapeBuilder("Test landscape")
|
||||||
lb.set_air_density(1.243)
|
lb.set_air_density(1.243)
|
||||||
lb.set_path_from_experimental_data(fp, z=0)
|
lb.set_path_from_experimental_data(fp, z=0)
|
||||||
lb.set_point_sources(source)
|
lb.set_point_sources(source)
|
||||||
landscape = lb.build()
|
landscape = lb.build()
|
||||||
return landscape
|
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
|
||||||
|
|||||||
@ -91,11 +91,11 @@ class LandscapeBuilder:
|
|||||||
ds=speed*acquisition_time,
|
ds=speed*acquisition_time,
|
||||||
velocity=speed
|
velocity=speed
|
||||||
)
|
)
|
||||||
|
|
||||||
x, y = sg.generate(
|
x, y = sg.generate(
|
||||||
segments=segments
|
segments=segments
|
||||||
)
|
)
|
||||||
|
|
||||||
self._path = Path(list(zip(x, y)))
|
self._path = Path(list(zip(x, y)))
|
||||||
self._fit_landscape_to_path()
|
self._fit_landscape_to_path()
|
||||||
return self
|
return self
|
||||||
@ -114,7 +114,7 @@ class LandscapeBuilder:
|
|||||||
north_col=north_col_name,
|
north_col=north_col_name,
|
||||||
z=z
|
z=z
|
||||||
)
|
)
|
||||||
|
|
||||||
self._fit_landscape_to_path()
|
self._fit_landscape_to_path()
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|||||||
Reference in New Issue
Block a user