From c67b38e95ab925742657ca61199e7afde840492a Mon Sep 17 00:00:00 2001
From: "Daniel.Frisinghelli" <daniel.frisinghelli@eurac.edu>
Date: Mon, 25 Oct 2021 16:46:54 +0200
Subject: [PATCH] Check for existing files.

---
 climax/main/downscale_infer.py | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/climax/main/downscale_infer.py b/climax/main/downscale_infer.py
index 050fc5d..81b0b04 100644
--- a/climax/main/downscale_infer.py
+++ b/climax/main/downscale_infer.py
@@ -46,27 +46,27 @@ if __name__ == '__main__':
     # path to model state
     state_file = MODEL_PATH.joinpath(PREDICTAND, state_file)
 
-    # load pretrained model
-    if state_file.exists():
-        # load pretrained network
-        net, _ = Network.load_pretrained_model(state_file, NET)
-    else:
-        # initialize OBS predictand dataset
-        LOGGER.info('{} does not exist.'.format(state_file))
+    # check if target dataset already exists
+    target = TARGET_PATH.joinpath(PREDICTAND, state_file.name.replace(
+        state_file.suffix, '.nc'))
+    if target.exists() and not OVERWRITE:
+        LogConfig.init_log('{} already exists.'.format(target))
         sys.exit()
+    else:
+        # load pretrained model
+        if state_file.exists():
+            # load pretrained network
+            net, _ = Network.load_pretrained_model(state_file, NET)
+        else:
+            # initialize OBS predictand dataset
+            LOGGER.info('{} does not exist.'.format(state_file))
+            sys.exit()
 
     # initialize logging
     log_file = MODEL_PATH.joinpath(PREDICTAND,
                                    state_file.name.replace('.pt', '_log.txt'))
     dictConfig(log_conf(log_file))
 
-    # check if target dataset already exists
-    target = TARGET_PATH.joinpath(PREDICTAND, net.state_file.name.replace(
-        net.state_file.suffix, '.nc'))
-    if target.exists() and not OVERWRITE:
-        LogConfig.init_log('{} already exists.'.format(target))
-        sys.exit()
-
     # predict reference period
     LogConfig.init_log('Predicting reference period: {}'.format(
         ' - '.join([str(VALID_PERIOD[0]), str(VALID_PERIOD[-1])])))
-- 
GitLab