Skip to content
Snippets Groups Projects
Commit d6e567a3 authored by Lene Wasskog's avatar Lene Wasskog
Browse files

feat: Fix removal of result files and tmp files

parent e39d2f70
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment