diff --git a/PSILARTEMP.py b/PSILARTEMP.py index c1f531e7cab8c23e4f109fa5d4f59e579beafefc..629a7756d9f9dccedb01b80a19c978a01d5fa30d 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)