From 6925935ce47d7fd95b74bc5815c26797c79a56db Mon Sep 17 00:00:00 2001
From: Lene Wasskog <lene.wasskog@nibio.no>
Date: Thu, 27 Feb 2025 09:36:16 +0100
Subject: [PATCH] feat: Check if files exist before attempting to remove

---
 SEPTREFHUM.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/SEPTREFHUM.py b/SEPTREFHUM.py
index 833f055..398c121 100755
--- a/SEPTREFHUM.py
+++ b/SEPTREFHUM.py
@@ -253,7 +253,10 @@ for timestep in timesteps:
     # Merge the WARNING_STATUS and WHS variables into one GeoTIFF file with two bands. 
     # The WARNING_STATUS should always be band #1
     # We must delete the GeoTIFF file before merging
-    run_command(command=f'rm {result_tif_path}result_*{file_date}*.tif')
+    existing_result_files_for_date = f"{result_tif_path}result_*{file_date}*.tif"
+    files = glob.glob(existing_result_files_for_date)
+    if files:
+        run_command(command=f'rm {existing_result_files_for_date}')
     with open("/dev/null", "w") as devnull:
         run_command(command=f'gdal_translate -ot Int16 -of GTiff  NETCDF:"{tmpfile_path}result_{file_date}.nc":WARNING_STATUS {tmpfile_path}result_WARNING_STATUS_{file_date}_lcc.tif', stdout=devnull)
         run_command(command=f'gdal_translate -ot Float32 -of GTiff  NETCDF:"{tmpfile_path}result_{file_date}.nc":WHS {tmpfile_path}result_{file_date}_lcc.tif', stdout=devnull)
-- 
GitLab