diff --git a/README.md b/README.md index 89f2f527ab27612c4394e9b3bd25c1a6a0d4ce72..02267a551666b6366a2844d28f7f5173197c9aeb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/video_prediction_tools/env_setup/generate_runscript.py b/video_prediction_tools/env_setup/generate_runscript.py index a342ccbb917f0380ea8b89533787d1ad917496c9..3b541fccc9abe532e3be2029a024603d6128e5c5 100755 --- a/video_prediction_tools/env_setup/generate_runscript.py +++ b/video_prediction_tools/env_setup/generate_runscript.py @@ -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: diff --git a/video_prediction_tools/utils/runscript_generator/config_postprocess.py b/video_prediction_tools/utils/runscript_generator/config_postprocess.py index 5edf00302e50942714d33275f8a5cccdbd4f7ab2..ec5c9d0f436ba2112171f2f865bb92d429fbf715 100755 --- a/video_prediction_tools/utils/runscript_generator/config_postprocess.py +++ b/video_prediction_tools/utils/runscript_generator/config_postprocess.py @@ -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, @@ -101,7 +102,12 @@ class Config_Postprocess(Config_runscript_base): self.runscript_target = self.rscrpt_tmpl_prefix + self.dataset + "_" + exp_dir + ".sh" # Set results_dir - self.results_dir = os.path.join(base_dir, "results", exp_dir_base,self.model, exp_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 @@ -150,9 +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)) - status = False + 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 # # ----------------------------------------------------------------------------------- diff --git a/video_prediction_tools/utils/runscript_generator/config_utils.py b/video_prediction_tools/utils/runscript_generator/config_utils.py index 0624ceed4bdce9df30bf4cc0277d3f53af621bed..27e8f155f7fa40e4863ff3fe3500ac0093213033 100755 --- a/video_prediction_tools/utils/runscript_generator/config_utils.py +++ b/video_prediction_tools/utils/runscript_generator/config_utils.py @@ -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 @@ -289,9 +290,9 @@ class Config_runscript_base: pass 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)) - if not isinstance(ntries,int) and ntries <= 1: + if not isinstance(err, BaseException): + 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)) attempt = 0 diff --git a/video_prediction_tools/utils/runscript_generator/convert_runscript.sh b/video_prediction_tools/utils/runscript_generator/convert_runscript.sh index a5ab4188b93a4743050606358049c48c70697af4..cc20a3c746ce9c578a6b0985baf326cee56f357b 100755 --- a/video_prediction_tools/utils/runscript_generator/convert_runscript.sh +++ b/video_prediction_tools/utils/runscript_generator/convert_runscript.sh @@ -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