From cffd812c2efe16ac0bbd11b1696f64949699b28d Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Tue, 14 Jul 2026 06:05:18 -0500 Subject: [PATCH 1/2] run flynt on bias_correction.py --- .../core/bias_correction.py | 854 ++++-------------- 1 file changed, 159 insertions(+), 695 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/bias_correction.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/bias_correction.py index 49d5972e..3c907593 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/bias_correction.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/bias_correction.py @@ -168,8 +168,7 @@ def no_bias_correct(input_forcings, config_options, mpi_config, force_num): ) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to set final forcings during bias correction routine: " - + str(npe) + f"Unable to set final forcings during bias correction routine: {npe!s}" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -180,8 +179,7 @@ def no_bias_correct(input_forcings, config_options, mpi_config, force_num): ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to set final forcings for mesh nodes during bias correction routine: " - + str(npe) + f"Unable to set final forcings for mesh nodes during bias correction routine: {npe!s}" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -191,8 +189,7 @@ def no_bias_correct(input_forcings, config_options, mpi_config, force_num): ) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to set final forcings for mesh elements during bias correction routine: " - + str(npe) + f"Unable to set final forcings for mesh elements during bias correction routine: {npe!s}" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -203,8 +200,7 @@ def no_bias_correct(input_forcings, config_options, mpi_config, force_num): ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to set final forcings for mesh nodes during bias correction routine: " - + str(npe) + f"Unable to set final forcings for mesh nodes during bias correction routine: {npe!s}" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -311,10 +307,7 @@ def ncar_tbl_correction(input_forcings, config_options, mpi_config, force_num): } if mpi_config.rank == 0: config_options.statusMsg = ( - "Performing table lookup bias correction for: " - + input_forcings.netcdf_var_names[force_num] - + " For input: " - + input_forcings.product_name + f"Performing table lookup bias correction for: {input_forcings.netcdf_var_names[force_num]} For input: {input_forcings.product_name}" ) err_handler.log_msg(config_options, mpi_config) @@ -322,9 +315,7 @@ def ncar_tbl_correction(input_forcings, config_options, mpi_config, force_num): # bias correction only applies to the first 18 forecast hours. if int(input_forcings.fcst_hour2) > 18: config_options.statusMsg = ( - "Current forecast hour for: " - + input_forcings.product_name - + " is greater than allowed forecast range of 18 for table lookup bias correction." + f"Current forecast hour for: {input_forcings.product_name} is greater than allowed forecast range of 18 for table lookup bias correction." ) err_handler.log_warning(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -339,13 +330,7 @@ def ncar_tbl_correction(input_forcings, config_options, mpi_config, force_num): ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract: " - + input_forcings.netcdf_var_names[force_num] - + " from local forcing object for: " - + input_forcings.product_name - + "(" - + str(npe) - + ")" + f"Unable to extract: {input_forcings.netcdf_var_names[force_num]} from local forcing object for: {input_forcings.product_name}({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -355,13 +340,7 @@ def ncar_tbl_correction(input_forcings, config_options, mpi_config, force_num): ind_valid_elem = np.where(force_tmp_elem != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform valid search for: " - + input_forcings.netcdf_var_names[force_num] - + " from local forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform valid search for: {input_forcings.netcdf_var_names[force_num]} from local forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -374,13 +353,7 @@ def ncar_tbl_correction(input_forcings, config_options, mpi_config, force_num): ) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to apply table bias correction for: " - + input_forcings.netcdf_var_names[force_num] - + " from local forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to apply table bias correction for: {input_forcings.netcdf_var_names[force_num]} from local forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -391,11 +364,7 @@ def ncar_tbl_correction(input_forcings, config_options, mpi_config, force_num): ] = force_tmp_elem[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary LW array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary LW array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -414,13 +383,7 @@ def ncar_tbl_correction(input_forcings, config_options, mpi_config, force_num): ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract: " - + input_forcings.netcdf_var_names[force_num] - + " from local forcing object for: " - + input_forcings.product_name - + "(" - + str(npe) - + ")" + f"Unable to extract: {input_forcings.netcdf_var_names[force_num]} from local forcing object for: {input_forcings.product_name}({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -431,13 +394,7 @@ def ncar_tbl_correction(input_forcings, config_options, mpi_config, force_num): ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract: " - + input_forcings.netcdf_var_names[force_num] - + " from local forcing object for: " - + input_forcings.product_name - + "(" - + str(npe) - + ")" + f"Unable to extract: {input_forcings.netcdf_var_names[force_num]} from local forcing object for: {input_forcings.product_name}({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -447,13 +404,7 @@ def ncar_tbl_correction(input_forcings, config_options, mpi_config, force_num): ind_valid = np.where(force_tmp != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform valid search for: " - + input_forcings.netcdf_var_names[force_num] - + " from local forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform valid search for: {input_forcings.netcdf_var_names[force_num]} from local forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -465,13 +416,7 @@ def ncar_tbl_correction(input_forcings, config_options, mpi_config, force_num): ) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to apply table bias correction for: " - + input_forcings.netcdf_var_names[force_num] - + " from local forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to apply table bias correction for: {input_forcings.netcdf_var_names[force_num]} from local forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -483,11 +428,7 @@ def ncar_tbl_correction(input_forcings, config_options, mpi_config, force_num): ] = force_tmp[:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary LW array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary LW array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -499,11 +440,7 @@ def ncar_tbl_correction(input_forcings, config_options, mpi_config, force_num): ] = force_tmp[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary LW array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary LW array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -526,8 +463,7 @@ def ncar_blanket_adjustment_lw(input_forcings, config_options, mpi_config, force """ if mpi_config.rank == 0: config_options.statusMsg = ( - "Performing blanket bias correction on incoming longwave " - "radiation fluxes for input: " + input_forcings.product_name + f"Performing blanket bias correction on incoming longwave radiation fluxes for input: {input_forcings.product_name}" ) err_handler.log_msg(config_options, mpi_config) @@ -575,11 +511,7 @@ def ncar_blanket_adjustment_lw(input_forcings, config_options, mpi_config, force ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming LW from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming LW from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -589,11 +521,7 @@ def ncar_blanket_adjustment_lw(input_forcings, config_options, mpi_config, force ind_valid_elem = np.where(lw_tmp_elem != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming LW for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming LW for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -602,11 +530,7 @@ def ncar_blanket_adjustment_lw(input_forcings, config_options, mpi_config, force lw_tmp_elem[ind_valid_elem] = lw_tmp_elem[ind_valid_elem] + adj_lw except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform LW bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform LW bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -617,11 +541,7 @@ def ncar_blanket_adjustment_lw(input_forcings, config_options, mpi_config, force ] = lw_tmp_elem[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary LW array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary LW array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -639,11 +559,7 @@ def ncar_blanket_adjustment_lw(input_forcings, config_options, mpi_config, force ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming LW from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming LW from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -656,11 +572,7 @@ def ncar_blanket_adjustment_lw(input_forcings, config_options, mpi_config, force ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming LW from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming LW from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -670,11 +582,7 @@ def ncar_blanket_adjustment_lw(input_forcings, config_options, mpi_config, force ind_valid = np.where(lw_tmp != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming LW for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming LW for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -683,11 +591,7 @@ def ncar_blanket_adjustment_lw(input_forcings, config_options, mpi_config, force lw_tmp[ind_valid] = lw_tmp[ind_valid] + adj_lw except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform LW bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform LW bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -699,11 +603,7 @@ def ncar_blanket_adjustment_lw(input_forcings, config_options, mpi_config, force ] = lw_tmp[:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary LW array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary LW array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -714,11 +614,7 @@ def ncar_blanket_adjustment_lw(input_forcings, config_options, mpi_config, force ] = lw_tmp[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary LW array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary LW array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -745,8 +641,7 @@ def ncar_sw_hrrr_bias_correct( """ if mpi_config.rank == 0: config_options.statusMsg = ( - "Performing NCAR bias correction on incoming shortwave " - "radiation fluxes for input: " + input_forcings.product_name + f"Performing NCAR bias correction on incoming shortwave radiation fluxes for input: {input_forcings.product_name}" ) err_handler.log_msg(config_options, mpi_config) @@ -866,11 +761,7 @@ def ncar_sw_hrrr_bias_correct( ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming shortwave forcing from object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming shortwave forcing from object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -881,11 +772,7 @@ def ncar_sw_hrrr_bias_correct( ind_valid_elem = np.where(sw_tmp_elem != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to run a search for valid SW values for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to run a search for valid SW values for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -902,8 +789,7 @@ def ncar_sw_hrrr_bias_correct( ) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to apply NCAR HRRR bias correction to incoming shortwave radiation: " - + str(npe) + f"Unable to apply NCAR HRRR bias correction to incoming shortwave radiation: {npe!s}" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -913,8 +799,7 @@ def ncar_sw_hrrr_bias_correct( input_forcings.final_forcings_elem[7, :] = sw_tmp_elem[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place bias-corrected incoming SW radiation fluxes back into the forcing " - "object: " + str(npe) + f"Unable to place bias-corrected incoming SW radiation fluxes back into the forcing object: {npe!s}" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -940,11 +825,7 @@ def ncar_sw_hrrr_bias_correct( ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming shortwave forcing from object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming shortwave forcing from object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -955,11 +836,7 @@ def ncar_sw_hrrr_bias_correct( ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming shortwave forcing from object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming shortwave forcing from object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -970,11 +847,7 @@ def ncar_sw_hrrr_bias_correct( ind_valid = np.where(sw_tmp != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to run a search for valid SW values for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to run a search for valid SW values for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -991,8 +864,7 @@ def ncar_sw_hrrr_bias_correct( ) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to apply NCAR HRRR bias correction to incoming shortwave radiation: " - + str(npe) + f"Unable to apply NCAR HRRR bias correction to incoming shortwave radiation: {npe!s}" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1003,8 +875,7 @@ def ncar_sw_hrrr_bias_correct( input_forcings.final_forcings[7, :, :] = sw_tmp[:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place bias-corrected incoming SW radiation fluxes back into the forcing " - "object: " + str(npe) + f"Unable to place bias-corrected incoming SW radiation fluxes back into the forcing object: {npe!s}" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1014,8 +885,7 @@ def ncar_sw_hrrr_bias_correct( input_forcings.final_forcings[7, :] = sw_tmp[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place bias-corrected incoming SW radiation fluxes back into the forcing " - "object: " + str(npe) + f"Unable to place bias-corrected incoming SW radiation fluxes back into the forcing object: {npe!s}" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1033,8 +903,7 @@ def ncar_temp_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc """Implement a bias correction to the forecast 2m temperature field.""" if mpi_config.rank == 0: config_options.statusMsg = ( - "Performing NCAR HRRR bias correction on incoming 2m temperature input: " - + input_forcings.product_name + f"Performing NCAR HRRR bias correction on incoming 2m temperature input: {input_forcings.product_name}" ) err_handler.log_msg(config_options, mpi_config) @@ -1088,11 +957,7 @@ def ncar_temp_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming temperature from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming temperature from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1102,11 +967,7 @@ def ncar_temp_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ind_valid_elem = np.where(temp_in_elem != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming temperature for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming temperature for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1115,11 +976,7 @@ def ncar_temp_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc temp_in_elem[ind_valid_elem] = temp_in_elem[ind_valid_elem] + bias_corr except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform temperature bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform temperature bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1130,11 +987,7 @@ def ncar_temp_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ] = temp_in_elem[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary temperature array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary temperature array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1150,11 +1003,7 @@ def ncar_temp_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming temperature from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming temperature from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1165,11 +1014,7 @@ def ncar_temp_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming temperature from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming temperature from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1179,11 +1024,7 @@ def ncar_temp_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ind_valid = np.where(temp_in != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming temperature for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming temperature for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1192,11 +1033,7 @@ def ncar_temp_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc temp_in[ind_valid] = temp_in[ind_valid] + bias_corr except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform temperature bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform temperature bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1208,11 +1045,7 @@ def ncar_temp_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ] = temp_in[:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary temperature array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary temperature array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1223,11 +1056,7 @@ def ncar_temp_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ] = temp_in[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary temperature array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary temperature array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1240,8 +1069,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force """Implement a bias correction to the forecast 2m temperature field.""" if mpi_config.rank == 0: config_options.statusMsg = ( - "Performing NCAR GFS bias correction on incoming 2m temperature input: " - + input_forcings.product_name + f"Performing NCAR GFS bias correction on incoming 2m temperature input: {input_forcings.product_name}" ) err_handler.log_msg(config_options, mpi_config) @@ -1271,11 +1099,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming temperature from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming temperature from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1286,11 +1110,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming temperature from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming temperature from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1300,11 +1120,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming temperature from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming temperature from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1315,11 +1131,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming temperature from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming temperature from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1332,11 +1144,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force ind_valid = np.where(temp_in != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming temperature for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming temperature for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1345,11 +1153,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force temp_in[ind_valid] = temp_in[ind_valid] + bias_corr except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform temperature bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform temperature bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1360,11 +1164,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] = temp_in[:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary temperature array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary temperature array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -1373,11 +1173,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force ind_valid = np.where(temp_in != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming temperature for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming temperature for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1386,11 +1182,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force temp_in[ind_valid] = temp_in[ind_valid] + bias_corr except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform temperature bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform temperature bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1399,11 +1191,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force ind_valid_elem = np.where(temp_in_elem != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming temperature for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming temperature for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1412,11 +1200,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force temp_in_elem[ind_valid_elem] = temp_in_elem[ind_valid_elem] + bias_corr except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform temperature bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform temperature bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1427,11 +1211,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] = temp_in[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary temperature array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary temperature array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1441,11 +1221,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] = temp_in_elem[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary temperature array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary temperature array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1454,11 +1230,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force ind_valid = np.where(temp_in != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming temperature for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming temperature for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1467,11 +1239,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force temp_in[ind_valid] = temp_in[ind_valid] + bias_corr except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform temperature bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform temperature bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1482,11 +1250,7 @@ def ncar_temp_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] = temp_in[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary temperature array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary temperature array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -1500,8 +1264,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for """Implement a bias correction to the forecast incoming longwave radiation field.""" if mpi_config.rank == 0: config_options.statusMsg = ( - "Performing NCAR bias correction on incoming longwave " - "radiation fluxes for input: " + input_forcings.product_name + f"Performing NCAR bias correction on incoming longwave radiation fluxes for input: {input_forcings.product_name}" ) err_handler.log_msg(config_options, mpi_config) @@ -1531,11 +1294,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming longwave from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming longwave from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1546,11 +1305,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming longwave from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming longwave from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1560,11 +1315,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming longwave from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming longwave from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1575,11 +1326,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming longwave from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming longwave from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1592,11 +1339,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for ind_valid = np.where(lwdown_in != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming longwave for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming longwave for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1604,11 +1347,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for lwdown_in[ind_valid] = lwdown_in[ind_valid] + bias_corr except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform longwave bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform longwave bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1618,11 +1357,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for ] = lwdown_in[:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary longwave array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary longwave array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1632,11 +1367,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for ind_valid = np.where(lwdown_in != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming longwave for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming longwave for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1644,11 +1375,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for lwdown_in[ind_valid] = lwdown_in[ind_valid] + bias_corr except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform longwave bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform longwave bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1656,11 +1383,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for ind_valid_elem = np.where(lwdown_in_elem != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming longwave for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming longwave for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1669,11 +1392,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for lwdown_in_elem[ind_valid_elem] = lwdown_in_elem[ind_valid_elem] + bias_corr except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform longwave bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform longwave bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1684,11 +1403,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for ] = lwdown_in[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary longwave array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary longwave array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1698,11 +1413,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for ] = lwdown_in_elem[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary longwave array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary longwave array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1711,11 +1422,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for ind_valid = np.where(lwdown_in != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming longwave for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming longwave for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1723,11 +1430,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for lwdown_in[ind_valid] = lwdown_in[ind_valid] + bias_corr except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform longwave bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform longwave bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1737,11 +1440,7 @@ def ncar_lwdown_gfs_bias_correct(input_forcings, config_options, mpi_config, for ] = lwdown_in[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary longwave array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary longwave array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1756,10 +1455,7 @@ def ncar_wspd_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc """Implement a bias correction to the forecast windspeed field.""" if mpi_config.rank == 0: config_options.statusMsg = ( - "Performing NCAR bias correction on incoming windspeed for input: " - + input_forcings.product_name - + " at step " - + str(config_options.current_output_step) + f"Performing NCAR bias correction on incoming windspeed for input: {input_forcings.product_name} at step {config_options.current_output_step!s}" ) err_handler.log_msg(config_options, mpi_config) @@ -1854,11 +1550,7 @@ def ncar_wspd_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming windspeed from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming windspeed from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1868,11 +1560,7 @@ def ncar_wspd_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ind_valid_elem = np.where(wind_in_elem != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming windspeed for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming windspeed for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1881,11 +1569,7 @@ def ncar_wspd_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc wind_in_elem[ind_valid_elem] = bias_corrected_elem[ind_valid_elem] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform windspeed bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform windspeed bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1896,11 +1580,7 @@ def ncar_wspd_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ] = wind_in_elem[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary windspeed array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary windspeed array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -1927,11 +1607,7 @@ def ncar_wspd_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming windspeed from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming windspeed from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1942,11 +1618,7 @@ def ncar_wspd_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming windspeed from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming windspeed from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1956,11 +1628,7 @@ def ncar_wspd_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ind_valid = np.where(wind_in != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming windspeed for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming windspeed for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1969,11 +1637,7 @@ def ncar_wspd_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc wind_in[ind_valid] = bias_corrected[ind_valid] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform windspeed bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform windspeed bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -1985,11 +1649,7 @@ def ncar_wspd_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ] = wind_in[:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary windspeed array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary windspeed array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) else: @@ -1999,11 +1659,7 @@ def ncar_wspd_hrrr_bias_correct(input_forcings, config_options, mpi_config, forc ] = wind_in[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary windspeed array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary windspeed array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -2017,8 +1673,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force """Implement a bias correction to the forecast windspeed field.""" if mpi_config.rank == 0: config_options.statusMsg = ( - "Performing NCAR bias correction on incoming windspeed for input: " - + input_forcings.product_name + f"Performing NCAR bias correction on incoming windspeed for input: {input_forcings.product_name}" ) err_handler.log_msg(config_options, mpi_config) @@ -2154,11 +1809,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming windspeed from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming windspeed from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2169,11 +1820,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming windspeed from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming windspeed from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2183,11 +1830,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming windspeed from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming windspeed from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2198,11 +1841,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract incoming windspeed from forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to extract incoming windspeed from forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2214,11 +1853,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force ind_valid = np.where(wind_in != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming windspeed for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming windspeed for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2227,11 +1862,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force wind_in[ind_valid] = bias_corrected[ind_valid] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform windspeed bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform windspeed bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2242,11 +1873,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] = wind_in[:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary windspeed array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary windspeed array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -2257,11 +1884,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force ind_valid = np.where(wind_in != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming windspeed for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming windspeed for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2270,11 +1893,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force wind_in[ind_valid] = bias_corrected[ind_valid] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform windspeed bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform windspeed bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2282,11 +1901,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force ind_valid_elem = np.where(wind_in_elem != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming windspeed for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming windspeed for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2295,11 +1910,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force wind_in_elem[ind_valid_elem] = bias_corrected_elem[ind_valid_elem] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform windspeed bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform windspeed bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2309,11 +1920,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] = wind_in[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary windspeed array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary windspeed array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -2324,11 +1931,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] = wind_in_elem[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary windspeed array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary windspeed array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -2338,11 +1941,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force ind_valid = np.where(wind_in != config_options.globalNdv) except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to calculate valid index in incoming windspeed for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to calculate valid index in incoming windspeed for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2351,11 +1950,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force wind_in[ind_valid] = bias_corrected[ind_valid] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to perform windspeed bias correction for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to perform windspeed bias correction for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2366,11 +1961,7 @@ def ncar_wspd_gfs_bias_correct(input_forcings, config_options, mpi_config, force ] = wind_in[:] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place temporary windspeed array back into forcing object for: " - + input_forcings.product_name - + " (" - + str(npe) - + ")" + f"Unable to place temporary windspeed array back into forcing object for: {input_forcings.product_name} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -2454,16 +2045,14 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for if mpi_config.rank == 0: config_options.statusMsg = ( - "Running NLDAS-CFSv2 CDF/PDF bias correction on variable: " - + input_forcings.netcdf_var_names[force_num] + f"Running NLDAS-CFSv2 CDF/PDF bias correction on variable: {input_forcings.netcdf_var_names[force_num]}" ) err_handler.log_msg(config_options, mpi_config) # Check to ensure we are running with CFSv2 here.... if input_forcings.product_name != "CFSv2_6Hr_Global_GRIB2": config_options.errMsg = ( - "Attempting to run CFSv2-NLDAS bias correction on: " - + input_forcings.product_name + f"Attempting to run CFSv2-NLDAS bias correction on: {input_forcings.product_name}" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -2473,15 +2062,11 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for id_nldas_param = nldas_param_file = None if mpi_config.rank == 0: nldas_param_file = ( - input_forcings.dScaleParamDirs - + "/NLDAS_Climo/nldas2_" - + config_options.current_output_date.strftime("%m%d%H") - + "_dist_params.nc" + f"{input_forcings.dScaleParamDirs}/NLDAS_Climo/nldas2_{config_options.current_output_date.strftime('%m%d%H')}_dist_params.nc" ) if not os.path.isfile(nldas_param_file): config_options.errMsg = ( - "Unable to locate necessary bias correction parameter file: " - + nldas_param_file + f"Unable to locate necessary bias correction parameter file: {nldas_param_file}" ) err_handler.log_critical(config_options, mpi_config) @@ -2493,11 +2078,7 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for ) # don't mask missing since it won't survive broadcast except OSError as err: config_options.errMsg = ( - "Unable to open parameter file: " - + nldas_param_file - + " (" - + str(err) - + ")" + f"Unable to open parameter file: {nldas_param_file} ({err!s})" ) err_handler.log_critical(config_options, mpi_config) raise err @@ -2505,59 +2086,44 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for # Ensure dimensions/variables are as expected. if "lat_0" not in id_nldas_param.dimensions.keys(): config_options.errMsg = ( - "Expected to find lat_0 dimension in: " + nldas_param_file + f"Expected to find lat_0 dimension in: {nldas_param_file}" ) err_handler.log_critical(config_options, mpi_config) if "lon_0" not in id_nldas_param.dimensions.keys(): config_options.errMsg = ( - "Expected to find lon_0 dimension in: " + nldas_param_file + f"Expected to find lon_0 dimension in: {nldas_param_file}" ) err_handler.log_critical(config_options, mpi_config) if id_nldas_param.dimensions["lat_0"].size != PARAM_NY: config_options.errMsg = ( - "Expected lat_0 size is {} - found size of: ".format(PARAM_NY) - + str(id_nldas_param.dimensions["lat_0"].size) - + " in: " - + nldas_param_file + f"Expected lat_0 size is {PARAM_NY} - found size of: {id_nldas_param.dimensions['lat_0'].size!s} in: {nldas_param_file}" ) err_handler.log_critical(config_options, mpi_config) if id_nldas_param.dimensions["lon_0"].size != PARAM_NX: config_options.errMsg = ( - "Expected lon_0 size is {} - found size of: ".format(PARAM_NX) - + str(id_nldas_param.dimensions["lon_0"].size) - + " in: " - + nldas_param_file + f"Expected lon_0 size is {PARAM_NX} - found size of: {id_nldas_param.dimensions['lon_0'].size!s} in: {nldas_param_file}" ) err_handler.log_critical(config_options, mpi_config) if nldas_param1_vars[force_num] not in id_nldas_param.variables.keys(): config_options.errMsg = ( - "Expected variable: " - + nldas_param1_vars[force_num] - + " not found " - + "in: " - + nldas_param_file + f"Expected variable: {nldas_param1_vars[force_num]} not found in: {nldas_param_file}" ) err_handler.log_critical(config_options, mpi_config) if nldas_param2_vars[force_num] not in id_nldas_param.variables.keys(): config_options.errMsg = ( - "Expected variable: " - + nldas_param2_vars[force_num] - + " not found " - + "in: " - + nldas_param_file + f"Expected variable: {nldas_param2_vars[force_num]} not found in: {nldas_param_file}" ) err_handler.log_critical(config_options, mpi_config) if force_num == 4: if "ZERO_PRECIP_PROB" not in id_nldas_param.variables.keys(): config_options.errMsg = ( - "Expected variable: ZERO_PRECIP_PROB not found in: " - + nldas_param_file + f"Expected variable: ZERO_PRECIP_PROB not found in: {nldas_param_file}" ) err_handler.log_critical(config_options, mpi_config) @@ -2566,13 +2132,7 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for nldas_param_1 = id_nldas_param.variables[nldas_param1_vars[force_num]][:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract: " - + nldas_param1_vars[force_num] - + " from: " - + nldas_param_file - + " (" - + str(npe) - + ")" + f"Unable to extract: {nldas_param1_vars[force_num]} from: {nldas_param_file} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -2581,33 +2141,19 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for nldas_param_2 = id_nldas_param.variables[nldas_param2_vars[force_num]][:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract: " - + nldas_param2_vars[force_num] - + " from: " - + nldas_param_file - + " (" - + str(npe) - + ")" + f"Unable to extract: {nldas_param2_vars[force_num]} from: {nldas_param_file} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) if nldas_param_1.shape[0] != PARAM_NY or nldas_param_1.shape[1] != PARAM_NX: config_options.errMsg = ( - "Parameter variable: " - + nldas_param1_vars[force_num] - + " from: " - + nldas_param_file - + " not of shape [{},{}].".format(PARAM_NY, PARAM_NX) + f"Parameter variable: {nldas_param1_vars[force_num]} from: {nldas_param_file} not of shape [{PARAM_NY},{PARAM_NX}]." ) err_handler.log_critical(config_options, mpi_config) if nldas_param_2.shape[0] != PARAM_NY or nldas_param_2.shape[1] != PARAM_NX: config_options.errMsg = ( - "Parameter variable: " - + nldas_param2_vars[force_num] - + " from: " - + nldas_param_file - + " not of shape [{},{}].".format(PARAM_NY, PARAM_NX) + f"Parameter variable: {nldas_param2_vars[force_num]} from: {nldas_param_file} not of shape [{PARAM_NY},{PARAM_NX}]." ) err_handler.log_critical(config_options, mpi_config) @@ -2624,11 +2170,7 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for ] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract _FillValue from: " - + nldas_param_file - + " (" - + str(npe) - + ")" + f"Unable to extract _FillValue from: {nldas_param_file} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -2639,11 +2181,7 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for nldas_zero_pcp = id_nldas_param.variables["ZERO_PRECIP_PROB"][:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract ZERO_PRECIP_PROB from: " - + nldas_param_file - + " (" - + str(npe) - + ")" + f"Unable to extract ZERO_PRECIP_PROB from: {nldas_param_file} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -2652,9 +2190,7 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for or nldas_zero_pcp.shape[1] != PARAM_NX ): config_options.errMsg = ( - "Parameter variable: ZERO_PRECIP_PROB from: " - + nldas_param_file - + " not of shape [{},{}].".format(PARAM_NY, PARAM_NX) + f"Parameter variable: ZERO_PRECIP_PROB from: {nldas_param_file} not of shape [{PARAM_NY},{PARAM_NX}]." ) err_handler.log_critical(config_options, mpi_config) @@ -2700,35 +2236,21 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for if mpi_config.rank == 0: # Read in the CFSv2 parameter files, based on the previous CFSv2 dates cfs_param_path1 = ( - input_forcings.dScaleParamDirs - + "/CFSv2_Climo/cfs_" - + cfs_param_path_vars[force_num] - + "_" - + input_forcings.fcst_date1.strftime("%m%d") - + "_" - + input_forcings.fcst_date1.strftime("%H") - + "_dist_params.nc" + f"{input_forcings.dScaleParamDirs}/CFSv2_Climo/cfs_{cfs_param_path_vars[force_num]}_{input_forcings.fcst_date1.strftime('%m%d')}_{input_forcings.fcst_date1.strftime('%H')}_dist_params.nc" ) cfs_param_path2 = ( - input_forcings.dScaleParamDirs - + "/CFSv2_Climo/cfs_" - + cfs_param_path_vars[force_num] - + "_" - + input_forcings.fcst_date2.strftime("%m%d") - + "_" - + input_forcings.fcst_date2.strftime("%H") - + "_dist_params.nc" + f"{input_forcings.dScaleParamDirs}/CFSv2_Climo/cfs_{cfs_param_path_vars[force_num]}_{input_forcings.fcst_date2.strftime('%m%d')}_{input_forcings.fcst_date2.strftime('%H')}_dist_params.nc" ) if not os.path.isfile(cfs_param_path1): config_options.errMsg = ( - "Unable to locate necessary parameter file: " + cfs_param_path1 + f"Unable to locate necessary parameter file: {cfs_param_path1}" ) err_handler.log_critical(config_options, mpi_config) if not os.path.isfile(cfs_param_path2): config_options.errMsg = ( - "Unable to locate necessary parameter file: " + cfs_param_path2 + f"Unable to locate necessary parameter file: {cfs_param_path2}" ) err_handler.log_critical(config_options, mpi_config) @@ -2737,22 +2259,14 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for id_cfs_param1 = Dataset(cfs_param_path1, "r") except OSError as err: config_options.errMsg = ( - "Unable to open parameter file: " - + cfs_param_path1 - + " (" - + str(err) - + ")" + f"Unable to open parameter file: {cfs_param_path1} ({err!s})" ) err_handler.log_critical(config_options, mpi_config) try: id_cfs_param2 = Dataset(cfs_param_path2, "r") except OSError as err: config_options.errMsg = ( - "Unable to open parameter file: " - + cfs_param_path2 - + " (" - + str(err) - + ")" + f"Unable to open parameter file: {cfs_param_path2} ({err!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -2760,27 +2274,23 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for err_handler.log_msg(config_options, mpi_config) if "DISTRIBUTION_PARAM_1" not in id_cfs_param1.variables.keys(): config_options.errMsg = ( - "Expected DISTRIBUTION_PARAM_1 variable not found in: " - + cfs_param_path1 + f"Expected DISTRIBUTION_PARAM_1 variable not found in: {cfs_param_path1}" ) err_handler.log_critical(config_options, mpi_config) if "DISTRIBUTION_PARAM_2" not in id_cfs_param1.variables.keys(): config_options.errMsg = ( - "Expected DISTRIBUTION_PARAM_1 variable not found in: " - + cfs_param_path1 + f"Expected DISTRIBUTION_PARAM_1 variable not found in: {cfs_param_path1}" ) err_handler.log_critical(config_options, mpi_config) if "DISTRIBUTION_PARAM_1" not in id_cfs_param2.variables.keys(): config_options.errMsg = ( - "Expected DISTRIBUTION_PARAM_1 variable not found in: " - + cfs_param_path2 + f"Expected DISTRIBUTION_PARAM_1 variable not found in: {cfs_param_path2}" ) err_handler.log_critical(config_options, mpi_config) if "DISTRIBUTION_PARAM_2" not in id_cfs_param2.variables.keys(): config_options.errMsg = ( - "Expected DISTRIBUTION_PARAM_1 variable not found in: " - + cfs_param_path2 + f"Expected DISTRIBUTION_PARAM_1 variable not found in: {cfs_param_path2}" ) err_handler.log_critical(config_options, mpi_config) @@ -2789,22 +2299,14 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for param_1 = id_cfs_param2.variables["DISTRIBUTION_PARAM_1"][:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract DISTRIBUTION_PARAM_1 from: " - + cfs_param_path2 - + " (" - + str(npe) - + ")" + f"Unable to extract DISTRIBUTION_PARAM_1 from: {cfs_param_path2} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) try: param_2 = id_cfs_param2.variables["DISTRIBUTION_PARAM_2"][:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract DISTRIBUTION_PARAM_2 from: " - + cfs_param_path2 - + " (" - + str(npe) - + ")" + f"Unable to extract DISTRIBUTION_PARAM_2 from: {cfs_param_path2} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -2824,44 +2326,36 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for prev_param_1 = id_cfs_param1.variables["DISTRIBUTION_PARAM_1"][:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract DISTRIBUTION_PARAM_1 from: " - + cfs_param_path1 - + " (" - + str(npe) - + ")" + f"Unable to extract DISTRIBUTION_PARAM_1 from: {cfs_param_path1} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) try: prev_param_2 = id_cfs_param1.variables["DISTRIBUTION_PARAM_2"][:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to extract DISTRIBUTION_PARAM_2 from: " - + cfs_param_path1 - + " (" - + str(npe) - + ")" + f"Unable to extract DISTRIBUTION_PARAM_2 from: {cfs_param_path1} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) if param_1.shape[0] != PARAM_NY and param_1.shape[1] != PARAM_NX: config_options.errMsg = ( - "Unexpected DISTRIBUTION_PARAM_1 found in: " + cfs_param_path2 + f"Unexpected DISTRIBUTION_PARAM_1 found in: {cfs_param_path2}" ) err_handler.log_critical(config_options, mpi_config) if param_2.shape[0] != PARAM_NY and param_2.shape[1] != PARAM_NX: config_options.errMsg = ( - "Unexpected DISTRIBUTION_PARAM_2 found in: " + cfs_param_path2 + f"Unexpected DISTRIBUTION_PARAM_2 found in: {cfs_param_path2}" ) err_handler.log_critical(config_options, mpi_config) if prev_param_1.shape[0] != PARAM_NY and prev_param_1.shape[1] != PARAM_NX: config_options.errMsg = ( - "Unexpected DISTRIBUTION_PARAM_1 found in: " + cfs_param_path1 + f"Unexpected DISTRIBUTION_PARAM_1 found in: {cfs_param_path1}" ) err_handler.log_critical(config_options, mpi_config) if prev_param_2.shape[0] != PARAM_NY and prev_param_2.shape[1] != PARAM_NX: config_options.errMsg = ( - "Unexpected DISTRIBUTION_PARAM_2 found in: " + cfs_param_path1 + f"Unexpected DISTRIBUTION_PARAM_2 found in: {cfs_param_path1}" ) err_handler.log_critical(config_options, mpi_config) @@ -2874,28 +2368,20 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for zero_pcp = id_cfs_param2.variables["ZERO_PRECIP_PROB"][:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to locate ZERO_PRECIP_PROB in: " - + cfs_param_path2 - + " (" - + str(npe) - + ")" + f"Unable to locate ZERO_PRECIP_PROB in: {cfs_param_path2} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) try: prev_zero_pcp = id_cfs_param2.variables["ZERO_PRECIP_PROB"][:, :] except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to locate ZERO_PRECIP_PROB in: " - + cfs_param_path1 - + " (" - + str(npe) - + ")" + f"Unable to locate ZERO_PRECIP_PROB in: {cfs_param_path1} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) if zero_pcp.shape[0] != PARAM_NY and zero_pcp.shape[1] != PARAM_NX: config_options.errMsg = ( - "Unexpected ZERO_PRECIP_PROB found in: " + cfs_param_path2 + f"Unexpected ZERO_PRECIP_PROB found in: {cfs_param_path2}" ) err_handler.log_critical(config_options, mpi_config) if ( @@ -2903,7 +2389,7 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for and prev_zero_pcp.shape[1] != PARAM_NX ): config_options.errMsg = ( - "Unexpected ZERO_PRECIP_PROB found in: " + cfs_param_path1 + f"Unexpected ZERO_PRECIP_PROB found in: {cfs_param_path1}" ) err_handler.log_critical(config_options, mpi_config) @@ -2972,33 +2458,21 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for id_nldas_param.close() except OSError as err: config_options.errMsg = ( - "Unable to close parameter file: " - + nldas_param_file - + " (" - + str(err) - + ")" + f"Unable to close parameter file: {nldas_param_file} ({err!s})" ) err_handler.log_critical(config_options, mpi_config) try: id_cfs_param1.close() except OSError as err: config_options.errMsg = ( - "Unable to close parameter file: " - + cfs_param_path1 - + " (" - + str(err) - + ")" + f"Unable to close parameter file: {cfs_param_path1} ({err!s})" ) err_handler.log_critical(config_options, mpi_config) try: id_cfs_param2.close() except OSError as err: config_options.errMsg = ( - "Unable to close parameter file: " - + cfs_param_path2 - + " (" - + str(err) - + ")" + f"Unable to close parameter file: {cfs_param_path2} ({err!s})" ) err_handler.log_critical(config_options, mpi_config) @@ -3279,7 +2753,7 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for input_forcings.esmf_field_in.data[...] = cfs_data except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to place CFSv2 forcing data into temporary ESMF field: " + str(npe) + f"Unable to place CFSv2 forcing data into temporary ESMF field: {npe!s}" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -3290,11 +2764,7 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for ) except ValueError as ve: config_options.errMsg = ( - "Unable to regrid CFSv2 variable: " - + input_forcings.netcdf_var_names[force_num] - + " (" - + str(ve) - + ")" + f"Unable to regrid CFSv2 variable: {input_forcings.netcdf_var_names[force_num]} ({ve!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -3306,11 +2776,7 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for ] = config_options.globalNdv except NumpyExceptions as npe: config_options.errMsg = ( - "Unable to run mask calculation on CFSv2 variable: " - + input_forcings.netcdf_var_names[force_num] - + " (" - + str(npe) - + ")" + f"Unable to run mask calculation on CFSv2 variable: {input_forcings.netcdf_var_names[force_num]} ({npe!s})" ) err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) @@ -3320,8 +2786,6 @@ def cfsv2_nldas_nwm_bias_correct(input_forcings, config_options, mpi_config, for input_forcings.input_map_output[force_num], :, : ] = input_forcings.esmf_field_out.data except NumpyExceptions as npe: - config_options.errMsg = "Unable to extract ESMF field data for CFSv2: " + str( - npe - ) + config_options.errMsg = f"Unable to extract ESMF field data for CFSv2: {npe!s}" err_handler.log_critical(config_options, mpi_config) err_handler.check_program_status(config_options, mpi_config) From 8f3ca876301954325329f49c87838a833185b4cc Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Tue, 14 Jul 2026 06:11:40 -0500 Subject: [PATCH 2/2] run flynt on forecastMod.py --- .../core/forecastMod.py | 40 ++++++------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/forecastMod.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/forecastMod.py index a0aadf92..ffa03745 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/forecastMod.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/forecastMod.py @@ -46,15 +46,11 @@ def process_forecasts( if ConfigOptions.ana_flag: fcstCycleOutDir = ( - ConfigOptions.output_dir - + "/" - + ConfigOptions.e_date_proc.strftime("%Y%m%d%H") + f"{ConfigOptions.output_dir}/{ConfigOptions.e_date_proc.strftime('%Y%m%d%H')}" ) else: fcstCycleOutDir = ( - ConfigOptions.output_dir - + "/" - + ConfigOptions.current_fcst_cycle.strftime("%Y%m%d%H") + f"{ConfigOptions.output_dir}/{ConfigOptions.current_fcst_cycle.strftime('%Y%m%d%H')}" ) # reset skips if present @@ -68,12 +64,10 @@ def process_forecasts( fcstCycleOutDir = ConfigOptions.ana_out_dir # completeFlag = ConfigOptions.scratch_dir + "/WrfHydroForcing.COMPLETE" - completeFlag = fcstCycleOutDir + "/WrfHydroForcing.COMPLETE" + completeFlag = f"{fcstCycleOutDir}/WrfHydroForcing.COMPLETE" if os.path.isfile(completeFlag): ConfigOptions.statusMsg = ( - "Forecast Cycle: " - + ConfigOptions.current_fcst_cycle.strftime("%Y-%m-%d %H:%M") - + " has already completed." + f"Forecast Cycle: {ConfigOptions.current_fcst_cycle.strftime('%Y-%m-%d %H:%M')} has already completed." ) err_handler.log_msg(ConfigOptions, MpiConfig) # We have already completed processing this cycle, @@ -88,7 +82,7 @@ def process_forecasts( os.mkdir(fcstCycleOutDir) except Exception: ConfigOptions.errMsg = ( - "Unable to create output directory: " + fcstCycleOutDir + f"Unable to create output directory: {fcstCycleOutDir}" ) err_handler.err_out_screen_para(ConfigOptions.errMsg, MpiConfig) err_handler.check_program_status(ConfigOptions, MpiConfig) @@ -98,14 +92,11 @@ def process_forecasts( ConfigOptions.statusMsg = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" err_handler.log_msg(ConfigOptions, MpiConfig) ConfigOptions.statusMsg = ( - "Processing Forecast Cycle: " - + ConfigOptions.current_fcst_cycle.strftime("%Y-%m-%d %H:%M") + f"Processing Forecast Cycle: {ConfigOptions.current_fcst_cycle.strftime('%Y-%m-%d %H:%M')}" ) err_handler.log_msg(ConfigOptions, MpiConfig) ConfigOptions.statusMsg = ( - "Forecast Cycle Length is: " - + str(ConfigOptions.cycle_length_minutes) - + " minutes" + f"Forecast Cycle Length is: {ConfigOptions.cycle_length_minutes!s} minutes" ) err_handler.log_msg(ConfigOptions, MpiConfig) # MpiConfig.comm.barrier() @@ -148,8 +139,7 @@ def process_forecasts( ConfigOptions.statusMsg = "=========================================" err_handler.log_msg(ConfigOptions, MpiConfig, True) ConfigOptions.statusMsg = ( - "Processing for output timestep: " - + file_date.strftime("%Y-%m-%d %H:%M") + f"Processing for output timestep: {file_date.strftime('%Y-%m-%d %H:%M')}" ) err_handler.log_msg(ConfigOptions, MpiConfig, True) # MpiConfig.comm.barrier() @@ -157,19 +147,14 @@ def process_forecasts( # Compose the expected path to the output file. Check to see if the file exists, # if so, continue to the next time step. Also initialize our output arrays if necessary. OutputObj.outPath = ( - fcstCycleOutDir - + "/" - + file_date.strftime("%Y%m%d%H%M") - + ".LDASIN_DOMAIN1" + f"{fcstCycleOutDir}/{file_date.strftime('%Y%m%d%H%M')}.LDASIN_DOMAIN1" ) # MpiConfig.comm.barrier() if os.path.isfile(OutputObj.outPath): if MpiConfig.rank == 0: ConfigOptions.statusMsg = ( - "Output file: " - + OutputObj.outPath - + " exists. Moving to the next output timestep." + f"Output file: {OutputObj.outPath} exists. Moving to the next output timestep." ) err_handler.log_msg(ConfigOptions, MpiConfig) err_handler.check_program_status(ConfigOptions, MpiConfig) @@ -330,8 +315,7 @@ def process_forecasts( if (not ConfigOptions.ana_flag) or (fcstCycleNum == (ConfigOptions.nFcsts - 1)): if MpiConfig.rank == 0: ConfigOptions.statusMsg = ( - "Forcings complete for forecast cycle: " - + ConfigOptions.current_fcst_cycle.strftime("%Y-%m-%d %H:%M") + f"Forcings complete for forecast cycle: {ConfigOptions.current_fcst_cycle.strftime('%Y-%m-%d %H:%M')}" ) err_handler.log_msg(ConfigOptions, MpiConfig) err_handler.check_program_status(ConfigOptions, MpiConfig) @@ -342,7 +326,7 @@ def process_forecasts( open(completeFlag, "a").close() except Exception: ConfigOptions.errMsg = ( - "Unable to create completion file: " + completeFlag + f"Unable to create completion file: {completeFlag}" ) err_handler.log_critical(ConfigOptions, MpiConfig) err_handler.check_program_status(ConfigOptions, MpiConfig)