diff --git a/ADASMELIAE.py b/ADASMELIAE.py index b2c07238a6818956b87446cb57c749298fe3da93..8d37f8e643b484fa2d45880add19e080920c265a 100755 --- a/ADASMELIAE.py +++ b/ADASMELIAE.py @@ -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 = []