mirror of
https://github.com/pim-n/pg-rad
synced 2026-04-24 22:48:10 +02:00
update plotting. add export functionality. update main to work with new plotting and saving/export functionality.
This commit is contained in:
@ -17,6 +17,7 @@ from pg_rad.inputparser.parser import ConfigParser
|
||||
from pg_rad.landscape.director import LandscapeDirector
|
||||
from pg_rad.plotting.result_plotter import ResultPlotter
|
||||
from pg_rad.simulator.engine import SimulationEngine
|
||||
from pg_rad.utils.export import generate_folder_name, save_results
|
||||
|
||||
|
||||
def main():
|
||||
@ -39,9 +40,14 @@ def main():
|
||||
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
||||
)
|
||||
parser.add_argument(
|
||||
"--saveplot",
|
||||
"--showplots",
|
||||
action="store_true",
|
||||
help="Save the plot or not."
|
||||
help="Show the plots immediately."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--save",
|
||||
action="store_true",
|
||||
help="Save the outputs"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
@ -49,7 +55,7 @@ def main():
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if args.example:
|
||||
example_yaml = """
|
||||
input_config = """
|
||||
name: Example landscape
|
||||
speed: 8.33
|
||||
acquisition_time: 1
|
||||
@ -72,62 +78,58 @@ def main():
|
||||
|
||||
detector: LU_NaI_3inch
|
||||
"""
|
||||
elif args.config:
|
||||
input_config = args.config
|
||||
|
||||
cp = ConfigParser(example_yaml).parse()
|
||||
try:
|
||||
cp = ConfigParser(input_config).parse()
|
||||
landscape = LandscapeDirector.build_from_config(cp)
|
||||
output = SimulationEngine(
|
||||
landscape=landscape,
|
||||
runtime_spec=cp.runtime,
|
||||
sim_spec=cp.options,
|
||||
sim_spec=cp.options
|
||||
).simulate()
|
||||
|
||||
plotter = ResultPlotter(landscape, output)
|
||||
plotter.plot()
|
||||
|
||||
elif args.config:
|
||||
try:
|
||||
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)
|
||||
if args.save:
|
||||
folder_name = generate_folder_name(output)
|
||||
save_results(output, folder_name)
|
||||
plotter.save(folder_name)
|
||||
if args.showplots:
|
||||
plotter.plot()
|
||||
except (
|
||||
MissingConfigKeyError,
|
||||
KeyError
|
||||
) as e:
|
||||
logger.critical(e)
|
||||
logger.critical(
|
||||
"The config file is missing required keys or may be an "
|
||||
"invalid YAML file. Check the log above. Consult the "
|
||||
"documentation for examples of how to write a config file."
|
||||
)
|
||||
sys.exit(1)
|
||||
except (
|
||||
OutOfBoundsError,
|
||||
DimensionError,
|
||||
InvalidIsotopeError,
|
||||
InvalidConfigValueError,
|
||||
NotImplementedError
|
||||
) 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,
|
||||
InvalidYAMLError
|
||||
) as e:
|
||||
logger.critical(e)
|
||||
sys.exit(1)
|
||||
except (
|
||||
MissingConfigKeyError,
|
||||
KeyError
|
||||
) as e:
|
||||
logger.critical(e)
|
||||
logger.critical(
|
||||
"The config file is missing required keys or may be an "
|
||||
"invalid YAML file. Check the log above. Consult the "
|
||||
"documentation for examples of how to write a config file."
|
||||
)
|
||||
sys.exit(1)
|
||||
except (
|
||||
OutOfBoundsError,
|
||||
DimensionError,
|
||||
InvalidIsotopeError,
|
||||
InvalidConfigValueError,
|
||||
NotImplementedError
|
||||
) 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,
|
||||
InvalidYAMLError
|
||||
) as e:
|
||||
logger.critical(e)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user