From 02445d4eef71d7388cbd536a4f59cc118ccbb7ac Mon Sep 17 00:00:00 2001 From: Remy Prechelt <prechelt@hawaii.edu> Date: Sun, 7 Feb 2021 00:12:45 -1000 Subject: [PATCH] Add loading of the summary files for each output. --- python/corsika/io/library.py | 28 +++++++++++++++++++++++++++- python/corsika/io/outputs/output.py | 24 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/python/corsika/io/library.py b/python/corsika/io/library.py index 1db756baf..236fc97ac 100644 --- a/python/corsika/io/library.py +++ b/python/corsika/io/library.py @@ -45,8 +45,9 @@ class Library(object): # store the top-level path self.path = path - # load the config file + # load the config and summary files self.config = self.load_config(path) + self.summary = self.load_summary(path) # build the list of outputs self.__outputs = self.__build_outputs(path) @@ -101,6 +102,31 @@ class Library(object): with open(op.join(path, "config.yaml"), "r") as f: return yaml.load(f, Loader=yaml.Loader) + @staticmethod + def load_summary(path: str) -> Dict[str, Any]: + """ + Load the top-level summary from a given library path. + + + Parameters + ---------- + path: str + The path to the directory containing the library. + + Returns + ------- + dict: + The summary as a python dictionary. + + Raises + ------ + FileNotFoundError + If the summary file cannot be found + + """ + with open(op.join(path, "summary.yaml"), "r") as f: + return yaml.load(f, Loader=yaml.Loader) + @staticmethod def __valid_library(path: str) -> bool: """ diff --git a/python/corsika/io/outputs/output.py b/python/corsika/io/outputs/output.py index 7d7e27e82..80527ad66 100644 --- a/python/corsika/io/outputs/output.py +++ b/python/corsika/io/outputs/output.py @@ -106,3 +106,27 @@ class Output(ABC): """ with open(op.join(path, "config.yaml"), "r") as f: return yaml.load(f, Loader=yaml.Loader) + + @staticmethod + def load_summary(path: str) -> Dict[str, Any]: + """ + Load the top-level summary from a given library path. + + Parameters + ---------- + path: str + The path to the directory containing the library. + + Returns + ------- + dict: + The summary as a python dictionary. + + Raises + ------ + FileNotFoundError + If the summary file cannot be found + + """ + with open(op.join(path, "summary.yaml"), "r") as f: + return yaml.load(f, Loader=yaml.Loader) -- GitLab