Skip to content
Snippets Groups Projects
Commit 552bc2a6 authored by Michael Langguth's avatar Michael Langguth
Browse files

Clearer error-handling and inclusion of climatology-file to postprocess runscript generator.

parent deeedd41
Branches
No related tags found
No related merge requests found
......@@ -33,9 +33,10 @@ class Config_Postprocess(Config_runscript_base):
self.model = None
self.checkpoint_dir = None
self.results_dir = None
self.clim_f = None
#self.lquick = None
# list of variables to be written to runscript
self.list_batch_vars = ["VIRT_ENV_NAME", "results_dir", "checkpoint_dir", "model"] # , "lquick"]
self.list_batch_vars = ["VIRT_ENV_NAME", "results_dir", "checkpoint_dir", "clim_f"] # , "lquick"]
# copy over method for keyboard interaction
self.run_config = Config_Postprocess.run_postprocess
#
......@@ -62,14 +63,14 @@ class Config_Postprocess(Config_runscript_base):
# First choose the basic experiment directory
dir_base = Config_Postprocess.handle_source_dir(self, "models")
expbase_req_str = "Choose an experiment from the list above:"
expbase_err = NotADirectoryError("Could not find passed directory.")
expbase_req_str = "Choose an experiment set from the list above:"
expbase_err = NotADirectoryError("Please select an experiment from the ones listed above.")
dir_base = Config_Postprocess.keyboard_interaction(expbase_req_str, Config_Postprocess.check_dir, expbase_err,
prefix2arg=dir_base+"/", ntries=2)
# Choose the model
model_req_str = "Enter the name of the trained model:"
model_err = NotADirectoryError("No directory for trained model exists.")
model_req_str = "Enter the name of the model:"
model_err = NotADirectoryError("Select a model listed above (if any).")
dir_base = Config_Postprocess.keyboard_interaction(model_req_str, Config_Postprocess.check_model, model_err,
prefix2arg=dir_base+"/", ntries=2)
......@@ -78,14 +79,14 @@ class Config_Postprocess(Config_runscript_base):
_ = Config_Postprocess.get_subdir_list(dir_base)
# Chose the checkpoint directory
ckp_req_str = "Choose a checkpoint directory from the list above:"
ckp_req_err = NotADirectoryError("Could not find the passed directory.")
ckp_req_str = "Choose a trained model from the list above:"
ckp_req_err = NotADirectoryError("Choose a trained model from the ones listed above (if any).")
dir_base = Config_Postprocess.keyboard_interaction(ckp_req_str, Config_Postprocess.check_dir, ckp_req_err,
prefix2arg=dir_base+"/", ntries=2)
# List the subdirectories...
_ = Config_Postprocess.get_subdir_list(dir_base)
# ... and obtain the model directory with checkpoints
trained_dir_req_str = "Choose a trained model from the experiment list above:"
trained_dir_req_str = "Choose a checkpoint from the list above:"
trained_err = FileNotFoundError("No trained model parameters found.")
self.checkpoint_dir = Config_Postprocess.keyboard_interaction(trained_dir_req_str,
Config_Postprocess.check_traindir,
......@@ -103,6 +104,11 @@ class Config_Postprocess(Config_runscript_base):
# Set results_dir
self.results_dir = os.path.join(base_dir, "results", exp_dir_base, self.model, exp_dir)
self.clim_f = os.path.join(os.path.dirname(base_dir), "T2climatology", "climatology_t2m_1991-2020.nc")
if not os.path.isfile(self.clim_f):
print("WARNING: Cannot find netCDF-file with climatology of 2m temperature under '{0}'. Please adapt manually.".format(self.clim_f))
return
# Decide if quick evaluation should be performed
quick_req_str = "Should a reduced, quick evalutaion be performed (yes/no):"
......@@ -150,11 +156,14 @@ class Config_Postprocess(Config_runscript_base):
:param silent: flag if print-statement are executed
:return: status with True confirming success
"""
method = Config_Postprocess.check_dir.__name__
status = False
if not os.path.isdir(dir_in):
if not silent: print("{0} is not a directory".format(dir_in))
elif dir_in == "":
if not silent: print("{0}: Please enter a directory/checkpoint.")
if not silent and not dir_in.endswith("help"): print("%{0}: {1} is not a directory".format(method, dir_in))
elif dir_in.endswith("/"): # this most likely happens when prefix2arg is passed
if not silent: print("%{0}: Please enter a directory/checkpoint.".format(method))
else:
status = True
......@@ -220,7 +229,7 @@ class Config_Postprocess(Config_runscript_base):
if not silent:
print("{0} does not contain any model parameter files (model-*.meta).".format(checkpoint_dir))
else:
if not silent: print("Passed directory '{0}' does not exist!".format(checkpoint_dir))
if not silent and not checkpoint_dir.endswith("help"): print("Passed directory '{0}' does not exist!".format(checkpoint_dir))
return status
#
# -----------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment