mirror of
https://github.com/pim-n/pg-rad
synced 2026-03-23 21:58:12 +01:00
update main.py --test case to conform to new architecture. Update error handling in --config case.
This commit is contained in:
@ -5,10 +5,17 @@ import sys
|
||||
from pandas.errors import ParserError
|
||||
from yaml import YAMLError
|
||||
|
||||
from pg_rad.exceptions.exceptions import MissingNestedKeyError
|
||||
from pg_rad.exceptions.exceptions import (
|
||||
MissingConfigKeyError,
|
||||
OutOfBoundsError,
|
||||
DimensionError,
|
||||
InvalidIsotopeError
|
||||
)
|
||||
from pg_rad.logger.logger import setup_logger
|
||||
from pg_rad.inputparser.parser import ConfigParser
|
||||
from pg_rad.landscape.director import LandscapeDirector
|
||||
from pg_rad.plotting.landscape_plotter import LandscapeSlicePlotter
|
||||
from pg_rad.plotting.result_plotter import ResultPlotter
|
||||
from pg_rad.simulator.engine import SimulationEngine
|
||||
|
||||
|
||||
def main():
|
||||
@ -23,7 +30,7 @@ def main():
|
||||
parser.add_argument(
|
||||
"--test",
|
||||
action="store_true",
|
||||
help="Load and run the test landscape"
|
||||
help="Load and run the test landscape."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--loglevel",
|
||||
@ -41,19 +48,52 @@ def main():
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if args.test:
|
||||
landscape = LandscapeDirector().build_test_landscape()
|
||||
plotter = LandscapeSlicePlotter()
|
||||
plotter.plot(landscape, save=args.saveplot)
|
||||
test_yaml = """
|
||||
name: Test landscape
|
||||
speed: 8.33
|
||||
acquisition_time: 1
|
||||
|
||||
path:
|
||||
length: 1000
|
||||
segments:
|
||||
- straight
|
||||
|
||||
sources:
|
||||
test_source:
|
||||
activity_MBq: 1000
|
||||
position: [500, 100, 0]
|
||||
isotope: CS137
|
||||
"""
|
||||
|
||||
cp = ConfigParser(test_yaml).parse()
|
||||
landscape = LandscapeDirector.build_from_config(cp)
|
||||
|
||||
output = SimulationEngine(
|
||||
landscape=landscape,
|
||||
runtime_spec=cp.runtime,
|
||||
sim_spec=cp.options
|
||||
).simulate()
|
||||
|
||||
plotter = ResultPlotter(landscape, output)
|
||||
plotter.plot()
|
||||
|
||||
elif args.config:
|
||||
try:
|
||||
landscape = LandscapeDirector.build_from_config(args.config)
|
||||
plotter = LandscapeSlicePlotter()
|
||||
plotter.plot(landscape, save=args.saveplot)
|
||||
cp = ConfigParser(args.config).parse()
|
||||
landscape = LandscapeDirector.build_from_config(cp)
|
||||
|
||||
output = SimulationEngine(
|
||||
landscape=landscape,
|
||||
runtime_spec=cp.runtime,
|
||||
sim_spec=cp.options
|
||||
).simulate()
|
||||
|
||||
plotter = ResultPlotter(landscape, output)
|
||||
plotter.plot()
|
||||
except (
|
||||
MissingNestedKeyError,
|
||||
MissingConfigKeyError,
|
||||
KeyError,
|
||||
YAMLError
|
||||
YAMLError,
|
||||
):
|
||||
logger.critical(
|
||||
"The provided config file is invalid. "
|
||||
@ -61,6 +101,18 @@ def main():
|
||||
"an explanation of how to define a config file."
|
||||
)
|
||||
sys.exit(1)
|
||||
except (
|
||||
OutOfBoundsError,
|
||||
DimensionError,
|
||||
InvalidIsotopeError
|
||||
) as e:
|
||||
logger.critical(e)
|
||||
logger.critical(
|
||||
"One or more items in config are not specified correctly. "
|
||||
"Please consult this log and fix the problem."
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
except (
|
||||
FileNotFoundError,
|
||||
ParserError
|
||||
|
||||
Reference in New Issue
Block a user