From 79b52b78f09d963ae1129aa3b4dc0acda3047081 Mon Sep 17 00:00:00 2001 From: Gregory Ashton <gregory.ashton@ligo.org> Date: Thu, 17 May 2018 09:15:53 +1000 Subject: [PATCH] Improve file loading - Adds a filename option for direct loading - Raise an error if no information given --- tupak/result.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tupak/result.py b/tupak/result.py index 19aa9a1ea..86ca51802 100644 --- a/tupak/result.py +++ b/tupak/result.py @@ -17,13 +17,26 @@ def result_file_name(outdir, label): return '{}/{}_result.h5'.format(outdir, label) -def read_in_result(outdir, label): - """ Read in a saved .h5 data file """ - filename = result_file_name(outdir, label) +def read_in_result(outdir=None, label=None, filename=None): + """ Read in a saved .h5 data file + + Parameters + ---------- + outdir, label: str + If given, use the default naming convention for saved results file + filename: str + If given, try to load from this filename + + Returns: + result: tupak.result.Result instance + + """ + if filename is None: + filename = result_file_name(outdir, label) if os.path.isfile(filename): return Result(deepdish.io.load(filename)) else: - return None + raise ValueError("No information given to load file") class Result(dict): -- GitLab