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

Merge branch 'bing_issue#186_clean_GMD1_tag' into Gong2022_temperature_forecasts

parents 32906161 9a27de54
Branches
No related tags found
No related merge requests found
Pipeline #107079 failed
......@@ -195,6 +195,7 @@ The following steps are part of the workflow:
```
4) **Postprocessing**:<br> At this step, the test dataset is applied on the data model. The predictions are stored in netCDF-files, while the models get also evaluated by some score metrics. Besides, example plots covering the range of the MSE are created for visualization. Note that the `exp_id` is inferred from the chosen experiment when running `generate_runscript.py`.
Furthermore, the climatology reference data for calculating the anamoly correlation coefficient is expected to be placed under `<my_target_dir>`.
```bash
[sbatch] ./visualize_postprocess_era5_<exp_id>.sh
......
......@@ -80,7 +80,7 @@ def main():
# get workflow step by keyboard interaction
target_runscript_req = "Please enter the name of the workflow step for which a runscript should be created:"
target_runscript_err = ValueError("Workflow step is unknown. Please select one of the known listed above")
target_runscript_err = ValueError("Please select one of the known listed above.")
def check_target_runscript(runscript_name, silent=False):
if not runscript_name in known_wrkflw_steps:
......
......@@ -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
#
......@@ -60,16 +61,16 @@ class Config_Postprocess(Config_runscript_base):
# get the 'checkpoint-directory', i.e. the directory where the trained model parameters are stored
# Note that the remaining information (model, results-directory etc.) can be retrieved form it!!!
# First chosse the basic experiment directory
# 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,9 +156,14 @@ class Config_Postprocess(Config_runscript_base):
:param silent: flag if print-statement are executed
:return: status with True confirming success
"""
if not os.path.isdir(dir_in):
if not silent: print("{0} is not a directory".format(dir_in))
method = Config_Postprocess.check_dir.__name__
status = False
if not os.path.isdir(dir_in):
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
......@@ -184,7 +195,7 @@ class Config_Postprocess(Config_runscript_base):
print("The base directory does not exist as well!")
return status
if not model_in: # user just printed 'Enter'
if not model_in: # user just pressed 'Enter'
_ = Config_Postprocess.get_subdir_list(os.path.dirname(model_path))
return status
......@@ -218,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
#
# -----------------------------------------------------------------------------------
......
......@@ -267,6 +267,7 @@ class Config_runscript_base:
:param console_str: Request printed to the console
:param check_input: function returning boolean which needs to be passed by input from keyboard interaction.
Must have two arguments with the latter being an optional bool called silent.
:param err: Error to be raised in case of failure
:param ntries: maximum number of tries (default: 1)
:param test_arg: test argument to check_input-function (default: "xxx")
:param prefix2arg: optional prefix that might be added to string from keyboard-interaction before it enters
......@@ -290,7 +291,7 @@ class Config_runscript_base:
except:
raise Exception("%{0}: Cannot approve check_input-argument to be proper.".format(method_name))
if not isinstance(err, BaseException):
raise ValueError("%{0}: err_str-argument must be an instance of BaseException!".format(method_name))
raise ValueError("%{0}: err-argument must be an instance of BaseException!".format(method_name))
if not isinstance(ntries, int) and ntries <= 1:
raise ValueError("%{0}: ntries-argument must be an integer greater equal 1!".format(method_name))
......
......@@ -101,6 +101,6 @@ else
fi
sed -i "s/--mail-user=.*/--mail-user=$USER_EMAIL/g" ${target_script}
if [[ "${HOST_NAME}" == hdfml* || "${HOST_NAME}" == *juwels* ]]; then
sed -i "s/--account=.*/--mail-user=deepacf/g" ${target_script}
sed -i "s/--account=.*/--account=deepacf/g" ${target_script}
fi
# end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment