From 7723227c2dd16f2fcf34635acd84b355071edea3 Mon Sep 17 00:00:00 2001 From: lewa <lene.wasskog@nibio.no> Date: Thu, 20 Jun 2024 12:07:20 +0200 Subject: [PATCH] fix: Filename bug --- ADASMELIAE.py | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/ADASMELIAE.py b/ADASMELIAE.py index b53360a..8c347bc 100755 --- a/ADASMELIAE.py +++ b/ADASMELIAE.py @@ -233,33 +233,33 @@ if __name__ == "__main__": filename = os.path.basename(file) 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_{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}") - - # Ensure warning status 0 for all points on first day after model end date, mask if mask file is given - if current_file_date > model_end_date: - tmp_file = "tmp" + file - os.rename(file, tmp_file) + # Ensure warning status 0 for all points on first day after model end date, mask if mask file is given + if current_file_date > model_end_date: + original_file = file + tmp_file = f"{tmp_dir}day_with_warning_status_0.nc" + run_command( + command=f'cdo -s -aexpr,"WARNING_STATUS = 0" {original_file} {tmp_file}', + ) + if mask_file_path is not None: + logging.info(f"Mask {tmp_file} with {os.path.basename(mask_file_path)}") run_command( - command=f'cdo -s -aexpr,"WARNING_STATUS = 0" {tmp_file} {file}', + command=f"cdo -P 6 -maskregion,{mask_file_path} {tmp_file} {original_file}", ) - os.rename(file, tmp_file) - if mask_file_path is not None: - logging.info(f"Mask {file} with {os.path.basename(mask_file_path)}") - run_command( - command=f"cdo -P 6 -maskregion,{mask_file_path} {tmp_file} {file}", - ) - else: - os.rename(tmp_file, file) + else: + os.rename(tmp_file, original_file) + + 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}") + with open("/dev/null", "w") as devnull: # For warning status: run_command( @@ -281,9 +281,9 @@ 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 + # 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 -- GitLab