From d6e567a34ce7a22975b0a207c919361e150cb155 Mon Sep 17 00:00:00 2001 From: Lene Wasskog <lene.wasskog@nibio.no> Date: Tue, 25 Feb 2025 15:00:41 +0100 Subject: [PATCH] feat: Fix removal of result files and tmp files --- PSILARTEMP.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/PSILARTEMP.py b/PSILARTEMP.py index c1f531e..629a775 100755 --- a/PSILARTEMP.py +++ b/PSILARTEMP.py @@ -122,15 +122,15 @@ timesteps = result.variables["time"][:] # print(timesteps) timestep_index = 1 timestep_dates = [] + +# Remove existing tif files from result folder +subprocess.run(f"rm {out_path}result_*{year}*.tif", shell=True) + for timestep in timesteps: timestep_date = datetime.fromtimestamp(timestep).astimezone(local_timezone) file_date = timestep_date.astimezone(local_timezone).strftime("%Y-%m-%d") # print(f"{timestep_index}: {file_date}") timestep_dates.append(file_date) - # We must delete the GeoTIFF file before merging - # """ - subprocess.run(f"rm {tmp_path}result_*{file_date}_lcc.tif", shell=True) - subprocess.run(f"rm {out_path}result_*{file_date}.tif", shell=True) with open("/dev/null", "w") as devnull: subprocess.run( f'gdal_translate -ot Int16 -of GTiff -b {timestep_index} NETCDF:"{tmp_path}result.nc":WARNING_STATUS {tmp_path}result_WARNING_STATUS_{file_date}_lcc.tif', @@ -188,6 +188,11 @@ output = template.render( "language_codes": language_codes, } ) + +# Remove temporary files +subprocess.run(f"rm {tmp_path}*.tif", shell=True) +subprocess.run(f"rm {tmp_path}*.nc", shell=True) + mapfile_outdir = f'{os.getenv("MAPFILE_DIR")}{year}/' os.makedirs(mapfile_outdir, exist_ok=True) -- GitLab