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

feat: Ensure warning status 0 on first day after model end date

parent f8d1db2f
No related branches found
No related tags found
No related merge requests found
......@@ -133,7 +133,6 @@ def remove_old_results():
if glob.glob(f"rm {result_mapfile_dir}*.map"):
run_command(command=f"rm {result_mapfile_dir}*.map")
# Get unique dates in given file
def get_unique_dates(input_file):
result = run_command_get_output(f"cdo showdate {input_file}")
......@@ -228,14 +227,23 @@ if __name__ == "__main__":
for file in timestep_files:
filename = os.path.basename(file)
date_str = filename.split("_")[1].split(".")[0]
current_file_date_str = filename.split("_")[1].split(".")[0]
current_file_date = datetime.strptime(current_file_date_str, "%Y-%m-%d").date()
with open("/dev/null", "w") as devnull:
warning_status_lcc = f"{tmp_dir}result_WARNING_STATUS_{date_str}_lcc.tif"
result_lcc = f"{tmp_dir}result_{date_str}_lcc.tif"
warning_status = f"{result_tif_dir}result_WARNING_STATUS_{date_str}.tif"
result = f"{result_tif_dir}result_{date_str}.tif"
warning_status_lcc = f"{tmp_dir}result_WARNING_STATUS_{current_file_date_str}_lcc.tif"
result_lcc = f"{tmp_dir}result_{current_file_date_str}_lcc.tif"
warning_status = f"{result_tif_dir}result_WARNING_STATUS_{current_file_date_str}.tif"
result = f"{result_tif_dir}result_{current_file_date_str}.tif"
logging.debug(f"Calculate result for {current_file_date_str}")
logging.debug(f"Calculate result for {date_str}")
# Ensure warning status 0 for all points on first day after model end date
if current_file_date > model_end_date:
tmp_file = file + "tmp"
os.rename(file, tmp_file)
run_command(
command=f'cdo -s -aexpr,"WARNING_STATUS = 0" {tmp_file} {file}',
)
# For warning status:
run_command(
......@@ -247,7 +255,7 @@ if __name__ == "__main__":
command=f"gdal_translate -ot Float32 -of GTiff NETCDF:'{file}':{tm_max} {result_lcc}",
stdout=devnull,
)
# Need to reproject the files, to ensure we have the projection given in the generted mapfile. We always use EPSG:4326 for this
# Need to reproject the files, to ensure we have the projection given in the generated mapfile. We always use EPSG:4326 for this
run_command(
command=f"gdalwarp -t_srs EPSG:4326 {warning_status_lcc} {warning_status}",
stdout=devnull,
......@@ -257,6 +265,10 @@ if __name__ == "__main__":
stdout=devnull,
)
# Should not generate grey files for more than one day after model end date
if current_file_date > model_end_date:
break
# Generate mapfile
# Building data sets for language specific legends
languages = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment