Commit 79b52b78 authored by Gregory Ashton's avatar Gregory Ashton

Improve file loading

- Adds a filename option for direct loading
- Raise an error if no information given
parent a313d514
Pipeline #19435 failed with stages
in 34 seconds
...@@ -17,13 +17,26 @@ def result_file_name(outdir, label): ...@@ -17,13 +17,26 @@ def result_file_name(outdir, label):
return '{}/{}_result.h5'.format(outdir, label) return '{}/{}_result.h5'.format(outdir, label)
def read_in_result(outdir, label): def read_in_result(outdir=None, label=None, filename=None):
""" Read in a saved .h5 data file """ """ Read in a saved .h5 data file
filename = result_file_name(outdir, label)
outdir, label: str
If given, use the default naming convention for saved results file
filename: str
If given, try to load from this filename
result: tupak.result.Result instance
if filename is None:
filename = result_file_name(outdir, label)
if os.path.isfile(filename): if os.path.isfile(filename):
return Result( return Result(
else: else:
return None raise ValueError("No information given to load file")
class Result(dict): class Result(dict):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment