From b8c8fa2f0dbd8b6738c2271670f68c6093db11af Mon Sep 17 00:00:00 2001 From: Matthew Deshotel Date: Tue, 5 May 2026 16:33:54 -0400 Subject: [PATCH 01/71] move consts to consts.py --- .../NextGen_Forcings_Engine/core/consts.py | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py index 2b3567dd..b442aecd 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py @@ -1259,3 +1259,117 @@ }, } } + +CONFIGOPTIONS = { + "ConfigOptions": [ + "bmi_time", + "current_time", + "input_forcings", + "supp_precip_forcings", + "input_force_dirs", + "input_force_types", + "supp_precip_dirs", + "supp_precip_file_types", + "supp_precip_param_dir", + "input_force_mandatory", + "supp_precip_mandatory", + "supp_pcp_max_hours", + "number_inputs", + "number_supp_pcp", + "output_freq", + "sub_output_hour", + "sub_output_freq", + "scratch_dir", + "num_output_steps", + "num_supp_output_steps", + "actual_output_steps", + "realtime_flag", + "refcst_flag", + "ana_flag", + "e_date_proc", + "first_fcst_cycle", + "current_fcst_cycle", + "current_output_step", + "cycle_length_minutes", + "prev_output_date", + "current_output_date", + "look_back", + "future_time", + "fcst_freq", + "nFcsts", + "fcst_shift", + "fcst_input_horizons", + "fcst_input_offsets", + "process_window", + "spatial_meta", + "grid_type", + "grid_meta", + "ExactExtract", + "lat_var", + "lon_var", + "hgt_var", + "cosalpha_var", + "sinalpha_var", + "slope_var", + "slope_azimuth_var", + "slope_var_elem", + "slope_azimuth_var_elem", + "nodecoords_var", + "elemcoords_var", + "elemconn_var", + "numelemconn_var", + "element_id_var", + "hgt_elem_var", + "ignored_border_widths", + "regrid_opt", + "weightsDir", + "regrid_opt_supp_pcp", + "errMsg", + "statusMsg", + "logFile", + "logHandle", + "dScaleParamDirs", + "paramFlagArray", + "forceTemoralInterp", + "suppTemporalInterp", + "t2dDownscaleOpt", + "swDownscaleOpt", + "psfcDownscaleOpt", + "precipDownscaleOpt", + "q2dDownscaleOpt", + "t2BiasCorrectOpt", + "psfcBiasCorrectOpt", + "q2BiasCorrectOpt", + "windBiasCorrect", + "swBiasCorrectOpt", + "lwBiasCorrectOpt", + "precipBiasCorrectOpt", + "cfsv2EnsMember", + "customSuppPcpFreq", + "customFcstFreq", + "rqiMethod", + "nwmVersion", + "nwmConfig", + "forcing_output", + "aws", + "aws_obj", + "aws_time", + "nwm_geogrid", + "geopackage", + "uid64", + ], + "var_rename_map": {"config_path": "cfg_bmi"}, + "cfg_bmi_to_attrs_map": { + "SuppPcp": "supp_precip_forcings", + "OutputFrequency": "output_freq", + "SubOutputHour": "sub_output_hour", + "SubOutFreq": "sub_output_freq", + "ScratchDir": "scratch_dir", + "compressOutput": "useCompression", + "AnAFlag": "ana_flag", + "LookBack": "look_back", + "ForecastFrequency": "fcst_freq", + "SpatialMetaIn": "spatial_meta", + }, + "file_types": ["GRIB1", "GRIB2", "NETCDF", "NETCDF4", "NWM", "ZARR"], +} From deaa0310b9e567c61d7236476958c26464f44b85 Mon Sep 17 00:00:00 2001 From: Matthew Deshotel Date: Tue, 5 May 2026 16:34:18 -0400 Subject: [PATCH 02/71] break intialize method into properties with setters to validate. --- .../NextGen_Forcings_Engine/core/config.py | 3096 +++++++---------- 1 file changed, 1209 insertions(+), 1887 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py index 17bb9f8b..4c7b3add 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py @@ -5,10 +5,16 @@ import re import uuid from datetime import datetime, timedelta, timezone +from functools import cached_property # Use the Error, Warning, and Trapping System Package for logging import numpy as np +from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core import mpi_utils +from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.consts import ( + CONFIGOPTIONS, + FORCINGINPUTMOD, +) from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.err_handler import ( err_out_screen, ) @@ -16,125 +22,35 @@ calculate_lookback_window, ) -from . import mpi_utils - LOG = logging.getLogger("FORCING") -FORCE_COUNT = 27 class ConfigOptions: """Configuration abstract class for configuration options read in from the file specified by the user.""" - def __init__(self, config: dict, b_date=None, geogrid_arg=None): + def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> None: """Initialize the configuration class to empty None attributes. - param config: The user-specified path to the configuration file. + The attributes of this class are populated by the validate_config function, which reads in the configuration file and checks that all necessary options are provided and properly formatted. The attributes of this class are used to control the flow of the program and the processing of input forcings. + + Args: + cfg_bmi (dict): The configuration dictionary read in from the configuration file specified by the user. This should be read in using the config_utils.read_config function, which also handles any necessary preprocessing of the configuration file. + b_date (str, optional): The beginning date of processing in the format YYYYMMDDHHMM. This is used to calculate the processing window for realtime simulations. If not provided, it will be read from the configuration file. + geogrid (str, optional): The filepath to the geogrid file to be used for processing. This is used to specify the grid information for regridding input forcings. If not provided, it will be read from the configuration file. + """ - self.bmi_time = None - self.current_time = None self.bmi_time_index = 0 - self.input_forcings = None self.precip_only_flag = False - self.supp_precip_forcings = None - self.input_force_dirs = None - self.input_force_types = None - self.supp_precip_dirs = None - self.supp_precip_file_types = None - self.supp_precip_param_dir = None - self.input_force_mandatory = None - self.supp_precip_mandatory = None - self.supp_pcp_max_hours = None - self.number_inputs = None - self.number_supp_pcp = None self.number_custom_inputs = 0 - self.output_freq = None - self.sub_output_hour = None - self.sub_output_freq = None - self.scratch_dir = None self.useCompression = 0 self.useFloats = 0 - self.num_output_steps = None - self.num_supp_output_steps = None - self.actual_output_steps = None - self.realtime_flag = None - self.refcst_flag = None - self.ana_flag = None - self.b_date_proc = b_date - self.e_date_proc = None - self.first_fcst_cycle = None - self.current_fcst_cycle = None - self.current_output_step = None - self.cycle_length_minutes = None - self.prev_output_date = None - self.current_output_date = None - self.look_back = None - self.future_time = None - self.fcst_freq = None - self.nFcsts = None - self.fcst_shift = None - self.fcst_input_horizons = None - self.fcst_input_offsets = None - self.process_window = None - self.spatial_meta = None - self.grid_type = None - self.grid_meta = None - self.ExactExtract = None - self.lat_var = None - self.lon_var = None - self.hgt_var = None - self.cosalpha_var = None - self.sinalpha_var = None - self.slope_var = None - self.slope_azimuth_var = None - self.slope_var_elem = None - self.slope_azimuth_var_elem = None - self.nodecoords_var = None - self.elemcoords_var = None - self.elemconn_var = None - self.numelemconn_var = None - self.element_id_var = None - self.hgt_elem_var = None - self.ignored_border_widths = None - self.regrid_opt = None - self.weightsDir = None - self.regrid_opt_supp_pcp = None - self.config_path = config - self.errMsg = None - self.statusMsg = None - self.logFile = None - self.logHandle = None - self.dScaleParamDirs = None - self.paramFlagArray = None - self.forceTemoralInterp = None - self.suppTemporalInterp = None - self.t2dDownscaleOpt = None - self.swDownscaleOpt = None - self.psfcDownscaleOpt = None - self.precipDownscaleOpt = None - self.q2dDownscaleOpt = None - self.t2BiasCorrectOpt = None - self.psfcBiasCorrectOpt = None - self.q2BiasCorrectOpt = None - self.windBiasCorrect = None - self.swBiasCorrectOpt = None - self.lwBiasCorrectOpt = None - self.precipBiasCorrectOpt = None + self._b_date_proc = b_date + self._cfg_bmi = cfg_bmi self.runCfsNldasBiasCorrect = False - self.cfsv2EnsMember = None - self.customSuppPcpFreq = None - self.customFcstFreq = None - self.rqiMethod = None self.rqiThresh = 1.0 self.globalNdv = -9999.0 self.d_program_init = datetime.now(timezone.utc) self.errFlag = 0 - self.nwmVersion = None - self.nwmConfig = None - self.include_lqfrac = False - self.forcing_output = None - self.aws = None - self.aws_obj = None - self.aws_time = None self.aorc_conus_source = "s3://noaa-nws-aorc-v1-1-1km" self.aorc_conus_year_url = "{source}/{year}.zarr" self.aorc_alaska_source = "s3://ngwpc-data/AORC/Alaska" @@ -142,20 +58,159 @@ def __init__(self, config: dict, b_date=None, geogrid_arg=None): "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4" ) self.nwm_source = "s3://noaa-nwm-retrospective-3-0-pds" - - self.nwm_geogrid = None - self.geogrid = geogrid_arg - self.geopackage = None - - self.uid64 = None + self._geogrid = geogrid self.broadcast_new_64bit_uid() self._scratch_dir_has_been_uniquefied = False + # set list of attibutes from consts.py to None. + # These are indexed from the consts dictionary using the class name + for attr in CONFIGOPTIONS[self.__class__.__name__]: + setattr(self, attr, None) + self._validate_config() + + @property + def cfg_bmi(self) -> dict: + """Return the configuration dictionary read in from the configuration file specified by the user.""" + return self._cfg_bmi + + @cfg_bmi.setter + def cfg_bmi(self, value: dict) -> None: + """Set the configuration dictionary read in from the configuration file specified by the user.""" + if not isinstance(value, dict): + raise TypeError( + f"Expected dict, got {type(value)} for type of cfg_bmi: {value}" + ) + self._validate_config() + self._cfg_bmi = value + + @property + def force_count(self) -> int: + """Calculate the number of total possible input forcing options based on the length of the InputForcings list in the consts.py file. This is used for error checking to ensure users specify valid input forcing options in the configuration file.""" + return len(FORCINGINPUTMOD["InputForcings"]["PRODUCT_NAME"]) + + @property + def supp_precip_count(self) -> int: + """Calculate the number of total possible supplemental precip forcing options based on the length of the SuppPrecipForcings list in the consts.py file. This is used for error checking to ensure users specify valid supplemental precip forcing options in the configuration file.""" + # TODO make this dynamic based on the length of the SUPPPRECIPMOD list in consts.py, but for now hardcoding to 15 since that is the number of options currently available in consts.py and this will avoid any issues with the formatting of the consts.py file causing errors in the program. This is used for error checking to ensure users specify valid supplemental precip forcing options in the configuration file. + # return len(SUPPPRECIPMOD["suppPrecipMod"]["PRODUCT_NAMES"]) + return 15 + + @property + def number_supp_pcp(self) -> int: + """Calculate the number of supplemental precip forcings specified by the user in the configuration file.""" + return len(self.supp_precip_forcings) + + @property + def precip_only_flag(self) -> bool: + """Flag to indicate whether the user has chosen to run the supplemental precip forcings module only, which will trigger some different processing pathways and error checking for certain configuration options.""" + if self.number_supp_pcp == 1: + if int(self.supp_precip_forcings[0]) == 14: + return True + + def set_attrs(self): + """Set the attributes of the class based on the configuration file. This is used to populate the attributes of the class after they have been read in and validated from the configuration file.""" + for cfg_bmi_attr, config_options_attr in CONFIGOPTIONS[ + "cfg_bmi_to_attrs_map" + ].items(): + setattr( + self, config_options_attr, self.extract_input_variable(cfg_bmi_attr) + ) + + if self.output_freq <= 0: + err_out_screen( + "Please specify an OutputFrequency that is greater than zero minutes." + ) + + def extract_input_variable(self, variable_name: str) -> str: + """Extract the variable name from the configuration file for a given variable.""" + try: + return self.cfg_bmi[variable_name] + except ValueError as e: + err_out_screen( + f"Improper {variable_name} value specified in the configuration file. Error: {e}" + ) + except (KeyError, configparser.NoOptionError) as e: + err_out_screen( + f"Unable to locate {variable_name} in the configuration file. Error: {e}" + ) + except json.decoder.JSONDecodeError as e: + err_out_screen( + f"Improper {variable_name} file option specified in configuration file. Error: {e}", + e, + ) + + def extract_input_variable_set_default(self, variable_name: str, default=0) -> str: + """Extract the variable name from the configuration file for a given variable, and set it to a default value if it is not found.""" + try: + variable = self.cfg_bmi[variable_name] + except (KeyError, configparser.NoOptionError) as e: + variable = default + except ValueError as e: + err_out_screen( + f"Improper {variable_name} value: {self.cfg_bmi[variable_name]}", e + ) + if variable not in [0, 1]: + err_out_screen(f"Please choose a {variable_name} value of 0 or 1.") + return variable + + def try_config_get(self, variable_name: str, default=None) -> str: + """Try to get a variable from the configuration file, and return a default value if it is not found.""" + try: + var = self.cfg_bmi.get(variable_name, default) + if var is None: + err_out_screen( + f"Unable to locate {variable_name} in the configuration file." + ) + return var + except (KeyError, configparser.NoOptionError) as e: + err_out_screen( + f"Unable to locate {variable_name} in the configuration file.", e + ) + + def check_number_of_inputs( + self, value: list, variable_name: str, input_type: str + ) -> None: + """Check that the number of inputs specified by the user in the configuration file matches the expected number of inputs for a given variable.""" + if len(value) != self.number_inputs: + err_out_screen( + f"Number of {variable_name} values must match the number of {input_type} in the configuration file." + ) + + def check_number_of_inputs_forcings(self, value: list, variable_name: str) -> None: + """Check that the number of inputs specified by the user in the configuration file matches the expected number of inputs for a given variable, specifically for input forcings variables which should match the number of input forcing options specified by the user in the configuration file.""" + return self.check_number_of_inputs(value, variable_name, " InputForcings") + + def check_number_of_inputs_supp_pcp(self, value: list, variable_name: str) -> None: + """Check that the number of inputs specified by the user in the configuration file matches the expected number of inputs for a given variable, specifically for supplemental precip forcing variables which should match the number of supplemental precip forcing options specified by the user in the configuration file.""" + return self.check_number_of_inputs( + value, variable_name, " supplemental precip forcings" + ) + + def check_input_values_in_range( + self, value: list, variable_name: str, valid_input_options: list + ) -> None: + """Check that the input values specified by the user in the configuration file are within a valid range for a given variable.""" + for val in value: + if val in valid_input_options: + err_out_screen( + f"Invalid {variable_name} value '{val}' specified in configuration file. Please specify valid values: {valid_input_options}." + ) + + def check_input_values_positive(self, value: list, variable_name: str) -> None: + """Check that the input values specified by the user in the configuration file are positive for a given variable.""" + for val in value: + if val <= 0: + err_out_screen( + f"Invalid {variable_name} value '{val}' specified in configuration file. Please specify values greater than zero." + ) + def uniquefy_scratch_dir_as_child(self, uid: str) -> None: """Modify the existing scratch dir by adding the UID string available to all ranks from the MpiConfig class. + This may only be called once. Subsequent calls will result in an error. - This must be called by all ranks, once.""" + This must be called by all ranks, once. + """ LOG.debug(f"Uniquefying scratch dir: adding suffix {uid} to {self.scratch_dir}") if not isinstance(uid, str): raise TypeError(f"Expected str, got {type(uid)} for type of uid: {uid}") @@ -174,56 +229,88 @@ def make_scratch_dir(self) -> None: os.makedirs(self.scratch_dir, exist_ok=True) LOG.debug(f"Scratch dir: {self.scratch_dir}") - def broadcast_new_64bit_uid(self): + def broadcast_new_64bit_uid(self) -> None: """Broadcast a random uint64 then save the hash of that to self.uid64, which effectively broadcasts the same unique string to all ranks. - Should be called once to avoid confusion.""" + + Should be called once to avoid confusion. + """ if self.uid64 is not None: raise RuntimeError("self.uid64 has already been initialized.") self.uid64 = mpi_utils.get_new_broadcasted_uid() - def validate_config(self, cfg_bmi: dict) -> None: - """Validate in options from the configuration file and check that proper options were provided.""" - # Ensure b_date_proc is set; if not, read from the configuration file - if self.b_date_proc is None: + @property + def b_date_proc(self) -> str: + """Get the beginning date of processing for reforecast simulations. This is used to calculate the processing window for reforecast simulations, and is only necessary if the user is running a reforecast simulation with a specified processing window rather than a realtime simulation.""" + return self._bdate_proc + + @b_date_proc.setter + def b_date_proc(self, value: str | datetime) -> None: + """Set the beginning date of processing for reforecast simulations. This is used to calculate the processing window for reforecast simulations, and is only necessary if the user is running a reforecast simulation with a specified processing window rather than a realtime simulation.""" + if value is None: + value = self.try_config_get("RefcstBDateProc") + if isinstance(value, datetime): + self._b_date_proc = value + if value != -9999: + if isinstance(value, str) and len(value) != 12: + err_out_screen( + "Improper RefcstBDateProc length entered into the configuration file. Please check your entry." + ) try: - self.b_date_proc = cfg_bmi.get( - "RefcstBDateProc", None - ) # Default to None if not found - if self.b_date_proc is None: - err_out_screen( - "Unable to locate RefcstBDateProc under Logistics section in configuration file." - ) - except KeyError as e: + self._b_date_proc = datetime.strptime(value, "%Y%m%d%H%M") + except ValueError as e: err_out_screen( - "Unable to locate RefcstBDateProc under Logistics section in configuration file.", + "Improper RefcstBDateProc value entered into the configuration file. Please check your entry.", e, ) + else: + self._b_date_proc = -9999 + LOG.info(f"Begin date: {value}") - # Ensure geopackage is set; if not, read from the configuration file - if self.geopackage is None: - try: - self.geopackage = cfg_bmi.get( - "Geopackage", None - ) # Default to None if not found - if self.geopackage is None: - err_out_screen( - "Unable to locate Geopackage in the configuration file." - ) - except KeyError as e: - err_out_screen( - "Unable to locate Geopackage in the configuration file.", e - ) + @property + def realtime_flag(self) -> bool: + """Flag to indicate whether the user has chosen to run a realtime simulation, which will trigger some different processing pathways and error checking for certain configuration options, and will also control how the processing window is calculated.""" + if self.look_back == -9999: + return False + elif self.b_date_proc == -9999: + return True + else: + return False - # Ensure geogrid is set; if not, read from the configuration file - if self.geogrid is None: - try: - geogrid_base = cfg_bmi.get( - "GeogridIn", None - ) # Default to None if not found - except KeyError as e: - err_out_screen( - "Unable to locate GeogridIn in the configuration file.", e - ) + @property + def refcst_flag(self) -> bool: + """Flag to indicate whether the user has chosen to run a reforecast simulation, which will trigger some different processing pathways and error checking for certain configuration options, and will also control how the processing window is calculated.""" + if self.look_back == -9999: + return True + elif self.b_date_proc == -9999: + return True + else: + return False + + @property + def geopackage(self) -> str: + """Get the pathway to the geopackage file to be used for processing. This is used to specify the grid information for regridding input forcings, and is only necessary if the user is running a simulation that requires regridding of input forcings.""" + return self._geopackage + + @geopackage.setter + def geopackage(self, value: str) -> None: + """Set the pathway to the geopackage file to be used for processing. This is used to specify the grid information for regridding input forcings, and is only necessary if the user is running a simulation that requires regridding of input forcings.""" + if value is not None: + self._geopackage = value + else: + self._geopackage = self.try_config_get("Geopackage") + + @property + def geogrid(self) -> str: + """Get the pathway to the geogrid file to be used for processing. This is used to specify the grid information for regridding input forcings, and is only necessary if the user is running a simulation that requires regridding of input forcings.""" + return self._geogrid + + @geogrid.setter + def geogrid(self, value: str) -> None: + """Set the pathway to the geogrid file to be used for processing. This is used to specify the grid information for regridding input forcings, and is only necessary if the user is running a simulation that requires regridding of input forcings.""" + if value is not None: + self._geogrid = value + else: + geogrid_base = self.try_config_get("GeogridIn") if geogrid_base is None: err_out_screen("Unable to locate GeogridIn in the configuration file.") self.geogrid = None @@ -232,1467 +319,723 @@ def validate_config(self, cfg_bmi: dict) -> None: geogrid_filename = os.path.basename(geogrid_base) if self.uid64 is None: raise ValueError("self.uid64 cannot be None, please initialize it.") - self.geogrid = os.path.join( + self._geogrid = os.path.join( geogrid_parent, f"{self.uid64}_{geogrid_filename}" ) - # Create directory for esmf_mesh file - if not os.path.isdir(geogrid_parent): - try: - os.makedirs(geogrid_parent, exist_ok=True) - LOG.debug(f"Created esmf mesh directory: {geogrid_parent}") - except OSError as e: - err_out_screen( - f"Unable to create esmf_mesh directory: {geogrid_parent}. Error: {e}" - ) - - # Read in the base input forcing options as an array of values to map. - try: - self.supp_precip_forcings = cfg_bmi["SuppPcp"] - except KeyError as e: - err_out_screen( - "Unable to locate SuppPcp under SuppForcing section in configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate SuppPcp under SuppForcing section in configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen("Improper SuppPcp option specified in configuration file", e) - - self.number_supp_pcp = len(self.supp_precip_forcings) - - if self.number_supp_pcp == 1: - if int(self.supp_precip_forcings[0]) == 14: - self.precip_only_flag = True + self.try_make_dir(geogrid_parent, " esmf_mesh") - if not self.precip_only_flag: - # Read in the base input forcing options as an array of values to map. + def try_make_dir(self, directory: str, optional_str: str = "") -> None: + """Try to make a directory, and catch any errors.""" + if not os.path.isdir(directory): try: - self.input_forcings = cfg_bmi["InputForcings"] - except KeyError as e: - err_out_screen( - "Unable to locate InputForcings under Input section in configuration file.", - e, - ) - except configparser.NoOptionError as e: + os.makedirs(directory, exist_ok=True) + LOG.debug(f"Created{optional_str} directory: {directory}") + except OSError as e: err_out_screen( - "Unable to locate InputForcings under Input section in configuration file.", - e, + f"Unable to create{optional_str} directory: {directory}. Error: {e}" ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper InputForcings option specified in configuration file", e + + @property + def input_forcing_options(self) -> list: + """Get the list of input forcing options specified by the user in the configuration file. This is used to control which input forcings are processed and how they are processed based on the other configuration options specified for each input forcing.""" + return self._input_forcing_options + + @input_forcing_options.setter + def input_forcing_options(self, value: list) -> None: + """Set the list of input forcing options specified by the user in the configuration file. This is used to control which input forcings are processed and how they are processed based on the other configuration options specified for each input forcing.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("InputForcings") + if not self.precip_only_flag: + for force_opt in value: + self.check_input_values_in_range( + value, "InputForcings", list(range(1, self.force_count + 1)) ) + self._input_forcing_options = value + + @property + def number_inputs(self) -> int: + """Calculate the number of input forcing options specified by the user in the configuration file. This is used for error checking to ensure users specify valid input forcing options in the configuration file, and to control the flow of the program based on how many input forcings are being processed.""" + if not self.precip_only_flag: if len(self.input_forcings) == 0: err_out_screen( "Please choose at least one InputForcings dataset to process" ) - self.number_inputs = len(self.input_forcings) + return len(self.input_forcing_options) - # Check to make sure forcing options make sense - for force_opt in self.input_forcings: - if force_opt < 0 or force_opt > FORCE_COUNT: - err_out_screen( - f"Please specify InputForcings values between 1 and {FORCE_COUNT}." - ) - - # Keep tabs on how many custom input forcings we have. + @property + def number_custom_inputs(self) -> int: + """Calculate the number of custom input forcing options specified by the user in the configuration file. This is used to control the flow of the program based on how many custom input forcings are being processed, since custom input forcings require some different processing pathways.""" + if not self.precip_only_flag: + count = 0 + for force_opt in self.input_forcing_options: if force_opt == 10: - self.number_custom_inputs = self.number_custom_inputs + 1 + count += 1 + return count - # Flag to force mandatory configuration option to specify the NWM geogrid file if user requests - # NWM forcing files to be regridded to a given domain configuration - if force_opt == 27: - try: - self.nwm_geogrid = cfg_bmi["NWM_Geogrid"] - except KeyError as e: - err_out_screen( - "Unable to locate NWM Geogrid file required for the NWM forcings module. Need to specify the pathway to the NWM geo_em_DOMAIN.nc file to the NWM_Geogrid configuration input option within the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate NWM Geogrid file required for the NWM forcings module. Need to specify the pathway to the NWM geo_em_DOMAIN.nc file to the NWM_Geogrid configuration input option within the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper NWM Geogrid file option specified in configuration file", - e, - ) + @property + def nwm_geogrid(self) -> str: + """Get the pathway to the NWM geogrid file specified by the user in the configuration file. This is used to specify the grid information for regridding NWM input forcings, and is only necessary if the user has chosen to regrid NWM input forcings in the configuration file.""" + return self._nwm_geogrid + + @nwm_geogrid.setter + def nwm_geogrid(self, value: str) -> None: + """Set the pathway to the NWM geogrid file specified by the user in the configuration file. This is used to specify the grid information for regridding NWM input forcings, and is only necessary if the user has chosen to regrid NWM input forcings in the configuration file.""" + if value is None and not self.precip_only_flag: + if 27 in self.input_forcing_options: + value = self.extract_input_variable("NWM_Geogrid") + self._nwm_geogrid = value - # Read in the input forcings types (GRIB[1|2], NETCDF) - try: - # self.input_force_types = config.get('Input', 'InputForcingTypes').strip("[]").split(',') - # self.input_force_types = [ftype.strip() for ftype in self.input_force_types] - self.input_force_types = cfg_bmi["InputForcingTypes"] - if self.input_force_types == [""]: - self.input_force_types = [] - except KeyError as e: - err_out_screen( - "Unable to locate InputForcingTypes in Input section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate InputForcingTypes in Input section in the configuration file.", - e, - ) - if len(self.input_force_types) != self.number_inputs: - err_out_screen( - "Number of InputForcingTypes must match the number " - "of InputForcings in the configuration file." - ) - for file_type in self.input_force_types: - if file_type not in [ - "GRIB1", - "GRIB2", - "NETCDF", - "NETCDF4", - "NWM", - "ZARR", - "GRIB2_CFS", - ]: - err_out_screen( - f'Invalid forcing file type "{file_type}" specified. ' - "Only GRIB1, GRIB2, NETCDF, NWM, ZARR, and GRIB2_CFS are supported" - ) + @property + def input_force_types(self) -> list: + """Get the list of input forcing file types specified by the user in the configuration file. This is used to control how input forcings are read in and processed based on the file type specified for each input forcing in the configuration file.""" + return self._input_force_types + + @input_force_types.setter + def input_force_types(self, value: list) -> None: + """Set the list of input forcing file types specified by the user in the configuration file. This is used to control how input forcings are read in and processed based on the file type specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("InputForcingTypes") + if not self.precip_only_flag: + if value == [""]: + value = [] + self.check_number_of_inputs_forcings(value, "InputForcingTypes") + self.check_input_values_in_range( + value, "InputForcingTypes", self.file_types + ) + self._input_force_types = value - # Read in the input directories for each forcing option. - try: - self.input_force_dirs = cfg_bmi["InputForcingDirectories"] - except KeyError as e: - err_out_screen( - "Unable to locate InputForcingDirectories in Input section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate InputForcingDirectories in Input section in the configuration file.", - e, - ) - if len(self.input_force_dirs) != self.number_inputs: - err_out_screen( - "Number of InputForcingDirectories must match the number " - "of InputForcings in the configuration file." - ) + @property + def file_types(self): + """Get the list of input forcing file types specified by the user in the configuration file. This is used to control how input forcings are read in and processed based on the file type specified for each input forcing in the configuration file.""" + return self.CONFIGOPTIONS["file_types"] + + @property + def input_force_dirs(self) -> list: + """Get the list of input forcing directories specified by the user in the configuration file. This is used to control where input forcings are read in from for each input forcing specified by the user in the configuration file.""" + return self._input_force_dirs + + @input_force_dirs.setter + def input_force_dirs(self, value: list) -> None: + """Set the list of input forcing directories specified by the user in the configuration file. This is used to control where input forcings are read in from for each input forcing specified by the user in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("InputForcingDirectories") + if not self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "InputForcingDirectories") # Loop through and ensure all input directories exist. Also strip out any whitespace # or new line characters. - for dir_tmp in range(0, len(self.input_force_dirs)): - self.input_force_dirs[dir_tmp] = self.input_force_dirs[dir_tmp].strip() - - dir_path = self.input_force_dirs[dir_tmp] - forcing_type = self.input_forcings[dir_tmp] + for dir_tmp in range(0, len(value)): + value[dir_tmp] = value[dir_tmp].strip() + dir_path = value[dir_tmp] + forcing_type = self.input_forcing_options[dir_tmp] is_aws_forcing = forcing_type in [12, 21, 27] if not os.path.isdir(dir_path): if is_aws_forcing: self.aws = True else: - try: - os.makedirs(dir_path, exist_ok=True) - LOG.debug(f"Created missing forcing directory: {dir_path}") - except OSError as e: - err_out_screen( - f"Unable to create forcing directory: {dir_path}. Error: {e}" - ) - - # Read in the mandatory enforcement options for input forcings. - try: - self.input_force_mandatory = cfg_bmi["InputMandatory"] - except KeyError as e: - err_out_screen( - "Unable to locate InputMandatory under Input section in configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate InputMandatory under Input section in configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper InputMandatory option specified in configuration file", e - ) + self.try_make_dir(dir_path, " forcing") + self._input_force_dirs = value + + def input_force_mandatory(self) -> list: + """Get the list of input forcing mandatory flags specified by the user in the configuration file. This is used to control whether the program should raise an error if input forcings for a given forecast cycle are not found for each input forcing specified by the user in the configuration file.""" + return self._input_force_mandatory + + @input_force_mandatory.setter + def input_force_mandatory(self, value: list) -> None: + """Set the list of input forcing mandatory flags specified by the user in the configuration file. This is used to control whether the program should raise an error if input forcings for a given forecast cycle are not found for each input forcing specified by the user in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("InputMandatory") + self.check_number_of_inputs_forcings(value, "InputMandatory") + self.check_input_values_in_range(value, "InputMandatory", [0, 1]) + self._input_force_mandatory = value + + def customSuppPcpFreq(self) -> int: + """Get the custom supplemental precip output frequency specified by the user in the configuration file. This is used to control the output frequency of supplemental precip forcings if the user has chosen to run the supplemental precip forcings module only.""" + return self._customSuppPcpFreq + + @customSuppPcpFreq.setter + def customSuppPcpFreq(self, value: int) -> None: + """Set the custom supplemental precip output frequency specified by the user in the configuration file. This is used to control the output frequency of supplemental precip forcings if the user has chosen to run the supplemental precip forcings module only.""" + if value is None and self.precip_only_flag: + value = self.extract_input_variable("customSuppPcpFreq") + self.check_input_values_positive([value], "customSuppPcpFreq") + self._customSuppPcpFreq = value - if len(self.input_force_mandatory) != self.number_inputs: - err_out_screen( - "Please specify InputMandatory values for each corresponding input " - "forcings in the configuration file." - ) - # Check to make sure enforcement options makes sense. - for enforce_opt in self.input_force_mandatory: - if enforce_opt < 0 or enforce_opt > 1: - err_out_screen( - "Invalid InputMandatory chosen in the configuration file. Please choose a value of 0 or 1 for each corresponding input forcing." - ) + @property + def include_lqfrac(self): + """Get the flag for whether to include the liquid/solid precipitation fraction variable in the output files specified by the user in the configuration file. This is used to control whether the liquid/solid precipitation fraction variable is included in the output files.""" + return self._include_lqfrac - # Read in the output frequency - try: - self.output_freq = cfg_bmi["OutputFrequency"] - except ValueError as e: - err_out_screen( - "Improper OutputFrequency value specified in the configuration file." - ) - except KeyError as e: - err_out_screen( - "Unable to locate OutputFrequency in the configuration file." - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate OutputFrequency in the configuration file." - ) - if self.output_freq <= 0: - err_out_screen( - "Please specify an OutputFrequency that is greater than zero minutes." - ) + @include_lqfrac.setter + def include_lqfrac(self, value): + """Set the flag for whether to include the liquid/solid precipitation fraction variable in the output files specified by the user in the configuration file. This is used to control whether the liquid/solid precipitation fraction variable is included in the output files.""" + if value is None: + value = self.extract_input_variable_set_default("includeLQFrac", default=0) - if self.precip_only_flag: - # Read in the custom supp output frequency - try: - self.customSuppPcpFreq = int(cfg_bmi["customSuppPcpFreq"]) - except ValueError as e: - err_out_screen( - "Improper customSuppPcpFreq value specified in the configuration file.", - e, - ) - except KeyError as e: - err_out_screen( - "Unable to locate customSuppPcpFreq in the configuration file.", e - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate customSuppPcpFreq in the configuration file.", e - ) - if self.output_freq <= 0: - err_out_screen( - "Please specify an customSuppPcpFreq that is greater than zero minutes." - ) + @property + def include_lqfrac(self): + """Get the flag for whether to include the liquid/solid precipitation fraction variable in the output files specified by the user in the configuration file. This is used to control whether the liquid/solid precipitation fraction variable is included in the output files.""" + return self._include_lqfrac - # Read in the sub output hour - try: - self.sub_output_hour = int(cfg_bmi["SubOutputHour"]) - except ValueError as e: - err_out_screen( - "Improper SubOutputHour value specified in the configuration file.", e - ) - except KeyError as e: - err_out_screen( - "Unable to locate SubOutputHour in the configuration file.", e - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate SubOutputHour in the configuration file.", e - ) - if self.sub_output_hour < 0: - err_out_screen( - "Please specify an SubOutputHour that is greater than zero minutes." - ) - if self.sub_output_hour == 0: - self.sub_output_hour = None - # Read in the output frequency - try: - self.sub_output_freq = int(cfg_bmi["SubOutFreq"]) - except ValueError as e: - err_out_screen( - "Improper SubOutFreq value specified in the configuration file.", e - ) - except KeyError as e: - err_out_screen("Unable to locate SubOutFreq in the configuration file.", e) - except configparser.NoOptionError as e: - err_out_screen("Unable to locate SubOutFreq in the configuration file.", e) - if self.sub_output_freq < 0: - err_out_screen( - "Please specify an SubOutFreq that is greater than zero minutes." - ) - if self.sub_output_freq == 0: - self.sub_output_freq = None + @include_lqfrac.setter + def include_lqfrac(self, value): + if value is None: + value = self.extract_input_variable_set_default("includeLQFrac", default=0) + self._include_lqfrac = value - # TODO Can this be a /tmp directory? - # Read in the scratch temporary directory, which also may contain output forcing file if requested. - try: - self.scratch_dir = cfg_bmi["ScratchDir"] - except ValueError as e: - err_out_screen( - "Improper ScratchDir specified in the configuration file.", e - ) - except KeyError as e: - err_out_screen("Unable to locate ScratchDir in the configuration file.", e) - except configparser.NoOptionError as e: - err_out_screen("Unable to locate ScratchDir in the configuration file.", e) + @property + def forcing_output(self) -> int: + """Get the flag for whether to output the input forcings specified by the user in the configuration file. This is used to control whether the input forcings are output in addition to the processed forcings.""" + return self._forcing_output + + @forcing_output.setter + def forcing_output(self, value: int) -> None: + if value is None: + value = self.extract_input_variable_set_default("Output", default=0) + self._forcing_output = value + + def fcst_shift(self) -> int: + """Get the forecast shift specified by the user in the configuration file. This is used to control the calculation of the processing window for realtime simulations.""" + return self._fcst_shift + + @fcst_shift.setter + def fcst_shift(self, value: int) -> None: + if value is None: + value = self.extract_input_variable("ForecastShift") + self.check_input_values_positive([value], "ForecastShift") + self._fcst_shift = value - self.make_scratch_dir() + @property + def fcst_input_horizons(self) -> list: + """Get the list of forecast input horizons specified by the user in the configuration file. This is used to control the calculation of the forecast cycle length and the processing of input forcings based on the forecast time horizons specified for each input forcing.""" + return self._fcst_input_horizons + + @fcst_input_horizons.setter + def fcst_input_horizons(self, value: list) -> None: + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("ForecastInputHorizons") + if not self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "ForecastInputHorizons") + self.check_input_values_positive(value, "ForecastInputHorizons") + else: + if value is None: + value = self.extract_input_variable("ForecastInputHorizons") + self._fcst_input_horizons = value - # Read in compression option - try: - self.useCompression = cfg_bmi["compressOutput"] - except KeyError as e: - err_out_screen("Unable to locate compressOut in the configuration file.", e) - except configparser.NoOptionError as e: - err_out_screen("Unable to locate compressOut in the configuration file.", e) - except ValueError as e: - err_out_screen("Improper compressOut value.", e) - if self.useCompression < 0 or self.useCompression > 1: - err_out_screen("Please choose a compressOut value of 0 or 1.") + @property + def fcst_input_offsets(self): + """Get the list of forecast input offsets specified by the user in the configuration file. This is used to control the calculation of the processing window for both realtime and reforecast simulations based on the forecast time horizons and input offsets specified for each input forcing.""" + return self._fcst_input_offsets + + @fcst_input_offsets.setter + def fcst_input_offsets(self, value: list) -> None: + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("ForecastInputOffsets") + if not self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "ForecastInputOffsets") + self.check_input_values_positive(value, "ForecastInputOffsets") + self._fcst_input_offsets = value - # Read in floating-point option - try: - self.useFloats = cfg_bmi["floatOutput"] - except KeyError as e: - # err_out_screen('Unable to locate floatOutput in the configuration file.', e) - self.useFloats = 0 - except configparser.NoOptionError as e: - # err_out_screen('Unable to locate floatOutput in the configuration file.', e) - self.useFloats = 0 - except ValueError as e: - err_out_screen( - "Improper floatOutput value: {}".format(cfg_bmi["includeLQFraq"]) - ) - if self.useFloats < 0 or self.useFloats > 1: - err_out_screen("Please choose a floatOutput value of 0 or 1.") + @property + def cycle_length_minutes(self) -> int: + """Get the forecast cycle length in minutes, which is calculated based on the maximum of the forecast input horizons specified by the user in the configuration file. - # Read in lqfrac option - try: - self.include_lqfrac = cfg_bmi["includeLQFrac"] - except KeyError as e: - # err_out_screen('Unable to locate includeLQFraq in the configuration file.', e) - self.include_lqfrac = 0 - except configparser.NoOptionError as e: - # err_out_screen('Unable to locate includeLQFraq in the configuration file.', e) - self.useFinclude_lqfracloats = 0 - except ValueError as e: + Ensure the number maximum cycle length is an equal divider of the output time step specified by the user. + """ + cycle_len = max(self.fcst_input_horizons) + if cycle_len % self.output_freq != 0: err_out_screen( - "Improper includeLQFrac value: {}".format(cfg_bmi["includeLQFraq"]), e + "Please specify an output time step that is an equal divider of the maximum of the forecast time horizons specified." ) - if self.include_lqfrac < 0 or self.include_lqfrac > 1: - err_out_screen("Please choose an includeLQFrac value of 0 or 1.") + return cycle_len - # Read in Forcing output option - try: - self.forcing_output = cfg_bmi["Output"] - except KeyError as e: - self.forcing_output = 0 - except configparser.NoOptionError as e: - self.forcing_output = 0 - except ValueError as e: - err_out_screen( - "Improper Forcing Output value: {}".format(cfg_bmi["Output"]), e - ) - if self.forcing_output < 0 or self.forcing_output > 1: - err_out_screen( - "Please choose a Forcing Output value of 0 (No output) or 1 (output)." + def num_output_steps(self) -> int: + """Calculate the number of output time steps per forecast cycle based on the forecast cycle length and the output frequency specified by the user in the configuration file.""" + if self.sub_output_hour is None: + num_steps = int(self.cycle_length_minutes / self.output_freq) + else: + num_steps = ( + int( + (self.cycle_length_minutes - (self.sub_output_hour * 60)) + / self.sub_output_freq + ) + + int((self.sub_output_hour * 60) / self.output_freq) + - 1 ) + return num_steps - # Read AnA flag option - try: - # check both the Forecast section and if it's not there, the old BiasCorrection location - self.ana_flag = int(cfg_bmi["AnAFlag"]) - except KeyError as e: - err_out_screen("Unable to locate AnAFlag in the configuration file.", e) - except configparser.NoOptionError as e: - err_out_screen("Unable to locate AnAFlag in the configuration file.", e) - except ValueError as e: - err_out_screen("Improper AnAFlag value ", e) - if self.ana_flag < 0 or self.ana_flag > 1: - err_out_screen("Please choose a AnAFlag value of 0 or 1.") + def num_supp_output_steps(self) -> int: + """Calculate the number of supplemental precip output time steps per forecast cycle based on the forecast cycle length and the custom supplemental precip output frequency specified by the user in the configuration file.""" + if self.precip_only_flag: + return int(self.cycle_length_minutes / self.customSuppPcpFreq) - # For the NextGen Forcings Engine BMI, we are assuming a realtime or reforecast simulation. - try: - self.look_back = cfg_bmi["LookBack"] - if self.look_back <= 0 and self.look_back != -9999: - err_out_screen( - "Please specify a positive LookBack or -9999 for realtime." - ) - except ValueError as e: - err_out_screen( - "Improper LookBack value entered into the configuration file. Please check your entry.", - e, - ) - except KeyError as e: - err_out_screen( - "Unable to locate LookBack in the configuration file. Please verify entries exist.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate LookBack in the configuration file. Please verify entries exist.", - e, - ) + def actual_output_steps(self) -> int: + """Calculate the actual number of output time steps per forecast cycle based on whether the user has chosen to run a reforecast simulation with a specified processing window, which will only output time steps for which input forcings are available based on the processing window and forecast time horizons specified by the user in the configuration file.""" + if self.ana_flag: + return np.int32(self.nFcsts) + else: + return np.int32(self.num_output_steps) + + @property + def grid_type(self) -> str: + """Get the grid type specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings based on the grid type specified by the user in the configuration file.""" + return self._grid_type + + @grid_type.setter + def grid_type(self, value: str) -> None: + """Set the grid type specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings based on the grid type specified by the user in the configuration file.""" + if value is None: + value = self.extract_input_variable("GRID_TYPE") + self.check_input_values_in_range( + [value], "GRID_TYPE", ["gridded", "unstructured", "hydrofabric"] + ) + self._grid_type = value.lower() - # Process the beginning date of reforecast forcings to process + def raise_grid_type_error(self, grid_type: str, variable_name: str) -> None: + """Raise an error if a variable is requested that is not valid for the given grid type.""" + err_out_screen( + f"{variable_name} is not a valid variable for grid type {grid_type}. Please check your configuration file." + ) - if self.b_date_proc: - beg_date_tmp = self.b_date_proc - e = "" + @property + def lon_var(self) -> str: + """Get the longitude variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen a gridded grid type in the configuration file.""" + if self.grid_type == "gridded": + return self.extract_input_variable("LONVAR") else: - try: - beg_date_tmp = cfg_bmi["RefcstBDateProc"] - except KeyError as e: - err_out_screen( - "Unable to locate RefcstBDateProc under Logistics section in configuration file.", - e, - ) - beg_date_tmp = None - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate RefcstBDateProc under Logistics section in configuration file.", - e, - ) - beg_date_tmp = None + self.raise_grid_type_error(self.grid_type, "LONVAR") - if beg_date_tmp != -9999: - if isinstance(beg_date_tmp, str) and len(beg_date_tmp) != 12: - err_out_screen( - "Improper RefcstBDateProc length entered into the configuration file. Please check your entry.", - e, - ) - try: - self.b_date_proc = datetime.strptime(beg_date_tmp, "%Y%m%d%H%M") - except ValueError as e: - err_out_screen( - "Improper RefcstBDateProc value entered into the configuration file. Please check your entry.", - e, - ) + @property + def lat_var(self) -> str: + """Get the latitude variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen a gridded grid type in the configuration file.""" + if self.grid_type == "gridded": + return self.extract_input_variable("LATVAR") else: - self.b_date_proc = -9999 + self.raise_grid_type_error(self.grid_type, "LATVAR") - LOG.info(f"Begin date: {beg_date_tmp}") + @property + def nodecoords_var(self) -> str: + """Get the node coordinates variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen an unstructured or hydrofabric grid type in the configuration file.""" + if self.grid_type in ["unstructured", "hydrofabric"]: + return self.extract_input_variable("NodeCoords") + else: + self.raise_grid_type_error(self.grid_type, "NodeCoords") - # If the Retro flag is off, and lookback is off, then we assume we are - # running a reforecast. - if self.look_back == -9999: - self.realtime_flag = False - self.refcst_flag = True - elif self.b_date_proc == -9999: - self.realtime_flag = True - self.refcst_flag = True + @property + def elemcoords_var(self) -> str: + """Get the element coordinates variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen an unstructured or hydrofabric grid type in the configuration file.""" + if self.grid_type in ["unstructured", "hydrofabric"]: + return self.extract_input_variable("ElemCoords") else: - # The processing window will be calculated based on current time and the - # lookback option since this is a realtime instance. - self.realtime_flag = False - self.refcst_flag = False - # self.b_date_proc = -9999 - # self.e_date_proc = -9999 + self.raise_grid_type_error(self.grid_type, "ElemCoords") - # Calculate the delta time between the beginning and ending time of processing. - # self.process_window = self.e_date_proc - self.b_date_proc + @property + def elemconn_var(self) -> str: + """Get the element connectivity variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen an unstructured or hydrofabric grid type in the configuration file.""" + if self.grid_type in ["unstructured", "hydrofabric"]: + return self.extract_input_variable("ElemConn") + else: + self.raise_grid_type_error(self.grid_type, "ElemConn") - # Read in the ForecastFrequency option. - try: - self.fcst_freq = cfg_bmi["ForecastFrequency"] - except ValueError as e: - err_out_screen( - "Improper ForecastFrequency value entered into the configuration file. Please check your entry.", - e, - ) - except KeyError as e: - err_out_screen( - "Unable to locate ForecastFrequency in the configuration file. Please verify entries exist.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate ForecastFrequency in the configuration file. Please verify entries exist.", - e, - ) - if self.fcst_freq <= 0: - err_out_screen( - "Please specify a ForecastFrequency in the configuration file greater than zero." - ) - # Currently, we only support daily or sub-daily forecasts. Any other iterations should - # be done using custom config files for each forecast cycle. - if self.fcst_freq > 1440: - err_out_screen( - "Only forecast cycles of daily or sub-daily are supported at this time" - ) + @property + def numelemconn_var(self) -> str: + """Get the number of element connectivity variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen an unstructured or hydrofabric grid type in the configuration file.""" + if self.grid_type in ["unstructured", "hydrofabric"]: + return self.extract_input_variable("NumElemConn") + else: + self.raise_grid_type_error(self.grid_type, "NumElemConn") - # Read in the ForecastShift option. This is ONLY done for the realtime instance as - # it's used to calculate the beginning of the processing window. - if True: # was: self.realtime_flag: - try: - self.fcst_shift = cfg_bmi["ForecastShift"] - except ValueError as e: - err_out_screen( - "Improper ForecastShift value entered into the configuration file. Please check your entry.", - e, - ) - except KeyError as e: - err_out_screen( - "Unable to locate ForecastShift in the configuration file. Please verify entries exist.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate ForecastShift in the configuration file. Please verify entries exist.", - e, - ) - if self.fcst_shift < 0: + @property + def element_id_var(self) -> str: + """Get the element ID variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen a hydrofabric grid type in the configuration file.""" + if self.grid_type == "hydrofabric": + return self.extract_input_variable("ElemID") + else: + self.raise_grid_type_error(self.grid_type, "ElemID") + + @property + def ignored_border_widths(self) -> list: + """Get the list of ignored border widths specified by the user in the configuration file. This is used to control how the program processes input forcings based on the ignored border widths specified for each input forcing in the configuration file.""" + return self._ignored_border_widths + + @ignored_border_widths.setter + def ignored_border_widths(self, value: list) -> None: + """Set the list of ignored border widths specified by the user in the configuration file. This is used to control how the program processes input forcings based on the ignored border widths specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("IgnoredBorderWidths") + if self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "IgnoredBorderWidths") + self.check_input_values_positive(value, "IgnoredBorderWidths") + self._ignored_border_widths = value + + @property + def regrid_opt(self): + """Get the list of regridding options specified by the user in the configuration file. This is used to control how input forcings are regridded based on the regridding option specified for each input forcing in the configuration file.""" + return self._regrid_opt + + @regrid_opt.setter + def regrid_opt(self, value: list) -> None: + """Set the list of regridding options specified by the user in the configuration file. This is used to control how input forcings are regridded based on the regridding option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("RegridOpt") + if self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "RegridOpt") + self.check_input_values_in_range(value, "RegridOpt", [1, 2, 3]) + self._regrid_opt = value + + @property + def weightsDir(self) -> str: + """Get the pathway to the ESMF weights directory specified by the user in the configuration file. This is used to control where the program looks for ESMF weights files if the user has chosen to use pre-generated ESMF weights files for regridding input forcings in the configuration file.""" + return self._weightsDir + + @weightsDir.setter + def weightsDir(self, value: str) -> None: + """Set the pathway to the ESMF weights directory specified by the user in the configuration file. This is used to control where the program looks for ESMF weights files if the user has chosen to use pre-generated ESMF weights files for regridding input forcings in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.try_config_get("RegridWeightsDir") + if self.precip_only_flag: + if value is not None and not os.path.exists(value): err_out_screen( - "Please specify a ForecastShift in the configuration file greater than or equal to zero." + f"ESMF Weights file directory specified ({value}) but does not exist" ) + self._weightsDir = value - # Calculate the beginning/ending processing dates if we are running realtime - if self.realtime_flag: - calculate_lookback_window(self) - - # if self.refcst_flag: - # Calculate the number of forecasts to issue, and verify the user has chosen a - # correct divider based on the dates - # dt_tmp = self.e_date_proc - self.b_date_proc - # if (dt_tmp.days * 1440 + dt_tmp.seconds / 60.0) % self.fcst_freq != 0: - # err_out_screen('Please choose an equal divider forecast frequency for your ' - # 'specified reforecast range.') - # self.nFcsts = int((dt_tmp.days * 1440 + dt_tmp.seconds / 60.0) / self.fcst_freq) + @property + def forceTemoralInterp(self) -> list: + """Get the list of forcing temporal interpolation options specified by the user in the configuration file. This is used to control how input forcings are temporally interpolated based on the temporal interpolation option specified for each input forcing in the configuration file.""" + return self._forceTemoralInterp + + @forceTemoralInterp.setter + def forceTemoralInterp(self, value: list) -> None: + """Set the list of forcing temporal interpolation options specified by the user in the configuration file. This is used to control how input forcings are temporally interpolated based on the temporal interpolation option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("ForcingTemporalInterpolation") + if not self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "ForcingTemporalInterpolation") + self.check_input_values_in_range( + value, "ForcingTemporalInterpolation", [0, 1, 2] + ) + self._forceTemoralInterp = value - # Flag to constrain AORC forcing data cycle output - # for optTmp in self.input_forcings: - # if optTmp == 12: - # self.nFcsts = 1 - self.nFcsts = 1 + @property + def forceTemoralInterp(self): + """Get the list of forcing temporal interpolation options specified by the user in the configuration file. This is used to control how input forcings are temporally interpolated based on the temporal interpolation option specified for each input forcing in the configuration file.""" + return self._forceTemoralInterp + + @forceTemoralInterp.setter + def forceTemoralInterp(self, value): + """Set the list of forcing temporal interpolation options specified by the user in the configuration file. This is used to control how input forcings are temporally interpolated based on the temporal interpolation option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("ForcingTemporalInterpolation") + if not self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "ForcingTemporalInterpolation") + self.check_input_values_in_range( + value, "ForcingTemporalInterpolation", [0, 1, 2] + ) + self._forceTemoralInterp = value - if self.look_back != -9999: - calculate_lookback_window(self) + @property + def t2dDownscaleOpt(self) -> list: + """Get the list of temperature downscaling options specified by the user in the configuration file. This is used to control how temperature input forcings are downscaled based on the temperature downscaling option specified for each input forcing in the configuration file.""" + return self._t2dDownscaleOpt + + @t2dDownscaleOpt.setter + def t2dDownscaleOpt(self, value: list) -> None: + """Set the list of temperature downscaling options specified by the user in the configuration file. This is used to control how temperature input forcings are downscaled based on the temperature downscaling option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("TemperatureDownscaling") + if not self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "TemperatureDownscaling") + self.check_input_values_in_range(value, "TemperatureDownscaling", [0, 1, 2]) + self._t2dDownscaleOpt = value + @property + def psfcDownscaleOpt(self) -> list: + """Get the list of pressure downscaling options specified by the user in the configuration file. This is used to control how pressure input forcings are downscaled based on the pressure downscaling option specified for each input forcing in the configuration file.""" + return self._psfcDownscaleOpt + + @psfcDownscaleOpt.setter + def psfcDownscaleOpt(self, value: list) -> None: + """Set the list of pressure downscaling options specified by the user in the configuration file. This is used to control how pressure input forcings are downscaled based on the pressure downscaling option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("PressureDownscaling") if not self.precip_only_flag: - # Read in the ForecastInputHorizons options. - try: - self.fcst_input_horizons = cfg_bmi["ForecastInputHorizons"] - except KeyError as e: - err_out_screen( - "Unable to locate ForecastInputHorizons under Forecast section in configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate ForecastInputHorizons under Forecast section in configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper ForecastInputHorizons option specified in configuration file", - e, - ) - if len(self.fcst_input_horizons) != self.number_inputs: - err_out_screen( - "Please specify ForecastInputHorizon values for each corresponding input forcings for forecasts." - ) + self.check_number_of_inputs_forcings(value, "PressureDownscaling") + self.check_input_values_in_range(value, "PressureDownscaling", [0, 1]) + self._psfcDownscaleOpt = value - # Check to make sure the horizons options make sense. There will be additional - # checking later when input choices are mapped to input products. - for horizonOpt in self.fcst_input_horizons: - if horizonOpt <= 0: - err_out_screen( - "Please specify ForecastInputHorizon values greater than zero." - ) - else: - # Read in the ForecastInputHorizons options. - try: - self.fcst_input_horizons = cfg_bmi["ForecastInputHorizons"] - except KeyError as e: - err_out_screen( - "Unable to locate ForecastInputHorizons under Forecast section in configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate ForecastInputHorizons under Forecast section in configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper ForecastInputHorizons option specified in configuration file", - e, - ) - if len(self.fcst_input_horizons) != 1: - err_out_screen( - "Please specify ForecastInputHorizon values for each corresponding input forcings for forecasts." - ) + @property + def swDownscaleOpt(self) -> list: + """Get the list of shortwave downscaling options specified by the user in the configuration file. This is used to control how shortwave radiation input forcings are downscaled based on the shortwave downscaling option specified for each input forcing in the configuration file.""" + return self._swDownscaleOpt + + @swDownscaleOpt.setter + def swDownscaleOpt(self, value: list) -> None: + """Set the list of shortwave downscaling options specified by the user in the configuration file. This is used to control how shortwave radiation input forcings are downscaled based on the shortwave downscaling option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("ShortwaveDownscaling") + if not self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "ShortwaveDownscaling") + self.check_input_values_in_range(value, "ShortwaveDownscaling", [0, 1]) + self._swDownscaleOpt = value + @property + def q2dDownscaleOpt(self) -> list: + """Get the list of humidity downscaling options specified by the user in the configuration file. This is used to control how humidity input forcings are downscaled based on the humidity downscaling option specified for each input forcing in the configuration file.""" + return self._q2dDownscaleOpt + + @q2dDownscaleOpt.setter + def q2dDownscaleOpt(self, value: list) -> None: + """Set the list of humidity downscaling options specified by the user in the configuration file. This is used to control how humidity input forcings are downscaled based on the humidity downscaling option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("HumidityDownscaling") if not self.precip_only_flag: - # Read in the ForecastInputOffsets options. - try: - self.fcst_input_offsets = cfg_bmi["ForecastInputOffsets"] - except KeyError as e: - err_out_screen( - "Unable to locate ForecastInputOffsets under Forecast section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate ForecastInputOffsets under Forecast section in the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper ForecastInputOffsets option specified in the configuration file.", - e, - ) - if len(self.fcst_input_offsets) != self.number_inputs: - err_out_screen( - "Please specify ForecastInputOffset values for each corresponding input forcings for forecasts." - ) - # Check to make sure the input offset options make sense. There will be additional - # checking later when input choices are mapped to input products. - for inputOffset in self.fcst_input_offsets: - if inputOffset < 0: - err_out_screen( - "Please specify ForecastInputOffset values greater than or equal to zero." - ) + self.check_number_of_inputs_forcings(value, "HumidityDownscaling") + self.check_input_values_in_range(value, "HumidityDownscaling", [0, 1]) + self._q2dDownscaleOpt = value - # Calculate the length of the forecast cycle, based on the maximum - # length of the input forcing length chosen by the user. - self.cycle_length_minutes = max(self.fcst_input_horizons) + @property + def precipDownscaleOpt(self) -> list: + """Get the list of precipitation downscaling options specified by the user in the configuration file. This is used to control how precipitation input forcings are downscaled based on the precipitation downscaling option specified for each input forcing in the configuration file.""" + return self._precipDownscaleOpt - # Ensure the number maximum cycle length is an equal divider of the output - # time step specified by the user. - if self.cycle_length_minutes % self.output_freq != 0: - err_out_screen( - "Please specify an output time step that is an equal divider of the maximum of the forecast time horizons specified." - ) + @precipDownscaleOpt.setter + def precipDownscaleOpt(self, value: list) -> None: + """Set the list of precipitation downscaling options specified by the user in the configuration file. This is used to control how precipitation input forcings are downscaled based on the precipitation downscaling option specified for each input forcing in the configuration file.""" + if value is None: + value = self.extract_input_variable("PrecipDownscaling") + self.check_number_of_inputs_forcings(value, "PrecipDownscaling") + self.check_input_values_in_range(value, "PrecipDownscaling", [0, 1]) - if self.sub_output_hour is None: - # Calculate the number of output time steps per forecast cycle. - self.num_output_steps = int(self.cycle_length_minutes / self.output_freq) - if self.precip_only_flag: - self.num_supp_output_steps = ( - int(self.cycle_length_minutes) / self.customSuppPcpFreq - ) - if self.ana_flag: - self.actual_output_steps = np.int32(self.nFcsts) - else: - self.actual_output_steps = np.int32(self.num_output_steps) - else: - # Calculate the number of output time steps per forecast cycle. - self.num_output_steps = ( - int( - (self.cycle_length_minutes - (self.sub_output_hour * 60)) - / self.sub_output_freq - ) - + int((self.sub_output_hour * 60) / self.output_freq) - - 1 - ) - if self.precip_only_flag: - self.num_supp_output_steps = ( - int(self.cycle_length_minutes) / self.customSuppPcpFreq - ) - if self.ana_flag: - self.actual_output_steps = np.int32(self.nFcsts) - else: - self.actual_output_steps = np.int32(self.num_output_steps) + self._precipDownscaleOpt = value - # Process the grid type - try: - self.grid_type = cfg_bmi["GRID_TYPE"] - except KeyError as e: - err_out_screen("Unable to locate GRID_TYPE in the configuration file.", e) - except configparser.NoOptionError as e: - err_out_screen("Unable to locate GRID_TYPE in the configuration file.", e) + @property + def dScaleParamDirs(self) -> list: + """Get the list of downscaling parameter directories specified by the user in the configuration file. This is used to control where the program looks for downscaling parameter files for each input forcing based on the downscaling parameter directory specified for each input forcing in the configuration file.""" + return self._dScaleParamDirs + + @dScaleParamDirs.setter + def dScaleParamDirs(self, value: list) -> None: + """Set the list of downscaling parameter directories specified by the user in the configuration file. This is used to control where the program looks for downscaling parameter files for each input forcing based on the downscaling parameter directory specified for each input forcing in the configuration file.""" + if value is None: + value = self.extract_input_variable("DownscalingParamDirs") + self.check_number_of_inputs_forcings(value, "DownscalingParamDirs") + for dirTmp in range(0, len(value)): + dir_path = value[dirTmp] + if not os.path.isdir(dir_path): + err_out_screen( + f"Unable to locate parameter directory: {os.path.abspath(dir_path)}" + ) + self._dScaleParamDirs = value + + def perform_downscaling(self) -> bool: + """Determine whether downscaling of input forcings is necessary based on the downscaling options specified by the user for each input forcing in the configuration file.""" if ( - self.grid_type.lower() != "gridded" - and self.grid_type.lower() != "unstructured" - and self.grid_type.lower() != "hydrofabric" + 1 in self.q2dDownscaleOpt + or 1 in self.swDownscaleOpt + or 1 in self.psfcDownscaleOpt + or 1 in self.t2dDownscaleOpt + or 2 in self.t2dDownscaleOpt ): - err_out_screen( - 'GRID_TYPE in the configuration file only accepts "unstructured", "gridded", or "hydrofabric" as options.' + return True + + @property + def sinalpha_var(self) -> str: + """Get the sine of the grid orientation variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the grid orientation variable specified for each input forcing in the configuration file.""" + if self.perform_downscaling: + return self.extract_input_variable("SINALPHA") + + @property + def cosalpha_var(self) -> str: + """Get the cosine of the grid orientation variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the grid orientation variable specified for each input forcing in the configuration file.""" + if self.perform_downscaling: + return self.extract_input_variable("COSALPHA") + + @property + def slope_var(self) -> str: + """Get the slope variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the slope variable specified for each input forcing in the configuration file.""" + if self.perform_downscaling: + return self.extract_input_variable("SLOPE") + + @property + def slope_azimuth_var(self) -> str: + """Get the slope azimuth variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the slope azimuth variable specified for each input forcing in the configuration file.""" + if self.perform_downscaling: + return self.extract_input_variable("SLOPE_AZIMUTH") + + @property + def slope_var_elem(self) -> str: + """Get the slope variable name specified by the user in the configuration file for element-based grids. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the slope variable specified for each input forcing in the configuration file for element-based grids.""" + if self.perform_downscaling: + if self.grid_type == "unstructured": + return self.extract_input_variable("SLOPE_ELEM") + else: + self.raise_grid_type_error(self.grid_type, "SLOPE_ELEM") + + @property + def slope_azimuth_var_elem(self) -> str: + """Get the slope azimuth variable name specified by the user in the configuration file for element-based grids. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the slope azimuth variable specified for each input forcing in the configuration file for element-based grids.""" + if self.perform_downscaling: + if self.grid_type == "unstructured": + return self.extract_input_variable("SLOPE_AZIMUTH_ELEM") + else: + self.raise_grid_type_error(self.grid_type, "SLOPE_AZIMUTH_ELEM") + + @property + def hgt_elem_var(self) -> str: + """Get the height variable name specified by the user in the configuration file for element-based grids. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the height variable specified for each input forcing in the configuration file for element-based grids.""" + if self.perform_downscaling: + if self.grid_type == "unstructured": + return self.extract_input_variable("HGT_ELEM") + else: + self.raise_grid_type_error(self.grid_type, "HGT_ELEM") + + @property + def hgt_var(self) -> str: + """Get the height variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the height variable specified for each input forcing in the configuration file.""" + if self.perform_downscaling: + return self.extract_input_variable("HGT") + + @property + def t2BiasCorrectOpt(self) -> list: + """Get the list of temperature bias correction options specified by the user in the configuration file. This is used to control how temperature input forcings are bias corrected based on the temperature bias correction option specified for each input forcing in the configuration file.""" + return self._t2BiasCorrectOpt + + @t2BiasCorrectOpt.setter + def t2BiasCorrectOpt(self, value: list) -> None: + """Set the list of temperature bias correction options specified by the user in the configuration file. This is used to control how temperature input forcings are bias corrected based on the temperature bias correction option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("TemperatureBiasCorrection") + if not self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "TemperatureBiasCorrection") + self.check_input_values_in_range( + value, "TemperatureBiasCorrection", [0, 1, 2, 3, 4] ) + self._t2BiasCorrectOpt = value - if self.grid_type.lower() == "gridded": - # Process the geogrid variable information - try: - self.lon_var = cfg_bmi["LONVAR"] - except KeyError as e: - err_out_screen("Unable to locate LONVAR in the configuration file.", e) - except configparser.NoOptionError as e: - err_out_screen("Unable to locate LONVAR in the configuration file.", e) - try: - self.lat_var = cfg_bmi["LATVAR"] - except KeyError as e: - err_out_screen("Unable to locate LATVAR in the configuration file.", e) - except configparser.NoOptionError as e: - err_out_screen("Unable to locate LATVAR in the configuration file.", e) - - elif self.grid_type.lower() == "unstructured": - # Process the geogrid variable information - try: - self.nodecoords_var = cfg_bmi["NodeCoords"] - except KeyError as e: - err_out_screen( - "Unable to locate NodeCoords for unstructured mesh in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate NodeCoords for unstructured mesh in the configuration file.", - e, - ) - try: - self.elemcoords_var = cfg_bmi["ElemCoords"] - except KeyError as e: - err_out_screen( - "Unable to locate ElemCoords for unstructured mesh in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate ElemCoords for unstructured mesh in the configuration file.", - e, - ) - try: - self.elemconn_var = cfg_bmi["ElemConn"] - except KeyError as e: - err_out_screen( - "Unable to locate ElemConn for unstructured mesh in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate ElemConn for unstructured mesh in the configuration file.", - e, - ) - try: - self.numelemconn_var = cfg_bmi["NumElemConn"] - except KeyError as e: - err_out_screen( - "Unable to locate NumElemConn for unstructured mesh in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate NumElemConn for unstructured mesh in the configuration file.", - e, - ) - - elif self.grid_type.lower() == "hydrofabric": - # Process the geogrid variable information - try: - self.nodecoords_var = cfg_bmi["NodeCoords"] - except KeyError as e: - err_out_screen( - "Unable to locate NodeCoords for unstructured mesh in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate NodeCoords for unstructured mesh in the configuration file.", - e, - ) - try: - self.elemcoords_var = cfg_bmi["ElemCoords"] - except KeyError as e: - err_out_screen( - "Unable to locate ElemCoords for unstructured mesh in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate ElemCoords for unstructured mesh in the configuration file.", - e, - ) - try: - self.element_id_var = cfg_bmi["ElemID"] - except KeyError as e: - err_out_screen( - "Unable to locate ElemID for unstructured mesh in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate ElemID for unstructured mesh in the configuration file.", - e, - ) - try: - self.elemconn_var = cfg_bmi["ElemConn"] - except KeyError as e: - err_out_screen( - "Unable to locate ElemConn for unstructured mesh in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate ElemConn for unstructured mesh in the configuration file.", - e, - ) - try: - self.numelemconn_var = cfg_bmi["NumElemConn"] - except KeyError as e: - err_out_screen( - "Unable to locate NumElemConn for unstructured mesh in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate NumElemConn for unstructured mesh in the configuration file.", - e, - ) - - # Process geospatial information - - if self.geogrid: - LOG.debug(f"Geogrid: {self.geogrid}") - else: - try: - self.geogrid = cfg_bmi["GeogridIn"] - except KeyError as e: - err_out_screen( - "Unable to locate GeogridIn in the configuration file.", e - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate GeogridIn in the configuration file.", e - ) - - # Check for the optional geospatial land metadata file. - try: - self.spatial_meta = cfg_bmi["SpatialMetaIn"] - except KeyError as e: - err_out_screen( - "Unable to locate SpatialMetaIn in the configuration file.", e - ) - if len(self.spatial_meta) == 0: - # No spatial metadata file found. - self.spatial_meta = None - else: - if not os.path.isfile(self.spatial_meta): - err_out_screen( - "Unable to locate optional spatial metadata file: " - + self.spatial_meta - ) + @property + def psfcBiasCorrectOpt(self) -> list: + """Get the list of pressure bias correction options specified by the user in the configuration file. This is used to control how pressure input forcings are bias corrected based on the pressure bias correction option specified for each input forcing in the configuration file.""" + return self._psfcBiasCorrectOpt + + @psfcBiasCorrectOpt.setter + def psfcBiasCorrectOpt(self, value: list) -> None: + """Set the list of pressure bias correction options specified by the user in the configuration file. This is used to control how pressure input forcings are bias corrected based on the pressure bias correction option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("PressureBiasCorrection") + if not self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "PressureBiasCorrection") + self.check_input_values_in_range(value, "PressureBiasCorrection", [0, 1]) + self._psfcBiasCorrectOpt = value + @property + def q2BiasCorrectOpt(self): + """Get the list of humidity bias correction options specified by the user in the configuration file. This is used to control how humidity input forcings are bias corrected based on the humidity bias correction option specified for each input forcing in the configuration file.""" + return self._q2BiasCorrectOpt + + @q2BiasCorrectOpt.setter + def q2BiasCorrectOpt(self, value): + """Set the list of humidity bias correction options specified by the user in the configuration file. This is used to control how humidity input forcings are bias corrected based on the humidity bias correction option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("HumidityBiasCorrection") if not self.precip_only_flag: - # Check for the IgnoredBorderWidths - try: - self.ignored_border_widths = cfg_bmi["IgnoredBorderWidths"] - except (KeyError, configparser.NoOptionError): - # if didn't specify, no worries, just set to 0 - self.ignored_border_widths = [0.0] * self.number_inputs - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper IgnoredBorderWidths option specified in the configuration file." - "({} was supplied".format( - cfg_bmi["Geospatial"]["IgnoredBorderWidths"] - ), - e, - ) - if len(self.ignored_border_widths) != self.number_inputs: - err_out_screen( - "Please specify IgnoredBorderWidths values for each " - "corresponding input forcings for SuppForcing." - "({} was supplied".format(self.ignored_border_widths) - ) - if any(map(lambda x: x < 0, self.ignored_border_widths)): - err_out_screen( - "Please specify IgnoredBorderWidths values greater than or equal to zero:" - "({} was supplied".format(self.ignored_border_widths) - ) + self.check_number_of_inputs_forcings(value, "HumidityBiasCorrection") + self.check_input_values_in_range(value, "HumidityBiasCorrection", [0, 1, 2]) + self._q2BiasCorrectOpt = value + @property + def windBiasCorrect(self): + """Get the list of wind bias correction options specified by the user in the configuration file. This is used to control how wind input forcings are bias corrected based on the wind bias correction option specified for each input forcing in the configuration file.""" + return self._windBiasCorrect + + @windBiasCorrect.setter + def windBiasCorrect(self, value): + """Set the list of wind bias correction options specified by the user in the configuration file. This is used to control how wind input forcings are bias corrected based on the wind bias correction option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("WindBiasCorrection") if not self.precip_only_flag: - # Process regridding options. - try: - self.regrid_opt = cfg_bmi["RegridOpt"] - except KeyError as e: - err_out_screen( - "Unable to locate RegridOpt under the Regridding section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate RegridOpt under the Regridding section in the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper RegridOpt options specified in the configuration file.", e - ) - if len(self.regrid_opt) != self.number_inputs: - err_out_screen( - "Please specify RegridOpt values for each corresponding input forcings in the configuration file.", - e, - ) - # Check to make sure regridding options makes sense. - for regridOpt in self.regrid_opt: - if regridOpt < 1 or regridOpt > 3: - err_out_screen( - "Invalid RegridOpt chosen in the configuration file. Please choose a " - "value of 1-2 for each corresponding input forcing." - ) - try: - # Read weight file directory (optional) - self.weightsDir = cfg_bmi["RegridWeightsDir"] - except Exception: - # Set wieghtsDir to None; this will create regrid object in memory - self.weightsDir = None - if self.weightsDir: - # if we do have one specified, make sure it exists - if not os.path.exists(self.weightsDir): - err_out_screen( - "ESMF Weights file directory specified ({}) but does not exist" - ).format(self.weightsDir) + self.check_number_of_inputs_forcings(value, "WindBiasCorrection") + self.check_input_values_in_range(value, "WindBiasCorrection", [0, 4]) + self._windBiasCorrect = value - # Calculate the beginning/ending processing dates if we are running realtime - if self.realtime_flag: - calculate_lookback_window(self) - - # Create temporary array to hold flags if we need input parameter files. - param_flag = np.empty([len(self.input_forcings)], int) - param_flag[:] = 0 + @property + def swBiasCorrectOpt(self) -> list: + """Get the list of shortwave radiation bias correction options specified by the user in the configuration file. This is used to control how shortwave radiation input forcings are bias corrected based on the shortwave radiation bias correction option specified for each input forcing in the configuration file.""" + return self._swBiasCorrectOpt + + @swBiasCorrectOpt.setter + def swBiasCorrectOpt(self, value: list) -> None: + """Set the list of shortwave radiation bias correction options specified by the user in the configuration file. This is used to control how shortwave radiation input forcings are bias corrected based on the shortwave radiation bias correction option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("ShortwaveBiasCorrection") if not self.precip_only_flag: - # Read in temporal interpolation options. - try: - self.forceTemoralInterp = cfg_bmi["ForcingTemporalInterpolation"] - except KeyError as e: - err_out_screen( - "Unable to locate ForcingTemporalInterpolation under the Interpolation section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate ForcingTemporalInterpolation under the Interpolation section in the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper ForcingTemporalInterpolation options specified in the configuration file.", - e, - ) - if len(self.forceTemoralInterp) != self.number_inputs: - err_out_screen( - "Please specify ForcingTemporalInterpolation values for each corresponding input forcings in the configuration file." - ) - # Ensure the forcingTemporalInterpolation values make sense. - for temporalInterpOpt in self.forceTemoralInterp: - if temporalInterpOpt < 0 or temporalInterpOpt > 2: - err_out_screen( - "Invalid ForcingTemporalInterpolation chosen in the configuration file. " - "Please choose a value of 0-2 for each corresponding input forcing." - ) - - # Read in the temperature downscaling options. - try: - self.t2dDownscaleOpt = cfg_bmi["TemperatureDownscaling"] - except KeyError as e: - err_out_screen( - "Unable to locate TemperatureDownscaling under the Downscaling section of the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate TemperatureDownscaling under the Downscaling section of the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper TemperatureDownscaling options specified in the configuration file.", - e, - ) - if len(self.t2dDownscaleOpt) != self.number_inputs: - err_out_screen( - "Please specify TemperatureDownscaling values for each corresponding input forcings in the configuration file." - ) - # Ensure the downscaling options chosen make sense. - count_tmp = 0 - for optTmp in self.t2dDownscaleOpt: - if optTmp < 0 or optTmp > 2: - err_out_screen( - "Invalid TemperatureDownscaling options specified in the configuration file." - ) - if optTmp == 2: - param_flag[count_tmp] = 1 - count_tmp = count_tmp + 1 - - # Read in the pressure downscaling options. - try: - self.psfcDownscaleOpt = cfg_bmi["PressureDownscaling"] - except KeyError as e: - err_out_screen( - "Unable to locate PressureDownscaling under the Downscaling section of the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate PressureDownscaling under the Downscaling section of the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper PressureDownscaling options specified in the configuration file." - ) - if len(self.psfcDownscaleOpt) != self.number_inputs: - err_out_screen( - "Please specify PressureDownscaling values for each corresponding input forcings in the configuration file." - ) - # Ensure the downscaling options chosen make sense. - for optTmp in self.psfcDownscaleOpt: - if optTmp < 0 or optTmp > 1: - err_out_screen( - "Invalid PressureDownscaling options specified in the configuration file." - ) - - # Read in the shortwave downscaling options - try: - self.swDownscaleOpt = cfg_bmi["ShortwaveDownscaling"] - except KeyError as e: - err_out_screen( - "Unable to locate ShortwaveDownscaling under the Downscaling section of the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate ShortwaveDownscaling under the Downscaling section of the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper ShortwaveDownscaling options specified in the configuration file.", - e, - ) - if len(self.swDownscaleOpt) != self.number_inputs: - err_out_screen( - "Please specify ShortwaveDownscaling values for each corresponding input forcings in the configuration file." - ) - # Ensure the downscaling options chosen make sense. - for optTmp in self.swDownscaleOpt: - if optTmp < 0 or optTmp > 1: - err_out_screen( - "Invalid ShortwaveDownscaling options specified in the configuration file." - ) - - # Read in humidity downscaling options. - try: - self.q2dDownscaleOpt = cfg_bmi["HumidityDownscaling"] - except KeyError as e: - err_out_screen( - "Unable to locate HumidityDownscaling under the Downscaling section of the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate HumidityDownscaling under the Downscaling section of the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper HumidityDownscaling options specified in the configuration file.", - e, - ) - if len(self.q2dDownscaleOpt) != self.number_inputs: - err_out_screen( - "Please specify HumidityDownscaling values for each corresponding " - "input forcings in the configuration file." - ) - # Ensure the downscaling options chosen make sense. - for optTmp in self.q2dDownscaleOpt: - if optTmp < 0 or optTmp > 1: - err_out_screen( - "Invalid HumidityDownscaling options specified in the configuration file." - ) - - # Read in the precipitation downscaling options - try: - self.precipDownscaleOpt = cfg_bmi["PrecipDownscaling"] - except KeyError as e: - err_out_screen( - "Unable to locate PrecipDownscaling under the Downscaling section of the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate PrecipDownscaling under the Downscaling section of the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper PrecipDownscaling options specified in the configuration file.", - e, + self.check_number_of_inputs_forcings(value, "ShortwaveBiasCorrection") + self.check_input_values_in_range( + value, "ShortwaveBiasCorrection", [0, 1, 2] ) - if not self.precip_only_flag: - if len(self.precipDownscaleOpt) != self.number_inputs: - err_out_screen( - "Please specify PrecipDownscaling values for each corresponding " - "input forcings in the configuration file." - ) - # Ensure the downscaling options chosen make sense. - count_tmp = 0 - for optTmp in self.precipDownscaleOpt: - if optTmp < 0 or optTmp > 1: - err_out_screen( - "Invalid PrecipDownscaling options specified in the configuration file." - ) - if optTmp == 1: - param_flag[count_tmp] = 1 - count_tmp = count_tmp + 1 + self._swBiasCorrectOpt = value - # Read in the downscaling parameter directory. - try: - self.dScaleParamDirs = cfg_bmi["DownscalingParamDirs"] - except KeyError as e: - err_out_screen( - "Unable to locate DownscalingParamDirs in the configuration file.", e - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate DownscalingParamDirs in the configuration file.", e - ) - if len(self.dScaleParamDirs) != len(self.input_forcings): - err_out_screen( - "Please specify a downscaling parameter directory for each " - "corresponding downscaling option that requires one." + @property + def lwBiasCorrectOpt(self) -> list: + """Get the list of longwave radiation bias correction options specified by the user in the configuration file. This is used to control how longwave radiation input forcings are bias corrected based on the longwave radiation bias correction option specified for each input forcing in the configuration file.""" + return self._lwBiasCorrectOpt + + @lwBiasCorrectOpt.setter + def lwBiasCorrectOpt(self, value: list) -> None: + """Set the list of longwave radiation bias correction options specified by the user in the configuration file. This is used to control how longwave radiation input forcings are bias corrected based on the longwave radiation bias correction option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("LongwaveBiasCorrection") + if not self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "LongwaveBiasCorrection") + self.check_input_values_in_range( + value, "LongwaveBiasCorrection", [0, 1, 2, 4] ) - # Loop through each downscaling parameter directory and make sure they exist. - for dirTmp in range(0, len(self.dScaleParamDirs)): - if not os.path.isdir(self.dScaleParamDirs[dirTmp]): - err_out_screen( - "Unable to locate parameter directory: " - + os.path.abspath(self.dScaleParamDirs[dirTmp]) - ) + self._lwBiasCorrectOpt = value - if ( - [1] in self.q2dDownscaleOpt - or [1] in self.swDownscaleOpt - or [1] in self.psfcDownscaleOpt - or [1, 2] in self.t2dDownscaleOpt - ): - # Process the geogrid information for downscaling - try: - self.sinalpha_var = cfg_bmi["SINALPHA"] - except Exception: - self.sinalpha_var = None - try: - self.cosalpha_var = cfg_bmi["COSALPHA"] - except Exception: - self.cosalpha_var = None - if self.grid_type.lower() == "hydrofabric": - try: - self.slope_var = cfg_bmi["SLOPE"] - except KeyError as e: - err_out_screen( - "Unable to locate SLOPE variable in the hydrofabric configuration file. Required variable since user turned on a downscaling option.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate SLOPE variable in the hydrofabric configuration file. Required variable since user turned on a downscaling option.", - e, - ) - try: - self.slope_azimuth_var = cfg_bmi["SLOPE_AZIMUTH"] - except KeyError as e: - err_out_screen( - "Unable to locate SLOPE_AZIMUTH variable in the hydrofabric configuration file. Required variable since user turned on a downscaling option.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate SLOPE_AZIMUTH variable in the hydrofabric configuration file. Required variable since user turned on a downscaling option.", - e, - ) - else: - try: - self.slope_var = cfg_bmi["SLOPE"] - except Exception: - self.slope_var = None - try: - self.slope_azimuth_var = cfg_bmi["SLOPE_AZIMUTH"] - except Exception: - self.slope_azimuth_var = None - if self.grid_type.lower() == "unstructured": - try: - self.slope_var_elem = cfg_bmi["SLOPE_ELEM"] - except Exception: - self.slope_var_elem = None - try: - self.slope_azimuth_var_elem = cfg_bmi["SLOPE_AZIMUTH_ELEM"] - except Exception: - self.slope_azimuth_var_elem = None - - if self.grid_type.lower() == "unstructured": - try: - self.hgt_elem_var = cfg_bmi["HGTVAR_ELEM"] - except KeyError as e: - err_out_screen( - "Unable to locate HGTVAR_ELEM in the configuration file. Required variable since user turned on a downscaling option.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate HGTVAR_ELEM in the configuration file. Required variable since user turned on a downscaling option.", - e, - ) - - try: - self.hgt_var = cfg_bmi["HGTVAR"] - except KeyError as e: - err_out_screen( - "Unable to locate HGTVAR in the configuration file. Required variable since user turned on a downscaling option.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate HGTVAR in the configuration file. Required variable since user turned on a downscaling option.", - e, - ) - - # * Bias Correction Options * + @property + def precipBiasCorrectOpt(self): + """Get the list of precipitation bias correction options specified by the user in the configuration file. This is used to control how precipitation input forcings are bias corrected based on the precipitation bias correction option specified for each input forcing in the configuration file.""" + return self._precipBiasCorrectOpt + + @precipBiasCorrectOpt.setter + def precipBiasCorrectOpt(self, value): + """Set the list of precipitation bias correction options specified by the user in the configuration file. This is used to control how precipitation input forcings are bias corrected based on the precipitation bias correction option specified for each input forcing in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("PrecipBiasCorrection") if not self.precip_only_flag: - # Read in temperature bias correction options - try: - self.t2BiasCorrectOpt = cfg_bmi["TemperatureBiasCorrection"] - except KeyError as e: - err_out_screen( - "Unable to locate TemperatureBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate TemperatureBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except json.JSONDecodeError as e: - err_out_screen( - "Improper TemperatureBiasCorrection options specified in the configuration file.", - e, - ) - if len(self.t2BiasCorrectOpt) != self.number_inputs: - err_out_screen( - "Please specify TemperatureBiasCorrection values for each corresponding input forcings in the configuration file." - ) - # Ensure the bias correction options chosen make sense. - for optTmp in self.t2BiasCorrectOpt: - if optTmp < 0 or optTmp > 4: - err_out_screen( - "Invalid TemperatureBiasCorrection options specified in the configuration file." - ) - - # Read in surface pressure bias correction options. - try: - self.psfcBiasCorrectOpt = cfg_bmi["PressureBiasCorrection"] - except KeyError as e: - err_out_screen( - "Unable to locate PressureBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate PressureBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except json.JSONDecodeError as e: - err_out_screen( - "Improper PressureBiasCorrection options specified in the configuration file.", - e, - ) - if len(self.psfcDownscaleOpt) != self.number_inputs: - err_out_screen( - "Please specify PressureBiasCorrection values for each corresponding input forcings in the configuration file." - ) - # Ensure the bias correction options chosen make sense. - for optTmp in self.psfcBiasCorrectOpt: - if optTmp < 0 or optTmp > 1: - err_out_screen( - "Invalid PressureBiasCorrection options specified in the configuration file." - ) - if optTmp == 1: - # We are running NWM-Specific bias-correction of CFSv2 that needs to take place prior to regridding. - self.runCfsNldasBiasCorrect = True + self.check_number_of_inputs_forcings(value, "PrecipBiasCorrection") + self.check_input_values_in_range(value, "PrecipBiasCorrection", [0, 1]) + self._precipBiasCorrectOpt = value - # Read in humidity bias correction options. - try: - self.q2BiasCorrectOpt = cfg_bmi["HumidityBiasCorrection"] - except KeyError as e: - err_out_screen( - "Unable to locate HumidityBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate HumidityBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except json.JSONDecodeError as e: - err_out_screen( - "Improper HumdityBiasCorrection options specified in the configuration file.", - e, - ) - if len(self.q2BiasCorrectOpt) != self.number_inputs: - err_out_screen( - "Please specify HumidityBiasCorrection values for each corresponding input forcings in the configuration file." - ) - # Ensure the bias correction options chosen make sense. - for optTmp in self.q2BiasCorrectOpt: - if optTmp < 0 or optTmp > 2: - err_out_screen( - "Invalid HumidityBiasCorrection options specified in the configuration file." - ) - if optTmp == 1: - # We are running NWM-Specific bias-correction of CFSv2 that needs to take place prior to regridding. - self.runCfsNldasBiasCorrect = True - - # Read in wind bias correction options. - try: - self.windBiasCorrect = cfg_bmi["WindBiasCorrection"] - except KeyError as e: - err_out_screen( - "Unable to locate WindBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate WindBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except json.JSONDecodeError as e: - err_out_screen( - "Improper WindBiasCorrection options specified in the configuration file.", - e, - ) - if len(self.windBiasCorrect) != self.number_inputs: - err_out_screen( - "Please specify WindBiasCorrection values for each corresponding input forcings in the configuration file." - ) - # Ensure the bias correction options chosen make sense. - for optTmp in self.windBiasCorrect: - if optTmp < 0 or optTmp > 4: - err_out_screen( - "Invalid WindBiasCorrection options specified in the configuration file." - ) - if optTmp == 1: - # We are running NWM-Specific bias-correction of CFSv2 that needs to take place prior to regridding. - self.runCfsNldasBiasCorrect = True - - # Read in shortwave radiation bias correction options. - try: - self.swBiasCorrectOpt = cfg_bmi["SwBiasCorrection"] - except KeyError as e: - err_out_screen( - "Unable to locate SwBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate SwBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except json.JSONDecodeError as e: - err_out_screen( - "Improper SwBiasCorrection options specified in the configuration file.", - e, - ) - if len(self.swBiasCorrectOpt) != self.number_inputs: - err_out_screen( - "Please specify SwBiasCorrection values for each corresponding input forcings in the configuration file." - ) - # Ensure the bias correction options chosen make sense. - for optTmp in self.swBiasCorrectOpt: - if optTmp < 0 or optTmp > 2: - err_out_screen( - "Invalid SwBiasCorrection options specified in the configuration file." - ) - if optTmp == 1: - # We are running NWM-Specific bias-correction of CFSv2 that needs to take place prior to regridding. - self.runCfsNldasBiasCorrect = True - - # Read in longwave radiation bias correction options. - try: - self.lwBiasCorrectOpt = cfg_bmi["LwBiasCorrection"] - except KeyError as e: - err_out_screen( - "Unable to locate LwBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate LwBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except json.JSONDecodeError as e: - err_out_screen( - "Improper LwBiasCorrection options specified in the configuration file.", - e, - ) - if len(self.lwBiasCorrectOpt) != self.number_inputs: - err_out_screen( - "Please specify LwBiasCorrection values for each corresponding input forcings in the configuration file." - ) - # Ensure the bias correction options chosen make sense. - for optTmp in self.lwBiasCorrectOpt: - if optTmp < 0 or optTmp > 4: - err_out_screen( - "Invalid LwBiasCorrection options specified in the configuration file." - ) - if optTmp == 1: - # We are running NWM-Specific bias-correction of CFSv2 that needs to take place prior to regridding. - self.runCfsNldasBiasCorrect = True + @property + def bias_correction_properties(self) -> dict: + """Get the dictionary of bias correction properties specified by the user in the configuration file. This is used to control how input forcings are bias corrected based on the bias correction options specified for each input forcing in the configuration file.""" + bias_correction_properties = { + "surface temperature": self.t2BiasCorrectOpt, + "surface pressure": self.psfcBiasCorrectOpt, + "specific humidity": self.q2BiasCorrectOpt, + "wind forcings": self.windBiasCorrect, + "short-wave radiation": self.swBiasCorrectOpt, + "long-wave radiation": self.lwBiasCorrectOpt, + "Precipitation": self.precipBiasCorrectOpt, + } + return bias_correction_properties - # Read in precipitation bias correction options. - try: - self.precipBiasCorrectOpt = cfg_bmi["PrecipBiasCorrection"] - except KeyError as e: - err_out_screen( - "Unable to locate PrecipBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate PrecipBiasCorrection under the BiasCorrection section of the configuration file.", - e, - ) - except json.JSONDecodeError as e: - err_out_screen( - "Improper PrecipBiasCorrection options specified in the configuration file.", - e, - ) - if not self.precip_only_flag: - if len(self.precipBiasCorrectOpt) != self.number_inputs: - err_out_screen( - "Please specify PrecipBiasCorrection values for each corresponding input forcings in the configuration file." - ) - # Ensure the bias correction options chosen make sense. - for optTmp in self.precipBiasCorrectOpt: - if optTmp < 0 or optTmp > 1: - err_out_screen( - "Invalid PrecipBiasCorrection options specified in the configuration file." - ) - if optTmp == 1: - # We are running NWM-Specific bias-correction of CFSv2 that needs to take place prior to regridding. - self.runCfsNldasBiasCorrect = True - - # Putting a constraint here that CFSv2-NLDAS bias correction (NWM only) is chosen, it must be turned on - # for ALL variables. - if self.runCfsNldasBiasCorrect: - if ( - min(self.precipBiasCorrectOpt) != 1 - and max(self.precipBiasCorrectOpt) != 1 - ): - err_out_screen( - "CFSv2-NLDAS NWM bias correction must be activated for Precipitation under this configuration." - ) - if min(self.lwBiasCorrectOpt) != 1 and max(self.lwBiasCorrectOpt) != 1: - err_out_screen( - "CFSv2-NLDAS NWM bias correction must be activated for long-wave radiation under this configuration." - ) - if min(self.swBiasCorrectOpt) != 1 and max(self.swBiasCorrectOpt) != 1: - err_out_screen( - "CFSv2-NLDAS NWM bias correction must be activated for short-wave radiation under this configuration." - ) - if min(self.t2BiasCorrectOpt) != 1 and max(self.t2BiasCorrectOpt) != 1: - err_out_screen( - "CFSv2-NLDAS NWM bias correction must be activated for surface temperature under this configuration." - ) - if min(self.windBiasCorrect) != 1 and max(self.windBiasCorrect) != 1: - err_out_screen( - "CFSv2-NLDAS NWM bias correction must be activated for wind forcings under this configuration." - ) - if min(self.q2BiasCorrectOpt) != 1 and max(self.q2BiasCorrectOpt) != 1: - err_out_screen( - "CFSv2-NLDAS NWM bias correction must be activated for specific humidity under this configuration." - ) - if ( - min(self.psfcBiasCorrectOpt) != 1 - and max(self.psfcBiasCorrectOpt) != 1 - ): + @property + def runCfsNldasBiasCorrect(self) -> bool: + """Get the flag for whether to run the NWM-specific bias correction of CFSv2 input forcings specified by the user in the configuration file. This is used to control whether the NWM-specific bias correction of CFSv2 input forcings is run based on whether the user has chosen to run this bias correction in the configuration file.""" + for optTmp in self.bias_correction_properties.values(): + if optTmp == 1: + runCfsNldasBiasCorrect = True + break + if runCfsNldasBiasCorrect: + for ( + bias_correct_name, + bias_correct, + ) in self.bias_correction_properties.items(): + if min(bias_correct) != 1 and max(bias_correct) != 1: err_out_screen( - "CFSv2-NLDAS NWM bias correction must be activated for surface pressure under this configuration." + f"CFSv2-NLDAS NWM bias correction must be activated for {bias_correct_name} under this configuration." ) # Make sure we don't have any other forcings activated. This can only be ran for CFSv2. for opt_tmp in self.input_forcings: @@ -1701,168 +1044,229 @@ def validate_config(self, cfg_bmi: dict) -> None: "CFSv2-NLDAS NWM bias correction can only be used in CFSv2-only configurations" ) - # Read in supplemental precipitation options as an array of values to map. - try: - self.supp_precip_forcings = cfg_bmi["SuppPcp"] - except KeyError as e: - err_out_screen( - "Unable to locate SuppPcp under SuppForcing section in configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate SuppPcp under SuppForcing section in configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen("Improper SuppPcp option specified in configuration file", e) - self.number_supp_pcp = len(self.supp_precip_forcings) + def number_supp_pcp(self) -> int: + """Get the number of supplemental precipitation input forcings specified by the user in the configuration file. This is used to control how many supplemental precipitation input forcings are processed based on the number of supplemental precipitation input forcings specified in the configuration file.""" + return len(self.supp_precip_forcings) - # Read in the supp pcp types (GRIB[1|2], NETCDF) - try: - self.supp_precip_file_types = cfg_bmi["SuppPcpForcingTypes"] - self.supp_precip_file_types = [ - stype.strip() for stype in self.supp_precip_file_types - ] - if self.supp_precip_file_types == [""]: - self.supp_precip_file_types = [] - except KeyError as e: - err_out_screen( - "Unable to locate SuppPcpForcingTypes in SuppForcing section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate SuppPcpForcingTypes in SuppForcing section in the configuration file.", - e, - ) - if len(self.supp_precip_file_types) != self.number_supp_pcp: - err_out_screen( - "Number of SuppPcpForcingTypes ({}) must match the number " - "of SuppPcp inputs ({}) in the configuration file.".format( - len(self.supp_precip_file_types), self.number_supp_pcp - ) - ) - for file_type in self.supp_precip_file_types: - if file_type not in ["GRIB1", "GRIB2", "NETCDF"]: - err_out_screen( - 'Invalid SuppForcing file type "{}" specified. ' - "Only GRIB1, GRIB2, and NETCDF are supported".format(file_type) - ) + @property + def supp_precip_file_types(self) -> list: + """Get the list of supplemental precipitation input forcing file types specified by the user in the configuration file. This is used to control how supplemental precipitation input forcing files are read in and processed based on the file types specified for each supplemental precipitation input forcing in the configuration file.""" + return self._supp_precip_file_types + + @supp_precip_file_types.setter + def supp_precip_file_types(self, value: list) -> None: + """Set the list of supplemental precipitation input forcing file types specified by the user in the configuration file. This is used to control how supplemental precipitation input forcing files are read in and processed based on the file types specified for each supplemental precipitation input forcing in the configuration file.""" + if value is None: + value = self.try_config_get("SuppPcpForcingTypes") + if value is not None: + value = [stype.strip() for stype in value] + if value == [""]: + value = [] + + self.check_number_of_inputs_supp_pcp(value, "SuppPcpForcingTypes") + self.check_input_values_in_range( + value, + "SuppPcpForcingTypes", + self.supplemental_precip_file_type_options, + ) + self._supp_precip_file_types = value + @property + def supplemental_precip_file_type_options(self) -> list: + """Get the list of valid supplemental precipitation input forcing file types that can be specified by the user in the configuration file. This is used to control how supplemental precipitation input forcing files are read in and processed based on the file types specified for each supplemental precipitation input forcing in the configuration file.""" + return ["GRIB1", "GRIB2", "NETCDF"] + + @property + def rqiMethod(self) -> list: + """Get the list of radar quality index (RQI) thresholding methods specified by the user in the configuration file. This is used to control how radar-based supplemental precipitation input forcings are processed based on the RQI thresholding method specified for each radar-based supplemental precipitation input forcing in the configuration file.""" if self.number_supp_pcp > 0: - # Check to make sure supplemental precip options make sense. Also read in the RQI threshold - # if any radar products where chosen. for suppOpt in self.supp_precip_forcings: - if suppOpt < 0 or suppOpt > 16: - err_out_screen( - "Please specify SuppForcing values between 1 and 16." - ) - # Read in RQI threshold to apply to radar products. - if suppOpt in (1, 2, 7, 10, 11, 12): - try: - self.rqiMethod = cfg_bmi["RqiMethod"] - except KeyError as e: - err_out_screen( - "Unable to locate RqiMethod under SuppForcing section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate RqiMethod under SuppForcing section in the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper RqiMethod option in the configuration file.", e - ) + # Read in RQI threshold to apply to radar products. + if suppOpt in (1, 2, 7, 10, 11, 12): + rqiMethod = self.extract_input_variable("RqiMethod") # Check that if we have more than one RqiMethod, it's the correct number - if type(self.rqiMethod) is list: - if len(self.rqiMethod) != self.number_supp_pcp: - err_out_screen( - "Number of RqiMethods ({}) must match the number " - "of SuppPcp inputs ({}) in the configuration file, or " - "supply a single method for all inputs".format( - len(self.rqiMethod), self.number_supp_pcp - ) - ) - elif type(self.rqiMethod) is int: + if type(rqiMethod) is list: + self.check_number_of_inputs_supp_pcp(rqiMethod, "RqiMethod") + elif type(rqiMethod) is int: # Support 'classic' mode of single method - self.rqiMethod = [self.rqiMethod] * self.number_supp_pcp + rqiMethod = [rqiMethod] * self.number_supp_pcp # Make sure the RqiMethod(s) makes sense. - for method in self.rqiMethod: - if method < 0 or method > 2: - err_out_screen( - "Please specify RqiMethods of either 0, 1, or 2." - ) + for method in rqiMethod: + self.check_input_values_in_range(method, "RqiMethod", [0, 1, 2]) + return rqiMethod - try: - self.rqiThresh = cfg_bmi["RqiThreshold"] - except KeyError as e: - err_out_screen( - "Unable to locate RqiThreshold under SuppForcing section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate RqiThreshold under SuppForcing section in the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper RqiThreshold option in the configuration file.", e - ) + @property + def rqiThresh(self): + """Get the radar quality index (RQI) threshold value specified by the user in the configuration file. This is used to control how radar-based supplemental precipitation input forcings are processed based on the RQI threshold value specified in the configuration file.""" + if self.number_supp_pcp > 0: + for suppOpt in self.supp_precip_forcings: + # Read in RQI threshold to apply to radar products. + if suppOpt in (1, 2, 7, 10, 11, 12): + rqiThresh = self.extract_input_variable("RqiThresh") - # Check that if we have more than one RqiThreshold, it's the correct number - if type(self.rqiThresh) is list: - if len(self.rqiThresh) != self.number_supp_pcp: - err_out_screen( - "Number of RqiThresholds ({}) must match the number " - "of SuppPcp inputs ({}) in the configuration file, or " - "supply a single threshold for all inputs".format( - len(self.rqiThresh), self.number_supp_pcp - ) - ) - elif type(self.rqiThresh) is float: + # Check that if we have more than one RqiThresh, it's the correct number + if type(rqiThresh) is list: + self.check_number_of_inputs_supp_pcp(rqiThresh, "RqiThresh") + elif type(rqiThresh) is (int, float): # Support 'classic' mode of single threshold - self.rqiThresh = [self.rqiThresh] * self.number_supp_pcp + rqiThresh = [rqiThresh] * self.number_supp_pcp - # Make sure the RQI threshold makes sense. + # Make sure the RqiThresh(es) makes sense. for threshold in self.rqiThresh: if threshold < 0.0 or threshold > 1.0: err_out_screen( "Please specify RqiThresholds between 0.0 and 1.0." ) + return threshold - # Read in the input directories for each supplemental precipitation product. - try: - self.supp_precip_dirs = cfg_bmi["SuppPcpDirectories"] - except KeyError as e: - err_out_screen( - "Unable to locate SuppPcpDirectories in SuppForcing section in the configuration file.", - e, + @property + def supp_precip_dirs(self): + """Get the list of pathways to the supplemental precipitation input forcing directories specified by the user in the configuration file. This is used to control where the program looks for supplemental precipitation input forcing files for each supplemental precipitation input forcing based on the directory specified for each supplemental precipitation input forcing in the configuration file.""" + if self.number_supp_pcp > 0: + return self._supp_precip_dirs + + @supp_precip_dirs.setter + def supp_precip_dirs(self, value): + """Set the list of pathways to the supplemental precipitation input forcing directories specified by the user in the configuration file. This is used to control where the program looks for supplemental precipitation input forcing files for each supplemental precipitation input forcing based on the directory specified for each supplemental precipitation input forcing in the configuration file.""" + if value is None and self.number_supp_pcp > 0: + value = self.extract_input_variable("SuppPcpDirectories") + if value > 0: + self.check_number_of_inputs_supp_pcp(value, "SuppPcpDirectories") + for dirTmp in range(0, len(value)): + value[dirTmp] = value[dirTmp].strip() + if not os.path.isdir(value[dirTmp]): + try: + os.makedirs(value[dirTmp], exist_ok=True) + LOG.debug(f"Created supp pcp directory: {value[dirTmp]}") + except OSError as e: + err_out_screen( + f"Unable to create supp pcp directory: {value[dirTmp]}. Error: {e}" + ) + self._supp_precip_dirs = value + + @property + def supp_precip_mandatory(self): + """Get the list of flags for whether each supplemental precipitation input forcing specified by the user in the configuration file is mandatory or optional. This is used to control whether an error is raised if supplemental precipitation input forcing files are not found for each supplemental precipitation input forcing based on whether the user has specified each supplemental precipitation input forcing as mandatory or optional in the configuration file.""" + return self._supp_precip_mandatory + + @supp_precip_mandatory.setter + def supp_precip_mandatory(self, value): + """Set the list of flags for whether each supplemental precipitation input forcing specified by the user in the configuration file is mandatory or optional. This is used to control whether an error is raised if supplemental precipitation input forcing files are not found for each supplemental precipitation input forcing based on whether the user has specified each supplemental precipitation input forcing as mandatory or optional in the configuration file.""" + if value is None and self.number_supp_pcp > 0: + value = self.extract_input_variable("SuppPcpMandatory") + if self.number_supp_pcp > 0: + for enforceOpt in value: + self.check_input_values_in_range(enforceOpt, "SuppPcpMandatory", [0, 1]) + self._supp_precip_mandatory = value + + @property + def regrid_opt_supp_pcp(self): + """Get the list of regridding options for supplemental precipitation input forcings specified by the user in the configuration file. This is used to control how supplemental precipitation input forcings are regridded based on the regridding option specified for each supplemental precipitation input forcing in the configuration file.""" + return self._regrid_opt_supp_pcp + + @regrid_opt_supp_pcp.setter + def regrid_opt_supp_pcp(self, value): + """Set the list of regridding options for supplemental precipitation input forcings specified by the user in the configuration file. This is used to control how supplemental precipitation input forcings are regridded based on the regridding option specified for each supplemental precipitation input forcing in the configuration file.""" + if value is None and self.number_supp_pcp > 0: + value = self.extract_input_variable("RegridOptSuppPcp") + if self.number_supp_pcp > 0: + for optTmp in value: + self.check_input_values_in_range(optTmp, "RegridOptSuppPcp", [1, 2, 3]) + self._regrid_opt_supp_pcp = value + + @property + def suppTemporalInterp(self): + """Get the list of flags for whether temporal interpolation of supplemental precipitation input forcings specified by the user in the configuration file is performed or not. This is used to control whether temporal interpolation of supplemental precipitation input forcings is performed based on whether the user has chosen to perform temporal interpolation for each supplemental precipitation input forcing in the configuration file.""" + if self.number_supp_pcp > 0: + return self._suppTemporalInterp + + @suppTemporalInterp.setter + def suppTemporalInterp(self, value): + """Set the list of flags for whether temporal interpolation of supplemental precipitation input forcings specified by the user in the configuration file is performed or not. This is used to control whether temporal interpolation of supplemental precipitation input forcings is performed based on whether the user has chosen to perform temporal interpolation for each supplemental precipitation input forcing in the configuration file.""" + if value is None and self.number_supp_pcp > 0: + value = self.extract_input_variable("SuppPcpTemporalInterpolation") + if self.number_supp_pcp > 0: + for optTmp in value: + self.check_input_values_in_range( + optTmp, "SuppPcpTemporalInterpolation", [0, 1, 2] ) - except configparser.NoOptionError as e: + self._suppTemporalInterp = value + + @property + def supp_pcp_max_hours(self): + """Get the list of maximum forecast hours for supplemental precipitation input forcings specified by the user in the configuration file. This is used to control how supplemental precipitation input forcings are processed based on the maximum forecast hour specified for each supplemental precipitation input forcing in the configuration file.""" + if self.number_supp_pcp > 0: + return self._supp_pcp_max_hours + + @supp_pcp_max_hours.setter + def supp_pcp_max_hours(self, value): + """Set the list of maximum forecast hours for supplemental precipitation input forcings specified by the user in the configuration file. This is used to control how supplemental precipitation input forcings are processed based on the maximum forecast hour specified for each supplemental precipitation input forcing in the configuration file.""" + if value is None and self.number_supp_pcp > 0: + value = self.extract_input_variable("SuppPcpMaxHours") + if self.number_supp_pcp > 0: + if isinstance(value, list): + self.check_input_values_positive(value, "SuppPcpMaxHours") + elif isinstance(value, float) or isinstance(value, int): + self.check_input_values_positive(value, "SuppPcpMaxHours") + value = [value] * self.number_supp_pcp + self._supp_pcp_max_hours = value + + @property + def supp_input_offsets(self): + """Get the list of time offsets to apply to supplemental precipitation input forcing files specified by the user in the configuration file. This is used to control how supplemental precipitation input forcing files are processed based on the time offset specified for each supplemental precipitation input forcing in the configuration file.""" + return self._supp_input_offsets + + @supp_input_offsets.setter + def supp_input_offsets(self, value): + """Set the list of time offsets to apply to supplemental precipitation input forcing files specified by the user in the configuration file. This is used to control how supplemental precipitation input forcing files are processed based on the time offset specified for each supplemental precipitation input forcing in the configuration file.""" + if value is None and self.number_supp_pcp > 0: + value = self.extract_input_variable("SuppPcpInputOffsets") + if self.number_supp_pcp > 0: + self.check_number_of_inputs_supp_pcp(value, "SuppPcpInputOffsets") + + @property + def supp_precip_param_dir(self): + """Get the directory where downscaling parameters for supplemental precipitation input forcings are stored specified by the user in the configuration file. This is used to control where the program looks for downscaling parameter files for supplemental precipitation input forcings based on the directory specified for supplemental precipitation input forcings in the configuration file.""" + if self.number_supp_pcp > 0: + return self._supp_precip_param_dir + + @supp_precip_param_dir.setter + def supp_precip_param_dir(self, value): + """Set the directory where downscaling parameters for supplemental precipitation input forcings are stored specified by the user in the configuration file. This is used to control where the program looks for downscaling parameter files for supplemental precipitation input forcings based on the directory specified for supplemental precipitation input forcings in the configuration file.""" + if value is None and self.number_supp_pcp > 0: + value = self.extract_input_variable("SuppPcpDownscalingParamDir") + if self.number_supp_pcp > 0: + if not os.path.isdir(value): err_out_screen( - "Unable to locate SuppPcpDirectories in SuppForcing section in the configuration file.", - e, + f"Unable to locate parameter directory: {os.path.abspath(value)}" ) + self._supp_precip_param_dir = value + + @property + def supp_precip_dirs(self): + """Get the list of pathways to the supplemental precipitation input forcing directories specified by the user in the configuration file. This is used to control where the program looks for supplemental precipitation input forcing files for each supplemental precipitation input forcing based on the directory specified for each supplemental precipitation input forcing in the configuration file.""" + if self.number_supp_pcp > 0: + return self._supp_precip_dirs + @supp_precip_dirs.setter + def supp_precip_dirs(self, value): + """Set the list of pathways to the supplemental precipitation input forcing directories specified by the user in the configuration file. This is used to control where the program looks for supplemental precipitation input forcing files for each supplemental precipitation input forcing based on the directory specified for each supplemental precipitation input forcing in the configuration file.""" + if value is None and self.number_supp_pcp > 0: + value = self.extract_input_variable("SuppPcpDirectories") + if self.number_supp_pcp > 0: # Loop through and ensure all supp pcp directories exist. Also strip out any whitespace # or new line characters. - for dirTmp in range(0, len(self.supp_precip_dirs)): - self.supp_precip_dirs[dirTmp] = self.supp_precip_dirs[dirTmp].strip() - if not os.path.isdir(self.supp_precip_dirs[dirTmp]): + for dirTmp in range(0, len(value)): + value[dirTmp] = value[dirTmp].strip() + if not os.path.isdir(value[dirTmp]): try: - os.makedirs(self.supp_precip_dirs[dirTmp], exist_ok=True) - LOG.debug( - f"Created supp pcp directory: {self.supp_precip_dirs[dirTmp]}" - ) + os.makedirs(value[dirTmp], exist_ok=True) + LOG.debug(f"Created supp pcp directory: {value[dirTmp]}") except OSError as e: err_out_screen( - f"Unable to create supp pcp directory: {self.supp_precip_dirs[dirTmp]}. Error: {e}" + f"Unable to create supp pcp directory: {value[dirTmp]}. Error: {e}" ) # Special case for ExtAnA where we treat comma separated stage IV, MRMS data as one SuppPcp input @@ -1871,254 +1275,172 @@ def validate_config(self, cfg_bmi: dict) -> None: err_out_screen( "CONUS or Alaska Stage IV/MRMS SuppPcp option is only supported as a standalone option" ) - self.supp_precip_dirs = [",".join(self.supp_precip_dirs)] + value = [",".join(value)] + self._supp_precip_dirs = value - if len(self.supp_precip_dirs) != self.number_supp_pcp: - err_out_screen( - "Number of SuppPcpDirectories must match the number of SuppForcing in the configuration file." - ) + @property + def supp_precip_param_dir(self): + """Get the directory where downscaling parameters for supplemental precipitation input forcings are stored specified by the user in the configuration file. This is used to control where the program looks for downscaling parameter files for supplemental precipitation input forcings based on the directory specified for supplemental precipitation input forcings in the configuration file.""" + if self.number_supp_pcp > 0: + return self._supp_precip_param_dir - # Process supplemental precipitation enforcement options + @supp_precip_param_dir.setter + def supp_precip_param_dir(self, value): + """Set the directory where downscaling parameters for supplemental precipitation input forcings are stored specified by the user in the configuration file. This is used to control where the program looks for downscaling parameter files for supplemental precipitation input forcings based on the directory specified for supplemental precipitation input forcings in the configuration file.""" + if value is None and self.number_supp_pcp > 0: + value = self.extract_input_variable("SuppPcpDownscalingParamDir") + if self.number_supp_pcp > 0: try: - self.supp_precip_mandatory = cfg_bmi["SuppPcpMandatory"] - except KeyError as e: - err_out_screen( - "Unable to locate SuppPcpMandatory under the SuppForcing section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate SuppPcpMandatory under the SuppForcing section in the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper SuppPcpMandatory options specified in the configuration file.", - e, - ) - if len(self.supp_precip_mandatory) != self.number_supp_pcp: - err_out_screen( - "Please specify SuppPcpMandatory values for each corresponding " - "supplemental precipitation options in the configuration file." - ) - # Check to make sure enforcement options makes sense. - for enforceOpt in self.supp_precip_mandatory: - if enforceOpt < 0 or enforceOpt > 1: - err_out_screen( - "Invalid SuppPcpMandatory chosen in the configuration file. " - "Please choose a value of 0 or 1 for each corresponding " - "supplemental precipitation product." - ) + os.makedirs(value, exist_ok=True) + LOG.debug(f"Created missing SuppPcpParamDir: {value}") + except OSError as e: + err_out_screen(f"Unable to locate SuppPcpParamDir: {value}. Error: {e}") - # Read in the regridding options. - try: - self.regrid_opt_supp_pcp = cfg_bmi["RegridOptSuppPcp"] - except KeyError as e: - err_out_screen( - "Unable to locate RegridOptSuppPcp under the SuppForcing section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate RegridOptSuppPcp under the SuppForcing section in the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper RegridOptSuppPcp options specified in the configuration file.", - e, - ) - if len(self.regrid_opt_supp_pcp) != self.number_supp_pcp: - err_out_screen( - "Please specify RegridOptSuppPcp values for each corresponding supplemental " - "precipitation product in the configuration file." - ) - # Check to make sure regridding options makes sense. - for regridOpt in self.regrid_opt_supp_pcp: - if regridOpt < 1 or regridOpt > 3: - err_out_screen( - "Invalid RegridOptSuppPcp chosen in the configuration file. " - "Please choose a value of 1-3 for each corresponding " - "supplemental precipitation product." + @property + def cfsv2EnsMember(self): + """Get the CFSv2 ensemble member to process specified by the user in the configuration file. This is used to control which CFSv2 ensemble member is processed for CFSv2 input forcings based on the ensemble member specified in the configuration file.""" + return self._cfsv2EnsMember + + @cfsv2EnsMember.setter + def cfsv2EnsMember(self, value): + """Set the CFSv2 ensemble member to process specified by the user in the configuration file. This is used to control which CFSv2 ensemble member is processed for CFSv2 input forcings based on the ensemble member specified in the configuration file.""" + if value is None and not self.precip_only_flag: + # Read in Ensemble information + # Read in CFS ensemble member information IF we have chosen CFSv2 as an input + # forcing. + for opt_tmp in self.input_forcings: + if opt_tmp == 7: + value = self.extract_input_variable("cfsEnsNumber") + self.check_input_values_in_range( + value, "cfsEnsNumber", [1, 2, 3, 4] ) - # Read in temporal interpolation options. - try: - self.suppTemporalInterp = cfg_bmi["SuppPcpTemporalInterpolation"] - except KeyError as e: - err_out_screen( - "Unable to locate SuppPcpTemporalInterpolation under the SuppForcing section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate SuppPcpTemporalInterpolation under the SuppForcing section in the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper SuppPcpTemporalInterpolation options specified in the configuration file.", - e, - ) - if len(self.suppTemporalInterp) != self.number_supp_pcp: + @property + def customFcstFreq(self): + """Get the custom forecast frequency in minutes specified by the user in the configuration file. This is used to control how often forecasts are issued based on the custom forecast frequency specified in the configuration file.""" + return self._customFcstFreq + + @customFcstFreq.setter + def customFcstFreq(self, value): + """Set the custom forecast frequency in minutes specified by the user in the configuration file. This is used to control how often forecasts are issued based on the custom forecast frequency specified in the configuration file.""" + if value is None and not self.precip_only_flag: + value = self.extract_input_variable("CustomFcstFreq") + if len(self.customFcstFreq) != self.number_custom_inputs: err_out_screen( - "Please specify SuppPcpTemporalInterpolation values for each " - "corresponding supplemental precip products in the configuration file." + f"Improper custom_input fcst_freq specified. This number ({len(self.customFcstFreq)}) must match the frequency of custom input forcings selected ({self.number_custom_inputs})." ) - # Ensure the SuppPcpTemporalInterpolation values make sense. - for temporalInterpOpt in self.suppTemporalInterp: - if temporalInterpOpt < 0 or temporalInterpOpt > 2: - err_out_screen( - "Invalid SuppPcpTemporalInterpolation chosen in the configuration file. " - "Please choose a value of 0-2 for each corresponding input forcing" - ) + self._customFcstFreq = value - # Read in max time option - try: - self.supp_pcp_max_hours = cfg_bmi["SuppPcpMaxHours"] - except (KeyError, configparser.NoOptionError): - self.supp_pcp_max_hours = ( - None # if missing, don't care, just assume all time - ) + def _validate_config(self) -> None: + """Validate in options from the configuration file and check that proper options were provided.""" + self.b_date_proc - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper SuppPcpMaxHours options specified in the configuration file.", - e, - ) + # if not self.precip_only_flag: - if type(self.supp_pcp_max_hours) is list: - if len(self.supp_pcp_max_hours) != self.number_supp_pcp: - err_out_screen( - "Number of SuppPcpMaxHours ({}) must match the number " - "of SuppPcp inputs ({}) in the configuration file, or " - "supply a single threshold for all inputs".format( - len(self.supp_pcp_max_hours), self.number_supp_pcp - ) - ) - elif type(self.supp_pcp_max_hours) is float: - # Support 'classic' mode of single threshold - self.supp_pcp_max_hours = [ - self.supp_pcp_max_hours - ] * self.number_supp_pcp + if self.output_freq <= 0: + err_out_screen( + "Please specify an OutputFrequency that is greater than zero minutes." + ) - # Read in the SuppPcpInputOffsets options. - try: - self.supp_input_offsets = cfg_bmi["SuppPcpInputOffsets"] - except KeyError as e: - err_out_screen( - "Unable to locate SuppPcpInputOffsets under SuppForcing section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate SuppPcpInputOffsets under SuppForcing section in the configuration file.", - e, - ) - except json.decoder.JSONDecodeError as e: - err_out_screen( - "Improper SuppPcpInputOffsets option specified in the configuration file.", - e, - ) - if len(self.supp_input_offsets) != self.number_supp_pcp: - err_out_screen( - "Please specify SuppPcpInputOffsets values for each " - "corresponding input forcings for SuppForcing." - ) - # Check to make sure the input offset options make sense. There will be additional - # checking later when input choices are mapped to input products. - for inputOffset in self.supp_input_offsets: - if inputOffset < 0: - err_out_screen( - "Please specify SuppPcpInputOffsets values greater than or equal to zero." - ) + if self.sub_output_hour < 0: + err_out_screen( + "Please specify an SubOutputHour that is greater than zero minutes." + ) + if self.sub_output_hour == 0: + self.sub_output_hour = None - # Read in the optional parameter directory for supplemental precipitation. - try: - self.supp_precip_param_dir = cfg_bmi["SuppPcpParamDir"] - except KeyError as e: - err_out_screen( - "Unable to locate SuppPcpParamDir under the SuppForcing section in the configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate SuppPcpParamDir under the SuppForcing section in the configuration file.", - e, - ) - except ValueError as e: - err_out_screen( - "Improper SuppPcpParamDir option specified in the configuration file.", - e, - ) - if not os.path.isdir(self.supp_precip_param_dir): - try: - os.makedirs(self.supp_precip_param_dir, exist_ok=True) - LOG.debug( - f"Created missing SuppPcpParamDir: {self.supp_precip_param_dir}" - ) - except OSError as e: - err_out_screen( - f"Unable to locate SuppPcpParamDir: {self.supp_precip_param_dir}. Error: {e}" - ) + if self.sub_output_freq < 0: + err_out_screen( + "Please specify an SubOutFreq that is greater than zero minutes." + ) + if self._sub_output_freq == 0: + self.sub_output_freq = None - if not self.precip_only_flag: - # Read in Ensemble information - # Read in CFS ensemble member information IF we have chosen CFSv2 as an input - # forcing. - for opt_tmp in self.input_forcings: - if opt_tmp == 7: - try: - self.cfsv2EnsMember = cfg_bmi["cfsEnsNumber"] - LOG.debug(f"ens mem: {self.cfsv2EnsMember}") - LOG.debug(f"cfg ens mem: {cfg_bmi['cfsEnsNumber']}") - except KeyError as e: - err_out_screen( - "Unable to locate cfsEnsNumber under the Ensembles section of the configuration file", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate cfsEnsNumber under the Ensembles section of the configuration file", - e, - ) - except json.JSONDecodeError as e: - err_out_screen( - "Improper cfsEnsNumber options specified in the configuration file", - e, - ) - if int(self.cfsv2EnsMember) < 1 or int(self.cfsv2EnsMember) > 4: - err_out_screen( - "Please chose an cfsEnsNumber value of 1,2,3 or 4." - ) + # TODO Can this be a /tmp directory? + self.make_scratch_dir() - # Read in information for the custom input NetCDF files that are to be processed. - # Read in the ForecastInputHorizons options. - try: - self.customFcstFreq = cfg_bmi["custom_input_fcst_freq"] - except KeyError as e: - err_out_screen( - "Unable to locate custom_input_fcst_freq under Custom section in configuration file.", - e, - ) - except configparser.NoOptionError as e: - err_out_screen( - "Unable to locate custom_input_fcst_freq under Custom section in configuration file.", - e, - ) - except json.decoder.JSONDecodeError as je: + if self.useCompression not in [0, 1]: + err_out_screen("Please choose a compressOut value of 0 or 1.") + + if self.ana_flag in [0, 1]: + err_out_screen("Please choose a AnAFlag value of 0 or 1.") + + if self.look_back <= 0 and self.look_back != -9999: + err_out_screen("Please specify a positive LookBack or -9999 for realtime.") + + if self.fcst_freq <= 0: + err_out_screen( + "Please specify a ForecastFrequency in the configuration file greater than zero." + ) + # Currently, we only support daily or sub-daily forecasts. Any other iterations should + # be done using custom config files for each forecast cycle. + if self.fcst_freq > 1440: + err_out_screen( + "Only forecast cycles of daily or sub-daily are supported at this time" + ) + + # Read in the ForecastShift option. This is ONLY done for the realtime instance as + # it's used to calculate the beginning of the processing window. + if True: # was: self.realtime_flag: + self.fcst_shift = self.extract_input_variable("ForecastShift") + if self.fcst_shift < 0: err_out_screen( - "Improper custom_input_fcst_freq option specified in configuration file: " - + str(je) + "Please specify a ForecastShift in the configuration file greater than or equal to zero." ) - if len(self.customFcstFreq) != self.number_custom_inputs: + + # Calculate the beginning/ending processing dates if we are running realtime + if self.realtime_flag: + calculate_lookback_window(self) + + # if self.refcst_flag: + # Calculate the number of forecasts to issue, and verify the user has chosen a + # correct divider based on the dates + # dt_tmp = self.e_date_proc - self.b_date_proc + # if (dt_tmp.days * 1440 + dt_tmp.seconds / 60.0) % self.fcst_freq != 0: + # err_out_screen('Please choose an equal divider forecast frequency for your ' + # 'specified reforecast range.') + # self.nFcsts = int((dt_tmp.days * 1440 + dt_tmp.seconds / 60.0) / self.fcst_freq) + + # Flag to constrain AORC forcing data cycle output + # for optTmp in self.input_forcings: + # if optTmp == 12: + # self.nFcsts = 1 + self.nFcsts = 1 + + if self.look_back != -9999: + calculate_lookback_window(self) + + # Process geospatial information + + if len(self.spatial_meta) == 0: + # No spatial metadata file found. + self.spatial_meta = None + else: + if not os.path.isfile(self.spatial_meta): err_out_screen( - f"Improper custom_input fcst_freq specified. " - f"This number ({len(self.customFcstFreq)}) must " - f"match the frequency of custom input forcings selected " - f"({self.number_custom_inputs})." + "Unable to locate optional spatial metadata file: " + + self.spatial_meta ) + # Calculate the beginning/ending processing dates if we are running realtime + if self.realtime_flag: + calculate_lookback_window(self) + + # Create temporary array to hold flags if we need input parameter files. + param_flag = np.zeros([len(self.input_forcings)], int) + + count_tmp = 0 + for optTmp in self.precipDownscaleOpt: + if optTmp == 1: + param_flag[count_tmp] = 1 + count_tmp = count_tmp + 1 + + for suppOpt in self.supp_precip_forcings: + if suppOpt not in list(range(1, self.supp_precip_count + 1)): + err_out_screen( + f"Please specify SuppForcing values between 1 and {self.supp_precip_count}." + ) + @property def nwm_domain(self) -> str: """Extract NWM domain from the geogrid filename, using regex pattern.""" From e77baf7c5230eb2159a1b8e2e2947964fb96769c Mon Sep 17 00:00:00 2001 From: Matthew Deshotel Date: Wed, 13 May 2026 11:51:47 -0400 Subject: [PATCH 03/71] fix setter logic; update doc strings --- .../NextGen_Forcings_Engine/core/config.py | 1084 +++++++++-------- .../NextGen_Forcings_Engine/core/consts.py | 65 +- 2 files changed, 636 insertions(+), 513 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py index 4c7b3add..69cb32f7 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py @@ -5,7 +5,6 @@ import re import uuid from datetime import datetime, timedelta, timezone -from functools import cached_property # Use the Error, Warning, and Trapping System Package for logging import numpy as np @@ -39,15 +38,17 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No geogrid (str, optional): The filepath to the geogrid file to be used for processing. This is used to specify the grid information for regridding input forcings. If not provided, it will be read from the configuration file. """ + if geogrid is not None: + self.user_provided_geogrid_flag = True + else: + self.user_provided_geogrid_flag = False + + self.b_date_proc = b_date + self._cfg_bmi = cfg_bmi + self._geogrid = geogrid + self.bmi_time_index = 0 self.precip_only_flag = False - self.number_custom_inputs = 0 - self.useCompression = 0 - self.useFloats = 0 - self._b_date_proc = b_date - self._cfg_bmi = cfg_bmi - self.runCfsNldasBiasCorrect = False - self.rqiThresh = 1.0 self.globalNdv = -9999.0 self.d_program_init = datetime.now(timezone.utc) self.errFlag = 0 @@ -58,16 +59,56 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4" ) self.nwm_source = "s3://noaa-nwm-retrospective-3-0-pds" - self._geogrid = geogrid + self.broadcast_new_64bit_uid() self._scratch_dir_has_been_uniquefied = False + # Create temporary array to hold flags if we need input parameter files. + self.param_flag = np.zeros([len(self.input_forcings)], int) # set list of attibutes from consts.py to None. # These are indexed from the consts dictionary using the class name for attr in CONFIGOPTIONS[self.__class__.__name__]: setattr(self, attr, None) - self._validate_config() + + self.set_attrs(self.try_config_get_except_attr_map) + self.supp_precip_forcings = self.extract_input_variable("SuppPcp") + self.set_attrs(CONFIGOPTIONS["extract_input_variable_attrs_map"]) + + if self.precip_only_flag: + self.set_attrs( + CONFIGOPTIONS["extract_input_variable_attrs_map_precip_only"] + ) + else: + self.set_attrs( + CONFIGOPTIONS["extract_input_variable_attrs_map_not_precip_only"] + ) + if 27 in self.input_forcings: + self.nwm_geogrid = self.extract_input_variable("NWMGeogridIn") + + if self.perform_downscaling: + self.set_attrs(CONFIGOPTIONS["downscaling_attrs_map"]) + if self.grid_type == "unstructured": + self.set_attrs(CONFIGOPTIONS["downscaling_unstructred_attrs_map"]) + + for cfg_bmi_attr, config_options_attr in CONFIGOPTIONS[ + "extract_input_variable_set_default_attrs_map" + ].items(): + setattr( + self, + config_options_attr, + self.extract_input_variable_set_default(cfg_bmi_attr), + ) + + @property + def try_config_get_except_attr_map(self) -> dict: + """Get the mapping of configuration variable names to class attribute names for variables that are extracted directly from the configuration file without any additional processing. This is used to control how variables are extracted from the configuration file and assigned to class attributes in a consistent way based on the mapping specified in the consts.py file.""" + dict_map = CONFIGOPTIONS["try_config_get_except_attr_map"] + if self._b_date_proc is not None: + dict_map.pop("b_date_proc") + if self._geogrid is not None: + dict_map.pop("geogrid") + return dict_map @property def cfg_bmi(self) -> dict: @@ -81,7 +122,6 @@ def cfg_bmi(self, value: dict) -> None: raise TypeError( f"Expected dict, got {type(value)} for type of cfg_bmi: {value}" ) - self._validate_config() self._cfg_bmi = value @property @@ -108,20 +148,13 @@ def precip_only_flag(self) -> bool: if int(self.supp_precip_forcings[0]) == 14: return True - def set_attrs(self): + def set_attrs(self, attrs_dict: dict): """Set the attributes of the class based on the configuration file. This is used to populate the attributes of the class after they have been read in and validated from the configuration file.""" - for cfg_bmi_attr, config_options_attr in CONFIGOPTIONS[ - "cfg_bmi_to_attrs_map" - ].items(): + for cfg_bmi_attr, config_options_attr in attrs_dict.items(): setattr( self, config_options_attr, self.extract_input_variable(cfg_bmi_attr) ) - if self.output_freq <= 0: - err_out_screen( - "Please specify an OutputFrequency that is greater than zero minutes." - ) - def extract_input_variable(self, variable_name: str) -> str: """Extract the variable name from the configuration file for a given variable.""" try: @@ -154,10 +187,10 @@ def extract_input_variable_set_default(self, variable_name: str, default=0) -> s err_out_screen(f"Please choose a {variable_name} value of 0 or 1.") return variable - def try_config_get(self, variable_name: str, default=None) -> str: + def try_config_get(self, variable_name: str) -> str: """Try to get a variable from the configuration file, and return a default value if it is not found.""" try: - var = self.cfg_bmi.get(variable_name, default) + var = self.cfg_bmi.get(variable_name) if var is None: err_out_screen( f"Unable to locate {variable_name} in the configuration file." @@ -184,7 +217,7 @@ def check_number_of_inputs_forcings(self, value: list, variable_name: str) -> No def check_number_of_inputs_supp_pcp(self, value: list, variable_name: str) -> None: """Check that the number of inputs specified by the user in the configuration file matches the expected number of inputs for a given variable, specifically for supplemental precip forcing variables which should match the number of supplemental precip forcing options specified by the user in the configuration file.""" return self.check_number_of_inputs( - value, variable_name, " supplemental precip forcings" + value, variable_name, " SupplementalPrecipForcings" ) def check_input_values_in_range( @@ -222,12 +255,11 @@ def uniquefy_scratch_dir_as_child(self, uid: str) -> None: ) self.scratch_dir = os.path.join(self.scratch_dir, uid) self._scratch_dir_has_been_uniquefied = True - self.make_scratch_dir() - def make_scratch_dir(self) -> None: + def make_scratch_dir(self, scratch_dir: str) -> None: """Make the scratch dir and its parents.""" - os.makedirs(self.scratch_dir, exist_ok=True) - LOG.debug(f"Scratch dir: {self.scratch_dir}") + os.makedirs(scratch_dir, exist_ok=True) + LOG.debug(f"Scratch dir: {scratch_dir}") def broadcast_new_64bit_uid(self) -> None: """Broadcast a random uint64 then save the hash of that to self.uid64, which effectively broadcasts the same unique string to all ranks. @@ -238,16 +270,209 @@ def broadcast_new_64bit_uid(self) -> None: raise RuntimeError("self.uid64 has already been initialized.") self.uid64 = mpi_utils.get_new_broadcasted_uid() + @property + def supp_precip_forcings(self): + """Choose a set of supplemental precipitation file(s) to layer into the final LDASIN forcing files processed from the options above. The following is a mapping of numeric values to external input native forcing files. + + 1. MRMS GRIB2 hourly radar-only QPE + 2. MRMS GRIB2 hourly gage-corrected radar QPE + 3. WRF-ARW 2.5 km 48-hr Hawaii nest precipitation. + 4. WRF-ARW 2.5 km 48-hr Puerto Rico nest precipitation. + 5. CONUS MRMS GRIB2 hourly MultiSensor QPE (Pass 2 or Pass 1) + 6. Hawaii MRMS GRIB2 hourly MultiSensor QPE (Pass 2 or Pass 1) + 7. MRMS SBCv2 Liquid Water Fraction (netCDF only) + 8. NBM Conus MR + 9. NBM Alaska MR + 10. Alaska MRMS (no liquid water fraction) + 11. Alaska Stage IV NWS Precip + 12. CONUS Stage IV NWS Precip + 13. MRMS PrecipFlag precipitation classification file + 14. Custom Frequency Supplementary Precipitation product (sub-hourly precip) + 15. NBM Puerto Rico + 16. NBM Hawaii + - Example- SuppPcp: [1, 5, 13] + """ + return self._supp_precip_forcings + + @supp_precip_forcings.setter + def supp_precip_forcings(self, value: list) -> None: + """Set the list of supplemental precip forcing options specified by the user in the configuration file. This is used to control which supplemental precip forcings are processed and how they are processed based on the other configuration options specified for each supplemental precip forcing.""" + self.check_input_values_in_range( + value, + "SuppPcp", + list(range(1, self.supp_precip_count + 1)), + ) + self._supp_precip_forcings = value + + @property + def output_freq(self) -> int: + """Get the output frequency in minutes specified by the user in the configuration file. This is used to control the output frequency of the processed forcings, and is necessary for both realtime and reforecast simulations.""" + return self._output_freq + + @output_freq.setter + def output_freq(self, value: int) -> None: + """Specify the output frequency in minutes. Note that any frequencies at higher intervals than what if provided as input will entail input forcing data being temporally interpolated. + + Example- OutputFrequency: 60 + """ + self.check_input_values_positive([value], "OutputFrequency") + self._output_freq = value + + @property + def sub_output_hour(self) -> int: + """Get the sub-daily output hour specified by the user in the configuration file. This is used to control the output frequency of the processed forcings for sub-daily output frequencies, and is only necessary if the user has chosen a sub-daily output frequency in the configuration file.""" + return self._sub_output_hour + + @sub_output_hour.setter + def sub_output_hour(self, value: int) -> None: + """Sub output hour. + + New variable currently for NWMv3.1 operations to properly ingest GFS 13km forecast data that outputs various frequencies throughout the forecast cycle lifetime. This variable will properly account for reading time slices of the forecast cycle. Currently only needed for GFS 13km operational configuration. Otherwise, set this value to 0. + + Example- SubOutputHour: 0 + """ + self.check_input_values_positive([value], "SubOutputHour") + if value < 0: + err_out_screen( + "Please specify an SubOutputHour that is greater than zero minutes." + ) + if value == 0: + value = None + self._sub_output_hour = value + + @property + def sub_output_freq(self) -> int: + """Calculate the sub-daily output frequency in minutes based on the output frequency and sub-daily output hour specified by the user in the configuration file. This is used to control the output frequency of the processed forcings for sub-daily output frequencies, and is only necessary if the user has chosen a sub-daily output frequency in the configuration file.""" + return self._sub_output_freq + + @sub_output_freq.setter + def sub_output_freq(self, value: int) -> None: + """Sub output frequency. + + New variable currently for NWMv3.1 operations to properly ingest GFS 13km forecast data that outputs various frequencies throughout the forecast cycle lifetime. This variable will properly account for reading time slices of the forecast cycle. Currently only needed for GFS 13km operational configuration. Otherwise, set this value to 0. + + Example- SubOutputFreq: 0 + """ + if value < 0: + err_out_screen( + "Please specify an SubOutFreq that is greater than zero minutes." + ) + if value == 0: + value = None + self._sub_output_freq = value + + @property + def scratch_dir(self) -> str: + """Specify a scratch directory that will be used for storage of temporary files. These files will be removed automatically by the program. at the end of the BMI instance. However, this directory will also store the output forcing file if requested by the user as well (will not be deleted in this instance). + + Example- ScratchDir: "./ScratchDir + """ + return self._scratch_dir + + @scratch_dir.setter + def scratch_dir(self, value: str) -> None: + """Set the pathway to the scratch directory specified by the user in the configuration file. This is used to control where intermediate files are written during processing, and is necessary for both realtime and reforecast simulations.""" + self.make_scratch_dir(value) + self._scratch_dir = value + + @property + def useCompression(self) -> int: + """Flag to activate scale_factor / add_offset byte packing in the output files. 0 - Deactivate compression 1 - Activate compression, Only applicable in this instance when you request a netcdf output forcing file (Output: 1). Otherwise, just set to 0. + + Example- compressOutput: 0 + """ + return self._useCompression + + @useCompression.setter + def useCompression(self, value: int) -> None: + """Set the flag for whether to use compression when writing output files specified by the user in the configuration file. This is used to control whether output files are compressed, which can save disk space but may increase processing time.""" + if value is None: + value = 0 + self.check_input_values_in_range([value], "compressOutput", [0, 1]) + self._useCompression = value + + @property + def ana_flag(self) -> int: + """If this is AnA run, set AnAFlag to 1, otherwise 0. Setting this flag will change the behavior of some Bias Correction routines as the ForecastInputOffsets options. + + Example- AnAFlag: 1 + """ + return self._ana_flag + + @ana_flag.setter + def ana_flag(self, value: int) -> None: + """Set the flag for whether to include the analysis time step in the output files specified by the user in the configuration file. This is used to control whether the analysis time step is included in the output files, which can be useful for certain applications but may not be necessary for all users.""" + value = int(value) + self.check_input_values_in_range([value], "AnAFlag", [0, 1]) + self._ana_flag = value + + @property + def look_back(self) -> int: + """Specify a lookback period in minutes to process data. This is required if you are only processing an AnA operational configuration. This value should specify how far back you need to look in time from your "RefcstBDateProc" start date that you specified. In this instance, that start date will be your actual end date. If no LookBack specified, please specify -9999. + + Example- LookBack: 180 + """ + return self._look_back + + @look_back.setter + def look_back(self, value: int) -> None: + """Set the look back window in hours specified by the user in the configuration file. This is used to calculate the processing window for reforecast simulations, and is only necessary if the user is running a reforecast simulation with a specified processing window rather than a realtime simulation.""" + if value <= 0 and value != -9999: + err_out_screen("Please specify a positive LookBack or -9999 for realtime.") + if value != -9999: + calculate_lookback_window(self) + self._look_back = value + + @property + def fcst_freq(self) -> int: + """Specify a forecast frequency in minutes. This value specifies how often to generate a set of forecast forcings. If generating hourly retrospective forcings, specify this value to be 60. + + Example- ForecastFrequency: 60 + """ + return self._fcst_freq + + @fcst_freq.setter + def fcst_freq(self, value: int) -> None: + """Set the forecast frequency in hours specified by the user in the configuration file. This is used to calculate the processing window for reforecast simulations, and is only necessary if the user is running a reforecast simulation with a specified processing window rather than a realtime simulation.""" + self.check_input_values_positive([value], "ForecastFrequency") + if value > 1440: + err_out_screen( + "Only forecast cycles of daily or sub-daily are supported at this time" + ) + self._fcst_freq = value + + @property + def spatial_meta(self): + """Specify the optional land spatial metadata file. If found, coordinate projection information and coordinate will be translated from to the final output file. This variable is only a special case if the user is specifying the original WRF-Hydro domain from earlier NWM versions. Otherwise, just leave the one blank (''). + + Example- SpatialMetaIn: ./GEOGRID_LDASOUT_Spatial_Metadata_CONUS.nc + """ + return self._spatial_meta + + @spatial_meta.setter + def spatial_meta(self, value: str) -> None: + """Set the spatial metadata options specified by the user in the configuration file. This is used to control how spatial metadata is handled during processing, and is necessary for both realtime and reforecast simulations.""" + if len(value) == 0: + # No spatial metadata file found. + value = None + else: + if not os.path.isfile(value): + err_out_screen( + f"Unable to locate optional spatial metadata file: {value}." + ) + self._spatial_meta = value + @property def b_date_proc(self) -> str: - """Get the beginning date of processing for reforecast simulations. This is used to calculate the processing window for reforecast simulations, and is only necessary if the user is running a reforecast simulation with a specified processing window rather than a realtime simulation.""" + """If running an operational configuration in realtime or just using a retrospective dataset (NWM, AORC, ERA5), this will be the defined start date for the NextGen Forcing Engine BMI which is assumed to be the beginning of the forecast cycle (i.e. hour 0) or just the start date of the retrospective dataset. From there the first time step will be hour 1 from the start date specified here. If you're running an AnA configuration however, this variable becomes the end date of the simulation and the "LookBack" value specified above will be how far back you look in time for the AnA operational configuration. + + Example- RefcstBDateProc: 202210071400 + """ return self._bdate_proc @b_date_proc.setter def b_date_proc(self, value: str | datetime) -> None: - """Set the beginning date of processing for reforecast simulations. This is used to calculate the processing window for reforecast simulations, and is only necessary if the user is running a reforecast simulation with a specified processing window rather than a realtime simulation.""" - if value is None: - value = self.try_config_get("RefcstBDateProc") + """Set the beginning date of processing for reforecast simulations. This is used to calculate the processing window for reforecast simulations.""" if isinstance(value, datetime): self._b_date_proc = value if value != -9999: @@ -270,11 +495,15 @@ def b_date_proc(self, value: str | datetime) -> None: def realtime_flag(self) -> bool: """Flag to indicate whether the user has chosen to run a realtime simulation, which will trigger some different processing pathways and error checking for certain configuration options, and will also control how the processing window is calculated.""" if self.look_back == -9999: - return False + value = False elif self.b_date_proc == -9999: - return True + value = True else: - return False + value = False + # Calculate the beginning/ending processing dates if we are running realtime + if value: + calculate_lookback_window(self) + return value @property def refcst_flag(self) -> bool: @@ -294,34 +523,31 @@ def geopackage(self) -> str: @geopackage.setter def geopackage(self, value: str) -> None: """Set the pathway to the geopackage file to be used for processing. This is used to specify the grid information for regridding input forcings, and is only necessary if the user is running a simulation that requires regridding of input forcings.""" - if value is not None: - self._geopackage = value - else: - self._geopackage = self.try_config_get("Geopackage") + self._geopackage = value @property def geogrid(self) -> str: - """Get the pathway to the geogrid file to be used for processing. This is used to specify the grid information for regridding input forcings, and is only necessary if the user is running a simulation that requires regridding of input forcings.""" + """Specify a geogrid file (e.g. latitude, longitude, mesh connectivity, elevation, slope) that defines domain to which the forcings are being processed to. + + Example- GeogridIn: ./geo_em_CONUS.nc + """ return self._geogrid @geogrid.setter def geogrid(self, value: str) -> None: """Set the pathway to the geogrid file to be used for processing. This is used to specify the grid information for regridding input forcings, and is only necessary if the user is running a simulation that requires regridding of input forcings.""" - if value is not None: + if self.user_provided_geogrid_flag: self._geogrid = value + if value is None: + err_out_screen("Unable to locate GeogridIn in the configuration file.") else: - geogrid_base = self.try_config_get("GeogridIn") - if geogrid_base is None: - err_out_screen("Unable to locate GeogridIn in the configuration file.") - self.geogrid = None - else: - geogrid_parent = os.path.dirname(geogrid_base) - geogrid_filename = os.path.basename(geogrid_base) - if self.uid64 is None: - raise ValueError("self.uid64 cannot be None, please initialize it.") - self._geogrid = os.path.join( - geogrid_parent, f"{self.uid64}_{geogrid_filename}" - ) + geogrid_parent = os.path.dirname(value) + geogrid_filename = os.path.basename(value) + if self.uid64 is None: + raise ValueError("self.uid64 cannot be None, please initialize it.") + self._geogrid = os.path.join( + geogrid_parent, f"{self.uid64}_{geogrid_filename}" + ) self.try_make_dir(geogrid_parent, " esmf_mesh") def try_make_dir(self, directory: str, optional_str: str = "") -> None: @@ -336,21 +562,18 @@ def try_make_dir(self, directory: str, optional_str: str = "") -> None: ) @property - def input_forcing_options(self) -> list: + def input_forcings(self) -> list: """Get the list of input forcing options specified by the user in the configuration file. This is used to control which input forcings are processed and how they are processed based on the other configuration options specified for each input forcing.""" - return self._input_forcing_options + return self._input_forcings - @input_forcing_options.setter - def input_forcing_options(self, value: list) -> None: + @input_forcings.setter + def input_forcings(self, value: list) -> None: """Set the list of input forcing options specified by the user in the configuration file. This is used to control which input forcings are processed and how they are processed based on the other configuration options specified for each input forcing.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("InputForcings") if not self.precip_only_flag: - for force_opt in value: - self.check_input_values_in_range( - value, "InputForcings", list(range(1, self.force_count + 1)) - ) - self._input_forcing_options = value + self.check_input_values_in_range( + value, "InputForcings", list(range(1, self.force_count + 1)) + ) + self._input_forcings = value @property def number_inputs(self) -> int: @@ -360,30 +583,32 @@ def number_inputs(self) -> int: err_out_screen( "Please choose at least one InputForcings dataset to process" ) - return len(self.input_forcing_options) + return len(self.input_forcings) @property def number_custom_inputs(self) -> int: """Calculate the number of custom input forcing options specified by the user in the configuration file. This is used to control the flow of the program based on how many custom input forcings are being processed, since custom input forcings require some different processing pathways.""" if not self.precip_only_flag: count = 0 - for force_opt in self.input_forcing_options: + for force_opt in self.input_forcings: if force_opt == 10: count += 1 return count + else: + return 0 @property def nwm_geogrid(self) -> str: - """Get the pathway to the NWM geogrid file specified by the user in the configuration file. This is used to specify the grid information for regridding NWM input forcings, and is only necessary if the user has chosen to regrid NWM input forcings in the configuration file.""" + """Only for the NWM v3 retorspective forcing module option (27) that requires the geo_em_NWM_DOMAIN.nc file as input for the NextGen Forcings Engine to properly setup up the ESMF grid object for the NWM forcing files since that information is not readily available in the NWM v3 retrospective forcing files.""" return self._nwm_geogrid @nwm_geogrid.setter def nwm_geogrid(self, value: str) -> None: """Set the pathway to the NWM geogrid file specified by the user in the configuration file. This is used to specify the grid information for regridding NWM input forcings, and is only necessary if the user has chosen to regrid NWM input forcings in the configuration file.""" - if value is None and not self.precip_only_flag: - if 27 in self.input_forcing_options: - value = self.extract_input_variable("NWM_Geogrid") - self._nwm_geogrid = value + if not self.precip_only_flag and 27 in self.input_forcings: + self._nwm_geogrid = value + else: + self._nwm_geogrid = None @property def input_force_types(self) -> list: @@ -392,9 +617,10 @@ def input_force_types(self) -> list: @input_force_types.setter def input_force_types(self, value: list) -> None: - """Set the list of input forcing file types specified by the user in the configuration file. This is used to control how input forcings are read in and processed based on the file type specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("InputForcingTypes") + """Specify the file type for each forcing (comma separated). Valid types are GRIB1, GRIB2, NETCDF, and NETCDF4. + + Example- InputForcingTypes: [GRIB2,GRIB2]\ + """ if not self.precip_only_flag: if value == [""]: value = [] @@ -403,6 +629,8 @@ def input_force_types(self, value: list) -> None: value, "InputForcingTypes", self.file_types ) self._input_force_types = value + else: + self._input_force_types = None @property def file_types(self): @@ -416,9 +644,10 @@ def input_force_dirs(self) -> list: @input_force_dirs.setter def input_force_dirs(self, value: list) -> None: - """Set the list of input forcing directories specified by the user in the configuration file. This is used to control where input forcings are read in from for each input forcing specified by the user in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("InputForcingDirectories") + """Specify the input directories for each forcing product. If a user has the ability to connect to the AWS servers and they specify configuration #12 (CONUS AORC data) or configuration #27 (NWM retrospective forcing data) then this specific configuration input can be left as a blank string (""). + + Example- InputForcingDirectories: [./GFS,./NDFD] + """ if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "InputForcingDirectories") # Loop through and ensure all input directories exist. Also strip out any whitespace @@ -426,7 +655,7 @@ def input_force_dirs(self, value: list) -> None: for dir_tmp in range(0, len(value)): value[dir_tmp] = value[dir_tmp].strip() dir_path = value[dir_tmp] - forcing_type = self.input_forcing_options[dir_tmp] + forcing_type = self.input_forcings[dir_tmp] is_aws_forcing = forcing_type in [12, 21, 27] if not os.path.isdir(dir_path): @@ -435,6 +664,8 @@ def input_force_dirs(self, value: list) -> None: else: self.try_make_dir(dir_path, " forcing") self._input_force_dirs = value + else: + self._input_force_dirs = None def input_force_mandatory(self) -> list: """Get the list of input forcing mandatory flags specified by the user in the configuration file. This is used to control whether the program should raise an error if input forcings for a given forecast cycle are not found for each input forcing specified by the user in the configuration file.""" @@ -442,12 +673,16 @@ def input_force_mandatory(self) -> list: @input_force_mandatory.setter def input_force_mandatory(self, value: list) -> None: - """Set the list of input forcing mandatory flags specified by the user in the configuration file. This is used to control whether the program should raise an error if input forcings for a given forecast cycle are not found for each input forcing specified by the user in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("InputMandatory") + """Specify whether the input forcings listed above are mandatory, or optional. This is important for layering contingencies if a product is missing, but forcing files are still desired. 0 - Not mandatory, 1 - Mandatory. NOTE!!! If no files are found for any products, code will error out indicating the final field is all missing values. + + Example- InputMandatory: [1,1] + """ + if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "InputMandatory") self.check_input_values_in_range(value, "InputMandatory", [0, 1]) - self._input_force_mandatory = value + self._input_force_mandatory = value + else: + self._input_force_mandatory = None def customSuppPcpFreq(self) -> int: """Get the custom supplemental precip output frequency specified by the user in the configuration file. This is used to control the output frequency of supplemental precip forcings if the user has chosen to run the supplemental precip forcings module only.""" @@ -456,81 +691,85 @@ def customSuppPcpFreq(self) -> int: @customSuppPcpFreq.setter def customSuppPcpFreq(self, value: int) -> None: """Set the custom supplemental precip output frequency specified by the user in the configuration file. This is used to control the output frequency of supplemental precip forcings if the user has chosen to run the supplemental precip forcings module only.""" - if value is None and self.precip_only_flag: - value = self.extract_input_variable("customSuppPcpFreq") + if self.precip_only_flag: self.check_input_values_positive([value], "customSuppPcpFreq") - self._customSuppPcpFreq = value - - @property - def include_lqfrac(self): - """Get the flag for whether to include the liquid/solid precipitation fraction variable in the output files specified by the user in the configuration file. This is used to control whether the liquid/solid precipitation fraction variable is included in the output files.""" - return self._include_lqfrac - - @include_lqfrac.setter - def include_lqfrac(self, value): - """Set the flag for whether to include the liquid/solid precipitation fraction variable in the output files specified by the user in the configuration file. This is used to control whether the liquid/solid precipitation fraction variable is included in the output files.""" - if value is None: - value = self.extract_input_variable_set_default("includeLQFrac", default=0) - - @property - def include_lqfrac(self): - """Get the flag for whether to include the liquid/solid precipitation fraction variable in the output files specified by the user in the configuration file. This is used to control whether the liquid/solid precipitation fraction variable is included in the output files.""" - return self._include_lqfrac - - @include_lqfrac.setter - def include_lqfrac(self, value): - if value is None: - value = self.extract_input_variable_set_default("includeLQFrac", default=0) - self._include_lqfrac = value - - @property - def forcing_output(self) -> int: - """Get the flag for whether to output the input forcings specified by the user in the configuration file. This is used to control whether the input forcings are output in addition to the processed forcings.""" - return self._forcing_output - - @forcing_output.setter - def forcing_output(self, value: int) -> None: - if value is None: - value = self.extract_input_variable_set_default("Output", default=0) - self._forcing_output = value + self._customSuppPcpFreq = value + else: + self._customSuppPcpFreq = None def fcst_shift(self) -> int: - """Get the forecast shift specified by the user in the configuration file. This is used to control the calculation of the processing window for realtime simulations.""" + """Forecast cycles are determined by splitting up a day by equal ForecastFrequency interval. If there is a desire to shift the cycles to a different time step, ForecastShift will shift forecast cycles ahead by a determined set of minutes. For example, ForecastFrequency of 6 hours will produce forecasts cycles at 00, 06, 12, and 18 UTC. However, a ForecastShift of 1 hour will produce forecast cycles at 01, 07, 13, and 18 UTC. NOTE - This is only used by the realtime instance to calculate forecast cycles accordingly. Re-forecasts will use the beginning and ending dates specified in conjunction with the forecast frequency to determine forecast cycle dates. + + Example- ForecastShift: 0 + """ return self._fcst_shift @fcst_shift.setter def fcst_shift(self, value: int) -> None: + if True: # was: self.realtime_flag: + self.check_input_values_positive([value], "ForecastShift") + # Calculate the beginning/ending processing dates if we are running realtime + if self.realtime_flag: + calculate_lookback_window(self) + self._fcst_shift = value + + # NOTE this commented out code copied from pre-refactored code on 5/6/2026 + # if self.refcst_flag: + # Calculate the number of forecasts to issue, and verify the user has chosen a + # correct divider based on the dates + # dt_tmp = self.e_date_proc - self.b_date_proc + # if (dt_tmp.days * 1440 + dt_tmp.seconds / 60.0) % self.fcst_freq != 0: + # err_out_screen('Please choose an equal divider forecast frequency for your ' + # 'specified reforecast range.') + # self.nFcsts = int((dt_tmp.days * 1440 + dt_tmp.seconds / 60.0) / self.fcst_freq) + + # Flag to constrain AORC forcing data cycle output + # for optTmp in self.input_forcings: + # if optTmp == 12: + # self.nFcsts = 1 + + @property + def nFcsts(self): + """Get the number of forecasts to issue for a reforecast simulation based on the forecast shift and the processing window specified by the user in the configuration file. This is used to control how many forecast time steps are output for a reforecast simulation, and is only necessary if the user is running a reforecast simulation with a specified processing window rather than a realtime simulation.""" + return self._nFcsts + + @nFcsts.setter + def nFcsts(self, value: int) -> None: + """Set the number of forecasts to issue for a reforecast simulation based on the forecast shift and the processing window specified by the user in the configuration file. This is used to control how many forecast time steps are output for a reforecast simulation, and is only necessary if the user is running a reforecast simulation with a specified processing window rather than a realtime simulation.""" if value is None: - value = self.extract_input_variable("ForecastShift") - self.check_input_values_positive([value], "ForecastShift") - self._fcst_shift = value + value = 1 + self._nFcsts = value @property def fcst_input_horizons(self) -> list: - """Get the list of forecast input horizons specified by the user in the configuration file. This is used to control the calculation of the forecast cycle length and the processing of input forcings based on the forecast time horizons specified for each input forcing.""" + """Specify how much (in minutes) of each input forcing is desires for each forecast cycle. See documentation for examples. The length of this array must match the input forcing choices. + + - Example- ForecastInputHorizons: [60, 60] + """ return self._fcst_input_horizons @fcst_input_horizons.setter def fcst_input_horizons(self, value: list) -> None: - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("ForecastInputHorizons") if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "ForecastInputHorizons") self.check_input_values_positive(value, "ForecastInputHorizons") else: - if value is None: - value = self.extract_input_variable("ForecastInputHorizons") + if len(self.fcst_input_horizons) != 1: + err_out_screen( + "Please specify ForecastInputHorizon values for each corresponding input forcings for forecasts." + ) self._fcst_input_horizons = value @property def fcst_input_offsets(self): - """Get the list of forecast input offsets specified by the user in the configuration file. This is used to control the calculation of the processing window for both realtime and reforecast simulations based on the forecast time horizons and input offsets specified for each input forcing.""" + """Option for applying an offset to input forcings to use a different forecasted interval. For example, a user may wish to use 4-5 hour forecasted fields from an NWP grid from one of their input forcings. In that instance the offset would be 4 hours, but 0 for other remaining forcings. + + Example- ForecastInputOffsets: [0, 0] + """ return self._fcst_input_offsets @fcst_input_offsets.setter def fcst_input_offsets(self, value: list) -> None: - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("ForecastInputOffsets") if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "ForecastInputOffsets") self.check_input_values_positive(value, "ForecastInputOffsets") @@ -549,6 +788,7 @@ def cycle_length_minutes(self) -> int: ) return cycle_len + @property def num_output_steps(self) -> int: """Calculate the number of output time steps per forecast cycle based on the forecast cycle length and the output frequency specified by the user in the configuration file.""" if self.sub_output_hour is None: @@ -564,11 +804,13 @@ def num_output_steps(self) -> int: ) return num_steps + @property def num_supp_output_steps(self) -> int: """Calculate the number of supplemental precip output time steps per forecast cycle based on the forecast cycle length and the custom supplemental precip output frequency specified by the user in the configuration file.""" if self.precip_only_flag: return int(self.cycle_length_minutes / self.customSuppPcpFreq) + @property def actual_output_steps(self) -> int: """Calculate the actual number of output time steps per forecast cycle based on whether the user has chosen to run a reforecast simulation with a specified processing window, which will only output time steps for which input forcings are available based on the processing window and forecast time horizons specified by the user in the configuration file.""" if self.ana_flag: @@ -578,16 +820,17 @@ def actual_output_steps(self) -> int: @property def grid_type(self) -> str: - """Get the grid type specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings based on the grid type specified by the user in the configuration file.""" + """Tells the NextGen Forcings Engine BMI which grid type the engine is initalizing as a BMI instance. This is a required field and the proper string values should be "gridded", "hydrofabric", or "unstructured". + + Example- GRID_TYPE: "gridded" + """ return self._grid_type @grid_type.setter def grid_type(self, value: str) -> None: """Set the grid type specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings based on the grid type specified by the user in the configuration file.""" - if value is None: - value = self.extract_input_variable("GRID_TYPE") self.check_input_values_in_range( - [value], "GRID_TYPE", ["gridded", "unstructured", "hydrofabric"] + [value.lower()], "GRID_TYPE", ["gridded", "unstructured", "hydrofabric"] ) self._grid_type = value.lower() @@ -599,7 +842,10 @@ def raise_grid_type_error(self, grid_type: str, variable_name: str) -> None: @property def lon_var(self) -> str: - """Get the longitude variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen a gridded grid type in the configuration file.""" + """Naming convention of the longitude variable within the "GeogridIn" file the user has specified. Variable naming convention ONLY for gridded domain configurations. This is required so the NextGen Forcings Engine BMI can dyanmically initialize the domain geogrid as an ESMF regridding object. In the case for "gridded" domain configuration options and a user specifying downscaling options while only specifying a height variable feature on the grid, this netcdf variable (LONVAR) is then EXPECTED to contain a netcdf metadata attribute called "dx" that specifies the grid spacing in the longtiudinal direction. Otherwise, it will throw an error and not be able to calculate the slope and tilt of each grid cell. + + Example- LONVAR: "XLONG_M" + """ if self.grid_type == "gridded": return self.extract_input_variable("LONVAR") else: @@ -607,7 +853,10 @@ def lon_var(self) -> str: @property def lat_var(self) -> str: - """Get the latitude variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen a gridded grid type in the configuration file.""" + """Naming convention of the latitude variable within the "GeogridIn" file the user has specified. Variable naming convention ONLY for gridded domain configurations. This is required so the NextGen Forcings Engine BMI can dyanmically initialize the domain geogrid as an ESMF regridding object. In the case for "gridded" domain configuration options and a user specifying downscaling options while only specifying a height variable feature on the grid, this netcdf variable (LATVAR) is then EXPECTED to contain a netcdf metadata attribute called "dy" that specifies the grid spacing in the latitudinal direction. Otherwise, it will throw an error and not be able to calculate the slope and tilt of each grid cell. + + Example- LATVAR: "XLAT_M" + """ if self.grid_type == "gridded": return self.extract_input_variable("LATVAR") else: @@ -615,7 +864,10 @@ def lat_var(self) -> str: @property def nodecoords_var(self) -> str: - """Get the node coordinates variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen an unstructured or hydrofabric grid type in the configuration file.""" + """Naming convention of the node coordinates variable within the "GeogridIn" file the user has specified for ONLY an unstructured mesh or the NextGen hydrofabric. This is a 2-D array stating the latitude and longitude coordinates for all the nodes in the mesh. This is required so the NextGen Forcings Engine BMI can dyanmically initialize the domain geogrid as an ESMF regridding object. + + Example- NodeCoods: "nodecoords" + """ if self.grid_type in ["unstructured", "hydrofabric"]: return self.extract_input_variable("NodeCoords") else: @@ -623,7 +875,10 @@ def nodecoords_var(self) -> str: @property def elemcoords_var(self) -> str: - """Get the element coordinates variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen an unstructured or hydrofabric grid type in the configuration file.""" + """Naming convention of the element coordinates variable within the "GeogridIn" file the user has specified for ONLY an unstructured mesh or the NextGen hydrofabric. This is a 2-D array stating the latitude and longitude coordinates for all the elements in the mesh. This is required so the NextGen Forcings Engine BMI can dyanmically initialize the domain geogrid as an ESMF regridding object. + + Example- ElemCoods: "elemcoords" + """ if self.grid_type in ["unstructured", "hydrofabric"]: return self.extract_input_variable("ElemCoords") else: @@ -631,7 +886,10 @@ def elemcoords_var(self) -> str: @property def elemconn_var(self) -> str: - """Get the element connectivity variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen an unstructured or hydrofabric grid type in the configuration file.""" + """Naming convention of the element connectivity variable within the "GeogridIn" file the user has specified for ONLY an unstructured mesh or the NextGen hydrofabric. This is a 2-D array stating the node ids for each element connecting the entire mesh structure. This is required so the NextGen Forcings Engine BMI can dyanmically initialize the domain geogrid as an ESMF regridding object. + + Example- ElemConn: "elemconn" + """ if self.grid_type in ["unstructured", "hydrofabric"]: return self.extract_input_variable("ElemConn") else: @@ -639,7 +897,10 @@ def elemconn_var(self) -> str: @property def numelemconn_var(self) -> str: - """Get the number of element connectivity variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen an unstructured or hydrofabric grid type in the configuration file.""" + """Naming convention of the number of nodes per element variable within the "GeogridIn" file the user has specified for ONLY an unstructured mesh or the NextGen hydrofabric. This is a 1-D array stating the how many nodes are connecting each element within the unstructured mesh. This is required so the NextGen Forcings Engine BMI can dyanmically initialize the domain geogrid as an ESMF regridding object. + + Example- NumElemConn: "numelemconn" + """ if self.grid_type in ["unstructured", "hydrofabric"]: return self.extract_input_variable("NumElemConn") else: @@ -647,7 +908,10 @@ def numelemconn_var(self) -> str: @property def element_id_var(self) -> str: - """Get the element ID variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for regridding input forcings if the user has chosen a hydrofabric grid type in the configuration file.""" + """Naming convention of the element id variable within the "GeogridIn" file the user has specified for ONLY the NextGen hydrofabric. This is a 1-D array stating the catchment id numeric naming convention within the "divides" geopackage layer of a given NextGen hydrofabric file. This variable is required in order for the NextGen Forcings Engine to properly advertise the element ids of the unstructured mesh linked to the NextGen hydrofabric catchment ids. + + Example- ElemID: "element_ids" + """ if self.grid_type == "hydrofabric": return self.extract_input_variable("ElemID") else: @@ -655,29 +919,31 @@ def element_id_var(self) -> str: @property def ignored_border_widths(self) -> list: - """Get the list of ignored border widths specified by the user in the configuration file. This is used to control how the program processes input forcings based on the ignored border widths specified for each input forcing in the configuration file.""" + """Border width (in grid cells) to ignore for each input dataset. NOTE: generally, the first input forcing should always be zero or there will be missing data in the final output. + + Example- IgnoredBorderWidths: [0,10] + """ return self._ignored_border_widths @ignored_border_widths.setter def ignored_border_widths(self, value: list) -> None: """Set the list of ignored border widths specified by the user in the configuration file. This is used to control how the program processes input forcings based on the ignored border widths specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("IgnoredBorderWidths") - if self.precip_only_flag: + if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "IgnoredBorderWidths") self.check_input_values_positive(value, "IgnoredBorderWidths") self._ignored_border_widths = value @property def regrid_opt(self): - """Get the list of regridding options specified by the user in the configuration file. This is used to control how input forcings are regridded based on the regridding option specified for each input forcing in the configuration file.""" + """Choose regridding options for each input forcing files being used. Options available are: 1 - ESMF Bilinear, 2 - ESMF Nearest Neighbor, 3 - ESMF Conservative Bilinear. + + Example- RegridOpt: [1,1] + """ return self._regrid_opt @regrid_opt.setter def regrid_opt(self, value: list) -> None: """Set the list of regridding options specified by the user in the configuration file. This is used to control how input forcings are regridded based on the regridding option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("RegridOpt") if self.precip_only_flag: self.check_number_of_inputs_forcings(value, "RegridOpt") self.check_input_values_in_range(value, "RegridOpt", [1, 2, 3]) @@ -691,9 +957,7 @@ def weightsDir(self) -> str: @weightsDir.setter def weightsDir(self, value: str) -> None: """Set the pathway to the ESMF weights directory specified by the user in the configuration file. This is used to control where the program looks for ESMF weights files if the user has chosen to use pre-generated ESMF weights files for regridding input forcings in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.try_config_get("RegridWeightsDir") - if self.precip_only_flag: + if not self.precip_only_flag: if value is not None and not os.path.exists(value): err_out_screen( f"ESMF Weights file directory specified ({value}) but does not exist" @@ -707,26 +971,10 @@ def forceTemoralInterp(self) -> list: @forceTemoralInterp.setter def forceTemoralInterp(self, value: list) -> None: - """Set the list of forcing temporal interpolation options specified by the user in the configuration file. This is used to control how input forcings are temporally interpolated based on the temporal interpolation option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("ForcingTemporalInterpolation") - if not self.precip_only_flag: - self.check_number_of_inputs_forcings(value, "ForcingTemporalInterpolation") - self.check_input_values_in_range( - value, "ForcingTemporalInterpolation", [0, 1, 2] - ) - self._forceTemoralInterp = value - - @property - def forceTemoralInterp(self): - """Get the list of forcing temporal interpolation options specified by the user in the configuration file. This is used to control how input forcings are temporally interpolated based on the temporal interpolation option specified for each input forcing in the configuration file.""" - return self._forceTemoralInterp + """Specify an temporal interpolation for the forcing variables. Interpolation will be done between the two neighboring input forcing states that exist. If only one nearest state exist (I.E. only a state forward in time, or behind), then that state will be used as a "nearest neighbor". NOTE - All input options here must be of the same length of the input forcing number. Also note all temporal interpolation occurs BEFORE downscaling and bias correction. 0 - No temporal interpolation. 1 - Nearest Neighbor, 2 - Linear weighted, average. - @forceTemoralInterp.setter - def forceTemoralInterp(self, value): - """Set the list of forcing temporal interpolation options specified by the user in the configuration file. This is used to control how input forcings are temporally interpolated based on the temporal interpolation option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("ForcingTemporalInterpolation") + Example- ForcingTemporalInterpolation: [0,0] + """ if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "ForcingTemporalInterpolation") self.check_input_values_in_range( @@ -736,29 +984,36 @@ def forceTemoralInterp(self, value): @property def t2dDownscaleOpt(self) -> list: - """Get the list of temperature downscaling options specified by the user in the configuration file. This is used to control how temperature input forcings are downscaled based on the temperature downscaling option specified for each input forcing in the configuration file.""" + """Specify a temperature downscaling method: 0 - No downscaling, 1 - Use a simple lapse rate of 6.75 degrees Celsius to get from the model elevation to the WRF-Hydro elevation, 2 - Use a pre-calculated lapse rate regridded to the WRF-Hydro domain (only NWM), 3 - Use a dynamic lapse rate calculated at each timstep. + + Example- TemperatureDownscaling: [3, 3] + """ return self._t2dDownscaleOpt @t2dDownscaleOpt.setter def t2dDownscaleOpt(self, value: list) -> None: """Set the list of temperature downscaling options specified by the user in the configuration file. This is used to control how temperature input forcings are downscaled based on the temperature downscaling option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("TemperatureDownscaling") if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "TemperatureDownscaling") self.check_input_values_in_range(value, "TemperatureDownscaling", [0, 1, 2]) + count = 0 + for opt in value: + if opt == 2: + self.param_flag[count] = 1 + count += 1 self._t2dDownscaleOpt = value @property def psfcDownscaleOpt(self) -> list: - """Get the list of pressure downscaling options specified by the user in the configuration file. This is used to control how pressure input forcings are downscaled based on the pressure downscaling option specified for each input forcing in the configuration file.""" + """Specify a surface pressure downscaling method: 0 - No downscaling, 1 - Use input elevation and WRF-Hydro elevation to downscale surface pressure. + + Example- PressureDownscaling: [1, 1] + """ return self._psfcDownscaleOpt @psfcDownscaleOpt.setter def psfcDownscaleOpt(self, value: list) -> None: """Set the list of pressure downscaling options specified by the user in the configuration file. This is used to control how pressure input forcings are downscaled based on the pressure downscaling option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("PressureDownscaling") if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "PressureDownscaling") self.check_input_values_in_range(value, "PressureDownscaling", [0, 1]) @@ -766,14 +1021,15 @@ def psfcDownscaleOpt(self, value: list) -> None: @property def swDownscaleOpt(self) -> list: - """Get the list of shortwave downscaling options specified by the user in the configuration file. This is used to control how shortwave radiation input forcings are downscaled based on the shortwave downscaling option specified for each input forcing in the configuration file.""" + """Specify a shortwave radiation downscaling routine. 0 - No downscaling, 1 - Run a topographic adjustment using the WRF-Hydro elevation. + + Example- ShortwaveDownscaling: [1, 1] + """ return self._swDownscaleOpt @swDownscaleOpt.setter def swDownscaleOpt(self, value: list) -> None: """Set the list of shortwave downscaling options specified by the user in the configuration file. This is used to control how shortwave radiation input forcings are downscaled based on the shortwave downscaling option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("ShortwaveDownscaling") if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "ShortwaveDownscaling") self.check_input_values_in_range(value, "ShortwaveDownscaling", [0, 1]) @@ -781,14 +1037,15 @@ def swDownscaleOpt(self, value: list) -> None: @property def q2dDownscaleOpt(self) -> list: - """Get the list of humidity downscaling options specified by the user in the configuration file. This is used to control how humidity input forcings are downscaled based on the humidity downscaling option specified for each input forcing in the configuration file.""" + """Specify a specific humidity downscaling routine. 0 - No downscaling, 1 - Use regridded humidity, along with downscaled temperature/pressure to extrapolate a downscaled surface specific humidty. + + Example- HumidityDownscaling: [1, 1] + """ return self._q2dDownscaleOpt @q2dDownscaleOpt.setter def q2dDownscaleOpt(self, value: list) -> None: """Set the list of humidity downscaling options specified by the user in the configuration file. This is used to control how humidity input forcings are downscaled based on the humidity downscaling option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("HumidityDownscaling") if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "HumidityDownscaling") self.check_input_values_in_range(value, "HumidityDownscaling", [0, 1]) @@ -796,29 +1053,36 @@ def q2dDownscaleOpt(self, value: list) -> None: @property def precipDownscaleOpt(self) -> list: - """Get the list of precipitation downscaling options specified by the user in the configuration file. This is used to control how precipitation input forcings are downscaled based on the precipitation downscaling option specified for each input forcing in the configuration file.""" + """Specify a precipitation downscaling routine. 0 - No downscaling, 1 - NWM mountain mapper downscaling using monthly PRISM climo. + + Example- PrecipDownscaling: [0, 0] + """ return self._precipDownscaleOpt @precipDownscaleOpt.setter def precipDownscaleOpt(self, value: list) -> None: """Set the list of precipitation downscaling options specified by the user in the configuration file. This is used to control how precipitation input forcings are downscaled based on the precipitation downscaling option specified for each input forcing in the configuration file.""" - if value is None: - value = self.extract_input_variable("PrecipDownscaling") - self.check_number_of_inputs_forcings(value, "PrecipDownscaling") + if not self.precip_only_flag: + self.check_number_of_inputs_forcings(value, "PrecipDownscaling") self.check_input_values_in_range(value, "PrecipDownscaling", [0, 1]) - + count = 0 + for opt in value: + if opt == 1: + self.param_flag[count] = 1 + count += 1 self._precipDownscaleOpt = value @property def dScaleParamDirs(self) -> list: - """Get the list of downscaling parameter directories specified by the user in the configuration file. This is used to control where the program looks for downscaling parameter files for each input forcing based on the downscaling parameter directory specified for each input forcing in the configuration file.""" + """Specify the input parameter directory containing necessary downscaling grids. This is ONLY needed for the original NWM WRF-Hydro domain. Otherwise, just point it to a random directory and it will be ignored. + + Example- DownscalingParamDirs: ["./forcingParam/AnA", "./forcingParam/AnA"] + """ return self._dScaleParamDirs @dScaleParamDirs.setter def dScaleParamDirs(self, value: list) -> None: """Set the list of downscaling parameter directories specified by the user in the configuration file. This is used to control where the program looks for downscaling parameter files for each input forcing based on the downscaling parameter directory specified for each input forcing in the configuration file.""" - if value is None: - value = self.extract_input_variable("DownscalingParamDirs") self.check_number_of_inputs_forcings(value, "DownscalingParamDirs") for dirTmp in range(0, len(value)): dir_path = value[dirTmp] @@ -839,73 +1103,17 @@ def perform_downscaling(self) -> bool: ): return True - @property - def sinalpha_var(self) -> str: - """Get the sine of the grid orientation variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the grid orientation variable specified for each input forcing in the configuration file.""" - if self.perform_downscaling: - return self.extract_input_variable("SINALPHA") - - @property - def cosalpha_var(self) -> str: - """Get the cosine of the grid orientation variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the grid orientation variable specified for each input forcing in the configuration file.""" - if self.perform_downscaling: - return self.extract_input_variable("COSALPHA") - - @property - def slope_var(self) -> str: - """Get the slope variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the slope variable specified for each input forcing in the configuration file.""" - if self.perform_downscaling: - return self.extract_input_variable("SLOPE") - - @property - def slope_azimuth_var(self) -> str: - """Get the slope azimuth variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the slope azimuth variable specified for each input forcing in the configuration file.""" - if self.perform_downscaling: - return self.extract_input_variable("SLOPE_AZIMUTH") - - @property - def slope_var_elem(self) -> str: - """Get the slope variable name specified by the user in the configuration file for element-based grids. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the slope variable specified for each input forcing in the configuration file for element-based grids.""" - if self.perform_downscaling: - if self.grid_type == "unstructured": - return self.extract_input_variable("SLOPE_ELEM") - else: - self.raise_grid_type_error(self.grid_type, "SLOPE_ELEM") - - @property - def slope_azimuth_var_elem(self) -> str: - """Get the slope azimuth variable name specified by the user in the configuration file for element-based grids. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the slope azimuth variable specified for each input forcing in the configuration file for element-based grids.""" - if self.perform_downscaling: - if self.grid_type == "unstructured": - return self.extract_input_variable("SLOPE_AZIMUTH_ELEM") - else: - self.raise_grid_type_error(self.grid_type, "SLOPE_AZIMUTH_ELEM") - - @property - def hgt_elem_var(self) -> str: - """Get the height variable name specified by the user in the configuration file for element-based grids. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the height variable specified for each input forcing in the configuration file for element-based grids.""" - if self.perform_downscaling: - if self.grid_type == "unstructured": - return self.extract_input_variable("HGT_ELEM") - else: - self.raise_grid_type_error(self.grid_type, "HGT_ELEM") - - @property - def hgt_var(self) -> str: - """Get the height variable name specified by the user in the configuration file. This is used to control how the program reads in and processes the geogrid information for downscaling input forcings based on the height variable specified for each input forcing in the configuration file.""" - if self.perform_downscaling: - return self.extract_input_variable("HGT") - @property def t2BiasCorrectOpt(self) -> list: - """Get the list of temperature bias correction options specified by the user in the configuration file. This is used to control how temperature input forcings are bias corrected based on the temperature bias correction option specified for each input forcing in the configuration file.""" + """Specify a temperature bias correction method. 0 - No bias correction, 1 - CFSv2 - NLDAS2 Parametric Distribution - NWM ONLY, 2 - Custom NCAR bias-correction based on HRRRv3 analysis - based on hour of day (USE WITH CAUTION), 3 - NCAR parametric GFS bias correction, 4 - NCAR parametric HRRR bias correction. + + Example- TemperatureBiasCorrection: [0, 4] + """ return self._t2BiasCorrectOpt @t2BiasCorrectOpt.setter def t2BiasCorrectOpt(self, value: list) -> None: """Set the list of temperature bias correction options specified by the user in the configuration file. This is used to control how temperature input forcings are bias corrected based on the temperature bias correction option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("TemperatureBiasCorrection") if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "TemperatureBiasCorrection") self.check_input_values_in_range( @@ -915,14 +1123,15 @@ def t2BiasCorrectOpt(self, value: list) -> None: @property def psfcBiasCorrectOpt(self) -> list: - """Get the list of pressure bias correction options specified by the user in the configuration file. This is used to control how pressure input forcings are bias corrected based on the pressure bias correction option specified for each input forcing in the configuration file.""" + """Specify a surface pressure bias correction method. 0 - No bias correction, 1 - CFSv2 - NLDAS2 Parametric Distribution - NWM ONLY. + + Example- PressureBiasCorrection: [0,0] + """ return self._psfcBiasCorrectOpt @psfcBiasCorrectOpt.setter def psfcBiasCorrectOpt(self, value: list) -> None: """Set the list of pressure bias correction options specified by the user in the configuration file. This is used to control how pressure input forcings are bias corrected based on the pressure bias correction option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("PressureBiasCorrection") if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "PressureBiasCorrection") self.check_input_values_in_range(value, "PressureBiasCorrection", [0, 1]) @@ -930,14 +1139,15 @@ def psfcBiasCorrectOpt(self, value: list) -> None: @property def q2BiasCorrectOpt(self): - """Get the list of humidity bias correction options specified by the user in the configuration file. This is used to control how humidity input forcings are bias corrected based on the humidity bias correction option specified for each input forcing in the configuration file.""" + """Specify a specific humidity bias correction method. 0 - No bias correction, 1 - CFSv2 - NLDAS2 Parametric Distribution - NWM ONLY, 2 - Custom NCAR bias-correction based on HRRRv3 analysis - based on hour of day (USE WITH CAUTION). + + Example- HumidityBiasCorrection: [0,0] + """ return self._q2BiasCorrectOpt @q2BiasCorrectOpt.setter def q2BiasCorrectOpt(self, value): """Set the list of humidity bias correction options specified by the user in the configuration file. This is used to control how humidity input forcings are bias corrected based on the humidity bias correction option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("HumidityBiasCorrection") if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "HumidityBiasCorrection") self.check_input_values_in_range(value, "HumidityBiasCorrection", [0, 1, 2]) @@ -945,63 +1155,65 @@ def q2BiasCorrectOpt(self, value): @property def windBiasCorrect(self): - """Get the list of wind bias correction options specified by the user in the configuration file. This is used to control how wind input forcings are bias corrected based on the wind bias correction option specified for each input forcing in the configuration file.""" + """Specify a wind bias correction. 0 - No bias correction, 1 - CFSv2 - NLDAS2 Parametric Distribution - NWM ONLY, 2 - Custom NCAR bias-correction based on HRRRv3 analysis - based on hour of day (USE WITH CAUTION), 3 - NCAR parametric GFS bias correction, 4 - NCAR parametric HRRR bias correction. + + Example- WindBiasCorrection: [0, 4] + """ return self._windBiasCorrect @windBiasCorrect.setter def windBiasCorrect(self, value): """Set the list of wind bias correction options specified by the user in the configuration file. This is used to control how wind input forcings are bias corrected based on the wind bias correction option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("WindBiasCorrection") if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "WindBiasCorrection") - self.check_input_values_in_range(value, "WindBiasCorrection", [0, 4]) + self.check_input_values_in_range( + value, "WindBiasCorrection", [0, 1, 2, 3, 4] + ) self._windBiasCorrect = value @property def swBiasCorrectOpt(self) -> list: - """Get the list of shortwave radiation bias correction options specified by the user in the configuration file. This is used to control how shortwave radiation input forcings are bias corrected based on the shortwave radiation bias correction option specified for each input forcing in the configuration file.""" + """Specify a bias correction for incoming short wave radiation flux. 0 - No bias correction, 1 - CFSv2 - NLDAS2 Parametric Distribution - NWM ONLY, 2 - Custom NCAR bias-correction based on HRRRv3 analysis (USE WITH CAUTION). + + Example- SwBiasCorrection: [0, 2] + """ return self._swBiasCorrectOpt @swBiasCorrectOpt.setter def swBiasCorrectOpt(self, value: list) -> None: """Set the list of shortwave radiation bias correction options specified by the user in the configuration file. This is used to control how shortwave radiation input forcings are bias corrected based on the shortwave radiation bias correction option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("ShortwaveBiasCorrection") if not self.precip_only_flag: - self.check_number_of_inputs_forcings(value, "ShortwaveBiasCorrection") - self.check_input_values_in_range( - value, "ShortwaveBiasCorrection", [0, 1, 2] - ) + self.check_number_of_inputs_forcings(value, "SwBiasCorrection") + self.check_input_values_in_range(value, "SwBiasCorrection", [0, 1, 2]) self._swBiasCorrectOpt = value @property def lwBiasCorrectOpt(self) -> list: - """Get the list of longwave radiation bias correction options specified by the user in the configuration file. This is used to control how longwave radiation input forcings are bias corrected based on the longwave radiation bias correction option specified for each input forcing in the configuration file.""" + """Specify a bias correction for incoming long wave radiation flux. 0 - No bias correction, 1 - CFSv2 - NLDAS2 Parametric Distribution - NWM ONLY, 2 - Custom NCAR bias-correction based on HRRRv3 analysis, blanket adjustment (USE WITH CAUTION), 3 - NCAR parametric GFS bias correction. + + Example- LwBiasCorrection: [0, 2] + """ return self._lwBiasCorrectOpt @lwBiasCorrectOpt.setter def lwBiasCorrectOpt(self, value: list) -> None: """Set the list of longwave radiation bias correction options specified by the user in the configuration file. This is used to control how longwave radiation input forcings are bias corrected based on the longwave radiation bias correction option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("LongwaveBiasCorrection") if not self.precip_only_flag: - self.check_number_of_inputs_forcings(value, "LongwaveBiasCorrection") - self.check_input_values_in_range( - value, "LongwaveBiasCorrection", [0, 1, 2, 4] - ) + self.check_number_of_inputs_forcings(value, "LwBiasCorrection") + self.check_input_values_in_range(value, "LwBiasCorrection", [0, 1, 2, 3, 4]) self._lwBiasCorrectOpt = value @property def precipBiasCorrectOpt(self): - """Get the list of precipitation bias correction options specified by the user in the configuration file. This is used to control how precipitation input forcings are bias corrected based on the precipitation bias correction option specified for each input forcing in the configuration file.""" + """Specify a bias correction for precipitation. 0 - No bias correction, 1 - CFSv2 - NLDAS2 Parametric Distribution - NWM ONLY. + + Example- PrecipBiasCorrection: [0, 0] + """ return self._precipBiasCorrectOpt @precipBiasCorrectOpt.setter def precipBiasCorrectOpt(self, value): """Set the list of precipitation bias correction options specified by the user in the configuration file. This is used to control how precipitation input forcings are bias corrected based on the precipitation bias correction option specified for each input forcing in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("PrecipBiasCorrection") if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "PrecipBiasCorrection") self.check_input_values_in_range(value, "PrecipBiasCorrection", [0, 1]) @@ -1010,8 +1222,8 @@ def precipBiasCorrectOpt(self, value): @property def bias_correction_properties(self) -> dict: """Get the dictionary of bias correction properties specified by the user in the configuration file. This is used to control how input forcings are bias corrected based on the bias correction options specified for each input forcing in the configuration file.""" - bias_correction_properties = { - "surface temperature": self.t2BiasCorrectOpt, + return { + # "surface temperature": self.t2BiasCorrectOpt, #NOTE surface temperature was excluded from this consideration in the orignal code (5/7/2026 pre-refactor). Should it actually be included? "surface pressure": self.psfcBiasCorrectOpt, "specific humidity": self.q2BiasCorrectOpt, "wind forcings": self.windBiasCorrect, @@ -1019,16 +1231,17 @@ def bias_correction_properties(self) -> dict: "long-wave radiation": self.lwBiasCorrectOpt, "Precipitation": self.precipBiasCorrectOpt, } - return bias_correction_properties @property def runCfsNldasBiasCorrect(self) -> bool: """Get the flag for whether to run the NWM-specific bias correction of CFSv2 input forcings specified by the user in the configuration file. This is used to control whether the NWM-specific bias correction of CFSv2 input forcings is run based on whether the user has chosen to run this bias correction in the configuration file.""" - for optTmp in self.bias_correction_properties.values(): - if optTmp == 1: - runCfsNldasBiasCorrect = True - break - if runCfsNldasBiasCorrect: + run_cfs_nldas_bias_correct = False + for bias_option in self.bias_correction_properties.values(): + for opt in bias_option: + if opt == 1: + run_cfs_nldas_bias_correct = True + break + if run_cfs_nldas_bias_correct: for ( bias_correct_name, bias_correct, @@ -1043,7 +1256,9 @@ def runCfsNldasBiasCorrect(self) -> bool: err_out_screen( "CFSv2-NLDAS NWM bias correction can only be used in CFSv2-only configurations" ) + return run_cfs_nldas_bias_correct + @property def number_supp_pcp(self) -> int: """Get the number of supplemental precipitation input forcings specified by the user in the configuration file. This is used to control how many supplemental precipitation input forcings are processed based on the number of supplemental precipitation input forcings specified in the configuration file.""" return len(self.supp_precip_forcings) @@ -1056,13 +1271,10 @@ def supp_precip_file_types(self) -> list: @supp_precip_file_types.setter def supp_precip_file_types(self, value: list) -> None: """Set the list of supplemental precipitation input forcing file types specified by the user in the configuration file. This is used to control how supplemental precipitation input forcing files are read in and processed based on the file types specified for each supplemental precipitation input forcing in the configuration file.""" - if value is None: - value = self.try_config_get("SuppPcpForcingTypes") if value is not None: value = [stype.strip() for stype in value] if value == [""]: value = [] - self.check_number_of_inputs_supp_pcp(value, "SuppPcpForcingTypes") self.check_input_values_in_range( value, @@ -1078,120 +1290,103 @@ def supplemental_precip_file_type_options(self) -> list: @property def rqiMethod(self) -> list: - """Get the list of radar quality index (RQI) thresholding methods specified by the user in the configuration file. This is used to control how radar-based supplemental precipitation input forcings are processed based on the RQI thresholding method specified for each radar-based supplemental precipitation input forcing in the configuration file.""" + """Optional RQI method for radar-based data. 0 - Do not use any RQI filtering. Use all radar-based estimates. 1 - Use hourly MRMS Radar Quality Index grids, 2 - Use NWM monthly climatology grids (NWM only!!!!). + + Example- RqiMethod: 2 + """ + value = None if self.number_supp_pcp > 0: for suppOpt in self.supp_precip_forcings: # Read in RQI threshold to apply to radar products. if suppOpt in (1, 2, 7, 10, 11, 12): - rqiMethod = self.extract_input_variable("RqiMethod") + value = self.extract_input_variable("RqiMethod") # Check that if we have more than one RqiMethod, it's the correct number - if type(rqiMethod) is list: - self.check_number_of_inputs_supp_pcp(rqiMethod, "RqiMethod") - elif type(rqiMethod) is int: + if type(value) is list: + self.check_number_of_inputs_supp_pcp(value, "RqiMethod") + elif type(value) is int: # Support 'classic' mode of single method - rqiMethod = [rqiMethod] * self.number_supp_pcp + value = [value] * self.number_supp_pcp # Make sure the RqiMethod(s) makes sense. - for method in rqiMethod: + for method in value: self.check_input_values_in_range(method, "RqiMethod", [0, 1, 2]) - return rqiMethod + return value @property def rqiThresh(self): - """Get the radar quality index (RQI) threshold value specified by the user in the configuration file. This is used to control how radar-based supplemental precipitation input forcings are processed based on the RQI threshold value specified in the configuration file.""" + """Optional RQI threshold to be used to mask out. Currently used for MRMS products. Please choose a value from 0.0-1.0. Associated radar quality index files will be expected from MRMS data. + + Example- RqiThreshold: 0.9 + """ + value = 1.0 if self.number_supp_pcp > 0: - for suppOpt in self.supp_precip_forcings: + for supp_opt in self.supp_precip_forcings: # Read in RQI threshold to apply to radar products. - if suppOpt in (1, 2, 7, 10, 11, 12): - rqiThresh = self.extract_input_variable("RqiThresh") + if supp_opt in (1, 2, 7, 10, 11, 12): + value = self.extract_input_variable("RqiThresh") # Check that if we have more than one RqiThresh, it's the correct number - if type(rqiThresh) is list: - self.check_number_of_inputs_supp_pcp(rqiThresh, "RqiThresh") - elif type(rqiThresh) is (int, float): + if type(value) is list: + self.check_number_of_inputs_supp_pcp(value, "RqiThresh") + elif type(value) is (int, float): # Support 'classic' mode of single threshold - rqiThresh = [rqiThresh] * self.number_supp_pcp + value = [value] * self.number_supp_pcp # Make sure the RqiThresh(es) makes sense. - for threshold in self.rqiThresh: + for threshold in value: if threshold < 0.0 or threshold > 1.0: err_out_screen( "Please specify RqiThresholds between 0.0 and 1.0." ) - return threshold - - @property - def supp_precip_dirs(self): - """Get the list of pathways to the supplemental precipitation input forcing directories specified by the user in the configuration file. This is used to control where the program looks for supplemental precipitation input forcing files for each supplemental precipitation input forcing based on the directory specified for each supplemental precipitation input forcing in the configuration file.""" - if self.number_supp_pcp > 0: - return self._supp_precip_dirs - - @supp_precip_dirs.setter - def supp_precip_dirs(self, value): - """Set the list of pathways to the supplemental precipitation input forcing directories specified by the user in the configuration file. This is used to control where the program looks for supplemental precipitation input forcing files for each supplemental precipitation input forcing based on the directory specified for each supplemental precipitation input forcing in the configuration file.""" - if value is None and self.number_supp_pcp > 0: - value = self.extract_input_variable("SuppPcpDirectories") - if value > 0: - self.check_number_of_inputs_supp_pcp(value, "SuppPcpDirectories") - for dirTmp in range(0, len(value)): - value[dirTmp] = value[dirTmp].strip() - if not os.path.isdir(value[dirTmp]): - try: - os.makedirs(value[dirTmp], exist_ok=True) - LOG.debug(f"Created supp pcp directory: {value[dirTmp]}") - except OSError as e: - err_out_screen( - f"Unable to create supp pcp directory: {value[dirTmp]}. Error: {e}" - ) - self._supp_precip_dirs = value + return value @property def supp_precip_mandatory(self): - """Get the list of flags for whether each supplemental precipitation input forcing specified by the user in the configuration file is mandatory or optional. This is used to control whether an error is raised if supplemental precipitation input forcing files are not found for each supplemental precipitation input forcing based on whether the user has specified each supplemental precipitation input forcing as mandatory or optional in the configuration file.""" + """Specify whether the Supplemental Precips listed above are mandatory, or optional. This is important for layering contingencies if a product is missing, but forcing files are still desired. 0 - Not mandatory, 1 - Mandatory. + + Example- SuppPcpMandatory: [0, 0, 0] + """ return self._supp_precip_mandatory @supp_precip_mandatory.setter def supp_precip_mandatory(self, value): """Set the list of flags for whether each supplemental precipitation input forcing specified by the user in the configuration file is mandatory or optional. This is used to control whether an error is raised if supplemental precipitation input forcing files are not found for each supplemental precipitation input forcing based on whether the user has specified each supplemental precipitation input forcing as mandatory or optional in the configuration file.""" - if value is None and self.number_supp_pcp > 0: - value = self.extract_input_variable("SuppPcpMandatory") if self.number_supp_pcp > 0: - for enforceOpt in value: - self.check_input_values_in_range(enforceOpt, "SuppPcpMandatory", [0, 1]) + self.check_input_values_in_range(value, "SuppPcpMandatory", [0, 1]) self._supp_precip_mandatory = value @property def regrid_opt_supp_pcp(self): - """Get the list of regridding options for supplemental precipitation input forcings specified by the user in the configuration file. This is used to control how supplemental precipitation input forcings are regridded based on the regridding option specified for each supplemental precipitation input forcing in the configuration file.""" + """Specify regridding options for the supplemental precipitation products. Options available are: 1 - ESMF Bilinear, 2 - ESMF Nearest Neighbor, 3 - ESMF Conservative Bilinear. + + Example- RegridOptSuppPcp: [1, 1, 1] + """ return self._regrid_opt_supp_pcp @regrid_opt_supp_pcp.setter def regrid_opt_supp_pcp(self, value): """Set the list of regridding options for supplemental precipitation input forcings specified by the user in the configuration file. This is used to control how supplemental precipitation input forcings are regridded based on the regridding option specified for each supplemental precipitation input forcing in the configuration file.""" - if value is None and self.number_supp_pcp > 0: - value = self.extract_input_variable("RegridOptSuppPcp") if self.number_supp_pcp > 0: - for optTmp in value: - self.check_input_values_in_range(optTmp, "RegridOptSuppPcp", [1, 2, 3]) + self.check_input_values_in_range(value, "RegridOptSuppPcp", [1, 2, 3]) self._regrid_opt_supp_pcp = value @property def suppTemporalInterp(self): - """Get the list of flags for whether temporal interpolation of supplemental precipitation input forcings specified by the user in the configuration file is performed or not. This is used to control whether temporal interpolation of supplemental precipitation input forcings is performed based on whether the user has chosen to perform temporal interpolation for each supplemental precipitation input forcing in the configuration file.""" + """Specify the time interpretation methods for the supplemental precipitation products. + + Example- SuppPcpTemporalInterpolation: [0, 0, 0] + """ if self.number_supp_pcp > 0: return self._suppTemporalInterp @suppTemporalInterp.setter def suppTemporalInterp(self, value): """Set the list of flags for whether temporal interpolation of supplemental precipitation input forcings specified by the user in the configuration file is performed or not. This is used to control whether temporal interpolation of supplemental precipitation input forcings is performed based on whether the user has chosen to perform temporal interpolation for each supplemental precipitation input forcing in the configuration file.""" - if value is None and self.number_supp_pcp > 0: - value = self.extract_input_variable("SuppPcpTemporalInterpolation") if self.number_supp_pcp > 0: - for optTmp in value: - self.check_input_values_in_range( - optTmp, "SuppPcpTemporalInterpolation", [0, 1, 2] - ) + self.check_input_values_in_range( + value, "SuppPcpTemporalInterpolation", [0, 1, 2] + ) self._suppTemporalInterp = value @property @@ -1203,8 +1398,6 @@ def supp_pcp_max_hours(self): @supp_pcp_max_hours.setter def supp_pcp_max_hours(self, value): """Set the list of maximum forecast hours for supplemental precipitation input forcings specified by the user in the configuration file. This is used to control how supplemental precipitation input forcings are processed based on the maximum forecast hour specified for each supplemental precipitation input forcing in the configuration file.""" - if value is None and self.number_supp_pcp > 0: - value = self.extract_input_variable("SuppPcpMaxHours") if self.number_supp_pcp > 0: if isinstance(value, list): self.check_input_values_positive(value, "SuppPcpMaxHours") @@ -1215,59 +1408,36 @@ def supp_pcp_max_hours(self, value): @property def supp_input_offsets(self): - """Get the list of time offsets to apply to supplemental precipitation input forcing files specified by the user in the configuration file. This is used to control how supplemental precipitation input forcing files are processed based on the time offset specified for each supplemental precipitation input forcing in the configuration file.""" + """In AnA runs, this value is the offset from the available forecast and 00z. For example, if forecast are available at 06z and 18z, set this value to 6. + + Example- SuppPcpInputOffsets = [0, 0, 0] + """ return self._supp_input_offsets @supp_input_offsets.setter def supp_input_offsets(self, value): """Set the list of time offsets to apply to supplemental precipitation input forcing files specified by the user in the configuration file. This is used to control how supplemental precipitation input forcing files are processed based on the time offset specified for each supplemental precipitation input forcing in the configuration file.""" - if value is None and self.number_supp_pcp > 0: - value = self.extract_input_variable("SuppPcpInputOffsets") if self.number_supp_pcp > 0: self.check_number_of_inputs_supp_pcp(value, "SuppPcpInputOffsets") - @property - def supp_precip_param_dir(self): - """Get the directory where downscaling parameters for supplemental precipitation input forcings are stored specified by the user in the configuration file. This is used to control where the program looks for downscaling parameter files for supplemental precipitation input forcings based on the directory specified for supplemental precipitation input forcings in the configuration file.""" - if self.number_supp_pcp > 0: - return self._supp_precip_param_dir - - @supp_precip_param_dir.setter - def supp_precip_param_dir(self, value): - """Set the directory where downscaling parameters for supplemental precipitation input forcings are stored specified by the user in the configuration file. This is used to control where the program looks for downscaling parameter files for supplemental precipitation input forcings based on the directory specified for supplemental precipitation input forcings in the configuration file.""" - if value is None and self.number_supp_pcp > 0: - value = self.extract_input_variable("SuppPcpDownscalingParamDir") - if self.number_supp_pcp > 0: - if not os.path.isdir(value): - err_out_screen( - f"Unable to locate parameter directory: {os.path.abspath(value)}" - ) - self._supp_precip_param_dir = value - @property def supp_precip_dirs(self): - """Get the list of pathways to the supplemental precipitation input forcing directories specified by the user in the configuration file. This is used to control where the program looks for supplemental precipitation input forcing files for each supplemental precipitation input forcing based on the directory specified for each supplemental precipitation input forcing in the configuration file.""" - if self.number_supp_pcp > 0: - return self._supp_precip_dirs + """Specify the correponding supplemental precipitation directories that will be searched for input files. + + Example- SuppPcpDirectories: ['./MRMS_CONUS_GAUGE', './MRMS_CONUS_MULTISENSOR', './MRMS_CLASSIFICATION'] + """ + return self._supp_precip_dirs @supp_precip_dirs.setter def supp_precip_dirs(self, value): """Set the list of pathways to the supplemental precipitation input forcing directories specified by the user in the configuration file. This is used to control where the program looks for supplemental precipitation input forcing files for each supplemental precipitation input forcing based on the directory specified for each supplemental precipitation input forcing in the configuration file.""" - if value is None and self.number_supp_pcp > 0: - value = self.extract_input_variable("SuppPcpDirectories") if self.number_supp_pcp > 0: + self.check_number_of_inputs_supp_pcp(value, "SuppPcpDirectories") # Loop through and ensure all supp pcp directories exist. Also strip out any whitespace # or new line characters. for dirTmp in range(0, len(value)): value[dirTmp] = value[dirTmp].strip() - if not os.path.isdir(value[dirTmp]): - try: - os.makedirs(value[dirTmp], exist_ok=True) - LOG.debug(f"Created supp pcp directory: {value[dirTmp]}") - except OSError as e: - err_out_screen( - f"Unable to create supp pcp directory: {value[dirTmp]}. Error: {e}" - ) + self.try_make_dir(value[dirTmp], " supp pcp") # Special case for ExtAnA where we treat comma separated stage IV, MRMS data as one SuppPcp input if 11 in self.supp_precip_forcings or 12 in self.supp_precip_forcings: @@ -1277,34 +1447,31 @@ def supp_precip_dirs(self, value): ) value = [",".join(value)] self._supp_precip_dirs = value + else: + self._supp_precip_dirs = None @property def supp_precip_param_dir(self): - """Get the directory where downscaling parameters for supplemental precipitation input forcings are stored specified by the user in the configuration file. This is used to control where the program looks for downscaling parameter files for supplemental precipitation input forcings based on the directory specified for supplemental precipitation input forcings in the configuration file.""" + """Specify an optional directory that contains supplemental precipitation parameter fields, I.E monthly RQI climatology. This is ONLY needed for the original NWM WRF-Hydro domain. Otherwise, just point it to a random directory and it will be ignored. + + Example- SuppPcpParamDir: ['./forcingParam/AnA','./forcingParam/AnA','./forcingParam/AnA'] + """ if self.number_supp_pcp > 0: return self._supp_precip_param_dir @supp_precip_param_dir.setter def supp_precip_param_dir(self, value): """Set the directory where downscaling parameters for supplemental precipitation input forcings are stored specified by the user in the configuration file. This is used to control where the program looks for downscaling parameter files for supplemental precipitation input forcings based on the directory specified for supplemental precipitation input forcings in the configuration file.""" - if value is None and self.number_supp_pcp > 0: - value = self.extract_input_variable("SuppPcpDownscalingParamDir") if self.number_supp_pcp > 0: - try: - os.makedirs(value, exist_ok=True) - LOG.debug(f"Created missing SuppPcpParamDir: {value}") - except OSError as e: - err_out_screen(f"Unable to locate SuppPcpParamDir: {value}. Error: {e}") + self.try_make_dir(value, " SuppPcpParamDir") + self._supp_precip_param_dir = value + else: + self._supp_precip_param_dir = None @property def cfsv2EnsMember(self): - """Get the CFSv2 ensemble member to process specified by the user in the configuration file. This is used to control which CFSv2 ensemble member is processed for CFSv2 input forcings based on the ensemble member specified in the configuration file.""" - return self._cfsv2EnsMember - - @cfsv2EnsMember.setter - def cfsv2EnsMember(self, value): """Set the CFSv2 ensemble member to process specified by the user in the configuration file. This is used to control which CFSv2 ensemble member is processed for CFSv2 input forcings based on the ensemble member specified in the configuration file.""" - if value is None and not self.precip_only_flag: + if not self.precip_only_flag: # Read in Ensemble information # Read in CFS ensemble member information IF we have chosen CFSv2 as an input # forcing. @@ -1314,6 +1481,7 @@ def cfsv2EnsMember(self, value): self.check_input_values_in_range( value, "cfsEnsNumber", [1, 2, 3, 4] ) + return value @property def customFcstFreq(self): @@ -1322,124 +1490,18 @@ def customFcstFreq(self): @customFcstFreq.setter def customFcstFreq(self, value): - """Set the custom forecast frequency in minutes specified by the user in the configuration file. This is used to control how often forecasts are issued based on the custom forecast frequency specified in the configuration file.""" - if value is None and not self.precip_only_flag: - value = self.extract_input_variable("CustomFcstFreq") - if len(self.customFcstFreq) != self.number_custom_inputs: - err_out_screen( - f"Improper custom_input fcst_freq specified. This number ({len(self.customFcstFreq)}) must match the frequency of custom input forcings selected ({self.number_custom_inputs})." - ) - self._customFcstFreq = value - - def _validate_config(self) -> None: - """Validate in options from the configuration file and check that proper options were provided.""" - self.b_date_proc + """Options for specifying custom input NetCDF forcing files (in minutes). Choose the input frequency of files that are being processed. I.E., are the input files every 15 minutes, 60 minutes, 3-hours, etc. Please specify the length of custom input frequencies to match the number of custom NetCDF inputs selected above in the Logistics section. - # if not self.precip_only_flag: - - if self.output_freq <= 0: - err_out_screen( - "Please specify an OutputFrequency that is greater than zero minutes." - ) - - if self.sub_output_hour < 0: - err_out_screen( - "Please specify an SubOutputHour that is greater than zero minutes." - ) - if self.sub_output_hour == 0: - self.sub_output_hour = None - - if self.sub_output_freq < 0: - err_out_screen( - "Please specify an SubOutFreq that is greater than zero minutes." - ) - if self._sub_output_freq == 0: - self.sub_output_freq = None - - # TODO Can this be a /tmp directory? - self.make_scratch_dir() - - if self.useCompression not in [0, 1]: - err_out_screen("Please choose a compressOut value of 0 or 1.") - - if self.ana_flag in [0, 1]: - err_out_screen("Please choose a AnAFlag value of 0 or 1.") - - if self.look_back <= 0 and self.look_back != -9999: - err_out_screen("Please specify a positive LookBack or -9999 for realtime.") - - if self.fcst_freq <= 0: - err_out_screen( - "Please specify a ForecastFrequency in the configuration file greater than zero." - ) - # Currently, we only support daily or sub-daily forecasts. Any other iterations should - # be done using custom config files for each forecast cycle. - if self.fcst_freq > 1440: - err_out_screen( - "Only forecast cycles of daily or sub-daily are supported at this time" - ) - - # Read in the ForecastShift option. This is ONLY done for the realtime instance as - # it's used to calculate the beginning of the processing window. - if True: # was: self.realtime_flag: - self.fcst_shift = self.extract_input_variable("ForecastShift") - if self.fcst_shift < 0: + Example- custom_input_fcst_freq: [] + """ + if not self.precip_only_flag: + if len(value) != self.number_custom_inputs: err_out_screen( - "Please specify a ForecastShift in the configuration file greater than or equal to zero." + f"Improper custom_input fcst_freq specified. This number ({len(value)}) must match the frequency of custom input forcings selected ({self.number_custom_inputs})." ) - - # Calculate the beginning/ending processing dates if we are running realtime - if self.realtime_flag: - calculate_lookback_window(self) - - # if self.refcst_flag: - # Calculate the number of forecasts to issue, and verify the user has chosen a - # correct divider based on the dates - # dt_tmp = self.e_date_proc - self.b_date_proc - # if (dt_tmp.days * 1440 + dt_tmp.seconds / 60.0) % self.fcst_freq != 0: - # err_out_screen('Please choose an equal divider forecast frequency for your ' - # 'specified reforecast range.') - # self.nFcsts = int((dt_tmp.days * 1440 + dt_tmp.seconds / 60.0) / self.fcst_freq) - - # Flag to constrain AORC forcing data cycle output - # for optTmp in self.input_forcings: - # if optTmp == 12: - # self.nFcsts = 1 - self.nFcsts = 1 - - if self.look_back != -9999: - calculate_lookback_window(self) - - # Process geospatial information - - if len(self.spatial_meta) == 0: - # No spatial metadata file found. - self.spatial_meta = None + self._customFcstFreq = value else: - if not os.path.isfile(self.spatial_meta): - err_out_screen( - "Unable to locate optional spatial metadata file: " - + self.spatial_meta - ) - - # Calculate the beginning/ending processing dates if we are running realtime - if self.realtime_flag: - calculate_lookback_window(self) - - # Create temporary array to hold flags if we need input parameter files. - param_flag = np.zeros([len(self.input_forcings)], int) - - count_tmp = 0 - for optTmp in self.precipDownscaleOpt: - if optTmp == 1: - param_flag[count_tmp] = 1 - count_tmp = count_tmp + 1 - - for suppOpt in self.supp_precip_forcings: - if suppOpt not in list(range(1, self.supp_precip_count + 1)): - err_out_screen( - f"Please specify SuppForcing values between 1 and {self.supp_precip_count}." - ) + self._customFcstFreq = None @property def nwm_domain(self) -> str: diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py index b442aecd..16e399d6 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py @@ -1359,17 +1359,78 @@ "uid64", ], "var_rename_map": {"config_path": "cfg_bmi"}, - "cfg_bmi_to_attrs_map": { + "extract_input_variable_attrs_map": { "SuppPcp": "supp_precip_forcings", "OutputFrequency": "output_freq", "SubOutputHour": "sub_output_hour", "SubOutFreq": "sub_output_freq", "ScratchDir": "scratch_dir", - "compressOutput": "useCompression", + "compressOutput": "useCompression", # 0 "AnAFlag": "ana_flag", "LookBack": "look_back", "ForecastFrequency": "fcst_freq", + "ForecastShift": "fcst_shift", + "GRID_TYPE": "grid_type", + "DownscalingParamDirs": "dScaleParamDirs", + "SuppPcpDirectories": "supp_precip_dirs", + "SuppPcpMandatory": "supp_precip_mandatory", + "RegridOptSuppPcp": "regrid_opt_supp_pcp", + "SuppPcpTemporalInterpolation": "suppTemporalInterp", + "SuppPcpMaxHours": "supp_pcp_max_hours", + "SuppPcpInputOffsets": "supp_input_offsets", + "SuppPcpParamDirs": "supp_precip_param_dir", + }, + "extract_input_variable_attrs_map_precip_only": { + "customSuppPcpFreq": "customSuppPcpFreq", + }, + "extract_input_variable_attrs_map_not_precip_only": { + "ForecastInputHorizons": "fcst_input_horizons", # np + "ForecastInputOffsets": "fcst_input_offsets", # np + "IgnoredBorderWidths": "ignored_border_widths", # np + "RegridOpt": "regrid_opt", # np + "RegridWeightsDir": "weightsDir", # np + "ForcingTemporalInterpolation": "forceTemoralInterp", # np + "TemperatureDownscaling": "t2dDownscaleOpt", # np + "PressureDownscaling": "psfcDownscaleOpt", # np + "ShortwaveDownscaling": "swDownscaleOpt", # np + "HumidityDownscaling": "q2dDownscaleOpt", # np + "PrecipDownscaling": "precipDownscaleOpt", # np -complicated partial np + "TemperatureBiasCorrection": "t2BiasCorrectOpt", # np #no + "PressureBiasCorrection": "psfcBiasCorrectOpt", # np #yes + "HumidityBiasCorrection": "q2BiasCorrectOpt", # np #yes + "WindBiasCorrection": "windBiasCorrect", # np #yes + "SwBiasCorrection": "swBiasCorrectOpt", # np #yes + "LwBiasCorrection": "lwBiasCorrectOpt", # np #yes + "PrecipBiasCorrection": "precipBiasCorrectOpt", # np #yes + "InputForcings": "input_forcings", # np + "InputForcingTypes": "input_force_types", # np + "InputForcingDirectories": "input_force_dirs", # np + "InputMandatory": "input_force_mandatory", # np + "custom_input_fcst_freq": "customFcstFreq", # np + }, + "downscaling_attrs_map": { + "SINALPHA": "sinalpha_var", + "COSALPHA": "cosalpha_var", + "SLOPE": "slope_var", + "SLOPE_AZIMUTH": "slope_azimuth_var", + "HGT": "hgt_var", + }, + "downscaling_unstructred_attrs_map": { + "SLOPE_ELEM": "slope_var_elem", + "SLOPE_AZIMUTH_ELEM": "slope_azimuth_var_elem", + "HGT_ELEM": "hgt_elem_var", + }, + "extract_input_variable_set_default_attrs_map": { + "includeLQFrac": "include_lqfrac", + "floatOutput": "useFloats", + "Output": "forcing_output", + }, + "try_config_get_except_attr_map": { + "RefcstBDateProc": "b_date_proc", + "Geopackage": "geopackage", + "GeogridIn": "geogrid", "SpatialMetaIn": "spatial_meta", + "SuppPcpForcingTypes": "supp_precip_file_types", }, "file_types": ["GRIB1", "GRIB2", "NETCDF", "NETCDF4", "NWM", "ZARR"], } From f001e19267e7d03b7605304567dc466d911ea9c3 Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Mon, 18 May 2026 09:42:58 -0500 Subject: [PATCH 04/71] fix circular imports --- .../NextGen_Forcings_Engine/core/parallel.py | 16 ++++++++++------ .../NextGen_Forcings_Engine/esmf_utils.py | 8 ++++++-- .../NextGen_Forcings_Engine/os_utils.py | 16 +++++++++++++--- .../NextGen_Forcings_Engine/retry_utils.py | 9 ++++++++- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py index 742e4511..dee8126c 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py @@ -1,11 +1,12 @@ from __future__ import annotations + import atexit -from functools import partial import os import signal import sys -import typing -from typing import TypeVar +from functools import partial +from typing import TYPE_CHECKING + import mpi4py import numpy as np @@ -13,8 +14,11 @@ from mpi4py import MPI # noqa: E402 -from . import err_handler -from . import mpi_utils +if TYPE_CHECKING: + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( + ConfigOptions, + ) +from . import err_handler, mpi_utils # If MPI was initialized outside of python, # disable initialization/finalization behavior @@ -23,8 +27,8 @@ mpi4py.rc.finalize = False if typing.TYPE_CHECKING: - from .geoMod import GriddedGeoMeta from .config import ConfigOptions + from .geoMod import GriddedGeoMeta _T = TypeVar("_T") diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/esmf_utils.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/esmf_utils.py index 2076278a..f49b8960 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/esmf_utils.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/esmf_utils.py @@ -1,3 +1,6 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import types import esmpy as ESMF @@ -7,8 +10,9 @@ import shapely from . import retry_utils -from .core.config import ConfigOptions -from .core.parallel import MpiConfig +if TYPE_CHECKING: + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ConfigOptions + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.parallel import MpiConfig @retry_utils.retry_w_mpi_context( diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/os_utils.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/os_utils.py index 3d823c60..67827d49 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/os_utils.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/os_utils.py @@ -1,9 +1,19 @@ -from . import retry_utils +from __future__ import annotations + import traceback import types import typing -from .core.parallel import MpiConfig -from .core.config import ConfigOptions +from typing import TYPE_CHECKING + +from . import retry_utils + +if TYPE_CHECKING: + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( + ConfigOptions, + ) + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.parallel import ( + MpiConfig, + ) import os diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/retry_utils.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/retry_utils.py index 779dd7dd..f542c3ad 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/retry_utils.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/retry_utils.py @@ -1,10 +1,17 @@ +from __future__ import annotations + import functools import time import traceback import types +from typing import TYPE_CHECKING from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.parallel import MpiConfig -from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ConfigOptions + +if TYPE_CHECKING: + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( + ConfigOptions, + ) def retry_w_mpi_context( From ef3dc0cdd01f71f14282f6dfd205b3731aae84dc Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Mon, 18 May 2026 09:43:45 -0500 Subject: [PATCH 05/71] updat for NHF --- .../NextGen_hyfab_to_ESMF_Mesh.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ESMF_Mesh_Domain_Configuration_Production/NextGen_hyfab_to_ESMF_Mesh.py b/ESMF_Mesh_Domain_Configuration_Production/NextGen_hyfab_to_ESMF_Mesh.py index 1783ee34..c9426a94 100644 --- a/ESMF_Mesh_Domain_Configuration_Production/NextGen_hyfab_to_ESMF_Mesh.py +++ b/ESMF_Mesh_Domain_Configuration_Production/NextGen_hyfab_to_ESMF_Mesh.py @@ -1,11 +1,12 @@ +import argparse +import os +import pathlib +import uuid + import geopandas as gpd import netCDF4 import numpy as np import pandas as pd -import argparse -import pathlib -import os -import uuid gpd.options.display_precision = 16 np.set_printoptions(precision=128) From 4fef5ceaa0c61254c705330b6e357397b38e824f Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Mon, 18 May 2026 09:44:24 -0500 Subject: [PATCH 06/71] remove calls to validate_config and initialize --- .../NextGen_Forcings_Engine/bmi_model.py | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index 90bae785..06fe6d13 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -267,16 +267,16 @@ def initialize(self, config_file: str, output_path: str | None = None) -> None: self._job_meta = ConfigOptions(self.cfg_bmi) # Parse the configuration options - try: - self._job_meta.validate_config(self.cfg_bmi) - except KeyboardInterrupt as e: - err_handler.err_out_screen("User keyboard interrupt", e) - except ImportError as e: - err_handler.err_out_screen("Missing Python packages", e) - except InterruptedError as e: - err_handler.err_out_screen("External kill signal detected", e) - except Exception as e: - err_handler.err_out_screen("Unhandled exception", e) + # try: + # self._job_meta.validate_config(self.cfg_bmi) + # except KeyboardInterrupt as e: + # err_handler.err_out_screen("User keyboard interrupt", e) + # except ImportError as e: + # err_handler.err_out_screen("Missing Python packages", e) + # except InterruptedError as e: + # err_handler.err_out_screen("External kill signal detected", e) + # except Exception as e: + # err_handler.err_out_screen("Unhandled exception", e) # Set NWM version and config, if provided in the config if self.cfg_bmi.get("NWM_VERSION") is not None: @@ -445,8 +445,24 @@ def initialize_with_params( :param output_path: The output path for model results. If omitted, a default path will be generated. :raises ValueError: If an invalid grid type is specified, an exception is raised. """ + # This is required prior to the first log message. + LOG.bind() + + bmi_cfg_file = Path(config_file).resolve() + if not bmi_cfg_file.is_file(): + LOG.critical(f"Config file {bmi_cfg_file} not found, nothing to do...") + raise RuntimeError( + f"Config file {bmi_cfg_file} not found, nothing to do..." + ) + + LOG.info(f"Reading config file: {bmi_cfg_file}") + with bmi_cfg_file.open("r") as fp: + cfg = yaml.safe_load(fp) + + self.cfg_bmi = parse_config(cfg) # Set the job metadata parameters (b_date, geogrid) using config_options - self._job_meta = ConfigOptions(self.cfg_bmi, b_date=b_date, geogrid_arg=geogrid) + self.cfg_bmi = parse_config(cfg) + self._job_meta = ConfigOptions(self.cfg_bmi, b_date=b_date, geogrid=geogrid) # Now that _job_meta is set, call initialize() to set up the core model self.initialize(config_file, output_path=output_path) From 1d80cb8963654e85c3112fbd707a595708c8e005 Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Mon, 18 May 2026 09:44:58 -0500 Subject: [PATCH 07/71] debugging changes --- .../NextGen_Forcings_Engine/core/config.py | 143 +++++++++-------- .../NextGen_Forcings_Engine/core/consts.py | 144 +++++++++--------- 2 files changed, 154 insertions(+), 133 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py index 69cb32f7..f1b6c4d7 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py @@ -44,11 +44,10 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No self.user_provided_geogrid_flag = False self.b_date_proc = b_date - self._cfg_bmi = cfg_bmi - self._geogrid = geogrid + self.cfg_bmi = cfg_bmi + self.geogrid = geogrid self.bmi_time_index = 0 - self.precip_only_flag = False self.globalNdv = -9999.0 self.d_program_init = datetime.now(timezone.utc) self.errFlag = 0 @@ -60,9 +59,13 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No ) self.nwm_source = "s3://noaa-nwm-retrospective-3-0-pds" - self.broadcast_new_64bit_uid() - + self._scratch_dir_has_been_uniquefied = False + self.supp_precip_forcings = self.extract_input_variable("SuppPcp") + if not self.precip_only_flag: + self.input_forcings = self.extract_input_variable("InputForcings") + + # Create temporary array to hold flags if we need input parameter files. self.param_flag = np.zeros([len(self.input_forcings)], int) @@ -70,9 +73,11 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No # These are indexed from the consts dictionary using the class name for attr in CONFIGOPTIONS[self.__class__.__name__]: setattr(self, attr, None) + self.broadcast_new_64bit_uid() - self.set_attrs(self.try_config_get_except_attr_map) - self.supp_precip_forcings = self.extract_input_variable("SuppPcp") + for cfg_bmi_attr, config_options_attr in self.try_config_get_except_attr_map.items(): + setattr(self,config_options_attr,self.try_config_get(cfg_bmi_attr)) + self.set_attrs(CONFIGOPTIONS["extract_input_variable_attrs_map"]) if self.precip_only_flag: @@ -94,20 +99,24 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No for cfg_bmi_attr, config_options_attr in CONFIGOPTIONS[ "extract_input_variable_set_default_attrs_map" ].items(): + if config_options_attr=="supp_pcp_max_hours": + default=None + else: + default=0 setattr( self, config_options_attr, - self.extract_input_variable_set_default(cfg_bmi_attr), + self.extract_input_variable_set_default(cfg_bmi_attr,default), ) @property def try_config_get_except_attr_map(self) -> dict: """Get the mapping of configuration variable names to class attribute names for variables that are extracted directly from the configuration file without any additional processing. This is used to control how variables are extracted from the configuration file and assigned to class attributes in a consistent way based on the mapping specified in the consts.py file.""" dict_map = CONFIGOPTIONS["try_config_get_except_attr_map"] - if self._b_date_proc is not None: - dict_map.pop("b_date_proc") - if self._geogrid is not None: - dict_map.pop("geogrid") + if self._b_date_proc is not None and "RefcstBDateProc" in dict_map: + dict_map.pop("RefcstBDateProc") + if self.geogrid is not None and "GeogridIn" in dict_map: + dict_map.pop("GeogridIn") return dict_map @property @@ -127,7 +136,7 @@ def cfg_bmi(self, value: dict) -> None: @property def force_count(self) -> int: """Calculate the number of total possible input forcing options based on the length of the InputForcings list in the consts.py file. This is used for error checking to ensure users specify valid input forcing options in the configuration file.""" - return len(FORCINGINPUTMOD["InputForcings"]["PRODUCT_NAME"]) + return len(FORCINGINPUTMOD["PRODUCT_NAME"]) @property def supp_precip_count(self) -> int: @@ -144,9 +153,11 @@ def number_supp_pcp(self) -> int: @property def precip_only_flag(self) -> bool: """Flag to indicate whether the user has chosen to run the supplemental precip forcings module only, which will trigger some different processing pathways and error checking for certain configuration options.""" + precip_only = False if self.number_supp_pcp == 1: if int(self.supp_precip_forcings[0]) == 14: - return True + precip_only = True + return precip_only def set_attrs(self, attrs_dict: dict): """Set the attributes of the class based on the configuration file. This is used to populate the attributes of the class after they have been read in and validated from the configuration file.""" @@ -154,7 +165,12 @@ def set_attrs(self, attrs_dict: dict): setattr( self, config_options_attr, self.extract_input_variable(cfg_bmi_attr) ) - + def set_attrs_use_default(self,attrs_dict:dict): + """Set the attributes of the class based on the configuration file. Set default value to default if not found in config file.""" + for cfg_bmi_attr, config_options_attr in attrs_dict.items(): + setattr( + self, config_options_attr, self.extract_input_variable_set_default(cfg_bmi_attr) + ) def extract_input_variable(self, variable_name: str) -> str: """Extract the variable name from the configuration file for a given variable.""" try: @@ -183,8 +199,9 @@ def extract_input_variable_set_default(self, variable_name: str, default=0) -> s err_out_screen( f"Improper {variable_name} value: {self.cfg_bmi[variable_name]}", e ) - if variable not in [0, 1]: - err_out_screen(f"Please choose a {variable_name} value of 0 or 1.") + if default==0: + if variable not in [0, 1]: + err_out_screen(f"Please choose a {variable_name} value of 0 or 1.") return variable def try_config_get(self, variable_name: str) -> str: @@ -202,22 +219,22 @@ def try_config_get(self, variable_name: str) -> str: ) def check_number_of_inputs( - self, value: list, variable_name: str, input_type: str + self, value: list, variable_name: str, input_type: str,number_inputs:int ) -> None: """Check that the number of inputs specified by the user in the configuration file matches the expected number of inputs for a given variable.""" - if len(value) != self.number_inputs: + if len(value) != number_inputs: err_out_screen( f"Number of {variable_name} values must match the number of {input_type} in the configuration file." ) def check_number_of_inputs_forcings(self, value: list, variable_name: str) -> None: """Check that the number of inputs specified by the user in the configuration file matches the expected number of inputs for a given variable, specifically for input forcings variables which should match the number of input forcing options specified by the user in the configuration file.""" - return self.check_number_of_inputs(value, variable_name, " InputForcings") + return self.check_number_of_inputs(value, variable_name, " InputForcings",self.number_inputs) def check_number_of_inputs_supp_pcp(self, value: list, variable_name: str) -> None: """Check that the number of inputs specified by the user in the configuration file matches the expected number of inputs for a given variable, specifically for supplemental precip forcing variables which should match the number of supplemental precip forcing options specified by the user in the configuration file.""" return self.check_number_of_inputs( - value, variable_name, " SupplementalPrecipForcings" + value, variable_name, " SupplementalPrecipForcings",self.number_supp_pcp ) def check_input_values_in_range( @@ -225,11 +242,19 @@ def check_input_values_in_range( ) -> None: """Check that the input values specified by the user in the configuration file are within a valid range for a given variable.""" for val in value: - if val in valid_input_options: + if val not in valid_input_options: err_out_screen( f"Invalid {variable_name} value '{val}' specified in configuration file. Please specify valid values: {valid_input_options}." ) + def check_input_values_non_negative(self, value: list, variable_name: str) -> None: + """Check that the input values specified by the user in the configuration file are positive for a given variable.""" + for val in value: + if float(val) < 0: + err_out_screen( + f"Invalid {variable_name} value '{val}' specified in configuration file. Please specify values greater than or equal to zero." + ) + def check_input_values_positive(self, value: list, variable_name: str) -> None: """Check that the input values specified by the user in the configuration file are positive for a given variable.""" for val in value: @@ -237,7 +262,6 @@ def check_input_values_positive(self, value: list, variable_name: str) -> None: err_out_screen( f"Invalid {variable_name} value '{val}' specified in configuration file. Please specify values greater than zero." ) - def uniquefy_scratch_dir_as_child(self, uid: str) -> None: """Modify the existing scratch dir by adding the UID string available to all ranks from the MpiConfig class. @@ -297,11 +321,12 @@ def supp_precip_forcings(self): @supp_precip_forcings.setter def supp_precip_forcings(self, value: list) -> None: """Set the list of supplemental precip forcing options specified by the user in the configuration file. This is used to control which supplemental precip forcings are processed and how they are processed based on the other configuration options specified for each supplemental precip forcing.""" - self.check_input_values_in_range( - value, - "SuppPcp", - list(range(1, self.supp_precip_count + 1)), - ) + if len(value)>0: + self.check_input_values_in_range( + [int(i) for i in value], + "SuppPcp", + list(range(1, self.supp_precip_count + 1)), + ) self._supp_precip_forcings = value @property @@ -315,7 +340,7 @@ def output_freq(self, value: int) -> None: Example- OutputFrequency: 60 """ - self.check_input_values_positive([value], "OutputFrequency") + self.check_input_values_non_negative([value], "OutputFrequency") self._output_freq = value @property @@ -331,11 +356,7 @@ def sub_output_hour(self, value: int) -> None: Example- SubOutputHour: 0 """ - self.check_input_values_positive([value], "SubOutputHour") - if value < 0: - err_out_screen( - "Please specify an SubOutputHour that is greater than zero minutes." - ) + self.check_input_values_non_negative([value], "SubOutputHour") if value == 0: value = None self._sub_output_hour = value @@ -434,7 +455,7 @@ def fcst_freq(self) -> int: @fcst_freq.setter def fcst_freq(self, value: int) -> None: """Set the forecast frequency in hours specified by the user in the configuration file. This is used to calculate the processing window for reforecast simulations, and is only necessary if the user is running a reforecast simulation with a specified processing window rather than a realtime simulation.""" - self.check_input_values_positive([value], "ForecastFrequency") + self.check_input_values_non_negative([value], "ForecastFrequency") if value > 1440: err_out_screen( "Only forecast cycles of daily or sub-daily are supported at this time" @@ -468,7 +489,7 @@ def b_date_proc(self) -> str: Example- RefcstBDateProc: 202210071400 """ - return self._bdate_proc + return self._b_date_proc @b_date_proc.setter def b_date_proc(self, value: str | datetime) -> None: @@ -539,7 +560,8 @@ def geogrid(self, value: str) -> None: if self.user_provided_geogrid_flag: self._geogrid = value if value is None: - err_out_screen("Unable to locate GeogridIn in the configuration file.") + self._geogrid = value + # err_out_screen("Unable to locate GeogridIn in the configuration file.") else: geogrid_parent = os.path.dirname(value) geogrid_filename = os.path.basename(value) @@ -548,7 +570,8 @@ def geogrid(self, value: str) -> None: self._geogrid = os.path.join( geogrid_parent, f"{self.uid64}_{geogrid_filename}" ) - self.try_make_dir(geogrid_parent, " esmf_mesh") + self.try_make_dir(geogrid_parent, " esmf_mesh") + def try_make_dir(self, directory: str, optional_str: str = "") -> None: """Try to make a directory, and catch any errors.""" @@ -573,7 +596,7 @@ def input_forcings(self, value: list) -> None: self.check_input_values_in_range( value, "InputForcings", list(range(1, self.force_count + 1)) ) - self._input_forcings = value + self._input_forcings = value @property def number_inputs(self) -> int: @@ -628,14 +651,13 @@ def input_force_types(self, value: list) -> None: self.check_input_values_in_range( value, "InputForcingTypes", self.file_types ) - self._input_force_types = value - else: - self._input_force_types = None + self._input_force_types = value + @property def file_types(self): """Get the list of input forcing file types specified by the user in the configuration file. This is used to control how input forcings are read in and processed based on the file type specified for each input forcing in the configuration file.""" - return self.CONFIGOPTIONS["file_types"] + return CONFIGOPTIONS["file_types"] @property def input_force_dirs(self) -> list: @@ -663,10 +685,9 @@ def input_force_dirs(self, value: list) -> None: self.aws = True else: self.try_make_dir(dir_path, " forcing") - self._input_force_dirs = value - else: - self._input_force_dirs = None + self._input_force_dirs = value + @property def input_force_mandatory(self) -> list: """Get the list of input forcing mandatory flags specified by the user in the configuration file. This is used to control whether the program should raise an error if input forcings for a given forecast cycle are not found for each input forcing specified by the user in the configuration file.""" return self._input_force_mandatory @@ -680,10 +701,10 @@ def input_force_mandatory(self, value: list) -> None: if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "InputMandatory") self.check_input_values_in_range(value, "InputMandatory", [0, 1]) - self._input_force_mandatory = value - else: - self._input_force_mandatory = None + self._input_force_mandatory = value + + @property def customSuppPcpFreq(self) -> int: """Get the custom supplemental precip output frequency specified by the user in the configuration file. This is used to control the output frequency of supplemental precip forcings if the user has chosen to run the supplemental precip forcings module only.""" return self._customSuppPcpFreq @@ -692,11 +713,12 @@ def customSuppPcpFreq(self) -> int: def customSuppPcpFreq(self, value: int) -> None: """Set the custom supplemental precip output frequency specified by the user in the configuration file. This is used to control the output frequency of supplemental precip forcings if the user has chosen to run the supplemental precip forcings module only.""" if self.precip_only_flag: - self.check_input_values_positive([value], "customSuppPcpFreq") + self.check_input_values_non_negative([value], "customSuppPcpFreq") self._customSuppPcpFreq = value else: self._customSuppPcpFreq = None + @property def fcst_shift(self) -> int: """Forecast cycles are determined by splitting up a day by equal ForecastFrequency interval. If there is a desire to shift the cycles to a different time step, ForecastShift will shift forecast cycles ahead by a determined set of minutes. For example, ForecastFrequency of 6 hours will produce forecasts cycles at 00, 06, 12, and 18 UTC. However, a ForecastShift of 1 hour will produce forecast cycles at 01, 07, 13, and 18 UTC. NOTE - This is only used by the realtime instance to calculate forecast cycles accordingly. Re-forecasts will use the beginning and ending dates specified in conjunction with the forecast frequency to determine forecast cycle dates. @@ -707,7 +729,7 @@ def fcst_shift(self) -> int: @fcst_shift.setter def fcst_shift(self, value: int) -> None: if True: # was: self.realtime_flag: - self.check_input_values_positive([value], "ForecastShift") + self.check_input_values_non_negative([value], "ForecastShift") # Calculate the beginning/ending processing dates if we are running realtime if self.realtime_flag: calculate_lookback_window(self) @@ -752,7 +774,7 @@ def fcst_input_horizons(self) -> list: def fcst_input_horizons(self, value: list) -> None: if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "ForecastInputHorizons") - self.check_input_values_positive(value, "ForecastInputHorizons") + self.check_input_values_non_negative(value, "ForecastInputHorizons") else: if len(self.fcst_input_horizons) != 1: err_out_screen( @@ -772,7 +794,7 @@ def fcst_input_offsets(self): def fcst_input_offsets(self, value: list) -> None: if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "ForecastInputOffsets") - self.check_input_values_positive(value, "ForecastInputOffsets") + self.check_input_values_non_negative(value, "ForecastInputOffsets") self._fcst_input_offsets = value @property @@ -930,7 +952,7 @@ def ignored_border_widths(self, value: list) -> None: """Set the list of ignored border widths specified by the user in the configuration file. This is used to control how the program processes input forcings based on the ignored border widths specified for each input forcing in the configuration file.""" if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "IgnoredBorderWidths") - self.check_input_values_positive(value, "IgnoredBorderWidths") + self.check_input_values_non_negative(value, "IgnoredBorderWidths") self._ignored_border_widths = value @property @@ -1092,6 +1114,7 @@ def dScaleParamDirs(self, value: list) -> None: ) self._dScaleParamDirs = value + @property def perform_downscaling(self) -> bool: """Determine whether downscaling of input forcings is necessary based on the downscaling options specified by the user for each input forcing in the configuration file.""" if ( @@ -1377,8 +1400,7 @@ def suppTemporalInterp(self): Example- SuppPcpTemporalInterpolation: [0, 0, 0] """ - if self.number_supp_pcp > 0: - return self._suppTemporalInterp + return self._suppTemporalInterp @suppTemporalInterp.setter def suppTemporalInterp(self, value): @@ -1392,17 +1414,15 @@ def suppTemporalInterp(self, value): @property def supp_pcp_max_hours(self): """Get the list of maximum forecast hours for supplemental precipitation input forcings specified by the user in the configuration file. This is used to control how supplemental precipitation input forcings are processed based on the maximum forecast hour specified for each supplemental precipitation input forcing in the configuration file.""" - if self.number_supp_pcp > 0: - return self._supp_pcp_max_hours + return self._supp_pcp_max_hours @supp_pcp_max_hours.setter def supp_pcp_max_hours(self, value): """Set the list of maximum forecast hours for supplemental precipitation input forcings specified by the user in the configuration file. This is used to control how supplemental precipitation input forcings are processed based on the maximum forecast hour specified for each supplemental precipitation input forcing in the configuration file.""" if self.number_supp_pcp > 0: if isinstance(value, list): - self.check_input_values_positive(value, "SuppPcpMaxHours") + self.check_number_of_inputs_supp_pcp(value, "SuppPcpMaxHours") elif isinstance(value, float) or isinstance(value, int): - self.check_input_values_positive(value, "SuppPcpMaxHours") value = [value] * self.number_supp_pcp self._supp_pcp_max_hours = value @@ -1456,8 +1476,7 @@ def supp_precip_param_dir(self): Example- SuppPcpParamDir: ['./forcingParam/AnA','./forcingParam/AnA','./forcingParam/AnA'] """ - if self.number_supp_pcp > 0: - return self._supp_precip_param_dir + return self._supp_precip_param_dir @supp_precip_param_dir.setter def supp_precip_param_dir(self, value): diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py index 16e399d6..5a4490f2 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py @@ -1264,90 +1264,90 @@ "ConfigOptions": [ "bmi_time", "current_time", - "input_forcings", - "supp_precip_forcings", - "input_force_dirs", - "input_force_types", + # "input_forcings", + # "supp_precip_forcings", + # "input_force_dirs", + # "input_force_types", "supp_precip_dirs", - "supp_precip_file_types", + # "supp_precip_file_types", "supp_precip_param_dir", - "input_force_mandatory", + # "input_force_mandatory", "supp_precip_mandatory", - "supp_pcp_max_hours", - "number_inputs", - "number_supp_pcp", - "output_freq", - "sub_output_hour", - "sub_output_freq", - "scratch_dir", - "num_output_steps", - "num_supp_output_steps", - "actual_output_steps", - "realtime_flag", - "refcst_flag", - "ana_flag", + # "supp_pcp_max_hours", + # "number_inputs", + # "number_supp_pcp", + # "output_freq", + # "sub_output_hour", + # "sub_output_freq", + # "scratch_dir", + # "num_output_steps", + # "num_supp_output_steps", + # "actual_output_steps", + # "realtime_flag", + # "refcst_flag", + # "ana_flag", "e_date_proc", "first_fcst_cycle", "current_fcst_cycle", "current_output_step", - "cycle_length_minutes", + # "cycle_length_minutes", "prev_output_date", "current_output_date", - "look_back", + # "look_back", "future_time", - "fcst_freq", + # "fcst_freq", "nFcsts", - "fcst_shift", - "fcst_input_horizons", - "fcst_input_offsets", + # "fcst_shift", + # "fcst_input_horizons", + # "fcst_input_offsets", "process_window", - "spatial_meta", - "grid_type", + # "spatial_meta", + # "grid_type", "grid_meta", "ExactExtract", - "lat_var", - "lon_var", - "hgt_var", - "cosalpha_var", - "sinalpha_var", - "slope_var", - "slope_azimuth_var", - "slope_var_elem", - "slope_azimuth_var_elem", - "nodecoords_var", - "elemcoords_var", - "elemconn_var", - "numelemconn_var", - "element_id_var", - "hgt_elem_var", - "ignored_border_widths", - "regrid_opt", - "weightsDir", - "regrid_opt_supp_pcp", + # "lat_var", + # "lon_var", + # "hgt_var", + # "cosalpha_var", + # "sinalpha_var", + # "slope_var", + # "slope_azimuth_var", + # "slope_var_elem", + # "slope_azimuth_var_elem", + # "nodecoords_var", + # "elemcoords_var", + # "elemconn_var", + # "numelemconn_var", + # "element_id_var", + # "hgt_elem_var", + # "ignored_border_widths", + # "regrid_opt", + # "weightsDir", + # "regrid_opt_supp_pcp", "errMsg", "statusMsg", "logFile", "logHandle", - "dScaleParamDirs", + # "dScaleParamDirs", "paramFlagArray", - "forceTemoralInterp", - "suppTemporalInterp", - "t2dDownscaleOpt", - "swDownscaleOpt", - "psfcDownscaleOpt", - "precipDownscaleOpt", - "q2dDownscaleOpt", - "t2BiasCorrectOpt", - "psfcBiasCorrectOpt", - "q2BiasCorrectOpt", - "windBiasCorrect", - "swBiasCorrectOpt", - "lwBiasCorrectOpt", - "precipBiasCorrectOpt", - "cfsv2EnsMember", - "customSuppPcpFreq", - "customFcstFreq", - "rqiMethod", + # "forceTemoralInterp", + # "suppTemporalInterp", + # "t2dDownscaleOpt", + # "swDownscaleOpt", + # "psfcDownscaleOpt", + # "precipDownscaleOpt", + # "q2dDownscaleOpt", + # "t2BiasCorrectOpt", + # "psfcBiasCorrectOpt", + # "q2BiasCorrectOpt", + # "windBiasCorrect", + # "swBiasCorrectOpt", + # "lwBiasCorrectOpt", + # "precipBiasCorrectOpt", + # "cfsv2EnsMember", + # "customSuppPcpFreq", + # "customFcstFreq", + # "rqiMethod", "nwmVersion", "nwmConfig", "forcing_output", @@ -1360,7 +1360,7 @@ ], "var_rename_map": {"config_path": "cfg_bmi"}, "extract_input_variable_attrs_map": { - "SuppPcp": "supp_precip_forcings", + # "SuppPcp": "supp_precip_forcings", "OutputFrequency": "output_freq", "SubOutputHour": "sub_output_hour", "SubOutFreq": "sub_output_freq", @@ -1376,19 +1376,19 @@ "SuppPcpMandatory": "supp_precip_mandatory", "RegridOptSuppPcp": "regrid_opt_supp_pcp", "SuppPcpTemporalInterpolation": "suppTemporalInterp", - "SuppPcpMaxHours": "supp_pcp_max_hours", "SuppPcpInputOffsets": "supp_input_offsets", - "SuppPcpParamDirs": "supp_precip_param_dir", + "SuppPcpParamDir": "supp_precip_param_dir", + "SuppPcpForcingTypes": "supp_precip_file_types", }, "extract_input_variable_attrs_map_precip_only": { "customSuppPcpFreq": "customSuppPcpFreq", }, "extract_input_variable_attrs_map_not_precip_only": { + # "InputForcings": "input_forcings", # np "ForecastInputHorizons": "fcst_input_horizons", # np "ForecastInputOffsets": "fcst_input_offsets", # np "IgnoredBorderWidths": "ignored_border_widths", # np "RegridOpt": "regrid_opt", # np - "RegridWeightsDir": "weightsDir", # np "ForcingTemporalInterpolation": "forceTemoralInterp", # np "TemperatureDownscaling": "t2dDownscaleOpt", # np "PressureDownscaling": "psfcDownscaleOpt", # np @@ -1402,7 +1402,6 @@ "SwBiasCorrection": "swBiasCorrectOpt", # np #yes "LwBiasCorrection": "lwBiasCorrectOpt", # np #yes "PrecipBiasCorrection": "precipBiasCorrectOpt", # np #yes - "InputForcings": "input_forcings", # np "InputForcingTypes": "input_force_types", # np "InputForcingDirectories": "input_force_dirs", # np "InputMandatory": "input_force_mandatory", # np @@ -1424,13 +1423,16 @@ "includeLQFrac": "include_lqfrac", "floatOutput": "useFloats", "Output": "forcing_output", + "SuppPcpMaxHours": "supp_pcp_max_hours", + "RegridWeightsDir": "weightsDir", # np }, "try_config_get_except_attr_map": { "RefcstBDateProc": "b_date_proc", "Geopackage": "geopackage", "GeogridIn": "geogrid", "SpatialMetaIn": "spatial_meta", - "SuppPcpForcingTypes": "supp_precip_file_types", + + }, "file_types": ["GRIB1", "GRIB2", "NETCDF", "NETCDF4", "NWM", "ZARR"], } From 7d4ee6d67c1438ba0fdcc32b81c59c3ed2ec1713 Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Tue, 19 May 2026 16:21:46 -0500 Subject: [PATCH 08/71] handle circular imports --- .../NextGen_Forcings_Engine/os_utils.py | 2 +- .../NextGen_Forcings_Engine/retry_utils.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/os_utils.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/os_utils.py index 67827d49..7853da24 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/os_utils.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/os_utils.py @@ -5,7 +5,7 @@ import typing from typing import TYPE_CHECKING -from . import retry_utils +from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine import retry_utils if TYPE_CHECKING: from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/retry_utils.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/retry_utils.py index f542c3ad..81594156 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/retry_utils.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/retry_utils.py @@ -4,14 +4,15 @@ import time import traceback import types -from typing import TYPE_CHECKING - -from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.parallel import MpiConfig +from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( ConfigOptions, ) + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.parallel import ( + MpiConfig, + ) def retry_w_mpi_context( @@ -47,6 +48,13 @@ def wrapper( *args, **kwargs, ): + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( + ConfigOptions, + ) + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.parallel import ( + MpiConfig, + ) + if not isinstance(mpi_config, MpiConfig): raise TypeError( f"Expected type {MpiConfig} for mpi_config, got: {type(mpi_config)}" From 7c52026f0ff245ab884a06ffe4280a9c75a9d4ab Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Tue, 19 May 2026 16:22:53 -0500 Subject: [PATCH 09/71] remove commented out attributes --- .../NextGen_Forcings_Engine/core/consts.py | 69 ------------------- 1 file changed, 69 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py index 5a4490f2..c1a95c50 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py @@ -1264,90 +1264,25 @@ "ConfigOptions": [ "bmi_time", "current_time", - # "input_forcings", - # "supp_precip_forcings", - # "input_force_dirs", - # "input_force_types", "supp_precip_dirs", - # "supp_precip_file_types", "supp_precip_param_dir", - # "input_force_mandatory", "supp_precip_mandatory", - # "supp_pcp_max_hours", - # "number_inputs", - # "number_supp_pcp", - # "output_freq", - # "sub_output_hour", - # "sub_output_freq", - # "scratch_dir", - # "num_output_steps", - # "num_supp_output_steps", - # "actual_output_steps", - # "realtime_flag", - # "refcst_flag", - # "ana_flag", "e_date_proc", "first_fcst_cycle", "current_fcst_cycle", "current_output_step", - # "cycle_length_minutes", "prev_output_date", "current_output_date", - # "look_back", "future_time", - # "fcst_freq", "nFcsts", - # "fcst_shift", - # "fcst_input_horizons", - # "fcst_input_offsets", "process_window", - # "spatial_meta", - # "grid_type", "grid_meta", "ExactExtract", - # "lat_var", - # "lon_var", - # "hgt_var", - # "cosalpha_var", - # "sinalpha_var", - # "slope_var", - # "slope_azimuth_var", - # "slope_var_elem", - # "slope_azimuth_var_elem", - # "nodecoords_var", - # "elemcoords_var", - # "elemconn_var", - # "numelemconn_var", - # "element_id_var", - # "hgt_elem_var", - # "ignored_border_widths", - # "regrid_opt", - # "weightsDir", - # "regrid_opt_supp_pcp", "errMsg", "statusMsg", "logFile", "logHandle", - # "dScaleParamDirs", "paramFlagArray", - # "forceTemoralInterp", - # "suppTemporalInterp", - # "t2dDownscaleOpt", - # "swDownscaleOpt", - # "psfcDownscaleOpt", - # "precipDownscaleOpt", - # "q2dDownscaleOpt", - # "t2BiasCorrectOpt", - # "psfcBiasCorrectOpt", - # "q2BiasCorrectOpt", - # "windBiasCorrect", - # "swBiasCorrectOpt", - # "lwBiasCorrectOpt", - # "precipBiasCorrectOpt", - # "cfsv2EnsMember", - # "customSuppPcpFreq", - # "customFcstFreq", - # "rqiMethod", "nwmVersion", "nwmConfig", "forcing_output", @@ -1360,7 +1295,6 @@ ], "var_rename_map": {"config_path": "cfg_bmi"}, "extract_input_variable_attrs_map": { - # "SuppPcp": "supp_precip_forcings", "OutputFrequency": "output_freq", "SubOutputHour": "sub_output_hour", "SubOutFreq": "sub_output_freq", @@ -1384,7 +1318,6 @@ "customSuppPcpFreq": "customSuppPcpFreq", }, "extract_input_variable_attrs_map_not_precip_only": { - # "InputForcings": "input_forcings", # np "ForecastInputHorizons": "fcst_input_horizons", # np "ForecastInputOffsets": "fcst_input_offsets", # np "IgnoredBorderWidths": "ignored_border_widths", # np @@ -1431,8 +1364,6 @@ "Geopackage": "geopackage", "GeogridIn": "geogrid", "SpatialMetaIn": "spatial_meta", - - }, "file_types": ["GRIB1", "GRIB2", "NETCDF", "NETCDF4", "NWM", "ZARR"], } From 3e5dc1e530f87949f9f9cffdf4782bdba48293e3 Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Tue, 19 May 2026 16:24:07 -0500 Subject: [PATCH 10/71] use dir instead of vars --- .../NextGen_Forcings_Engine/core/forcingInputMod.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/forcingInputMod.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/forcingInputMod.py index 356c04cb..1cb97ef7 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/forcingInputMod.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/forcingInputMod.py @@ -93,7 +93,8 @@ def _initialize_config_options(self) -> None: Check if the attibute allready exists before setting. """ - for key, val in list(vars(self.config_options).items()): + for key in dir(self.config_options): + val=getattr(self.config_options,key) if ( isinstance(val, list) and len(val) > 0 From 342e4941b7cf3e70a1b157a2f7fe2ebffb4f573d Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Tue, 19 May 2026 16:24:13 -0500 Subject: [PATCH 11/71] debugging --- .../NextGen_Forcings_Engine/core/config.py | 103 ++++++++++-------- 1 file changed, 59 insertions(+), 44 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py index f1b6c4d7..95dcc77e 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import configparser import json import logging @@ -5,6 +7,7 @@ import re import uuid from datetime import datetime, timedelta, timezone +from typing import TYPE_CHECKING, Any # Use the Error, Warning, and Trapping System Package for logging import numpy as np @@ -59,12 +62,10 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No ) self.nwm_source = "s3://noaa-nwm-retrospective-3-0-pds" - self._scratch_dir_has_been_uniquefied = False self.supp_precip_forcings = self.extract_input_variable("SuppPcp") if not self.precip_only_flag: self.input_forcings = self.extract_input_variable("InputForcings") - # Create temporary array to hold flags if we need input parameter files. self.param_flag = np.zeros([len(self.input_forcings)], int) @@ -75,19 +76,30 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No setattr(self, attr, None) self.broadcast_new_64bit_uid() - for cfg_bmi_attr, config_options_attr in self.try_config_get_except_attr_map.items(): - setattr(self,config_options_attr,self.try_config_get(cfg_bmi_attr)) - + for ( + cfg_bmi_attr, + config_options_attr, + ) in self.try_config_get_except_attr_map.items(): + setattr(self, config_options_attr, self.try_config_get(cfg_bmi_attr)) + self.set_attrs(CONFIGOPTIONS["extract_input_variable_attrs_map"]) if self.precip_only_flag: self.set_attrs( CONFIGOPTIONS["extract_input_variable_attrs_map_precip_only"] ) + self.set_attrs( + CONFIGOPTIONS["extract_input_variable_attrs_map_not_precip_only"], + set_none=True, + ) else: self.set_attrs( CONFIGOPTIONS["extract_input_variable_attrs_map_not_precip_only"] ) + self.set_attrs( + CONFIGOPTIONS["extract_input_variable_attrs_map_precip_only"], + set_none=True, + ) if 27 in self.input_forcings: self.nwm_geogrid = self.extract_input_variable("NWMGeogridIn") @@ -99,14 +111,14 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No for cfg_bmi_attr, config_options_attr in CONFIGOPTIONS[ "extract_input_variable_set_default_attrs_map" ].items(): - if config_options_attr=="supp_pcp_max_hours": - default=None + if config_options_attr == "supp_pcp_max_hours": + default = None else: - default=0 + default = 0 setattr( self, config_options_attr, - self.extract_input_variable_set_default(cfg_bmi_attr,default), + self.extract_input_variable_set_default(cfg_bmi_attr, default), ) @property @@ -159,18 +171,24 @@ def precip_only_flag(self) -> bool: precip_only = True return precip_only - def set_attrs(self, attrs_dict: dict): + def set_attrs(self, attrs_dict: dict, set_none: bool = False): """Set the attributes of the class based on the configuration file. This is used to populate the attributes of the class after they have been read in and validated from the configuration file.""" for cfg_bmi_attr, config_options_attr in attrs_dict.items(): - setattr( - self, config_options_attr, self.extract_input_variable(cfg_bmi_attr) - ) - def set_attrs_use_default(self,attrs_dict:dict): + if set_none: + attr = None + else: + attr = self.extract_input_variable(cfg_bmi_attr) + setattr(self, config_options_attr, attr) + + def set_attrs_use_default(self, attrs_dict: dict): """Set the attributes of the class based on the configuration file. Set default value to default if not found in config file.""" for cfg_bmi_attr, config_options_attr in attrs_dict.items(): setattr( - self, config_options_attr, self.extract_input_variable_set_default(cfg_bmi_attr) + self, + config_options_attr, + self.extract_input_variable_set_default(cfg_bmi_attr), ) + def extract_input_variable(self, variable_name: str) -> str: """Extract the variable name from the configuration file for a given variable.""" try: @@ -199,7 +217,7 @@ def extract_input_variable_set_default(self, variable_name: str, default=0) -> s err_out_screen( f"Improper {variable_name} value: {self.cfg_bmi[variable_name]}", e ) - if default==0: + if default == 0: if variable not in [0, 1]: err_out_screen(f"Please choose a {variable_name} value of 0 or 1.") return variable @@ -219,7 +237,7 @@ def try_config_get(self, variable_name: str) -> str: ) def check_number_of_inputs( - self, value: list, variable_name: str, input_type: str,number_inputs:int + self, value: list, variable_name: str, input_type: str, number_inputs: int ) -> None: """Check that the number of inputs specified by the user in the configuration file matches the expected number of inputs for a given variable.""" if len(value) != number_inputs: @@ -229,12 +247,14 @@ def check_number_of_inputs( def check_number_of_inputs_forcings(self, value: list, variable_name: str) -> None: """Check that the number of inputs specified by the user in the configuration file matches the expected number of inputs for a given variable, specifically for input forcings variables which should match the number of input forcing options specified by the user in the configuration file.""" - return self.check_number_of_inputs(value, variable_name, " InputForcings",self.number_inputs) + return self.check_number_of_inputs( + value, variable_name, " InputForcings", self.number_inputs + ) def check_number_of_inputs_supp_pcp(self, value: list, variable_name: str) -> None: """Check that the number of inputs specified by the user in the configuration file matches the expected number of inputs for a given variable, specifically for supplemental precip forcing variables which should match the number of supplemental precip forcing options specified by the user in the configuration file.""" return self.check_number_of_inputs( - value, variable_name, " SupplementalPrecipForcings",self.number_supp_pcp + value, variable_name, " SupplementalPrecipForcings", self.number_supp_pcp ) def check_input_values_in_range( @@ -262,6 +282,7 @@ def check_input_values_positive(self, value: list, variable_name: str) -> None: err_out_screen( f"Invalid {variable_name} value '{val}' specified in configuration file. Please specify values greater than zero." ) + def uniquefy_scratch_dir_as_child(self, uid: str) -> None: """Modify the existing scratch dir by adding the UID string available to all ranks from the MpiConfig class. @@ -321,7 +342,7 @@ def supp_precip_forcings(self): @supp_precip_forcings.setter def supp_precip_forcings(self, value: list) -> None: """Set the list of supplemental precip forcing options specified by the user in the configuration file. This is used to control which supplemental precip forcings are processed and how they are processed based on the other configuration options specified for each supplemental precip forcing.""" - if len(value)>0: + if len(value) > 0: self.check_input_values_in_range( [int(i) for i in value], "SuppPcp", @@ -572,7 +593,6 @@ def geogrid(self, value: str) -> None: ) self.try_make_dir(geogrid_parent, " esmf_mesh") - def try_make_dir(self, directory: str, optional_str: str = "") -> None: """Try to make a directory, and catch any errors.""" if not os.path.isdir(directory): @@ -653,7 +673,6 @@ def input_force_types(self, value: list) -> None: ) self._input_force_types = value - @property def file_types(self): """Get the list of input forcing file types specified by the user in the configuration file. This is used to control how input forcings are read in and processed based on the file type specified for each input forcing in the configuration file.""" @@ -662,7 +681,10 @@ def file_types(self): @property def input_force_dirs(self) -> list: """Get the list of input forcing directories specified by the user in the configuration file. This is used to control where input forcings are read in from for each input forcing specified by the user in the configuration file.""" - return self._input_force_dirs + if self._input_force_dirs: + return self._input_force_dirs + else: + None @input_force_dirs.setter def input_force_dirs(self, value: list) -> None: @@ -703,7 +725,6 @@ def input_force_mandatory(self, value: list) -> None: self.check_input_values_in_range(value, "InputMandatory", [0, 1]) self._input_force_mandatory = value - @property def customSuppPcpFreq(self) -> int: """Get the custom supplemental precip output frequency specified by the user in the configuration file. This is used to control the output frequency of supplemental precip forcings if the user has chosen to run the supplemental precip forcings module only.""" @@ -856,12 +877,6 @@ def grid_type(self, value: str) -> None: ) self._grid_type = value.lower() - def raise_grid_type_error(self, grid_type: str, variable_name: str) -> None: - """Raise an error if a variable is requested that is not valid for the given grid type.""" - err_out_screen( - f"{variable_name} is not a valid variable for grid type {grid_type}. Please check your configuration file." - ) - @property def lon_var(self) -> str: """Naming convention of the longitude variable within the "GeogridIn" file the user has specified. Variable naming convention ONLY for gridded domain configurations. This is required so the NextGen Forcings Engine BMI can dyanmically initialize the domain geogrid as an ESMF regridding object. In the case for "gridded" domain configuration options and a user specifying downscaling options while only specifying a height variable feature on the grid, this netcdf variable (LONVAR) is then EXPECTED to contain a netcdf metadata attribute called "dx" that specifies the grid spacing in the longtiudinal direction. Otherwise, it will throw an error and not be able to calculate the slope and tilt of each grid cell. @@ -870,8 +885,6 @@ def lon_var(self) -> str: """ if self.grid_type == "gridded": return self.extract_input_variable("LONVAR") - else: - self.raise_grid_type_error(self.grid_type, "LONVAR") @property def lat_var(self) -> str: @@ -881,8 +894,6 @@ def lat_var(self) -> str: """ if self.grid_type == "gridded": return self.extract_input_variable("LATVAR") - else: - self.raise_grid_type_error(self.grid_type, "LATVAR") @property def nodecoords_var(self) -> str: @@ -892,8 +903,6 @@ def nodecoords_var(self) -> str: """ if self.grid_type in ["unstructured", "hydrofabric"]: return self.extract_input_variable("NodeCoords") - else: - self.raise_grid_type_error(self.grid_type, "NodeCoords") @property def elemcoords_var(self) -> str: @@ -903,8 +912,6 @@ def elemcoords_var(self) -> str: """ if self.grid_type in ["unstructured", "hydrofabric"]: return self.extract_input_variable("ElemCoords") - else: - self.raise_grid_type_error(self.grid_type, "ElemCoords") @property def elemconn_var(self) -> str: @@ -914,8 +921,6 @@ def elemconn_var(self) -> str: """ if self.grid_type in ["unstructured", "hydrofabric"]: return self.extract_input_variable("ElemConn") - else: - self.raise_grid_type_error(self.grid_type, "ElemConn") @property def numelemconn_var(self) -> str: @@ -925,8 +930,6 @@ def numelemconn_var(self) -> str: """ if self.grid_type in ["unstructured", "hydrofabric"]: return self.extract_input_variable("NumElemConn") - else: - self.raise_grid_type_error(self.grid_type, "NumElemConn") @property def element_id_var(self) -> str: @@ -936,8 +939,6 @@ def element_id_var(self) -> str: """ if self.grid_type == "hydrofabric": return self.extract_input_variable("ElemID") - else: - self.raise_grid_type_error(self.grid_type, "ElemID") @property def ignored_border_widths(self) -> list: @@ -970,6 +971,8 @@ def regrid_opt(self, value: list) -> None: self.check_number_of_inputs_forcings(value, "RegridOpt") self.check_input_values_in_range(value, "RegridOpt", [1, 2, 3]) self._regrid_opt = value + else: + self._regrid_opt = None @property def weightsDir(self) -> str: @@ -1378,6 +1381,8 @@ def supp_precip_mandatory(self, value): if self.number_supp_pcp > 0: self.check_input_values_in_range(value, "SuppPcpMandatory", [0, 1]) self._supp_precip_mandatory = value + else: + self._supp_precip_mandatory = None @property def regrid_opt_supp_pcp(self): @@ -1393,6 +1398,8 @@ def regrid_opt_supp_pcp(self, value): if self.number_supp_pcp > 0: self.check_input_values_in_range(value, "RegridOptSuppPcp", [1, 2, 3]) self._regrid_opt_supp_pcp = value + else: + self._regrid_opt_supp_pcp = None @property def suppTemporalInterp(self): @@ -1410,6 +1417,8 @@ def suppTemporalInterp(self, value): value, "SuppPcpTemporalInterpolation", [0, 1, 2] ) self._suppTemporalInterp = value + else: + self._suppTemporalInterp = None @property def supp_pcp_max_hours(self): @@ -1425,6 +1434,8 @@ def supp_pcp_max_hours(self, value): elif isinstance(value, float) or isinstance(value, int): value = [value] * self.number_supp_pcp self._supp_pcp_max_hours = value + else: + self._supp_pcp_max_hours = None @property def supp_input_offsets(self): @@ -1439,6 +1450,9 @@ def supp_input_offsets(self, value): """Set the list of time offsets to apply to supplemental precipitation input forcing files specified by the user in the configuration file. This is used to control how supplemental precipitation input forcing files are processed based on the time offset specified for each supplemental precipitation input forcing in the configuration file.""" if self.number_supp_pcp > 0: self.check_number_of_inputs_supp_pcp(value, "SuppPcpInputOffsets") + self._supp_input_offsets = value + else: + self._supp_input_offsets = None @property def supp_precip_dirs(self): @@ -1490,6 +1504,7 @@ def supp_precip_param_dir(self, value): @property def cfsv2EnsMember(self): """Set the CFSv2 ensemble member to process specified by the user in the configuration file. This is used to control which CFSv2 ensemble member is processed for CFSv2 input forcings based on the ensemble member specified in the configuration file.""" + value = None if not self.precip_only_flag: # Read in Ensemble information # Read in CFS ensemble member information IF we have chosen CFSv2 as an input From ca428dabeb9f4a1b9ad8fbc047a604f3026c6c86 Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Wed, 20 May 2026 14:32:27 -0500 Subject: [PATCH 12/71] fix regrid_opt --- .../NextGen_Forcings_Engine/core/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py index 95dcc77e..037fff30 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py @@ -111,7 +111,7 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No for cfg_bmi_attr, config_options_attr in CONFIGOPTIONS[ "extract_input_variable_set_default_attrs_map" ].items(): - if config_options_attr == "supp_pcp_max_hours": + if config_options_attr in ["supp_pcp_max_hours","weightsDir"]: default = None else: default = 0 @@ -967,7 +967,7 @@ def regrid_opt(self): @regrid_opt.setter def regrid_opt(self, value: list) -> None: """Set the list of regridding options specified by the user in the configuration file. This is used to control how input forcings are regridded based on the regridding option specified for each input forcing in the configuration file.""" - if self.precip_only_flag: + if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "RegridOpt") self.check_input_values_in_range(value, "RegridOpt", [1, 2, 3]) self._regrid_opt = value From f3900952fc598eb1850a5895fa9c95bc11373ba8 Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Wed, 27 May 2026 13:51:03 -0500 Subject: [PATCH 13/71] refactor initialize method --- .../NextGen_Forcings_Engine/bmi_model.py | 408 +++++++++--------- NextGen_Forcings_Engine_BMI/run_bmi_model.py | 14 +- 2 files changed, 218 insertions(+), 204 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index 06fe6d13..47d79538 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -2,14 +2,15 @@ # This is needed for get_var_bytes import gc import hashlib +import logging import os # time debugging import time from collections import defaultdict -from pathlib import Path from datetime import datetime, timezone -import logging +from pathlib import Path + import netCDF4 as nc # import data_tools @@ -128,25 +129,15 @@ class NWMv3_Forcing_Engine_BMI_model_Base(Bmi): It includes methods for initializing the model, updating it, accessing model variables, and managing model configuration. This class is responsible for interacting with geospatial data and forcing inputs for the model simulation. - - Attributes - ---------- - _values : dict - Dictionary storing model values. - _start_time : float - The start time for the simulation. - _end_time : float - The end time for the simulation. - _model : object - The model object. - _comm : object - The MPI communicator. - var_array_lengths : int - Length of the variable arrays. - """ - def __init__(self): + def __init__( + self, + config_file: str, + b_date: str = None, + geogrid: str = None, + output_path: str = None, + ) -> None: """Create a model that is ready for initialization. Initializes the model with default values for time, variables, and grid types. @@ -177,7 +168,7 @@ def __init__(self): self.cfg_bmi = None self._job_meta = None self._mpi_meta = None - self.geo_meta = None + self._geo_meta = None self._grid_type = None self._grids = None self._grid_map = None @@ -188,122 +179,121 @@ def __init__(self): self._var_units_map = None self._input_forcing_mod = None self._supp_pcp_mod = None + self._output_obj = None self._model_parameters_list = [] - # Diagnostic timing setup - self._call_counts = defaultdict(int) self._call_times = defaultdict(float) self._total_start = None + self._att_map = BMI_MODEL["att_map"] + self._input_var_names = [] + self._model_parameters_list = [] + self._config_file = config_file + self._geogrid = geogrid + self.get_grid_edge_count - # ---------------------------------------------- - # Required, static attributes of the model - # ---------------------------------------------- - _att_map = BMI_MODEL["att_map"] - - # --------------------------------------------- - # Input variable names (CSDMS standard names) - # --------------------------------------------- - # Forcings engine requires no inputs currently - # and only provides model output - _input_var_names = [] - - _input_var_types = {} - - # ------------------------------------------------------ - # A list of static attributes/parameters. - # ------------------------------------------------------ - _model_parameters_list = [] - - # ------------------------------------------------------------ - # ------------------------------------------------------------ - # BMI: Model Control Functions - # ------------------------------------------------------------ - # ------------------------------------------------------------ - - # ------------------------------------------------------------------- - def initialize(self, config_file: str, output_path: str | None = None) -> None: - """Initialize the model using a configuration file. - - This function is part of the BMI (Basic Model Interface) specification and is automatically - invoked by the BMI system. When running standalone, call `initialize_with_params()` instead, - which sets additional parameters such as `b_date`, `geogrid`, and `output_path`. - - This function is responsible for: - - Setting up core model attributes, grids, and MPI communication. - - Reading the BMI configuration file and initializing basic model components. - - :param config_file: The path to the configuration file for model initialization. - :raises RuntimeError: If the configuration file is invalid or missing. - """ - - LOG.info("---------------------------") - LOG.info( - f"BMI Forcing Engine initializing with {config_file}{Pld(St.INITTING, modnm=MODNM)}" - ) + # Now that _job_meta is set, call initialize() to set up the core model + self.initialize(config_file, output_path=output_path) - # -------------- Read in the BMI configuration -------------------------# - if not isinstance(config_file, str) or len(config_file) == 0: + @property + def bmi_cfg_file(self): + """Validate and return the BMI configuration file path.""" + if not isinstance(self._config_file, str) or len(self._config_file) == 0: LOG.critical("No BMI initialize configuration provided, nothing to do...") raise RuntimeError( "No BMI initialize configuration provided, nothing to do..." ) - - bmi_cfg_file = Path(config_file).resolve() + bmi_cfg_file = Path(self._config_file).resolve() if not bmi_cfg_file.is_file(): LOG.critical(f"Config file {bmi_cfg_file} not found, nothing to do...") raise RuntimeError( f"Config file {bmi_cfg_file} not found, nothing to do..." ) - - LOG.info(f"Reading config file: {bmi_cfg_file}") - with bmi_cfg_file.open("r") as fp: + return bmi_cfg_file + + @property + def cfg_bmi(self): + """Read and parse the BMI configuration file.""" + if self._cfg_bmi is not None: + return self._cfg_bmi + LOG.info(f"Reading config file: {self.bmi_cfg_file}") + with self.bmi_cfg_file.open("r") as fp: cfg = yaml.safe_load(fp) - - self.cfg_bmi = parse_config(cfg) - - # If _job_meta was not set by initialize_with_params(), create a default one - if self._job_meta is None: - self._job_meta = ConfigOptions(self.cfg_bmi) - - # Parse the configuration options - # try: - # self._job_meta.validate_config(self.cfg_bmi) - # except KeyboardInterrupt as e: - # err_handler.err_out_screen("User keyboard interrupt", e) - # except ImportError as e: - # err_handler.err_out_screen("Missing Python packages", e) - # except InterruptedError as e: - # err_handler.err_out_screen("External kill signal detected", e) - # except Exception as e: - # err_handler.err_out_screen("Unhandled exception", e) - - # Set NWM version and config, if provided in the config - if self.cfg_bmi.get("NWM_VERSION") is not None: - self._job_meta.nwmVersion = self.cfg_bmi["NWM_VERSION"] - - # Place NWM configuration (if provided by the user). This will be placed into the final - # output files as a global attribute. - if self.cfg_bmi.get("NWM_CONFIG") is not None: - self._job_meta.nwmConfig = self.cfg_bmi["NWM_CONFIG"] - - # Initialize MPI communication - self._mpi_meta = MpiConfig(self._job_meta) - - self.geo_meta = HydrofabricGeoMeta(self._job_meta, self._mpi_meta) - + return parse_config(cfg) + + @cfg_bmi.setter + def cfg_bmi(self, value): + """Set the BMI configuration.""" + self._cfg_bmi = value + + @property + def _job_meta(self): + """Return the job metadata object.""" + return self.__job_meta + + @_job_meta.setter + def _job_meta(self, value): + """Set the job metadata object.""" + if value is None: + value = ConfigOptions( + self.cfg_bmi, b_date=self._b_date, geogrid_arg=self._geogrid + ) + try: + value.validate_config(self.cfg_bmi) + except KeyboardInterrupt as e: + err_handler.err_out_screen("User keyboard interrupt", e) + except ImportError as e: + err_handler.err_out_screen("Missing Python packages", e) + except InterruptedError as e: + err_handler.err_out_screen("External kill signal detected", e) + except Exception as e: + err_handler.err_out_screen("Unhandled exception", e) + value.nwmVersion = self.cfg_bmi.get("NWM_VERSION") + value.nwmConfig = self.cfg_bmi.get("NWM_CONFIG") + self.__job_meta = value + + @property + def _mpi_meta(self): + """Return the MPI metadata object.""" + if self.__mpi_meta is None: + self.__mpi_meta = MpiConfig(self._job_meta) + return self.__mpi_meta + + @_mpi_meta.setter + def _mpi_meta(self, value): + """Set the MPI metadata object.""" + self.__mpi_meta = value + + @property + def geo_meta(self): + """Return the geospatial metadata object.""" + if self._geo_meta is None: + self._geo_meta = HydrofabricGeoMeta(self._job_meta, self._mpi_meta) + return self._geo_meta + + @geo_meta.setter + def geo_meta(self, value): + """Set the geospatial metadata object.""" + self._geo_meta = value + + def init_mpi(self): + """Set up MPI communication for the model.""" try: comm = MPI.Comm.f2py(self._comm) if self._comm is not None else None self._mpi_meta.initialize_comm(comm=comm) except Exception as e: err_handler.err_out_screen(self._job_meta.errMsg, e) - ### Reassign the scratch dir to a new child dir of the current scratch dir, - ### applying uniqueness to the final path. This must be called by all ranks, once. + def init_scratch_dir(self): + """Set up the scratch directory for the model, ensuring it is unique for each job. + + Reassign the scratch dir to a new child dir of the current scratch dir, + applying uniqueness to the final path. This must be called by all ranks, once. + """ self._job_meta.uniquefy_scratch_dir_as_child(self._mpi_meta.uid64) - # LOG.debug(f"self._job_meta type: {type(self._job_meta)}") - # Call ESMF mesh creation process + def create_esmf_mesh(self): + """Create the ESMF mesh for the model.""" if self._mpi_meta.rank == 0: cat_ids = esmf_creation.create_mesh(self._job_meta) cat_count = np.array([ @@ -314,7 +304,13 @@ def initialize(self, config_file: str, output_path: str | None = None) -> None: cat_ids = np.empty(cat_count[0], dtype=np.int64) self._mpi_meta.comm.Bcast(cat_ids, root=0) - # Call forcing_extraction process + def fetch_raw_forcing_data(self): + """Fetch raw forcing data for the model. + + This function is responsible for retrieving the raw forcing data needed for the model simulation. + It is called during the initialization process and ensures that all necessary data is available + before the model runs. + """ if self._job_meta.nwmConfig not in ["AORC", "NWM"]: if self._mpi_meta.rank == 0: err_handler.log_msg( @@ -332,54 +328,79 @@ def initialize(self, config_file: str, output_path: str | None = None) -> None: ) self._mpi_meta.comm.Barrier() - # Assign grid type to BMI class for grid information - self._grid_type = self._job_meta.grid_type.lower() - self.set_var_names() + @property + def _grid_type(self): + """Return the grid type of the model.""" + return self._job_meta.grid_type.lower() - # ----- Create some lookup tabels from the long variable names --------# - self._var_name_map_long_first = { + @property + def _var_name_map_long_first(self): + """Return the variable name mapping from long names to short names.""" + return { long_name: self._var_name_units_map[long_name][0] for long_name in self._var_name_units_map.keys() } - self._var_name_map_short_first = { + + @property + def _var_name_map_short_first(self): + """Return the variable name mapping from short names to long names.""" + return { self._var_name_units_map[long_name][0]: long_name for long_name in self._var_name_units_map.keys() } - self._var_units_map = { + + @property + def _var_units_map(self): + """Return the variable units mapping.""" + return { long_name: self._var_name_units_map[long_name][1] for long_name in self._var_name_units_map.keys() } - # Check to make sure we have enough dimensionality to run regridding. We assume that hydrofabric discretizations are large - # enough that 1x1 (single catchment) will provide enough points. For gridded and unstructured domains, we need to make sure - # that the local grid size for each processor is at least 2x2 to run the regridding process. - # forcing_input dimensionality is checked in regrid.py. + @property + def dimensionality(self): + """Return the dimensionality of the model grid based on the grid type. - dimensionality = 1 if self._grid_type == "hydrofabric" else 2 + Check to make sure we have enough dimensionality to run regridding. We assume that hydrofabric discretizations are large + enough that 1x1 (single catchment) will provide enough points. For gridded and unstructured domains, we need to make sure + that the local grid size for each processor is at least 2x2 to run the regridding process. + forcing_input dimensionality is checked in regrid.py. + """ + if self._grid_type == "hydrofabric": + return 1 + else: + return 2 + def check_dimensionality(self): + """Check that the local grid size is sufficient for the specified number of cores.""" if ( - self.geo_meta.nx_local < dimensionality - or self.geo_meta.ny_local < dimensionality + self.geo_meta.nx_local < self.dimensionality + or self.geo_meta.ny_local < self.dimensionality ): self._job_meta.errMsg = ( f"You have specified too many cores for your WRF-Hydro grid. " - f"Local grid Must have x/y dimension size of {dimensionality}." + f"Local grid Must have x/y dimension size of {self.dimensionality}." ) err_handler.err_out_screen_para(self._job_meta.errMsg, self._mpi_meta) err_handler.check_program_status(self._job_meta, self._mpi_meta) - # Initialize our output object, which includes local slabs from the output grid. + def init_output_obj(self): + """Initialize our output object, which includes local slabs from the output grid.""" try: self._output_obj = ioMod.OutputObj(self._job_meta, self.geo_meta) except Exception as e: err_handler.err_out_screen_para(self._job_meta, self._mpi_meta) err_handler.check_program_status(self._job_meta, self._mpi_meta) - # Next, initialize our input forcing classes. These objects will contain - # information about our source products (I.E. data type, grid sizes, etc). - # Information will be mapped via the options specified by the user. - # In addition, input ESMF grid objects will be created to hold data for - # downscaling and regridding purposes. + def init_input_forcing_mod(self): + """Initialize the input forcing module. + + Next, initialize our input forcing classes. These objects will contain + information about our source products (I.E. data type, grid sizes, etc). + Information will be mapped via the options specified by the user. + In addition, input ESMF grid objects will be created to hold data for + downscaling and regridding purposes. + """ try: self._input_forcing_mod = forcingInputMod.init_dict( self._job_meta, self.geo_meta, self._mpi_meta @@ -388,84 +409,59 @@ def initialize(self, config_file: str, output_path: str | None = None) -> None: err_handler.err_out_screen_para(self._job_meta, self._mpi_meta) err_handler.check_program_status(self._job_meta, self._mpi_meta) - # If we have specified supplemental precipitation products, initialize - # the supp class. + def init_supp_pcp_mod(self): + """Initialize the supplemental precipitation module, if applicable.""" if self._job_meta.number_supp_pcp > 0: self._supp_pcp_mod = suppPrecipMod.init_dict(self._job_meta, self.geo_meta) else: self._supp_pcp_mod = None err_handler.check_program_status(self._job_meta, self._mpi_meta) - # ------------- Initialize the parameters, inputs and outputs ----------# + def initialize_parameters(self): + """Initialize the parameters, inputs and outputs.""" for parm in self._model_parameters_list: self._values[self._var_name_map_short_first[parm]] = self.cfg_bmi[parm] - self.get_size_of_arrays() - - # for model_input in self.get_input_var_names(): - # self._values[model_input] = np.zeros(self._varsize, dtype=float) - - # Set initial time, step, and true catchment IDs + def set_initial_time_and_step(self) -> None: + """Set the initial time and time step size for the model.""" self._values["current_model_time"] = self.cfg_bmi["initial_time"] self._values["time_step_size"] = self.cfg_bmi["time_step_seconds"] self._values["CAT-ID"] = cat_ids - # Initialize the Forcings Engine model - self._model = NWMv3ForcingEngineModel() + def initialize(self, config_file: str) -> None: + """Initialize the model using a configuration file. - self._configure_output_path(output_path) + This function is part of the BMI (Basic Model Interface) specification and is automatically + invoked by the BMI system. When running standalone, call `initialize_with_params()` instead, + which sets additional parameters such as `b_date`, `geogrid`, and `output_path`. - LOG.info(f"BMI Forcing Engine initialized{Pld(St.INITTED, modnm=MODNM)}") + This function is responsible for: + - Setting up core model attributes, grids, and MPI communication. + - Reading the BMI configuration file and initializing basic model components. - def initialize_with_params( - self, - config_file: str, - b_date: str = None, - geogrid: str = None, - output_path: str = None, - ) -> None: - """Initialize the NWMv3 Forcings Engine model with additional job metadata parameters. - - This function **must be called by the user** to fully initialize the NWMv3 Forcings Engine model, - including both core model setup and additional job metadata configuration (such as b_date, geogrid, and output path). - - It performs the following: - - Sets up job metadata (b_date, geogrid) by calling `config_options`. - - Calls the `initialize()` function to handle core model setup (reading the config file, - initializing basic model attributes like MPI, grids, etc.). - - Handles additional configuration options, such as determining the output path - for model results. - - **DO NOT call `initialize()` directly**. Always use this function, which ensures proper - initialization of all necessary parameters and job metadata. - - :param config_file: The configuration file path for the model initialization. - :param b_date: The start date for the simulation. Typically the forecast cycle start time. - :param geogrid: The path to the geospatial grid data, such as a geospatial file for the grid. - :param output_path: The output path for model results. If omitted, a default path will be generated. - :raises ValueError: If an invalid grid type is specified, an exception is raised. + :param config_file: The path to the configuration file for model initialization. + :raises RuntimeError: If the configuration file is invalid or missing. """ - # This is required prior to the first log message. - LOG.bind() - - bmi_cfg_file = Path(config_file).resolve() - if not bmi_cfg_file.is_file(): - LOG.critical(f"Config file {bmi_cfg_file} not found, nothing to do...") - raise RuntimeError( - f"Config file {bmi_cfg_file} not found, nothing to do..." - ) + self.init_mpi() + self.init_scratch_dir() + self.create_esmf_mesh() + self.fetch_raw_forcing_data() + self.set_var_names() + self.check_dimensionality() + self.init_output_obj() + self.init_input_forcing_mod() + self.init_supp_pcp_mod() + self.get_size_of_arrays() + self.set_initial_time_and_step() - LOG.info(f"Reading config file: {bmi_cfg_file}") - with bmi_cfg_file.open("r") as fp: - cfg = yaml.safe_load(fp) + # Initialize the Forcings Engine model + self._model = NWMv3ForcingEngineModel() - self.cfg_bmi = parse_config(cfg) - # Set the job metadata parameters (b_date, geogrid) using config_options - self.cfg_bmi = parse_config(cfg) - self._job_meta = ConfigOptions(self.cfg_bmi, b_date=b_date, geogrid=geogrid) + # Set catchment ids if using hydrofabric + if self._grid_type == "hydrofabric": + self._values["CAT-ID"] = self.geo_meta.element_ids_global - # Now that _job_meta is set, call initialize() to set up the core model - self.initialize(config_file, output_path=output_path) + self._configure_output_path(self.output_path) def _configure_output_path(self, output_path: str | None = None) -> None: """Set the output path and initializes the output NetCDF file if forcing output is enabled. @@ -1646,12 +1642,18 @@ class NWMv3_Forcing_Engine_BMI_model_Gridded(NWMv3_Forcing_Engine_BMI_model_Base geospatial data and forcing inputs for the model simulation. """ - def __init__(self): + def __init__( + self, + config_file: str, + b_date: str = None, + geogrid: str = None, + output_path: str = None, + ): """Create a model that is ready for initialization. Initializes the model with default values for time, variables, and grid types. """ - super().__init__() + super().__init__(config_file, b_date, geogrid, output_path) self.GeoMeta = GriddedGeoMeta def grid_ranks(self) -> list[int]: @@ -1712,12 +1714,18 @@ class NWMv3_Forcing_Engine_BMI_model_HydroFabric(NWMv3_Forcing_Engine_BMI_model_ geospatial data and forcing inputs for the model simulation. """ - def __init__(self): + def __init__( + self, + config_file: str, + b_date: str = None, + geogrid: str = None, + output_path: str = None, + ): """Create a model that is ready for initialization. Initializes the model with default values for time, variables, and grid types. """ - super().__init__() + super().__init__(config_file, b_date, geogrid, output_path) self.GeoMeta = HydrofabricGeoMeta def grid_ranks(self) -> list[int]: @@ -1774,12 +1782,18 @@ class NWMv3_Forcing_Engine_BMI_model_Unstructured(NWMv3_Forcing_Engine_BMI_model geospatial data and forcing inputs for the model simulation. """ - def __init__(self): + def __init__( + self, + config_file: str, + b_date: str = None, + geogrid: str = None, + output_path: str = None, + ): """Create a model that is ready for initialization. Initializes the model with default values for time, variables, and grid types. """ - super().__init__() + super().__init__(config_file, b_date, geogrid, output_path) self.GeoMeta = UnstructuredGeoMeta def grid_ranks(self) -> list[int]: diff --git a/NextGen_Forcings_Engine_BMI/run_bmi_model.py b/NextGen_Forcings_Engine_BMI/run_bmi_model.py index 70c56d52..85cb5de2 100755 --- a/NextGen_Forcings_Engine_BMI/run_bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/run_bmi_model.py @@ -343,17 +343,17 @@ def run_bmi( config = parse_config(yaml.safe_load(fp)) print("Creating an instance of the BMI model object") - model = BMIMODEL[config.get("GRID_TYPE")]() + model = BMIMODEL[config.get("GRID_TYPE")](cfg_path,b_date,geogrid,output_path=str(output_path) if output_path else None) # IMPORTANT: We are not calling initialize() directly here. # Instead, we call initialize_with_params(), which handles # the initialization process and internally calls initialize(). - model.initialize_with_params( - cfg_path, - b_date=b_date, - geogrid=geogrid, - output_path=str(output_path) if output_path else None, - ) + # model.initialize_with_params( + # cfg_path, + # b_date=b_date, + # geogrid=geogrid, + # output_path=str(output_path) if output_path else None, + # ) ngen_datetimes, start_time, end_time = get_date_times(start_time, end_time) num_iterations = len(ngen_datetimes) print_init(model, num_iterations) From 19d8bb7bd4b034b58e1236b1f236ed6e139cfb9c Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Thu, 28 May 2026 08:05:34 -0500 Subject: [PATCH 14/71] remove excessive code comments --- .../NextGen_Forcings_Engine/bmi_model.py | 226 ++++++------------ 1 file changed, 77 insertions(+), 149 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index 47d79538..5904bf67 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -35,6 +35,7 @@ ) from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.consts import BMI_MODEL from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.geoMod import ( + GeoMeta, GriddedGeoMeta, HydrofabricGeoMeta, UnstructuredGeoMeta, @@ -142,17 +143,11 @@ def __init__( Initializes the model with default values for time, variables, and grid types. """ - # This is required prior to the first log message. - if FORCING_USE_EWTS: - val = getenv_any("EWTS_USE_NGEN_BRIDGE", "").strip().lower() - if val in {"1", "true", "yes", "on"}: - configure_existing_logger(LOG) - else: - _configure_stdout_logging() - LOG.warning("ewts package installed but EWTS_USE_NGEN_BRIDGE not on. Falling back to default logging.") - else: - _configure_stdout_logging() + self.init_log(config_file) + self._config_file = config_file + self._geogrid = geogrid + self._b_date= b_date super(NWMv3_Forcing_Engine_BMI_model_Base, self).__init__() self._values = {} self._start_time = 0.0 @@ -169,14 +164,10 @@ def __init__( self._job_meta = None self._mpi_meta = None self._geo_meta = None - self._grid_type = None self._grids = None self._grid_map = None self._output_var_names = None self._var_name_units_map = None - self._var_name_map_long_first = None - self._var_name_map_short_first = None - self._var_units_map = None self._input_forcing_mod = None self._supp_pcp_mod = None self._output_obj = None @@ -188,15 +179,31 @@ def __init__( self._att_map = BMI_MODEL["att_map"] self._input_var_names = [] self._model_parameters_list = [] - self._config_file = config_file - self._geogrid = geogrid + self.get_grid_edge_count # Now that _job_meta is set, call initialize() to set up the core model - self.initialize(config_file, output_path=output_path) + self.initialize(config_file) + + self._model = NWMv3ForcingEngineModel() + + def init_log(self, config_file: str) -> None: + """Initialize the logging system for the model.""" + # This is required prior to the first log message. + if FORCING_USE_EWTS: + val = getenv_any("EWTS_USE_NGEN_BRIDGE", "").strip().lower() + if val in {"1", "true", "yes", "on"}: + configure_existing_logger(LOG) + else: + _configure_stdout_logging() + LOG.warning("ewts package installed but EWTS_USE_NGEN_BRIDGE not on. Falling back to default logging.") + else: + _configure_stdout_logging() + LOG.info("-" * 30) + LOG.info(f"BMI Forcing Engine initialized with {config_file}") @property - def bmi_cfg_file(self): + def bmi_cfg_file(self) -> Path: """Validate and return the BMI configuration file path.""" if not isinstance(self._config_file, str) or len(self._config_file) == 0: LOG.critical("No BMI initialize configuration provided, nothing to do...") @@ -212,7 +219,7 @@ def bmi_cfg_file(self): return bmi_cfg_file @property - def cfg_bmi(self): + def cfg_bmi(self) -> dict: """Read and parse the BMI configuration file.""" if self._cfg_bmi is not None: return self._cfg_bmi @@ -222,17 +229,17 @@ def cfg_bmi(self): return parse_config(cfg) @cfg_bmi.setter - def cfg_bmi(self, value): + def cfg_bmi(self, value: dict) -> None: """Set the BMI configuration.""" self._cfg_bmi = value @property - def _job_meta(self): + def _job_meta(self) -> ConfigOptions: """Return the job metadata object.""" return self.__job_meta @_job_meta.setter - def _job_meta(self, value): + def _job_meta(self, value: ConfigOptions) -> None: """Set the job metadata object.""" if value is None: value = ConfigOptions( @@ -253,30 +260,30 @@ def _job_meta(self, value): self.__job_meta = value @property - def _mpi_meta(self): + def _mpi_meta(self) -> MpiConfig: """Return the MPI metadata object.""" if self.__mpi_meta is None: self.__mpi_meta = MpiConfig(self._job_meta) return self.__mpi_meta @_mpi_meta.setter - def _mpi_meta(self, value): + def _mpi_meta(self, value: MpiConfig) -> None: """Set the MPI metadata object.""" self.__mpi_meta = value @property - def geo_meta(self): + def geo_meta(self) -> GeoMeta: """Return the geospatial metadata object.""" if self._geo_meta is None: self._geo_meta = HydrofabricGeoMeta(self._job_meta, self._mpi_meta) return self._geo_meta @geo_meta.setter - def geo_meta(self, value): + def geo_meta(self, value: GeoMeta) -> None: """Set the geospatial metadata object.""" self._geo_meta = value - def init_mpi(self): + def init_mpi(self) -> None: """Set up MPI communication for the model.""" try: comm = MPI.Comm.f2py(self._comm) if self._comm is not None else None @@ -284,7 +291,7 @@ def init_mpi(self): except Exception as e: err_handler.err_out_screen(self._job_meta.errMsg, e) - def init_scratch_dir(self): + def init_scratch_dir(self) -> None: """Set up the scratch directory for the model, ensuring it is unique for each job. Reassign the scratch dir to a new child dir of the current scratch dir, @@ -292,7 +299,7 @@ def init_scratch_dir(self): """ self._job_meta.uniquefy_scratch_dir_as_child(self._mpi_meta.uid64) - def create_esmf_mesh(self): + def create_esmf_mesh(self) -> None: """Create the ESMF mesh for the model.""" if self._mpi_meta.rank == 0: cat_ids = esmf_creation.create_mesh(self._job_meta) @@ -304,7 +311,7 @@ def create_esmf_mesh(self): cat_ids = np.empty(cat_count[0], dtype=np.int64) self._mpi_meta.comm.Bcast(cat_ids, root=0) - def fetch_raw_forcing_data(self): + def fetch_raw_forcing_data(self) -> None: """Fetch raw forcing data for the model. This function is responsible for retrieving the raw forcing data needed for the model simulation. @@ -329,12 +336,12 @@ def fetch_raw_forcing_data(self): self._mpi_meta.comm.Barrier() @property - def _grid_type(self): + def _grid_type(self) -> str: """Return the grid type of the model.""" return self._job_meta.grid_type.lower() @property - def _var_name_map_long_first(self): + def _var_name_map_long_first(self) -> dict: """Return the variable name mapping from long names to short names.""" return { long_name: self._var_name_units_map[long_name][0] @@ -342,7 +349,7 @@ def _var_name_map_long_first(self): } @property - def _var_name_map_short_first(self): + def _var_name_map_short_first(self) -> dict: """Return the variable name mapping from short names to long names.""" return { self._var_name_units_map[long_name][0]: long_name @@ -350,7 +357,7 @@ def _var_name_map_short_first(self): } @property - def _var_units_map(self): + def _var_units_map(self) -> dict: """Return the variable units mapping.""" return { long_name: self._var_name_units_map[long_name][1] @@ -358,7 +365,7 @@ def _var_units_map(self): } @property - def dimensionality(self): + def dimensionality(self) -> int: """Return the dimensionality of the model grid based on the grid type. Check to make sure we have enough dimensionality to run regridding. We assume that hydrofabric discretizations are large @@ -366,12 +373,9 @@ def dimensionality(self): that the local grid size for each processor is at least 2x2 to run the regridding process. forcing_input dimensionality is checked in regrid.py. """ - if self._grid_type == "hydrofabric": - return 1 - else: - return 2 + return {"hydrofabric": 1}.get(self._grid_type, 2) - def check_dimensionality(self): + def check_dimensionality(self) -> None: """Check that the local grid size is sufficient for the specified number of cores.""" if ( self.geo_meta.nx_local < self.dimensionality @@ -384,7 +388,7 @@ def check_dimensionality(self): err_handler.err_out_screen_para(self._job_meta.errMsg, self._mpi_meta) err_handler.check_program_status(self._job_meta, self._mpi_meta) - def init_output_obj(self): + def init_output_obj(self) -> None: """Initialize our output object, which includes local slabs from the output grid.""" try: self._output_obj = ioMod.OutputObj(self._job_meta, self.geo_meta) @@ -392,7 +396,7 @@ def init_output_obj(self): err_handler.err_out_screen_para(self._job_meta, self._mpi_meta) err_handler.check_program_status(self._job_meta, self._mpi_meta) - def init_input_forcing_mod(self): + def init_input_forcing_mod(self) -> None: """Initialize the input forcing module. Next, initialize our input forcing classes. These objects will contain @@ -409,7 +413,7 @@ def init_input_forcing_mod(self): err_handler.err_out_screen_para(self._job_meta, self._mpi_meta) err_handler.check_program_status(self._job_meta, self._mpi_meta) - def init_supp_pcp_mod(self): + def init_supp_pcp_mod(self) -> None: """Initialize the supplemental precipitation module, if applicable.""" if self._job_meta.number_supp_pcp > 0: self._supp_pcp_mod = suppPrecipMod.init_dict(self._job_meta, self.geo_meta) @@ -417,7 +421,7 @@ def init_supp_pcp_mod(self): self._supp_pcp_mod = None err_handler.check_program_status(self._job_meta, self._mpi_meta) - def initialize_parameters(self): + def initialize_parameters(self) -> None: """Initialize the parameters, inputs and outputs.""" for parm in self._model_parameters_list: self._values[self._var_name_map_short_first[parm]] = self.cfg_bmi[parm] @@ -428,6 +432,11 @@ def set_initial_time_and_step(self) -> None: self._values["time_step_size"] = self.cfg_bmi["time_step_seconds"] self._values["CAT-ID"] = cat_ids + def set_catchment_ids(self) -> None: + """Set catchment ids if using hydrofabric.""" + if self._grid_type == "hydrofabric": + self._values["CAT-ID"] = self.geo_meta.element_ids_global + def initialize(self, config_file: str) -> None: """Initialize the model using a configuration file. @@ -451,24 +460,17 @@ def initialize(self, config_file: str) -> None: self.init_output_obj() self.init_input_forcing_mod() self.init_supp_pcp_mod() + self.initialize_parameters() self.get_size_of_arrays() self.set_initial_time_and_step() + self.set_catchment_ids() - # Initialize the Forcings Engine model - self._model = NWMv3ForcingEngineModel() - - # Set catchment ids if using hydrofabric - if self._grid_type == "hydrofabric": - self._values["CAT-ID"] = self.geo_meta.element_ids_global - - self._configure_output_path(self.output_path) + self._configure_output_path() - def _configure_output_path(self, output_path: str | None = None) -> None: + def _configure_output_path(self) -> None: """Set the output path and initializes the output NetCDF file if forcing output is enabled. This is safe to call once after model initialization. - - :param output_path: Optional override path. """ gpkg_key = self._job_meta.geopackage time_key = str(time.time()).replace(".", "") @@ -484,14 +486,10 @@ def _configure_output_path(self, output_path: str | None = None) -> None: if ext is None: raise ValueError(f"Invalid grid_type: {self._job_meta.grid_type}") - if output_path: - self._output_obj.outPath = output_path + if self.output_path: + self._output_obj.outPath = self.output_path else: - filename = ( - f"NextGen_Forcings_Engine_{ext}_{gpkg_hash}_{time_hash}_output_" - + pd.Timestamp(self._job_meta.b_date_proc).strftime("%Y%m%d%H%M") - + ".nc" - ) + filename = f"NextGen_Forcings_Engine_{ext}_{gpkg_hash}_{time_hash}_output_{pd.Timestamp(self._job_meta.b_date_proc).strftime('%Y%m%d%H%M')}.nc" self._output_obj.outPath = os.path.join( self._job_meta.scratch_dir, filename ) @@ -501,8 +499,7 @@ def _configure_output_path(self, output_path: str | None = None) -> None: ) self._output_configured = True - # ------------------------------------------------------------ - def update(self): + def update(self) -> None: """Update the model by advancing one time step. This method increments the current model time by the time step size @@ -511,13 +508,11 @@ def update(self): :return: None """ - # Run the model to the next timestep self.update_until( self._values["current_model_time"] + self._values["time_step_size"] ) - # ------------------------------------------------------------ - def update_until(self, future_time: float): + def update_until(self, future_time: float) -> None: """Update the model to a specified future time. This method updates the model by running time steps until the @@ -529,9 +524,6 @@ def update_until(self, future_time: float): :return: None """ - # Method for running the model on the initial time if the model has not been run, - # and the future time is the same as the initial time. - if ( self._values["current_model_time"] == future_time @@ -565,8 +557,7 @@ def update_until(self, future_time: float): self._output_obj, ) - # ------------------------------------------------------------ - def finalize(self): + def finalize(self) -> None: """Finalize the model, performing necessary cleanup tasks. This method cleans up any temporary files created during the model run, @@ -582,10 +573,8 @@ def finalize(self): ) # Force destruction of ESMF objects - self.geo_meta = None - self._input_forcing_mod = None - self._supp_pcp_mod = None - self._model = None + for attr in ["geo_meta", "_input_forcing_mod", "_supp_pcp_mod", "_model"]: + setattr(self, attr, None) # Try moving this after all of the ESMF and model bits have # been disposed of - maybe they were keeping something open. @@ -597,13 +586,7 @@ def finalize(self): gc.collect() # make sure objects are deleted from memory LOG.info(Pld(St.COMPLETE, msg="Finishing BMI finalize()", modnm=MODNM)) - # ------------------------------------------------------------------- - # ------------------------------------------------------------------- - # BMI: Model Information Functions - # ------------------------------------------------------------------- - # ------------------------------------------------------------------- - - def get_attribute(self, att_name): + def get_attribute(self, att_name: str) -> Any: """Retrieve an attribute from the model's attribute map. This method searches the `_att_map` dictionary for the specified attribute name @@ -617,11 +600,7 @@ def get_attribute(self, att_name): except Exception as e: LOG.error(f"Could not find attribute: {att_name} - {e}") - # -------------------------------------------------------- - # Note: These are currently variables needed from other - # components vs. those read from files or GUI. - # -------------------------------------------------------- - def get_input_var_names(self): + def get_input_var_names(self) -> list[str]: """Get the list of input variable names. This method returns the list of input variable names defined in the model. @@ -630,7 +609,7 @@ def get_input_var_names(self): """ return self._input_var_names - def get_output_var_names(self): + def get_output_var_names(self) -> list[str]: """Get the list of output variable names. This method returns the list of output variable names defined in the model. @@ -639,8 +618,7 @@ def get_output_var_names(self): """ return self._output_var_names - # ------------------------------------------------------------ - def get_component_name(self): + def get_component_name(self) -> str: """Get the name of the component. This method retrieves the model name using the `get_attribute` method. @@ -649,8 +627,7 @@ def get_component_name(self): """ return self.get_attribute("model_name") - # ------------------------------------------------------------ - def get_input_item_count(self): + def get_input_item_count(self) -> int: """Get the count of input variables. This method returns the total number of input variables defined in the model. @@ -659,8 +636,7 @@ def get_input_item_count(self): """ return len(self._input_var_names) - # ------------------------------------------------------------ - def get_output_item_count(self): + def get_output_item_count(self) -> int: """Get the count of output variables. This method returns the total number of output variables defined in the model. @@ -669,7 +645,6 @@ def get_output_item_count(self): """ return len(self._output_var_names) - # ------------------------------------------------------------ def get_value(self, var_name: str, dest: NDArray[Any]) -> NDArray[Any]: """Copy the values of a variable into the provided destination array. @@ -722,7 +697,6 @@ def get_value(self, var_name: str, dest: NDArray[Any]) -> NDArray[Any]: return dest - # ------------------------------------------------------------------- def get_value_ptr(self, var_name: str) -> NDArray[Any]: """Get a reference to the values of a variable. @@ -819,12 +793,7 @@ def get_value_ptr(self, var_name: str) -> NDArray[Any]: # LOG.debug(f"[BMI get_value_ptr] Returning ravelled array for variable '{var_name}'") return arr.ravel() - # ------------------------------------------------------------------- - # ------------------------------------------------------------------- - # BMI: Variable Information Functions - # ------------------------------------------------------------------- - # ------------------------------------------------------------------- - def get_var_name(self, long_var_name): + def get_var_name(self, long_var_name: str) -> str: """Get the short name of the variable corresponding to the long variable name. :param long_var_name: The long variable name as defined in the model. @@ -832,8 +801,7 @@ def get_var_name(self, long_var_name): """ return self._var_name_map_long_first[long_var_name] - # ------------------------------------------------------------------- - def get_var_units(self, long_var_name): + def get_var_units(self, long_var_name: str) -> str: """Get the units of the variable corresponding to the long variable name. :param long_var_name: The long variable name as defined in the model. @@ -841,7 +809,6 @@ def get_var_units(self, long_var_name): """ return self._var_units_map[long_var_name] - # ------------------------------------------------------------------- def get_var_type(self, var_name: str) -> str: """Get the data type of a variable. @@ -851,8 +818,7 @@ def get_var_type(self, var_name: str) -> str: """ return str(self.get_value_ptr(var_name).dtype) - # ------------------------------------------------------------ - def get_var_grid(self, name): + def get_var_grid(self, name: str) -> int: """Get the grid associated with a variable. :param name: The name of the variable. @@ -873,8 +839,7 @@ def get_var_grid(self, name): return self._var_grid_id raise (UnknownBMIVariable(f"No known variable in BMI model: {name}")) - # ------------------------------------------------------------ - def get_var_itemsize(self, name): + def get_var_itemsize(self, name: str) -> int: """Get the item size (in bytes) of a variable. This function retrieves the memory size (in bytes) for each element of the variable @@ -885,8 +850,7 @@ def get_var_itemsize(self, name): """ return self.get_value_ptr(name).itemsize - # ------------------------------------------------------------ - def get_var_location(self, name): + def get_var_location(self, name: str) -> str: """Get the location of a variable in the grid. This function determines the location of a variable (whether it's at a "face" @@ -905,8 +869,7 @@ def get_var_location(self, name): else: raise ValueError(f"get_var_location: grid_id {self._var_grid_id} unknown") - # ------------------------------------------------------------------- - def get_var_rank(self, long_var_name): + def get_var_rank(self, long_var_name: str) -> np.int16: """Get the rank of a variable. This function retrieves the rank (number of dimensions) of a variable @@ -918,7 +881,6 @@ def get_var_rank(self, long_var_name): """ return np.int16(0) - # ------------------------------------------------------------------- def get_start_time(self) -> float: """Get the model's start time. @@ -929,8 +891,6 @@ def get_start_time(self) -> float: """ return self._start_time - # ------------------------------------------------------------------- - def get_end_time(self) -> float: """Get the model's end time. @@ -942,8 +902,6 @@ def get_end_time(self) -> float: """ return self._end_time - # ------------------------------------------------------------------- - def get_current_time(self) -> float: """Get the current time of the model. @@ -954,7 +912,6 @@ def get_current_time(self) -> float: """ return self._values["current_model_time"] - # ------------------------------------------------------------------- def get_time_step(self) -> float: """Get the model's time step size. @@ -965,7 +922,6 @@ def get_time_step(self) -> float: """ return self._values["time_step_size"] - # ------------------------------------------------------------------- def get_time_units(self) -> str: """Get the units of time for the model. @@ -976,8 +932,6 @@ def get_time_units(self) -> str: """ return self.get_attribute("time_units") - # ------------------------------------------------------------------- - def set_value(self, var_name: str, values: NDArray[Any]): """Set model values for the provided BMI variable. @@ -993,7 +947,6 @@ def set_value(self, var_name: str, values: NDArray[Any]): else: self._values[var_name][:] = values - # ------------------------------------------------------------ def set_value_at_indices( self, var_name: str, indices: NDArray[np.int_], src: NDArray[Any] ): @@ -1011,7 +964,6 @@ def set_value_at_indices( bmi_var_value_index = indices[i] self.get_value_ptr(var_name)[bmi_var_value_index] = src[i] - # ------------------------------------------------------------ def get_var_nbytes(self, var_name) -> int: """Get the number of bytes required for a variable. @@ -1023,7 +975,6 @@ def get_var_nbytes(self, var_name) -> int: """ return self.get_value_ptr(var_name).nbytes - # ------------------------------------------------------------ def get_value_at_indices( self, var_name: str, dest: NDArray[Any], indices: NDArray[np.int_] ) -> NDArray[Any]: @@ -1046,7 +997,6 @@ def get_value_at_indices( # JG Note: remaining grid funcs do not apply for type 'scalar' # Yet all functions in the BMI must be implemented # See https://bmi.readthedocs.io/en/latest/bmi.best_practices.html - # ------------------------------------------------------------ def get_grid_edge_count(self, grid_id: int) -> int: """Retrieve the number of edges for the specified grid. @@ -1113,7 +1063,6 @@ def get_grid_edge_count(self, grid_id: int) -> int: # If no valid grid is found, raise an exception or handle accordingly. raise ValueError("No valid grid found to calculate edge count.") - # ------------------------------------------------------------ def get_grid_edge_nodes( self, grid_id: int, edge_nodes: NDArray[np.int_] ) -> NDArray[np.int_]: @@ -1177,7 +1126,6 @@ def get_grid_edge_nodes( raise Exception("Unexpected error in retrieving edge nodes") - # ------------------------------------------------------------ def get_grid_face_count(self, grid_id: int) -> int: """Retrieve the number of faces for the specified grid. @@ -1204,7 +1152,6 @@ def get_grid_face_count(self, grid_id: int) -> int: # If the loop doesn't return, raise an exception indicating grid ID not found. raise ValueError("Grid ID not found in _grids.") - # ------------------------------------------------------------ def get_grid_face_edges( self, grid_id: int, face_edges: NDArray[np.int_] ) -> NDArray[np.int_]: @@ -1270,7 +1217,6 @@ def get_grid_face_edges( # If the loop doesn't return, raise an exception indicating an unexpected error raise Exception("Unexpected error in retrieving face edges.") - # ------------------------------------------------------------ def get_grid_face_nodes( self, grid_id: int, face_nodes: NDArray[np.int_] ) -> NDArray[np.int_]: @@ -1309,7 +1255,6 @@ def get_grid_face_nodes( # If the loop doesn't return, raise an exception indicating an unexpected error raise Exception("Unexpected error in retrieving face nodes.") - # ------------------------------------------------------------ def get_grid_node_count(self, grid_id: int) -> int: """Retrieve the number of nodes for the specified grid. @@ -1337,7 +1282,6 @@ def get_grid_node_count(self, grid_id: int) -> int: # If the loop doesn't return within the for loop, raise an exception raise ValueError("Grid ID not found in _grids.") - # ------------------------------------------------------------ def get_grid_nodes_per_face( self, grid_id: int, nodes_per_face: NDArray[np.int_] ) -> NDArray[np.int_]: @@ -1370,7 +1314,6 @@ def get_grid_nodes_per_face( # If the loop doesn't return, raise an exception indicating an unexpected error raise Exception("Unexpected error in retrieving nodes per face.") - # ------------------------------------------------------------ def get_grid_origin( self, grid_id: int, origin: NDArray[np.float64] ) -> NDArray[np.float64]: @@ -1389,7 +1332,6 @@ def get_grid_origin( return origin raise ValueError(f"get_grid_origin: grid_id {grid_id} unknown") - # ------------------------------------------------------------ def get_grid_rank(self, grid_id: int) -> int: """Retrieve the rank of the specified grid. @@ -1404,7 +1346,6 @@ def get_grid_rank(self, grid_id: int) -> int: return grid.rank raise ValueError(f"get_grid_rank: grid_id {grid_id} unknown") - # ------------------------------------------------------------ def get_grid_shape(self, grid_id: int, shape: NDArray[np.int_]) -> NDArray[np.int_]: """Retrieve the shape (dimensions) of the specified grid. @@ -1421,7 +1362,6 @@ def get_grid_shape(self, grid_id: int, shape: NDArray[np.int_]) -> NDArray[np.in return shape raise ValueError(f"get_grid_shape: grid_id {grid_id} unknown") - # ------------------------------------------------------------ def get_grid_size(self, grid_id: int) -> int: """Retrieve the size (total number of elements) of the specified grid. @@ -1436,7 +1376,6 @@ def get_grid_size(self, grid_id: int) -> int: return grid.size raise ValueError(f"get_grid_size: grid_id {grid_id} unknown") - # ------------------------------------------------------------ def get_grid_spacing( self, grid_id: int, spacing: NDArray[np.float64] ) -> NDArray[np.float64]: @@ -1455,8 +1394,6 @@ def get_grid_spacing( return spacing raise ValueError(f"get_grid_spacing: grid_id {grid_id} unknown") - # ------------------------------------------------------------ - def get_grid_type(self, grid_id: int) -> str: """Retrieve the type of the specified grid. @@ -1471,7 +1408,6 @@ def get_grid_type(self, grid_id: int) -> str: return grid.type raise ValueError(f"get_grid_type: grid_id {grid_id} unknown") - # ------------------------------------------------------------ def get_grid_x(self, grid_id: int, x: NDArray[np.float64]) -> NDArray[np.float64]: """Retrieve the x-coordinates (longitude or grid points) for the specified grid. @@ -1491,7 +1427,6 @@ def get_grid_x(self, grid_id: int, x: NDArray[np.float64]) -> NDArray[np.float64 return x raise ValueError(f"get_grid_x: grid_id {grid_id} unknown") - # ------------------------------------------------------------ def get_grid_y(self, grid_id: int, y: NDArray[np.float64]) -> NDArray[np.float64]: """Retrieve the y-coordinates (latitude or grid points) for the specified grid. @@ -1511,7 +1446,6 @@ def get_grid_y(self, grid_id: int, y: NDArray[np.float64]) -> NDArray[np.float64 return y raise ValueError(f"get_grid_y: grid_id {grid_id} unknown") - # ------------------------------------------------------------ def get_grid_z(self, grid_id: int, z: NDArray[np.float64]) -> NDArray[np.float64]: """Retrieve the z-coordinates (depth or grid points) for the specified grid. @@ -1531,12 +1465,6 @@ def get_grid_z(self, grid_id: int, z: NDArray[np.float64]) -> NDArray[np.float64 return z raise ValueError(f"get_grid_z: grid_id {grid_id} unknown") - # ------------------------------------------------------------ - # ------------------------------------------------------------ - # -- Random utility functions - # ------------------------------------------------------------ - # ------------------------------------------------------------ - def parse_config(cfg: dict) -> dict: """Parse the provided configuration dictionary (`cfg`) and modifies it based on certain rules. From 9b725fbc031617d48ed3ed09534b5d74da49d6af Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Fri, 26 Jun 2026 14:45:34 -0500 Subject: [PATCH 15/71] move init none attrs to consts.py --- .../NextGen_Forcings_Engine/bmi_model.py | 19 +++---------------- .../NextGen_Forcings_Engine/core/consts.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index 5904bf67..f007f576 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -147,35 +147,22 @@ def __init__( self._config_file = config_file self._geogrid = geogrid - self._b_date= b_date + self._b_date = b_date super(NWMv3_Forcing_Engine_BMI_model_Base, self).__init__() + for attr in BMI_MODEL[self.__class__.__base__.__name__]: + setattr(self, attr, None) self._values = {} self._start_time = 0.0 self._end_time = np.finfo(float).max - self._model = None - self._comm = None self.var_array_lengths = 1 # Track output configuration status self._output_configured = False # Initialize attributes in __init__ to avoid PyCharm errors - self.cfg_bmi = None - self._job_meta = None - self._mpi_meta = None - self._geo_meta = None - self._grids = None - self._grid_map = None - self._output_var_names = None - self._var_name_units_map = None - self._input_forcing_mod = None - self._supp_pcp_mod = None - self._output_obj = None self._model_parameters_list = [] - self._call_counts = defaultdict(int) self._call_times = defaultdict(float) - self._total_start = None self._att_map = BMI_MODEL["att_map"] self._input_var_names = [] self._model_parameters_list = [] diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py index c1a95c50..4420e8cb 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py @@ -10,6 +10,22 @@ ) BMI_MODEL = { + "NWMv3_Forcing_Engine_BMI_model_Base": [ + "_model", + "_comm", + "cfg_bmi", + "_job_meta", + "_mpi_meta", + "_geo_meta", + "_grids", + "_grid_map", + "_output_var_names", + "_var_name_units_map", + "_input_forcing_mod", + "_supp_pcp_mod", + "_output_obj", + "_total_start", + ], "att_map": { "model_name": "NWMv3.0 Forcings Engine BMI Python", "version": "1.0", From 8e2c8142622e7b6f692a06599794595cac0a7044 Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Wed, 1 Jul 2026 14:53:46 -0500 Subject: [PATCH 16/71] merge bmi_model refactor --- .../NextGen_Forcings_Engine/bmi_model.py | 36 +++++++++---------- .../NextGen_Forcings_Engine/core/config.py | 2 ++ .../NextGen_Forcings_Engine/core/regrid.py | 6 ++-- NextGen_Forcings_Engine_BMI/run_bmi_model.py | 16 +++------ 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index f007f576..da812bab 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -9,6 +9,7 @@ import time from collections import defaultdict from datetime import datetime, timezone +from functools import cached_property from pathlib import Path import netCDF4 as nc @@ -134,7 +135,6 @@ class NWMv3_Forcing_Engine_BMI_model_Base(Bmi): def __init__( self, - config_file: str, b_date: str = None, geogrid: str = None, output_path: str = None, @@ -143,14 +143,10 @@ def __init__( Initializes the model with default values for time, variables, and grid types. """ - self.init_log(config_file) - - self._config_file = config_file + self.output_path = output_path self._geogrid = geogrid self._b_date = b_date - super(NWMv3_Forcing_Engine_BMI_model_Base, self).__init__() - for attr in BMI_MODEL[self.__class__.__base__.__name__]: - setattr(self, attr, None) + self._values = {} self._start_time = 0.0 self._end_time = np.finfo(float).max @@ -167,14 +163,9 @@ def __init__( self._input_var_names = [] self._model_parameters_list = [] - self.get_grid_edge_count - - # Now that _job_meta is set, call initialize() to set up the core model - self.initialize(config_file) - - self._model = NWMv3ForcingEngineModel() + super(NWMv3_Forcing_Engine_BMI_model_Base, self).__init__() - def init_log(self, config_file: str) -> None: + def init_log(self) -> None: """Initialize the logging system for the model.""" # This is required prior to the first log message. if FORCING_USE_EWTS: @@ -187,9 +178,11 @@ def init_log(self, config_file: str) -> None: else: _configure_stdout_logging() LOG.info("-" * 30) - LOG.info(f"BMI Forcing Engine initialized with {config_file}") + LOG.info( + f"BMI Forcing Engine initialized with {self._config_file}{Pld(St.INITTING, modnm=MODNM)}" + ) - @property + @cached_property def bmi_cfg_file(self) -> Path: """Validate and return the BMI configuration file path.""" if not isinstance(self._config_file, str) or len(self._config_file) == 0: @@ -213,7 +206,8 @@ def cfg_bmi(self) -> dict: LOG.info(f"Reading config file: {self.bmi_cfg_file}") with self.bmi_cfg_file.open("r") as fp: cfg = yaml.safe_load(fp) - return parse_config(cfg) + self._cfg_bmi = parse_config(cfg) + return self._cfg_bmi @cfg_bmi.setter def cfg_bmi(self, value: dict) -> None: @@ -438,6 +432,11 @@ def initialize(self, config_file: str) -> None: :param config_file: The path to the configuration file for model initialization. :raises RuntimeError: If the configuration file is invalid or missing. """ + self._config_file = config_file + for attr in BMI_MODEL[self.__class__.__base__.__name__]: + setattr(self, attr, None) + self._model = NWMv3ForcingEngineModel() + self.init_log() self.init_mpi() self.init_scratch_dir() self.create_esmf_mesh() @@ -1631,7 +1630,6 @@ class NWMv3_Forcing_Engine_BMI_model_HydroFabric(NWMv3_Forcing_Engine_BMI_model_ def __init__( self, - config_file: str, b_date: str = None, geogrid: str = None, output_path: str = None, @@ -1640,7 +1638,7 @@ def __init__( Initializes the model with default values for time, variables, and grid types. """ - super().__init__(config_file, b_date, geogrid, output_path) + super().__init__(b_date, geogrid, output_path) self.GeoMeta = HydrofabricGeoMeta def grid_ranks(self) -> list[int]: diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py index 037fff30..3bc060a3 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py @@ -1128,6 +1128,8 @@ def perform_downscaling(self) -> bool: or 2 in self.t2dDownscaleOpt ): return True + else: + return False @property def t2BiasCorrectOpt(self) -> list: diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/regrid.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/regrid.py index fda67297..92ff26d8 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/regrid.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/regrid.py @@ -3985,7 +3985,7 @@ def regrid_nwm(input_forcings, config_options, wrf_hydro_geo_meta, mpi_config): ) input_forcings.height = None - if mpi_config.rank == 0: + if mpi_config.rank == 0 and config_options.perform_downscaling: pt.log_debug( f"Unable to locate HGT_surface in: {input_forcings.file_in2}. Downscaling will not be available." ) @@ -4282,7 +4282,7 @@ def regrid_nwm_aws(input_forcings, config_options, wrf_hydro_geo_meta, mpi_confi ) input_forcings.height = None - if mpi_config.rank == 0: + if mpi_config.rank == 0 and config_options.perform_downscaling: pt.log_info( f"Unable to locate HGT_surface in: {input_forcings.file_in2}. Downscaling will not be available." ) @@ -4849,7 +4849,7 @@ def regrid_custom_hourly_netcdf( else: input_forcings.height = None - if mpi_config.rank == 0: + if mpi_config.rank == 0 and config_options.perform_downscaling: pt.log_info( f"Unable to locate HGT_surface in: {input_forcings.file_in2}. Downscaling will not be available." ) diff --git a/NextGen_Forcings_Engine_BMI/run_bmi_model.py b/NextGen_Forcings_Engine_BMI/run_bmi_model.py index 85cb5de2..553b6cf6 100755 --- a/NextGen_Forcings_Engine_BMI/run_bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/run_bmi_model.py @@ -343,17 +343,11 @@ def run_bmi( config = parse_config(yaml.safe_load(fp)) print("Creating an instance of the BMI model object") - model = BMIMODEL[config.get("GRID_TYPE")](cfg_path,b_date,geogrid,output_path=str(output_path) if output_path else None) - - # IMPORTANT: We are not calling initialize() directly here. - # Instead, we call initialize_with_params(), which handles - # the initialization process and internally calls initialize(). - # model.initialize_with_params( - # cfg_path, - # b_date=b_date, - # geogrid=geogrid, - # output_path=str(output_path) if output_path else None, - # ) + model = BMIMODEL[config.get("GRID_TYPE")]( + b_date, geogrid, output_path=str(output_path) if output_path else None + ) + model.initialize(cfg_path) + ngen_datetimes, start_time, end_time = get_date_times(start_time, end_time) num_iterations = len(ngen_datetimes) print_init(model, num_iterations) From 2069b49560422744e8df475f98e589daedf88f77 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Fri, 24 Apr 2026 15:30:47 -0400 Subject: [PATCH 17/71] Simplify var passing within NWMv3ForcingEngineModel.run --- .../NextGen_Forcings_Engine/model.py | 176 ++++++------------ tests/test_utils.py | 40 +--- 2 files changed, 66 insertions(+), 150 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index c9cc75f4..4fde3687 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -15,6 +15,7 @@ disaggregateMod, downscale, err_handler, + forcingInputMod, layeringMod, ) from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( @@ -129,42 +130,12 @@ def run( :raises RuntimeError: If the model fails to initialize or if required arguments are missing. """ - LOG.debug( - f"{Pld(St.INPROG, msg=f'Starting timestep with future_time={future_time}', modnm=MODNM)}", - ) - ( - future_time, - config_options, - ) = self.determine_forecast( - future_time, - config_options, - ) - ( - config_options, - input_forcing_mod, - mpi_config, - ) = self.adjust_precip( - config_options, - input_forcing_mod, - mpi_config, - ) - ( - config_options, - mpi_config, - ) = self.log_forecast( - config_options, - mpi_config, - ) - ( - future_time, - config_options, - wrf_hydro_geo_meta, - input_forcing_mod, - supp_pcp_mod, - mpi_config, - output_obj, - input_forcings, - ) = self.loop_through_forcing_products( + + self.determine_forecast(future_time, config_options) + self.adjust_precip(config_options, input_forcing_mod, mpi_config) + self.log_forecast(config_options, mpi_config) + # TODO look into input_forcings usage in `process_suplemental_precip` and in `loop_through_forcing_products` at `disaggregate_fun`. + input_forcings = self.loop_through_forcing_products( future_time, config_options, wrf_hydro_geo_meta, @@ -173,13 +144,7 @@ def run( mpi_config, output_obj, ) - ( - config_options, - wrf_hydro_geo_meta, - supp_pcp_mod, - mpi_config, - output_obj, - ) = self.process_suplemental_precip( + self.process_suplemental_precip( config_options, wrf_hydro_geo_meta, supp_pcp_mod, @@ -187,23 +152,13 @@ def run( output_obj, input_forcings, ) - ( - config_options, - wrf_hydro_geo_meta, - mpi_config, - output_obj, - ) = self.write_output( + self.write_output( config_options, wrf_hydro_geo_meta, mpi_config, output_obj, ) - ( - model, - config_options, - wrf_hydro_geo_meta, - output_obj, - ) = self.update_dict( + self.update_dict( model, config_options, wrf_hydro_geo_meta, @@ -218,8 +173,13 @@ def determine_forecast( self, future_time: float, config_options: ConfigOptions, - ): - """Determine the forecast for the given future time and configuration.""" + ) -> None: + """Determine the forecast for the given future time and configuration. + + Warnings + -------- + Modifies mutable arguments in-place. + """ # Assign the future time to the configuration config_options.bmi_time = future_time self.disaggregate_fun = disaggregateMod.disaggregate_factory(config_options) @@ -275,38 +235,38 @@ def determine_forecast( if config_options.first_fcst_cycle is None: config_options.first_fcst_cycle = config_options.current_fcst_cycle - return ( - future_time, - config_options, - ) - @time_function def adjust_precip( self, config_options: ConfigOptions, input_forcing_mod: dict, mpi_config: MpiConfig, - ): - """Adjust precipitation for the given forecast cycle.""" + ) -> None: + """Adjust precipitation for the given forecast cycle. + + Warnings + -------- + Modifies mutable arguments in-place. + """ if not config_options.precip_only_flag: # reset skips if present for force_key in config_options.input_forcings: input_forcing_mod[force_key].skip = False err_handler.check_program_status(config_options, mpi_config) - return ( - config_options, - input_forcing_mod, - mpi_config, - ) @time_function def log_forecast( self, config_options: ConfigOptions, mpi_config: MpiConfig, - ): - """Log information about the current forecast cycle.""" + ) -> None: + """Log information about the current forecast cycle. + + Warnings + -------- + Modifies mutable arguments in-place. + """ # Log information about this forecast cycle if mpi_config.rank == 0: config_options.statusMsg = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -324,11 +284,6 @@ def log_forecast( err_handler.log_msg(config_options, mpi_config, True) # mpi_config.comm.barrier() - return ( - config_options, - mpi_config, - ) - @time_function def loop_through_forcing_products( self, @@ -339,8 +294,13 @@ def loop_through_forcing_products( supp_pcp_mod: dict, mpi_config: MpiConfig, output_obj: OutputObj, - ): - """Loop through each forcing product and process it for the current forecast cycle.""" + ) -> forcingInputMod.InputForcingsHydrofabric: + """Loop through each forcing product and process it for the current forecast cycle. + + Warnings + -------- + Modifies mutable arguments in-place. + """ # Loop through each output timestep. Perform the following functions: # 1.) Calculate all necessary input files per user options. # 2.) Read in input forcings from GRIB/NetCDF files. @@ -642,16 +602,7 @@ def loop_through_forcing_products( # err_handler.check_program_status(config_options, mpi_config) ############################################################################################## - return ( - future_time, - config_options, - wrf_hydro_geo_meta, - input_forcing_mod, - supp_pcp_mod, - mpi_config, - output_obj, - input_forcings, - ) + return input_forcings @time_function def process_suplemental_precip( @@ -662,8 +613,13 @@ def process_suplemental_precip( mpi_config: MpiConfig, output_obj: OutputObj, input_forcings: dict, - ): - """Process supplemental precipitation for the current forecast cycle.""" + ) -> None: + """Process supplemental precipitation for the current forecast cycle. + + Warnings + -------- + Modifies mutable arguments in-place. + """ if config_options.customSuppPcpFreq is not None: # Process supplemental precipitation if we specified in the configuration file. if config_options.number_supp_pcp > 0: @@ -717,14 +673,6 @@ def process_suplemental_precip( ) err_handler.check_program_status(config_options, mpi_config) - return ( - config_options, - wrf_hydro_geo_meta, - supp_pcp_mod, - mpi_config, - output_obj, - ) - @time_function def write_output( self, @@ -732,8 +680,13 @@ def write_output( wrf_hydro_geo_meta: GeoMeta, mpi_config: MpiConfig, output_obj: OutputObj, - ): - """Write the output for the current forecast cycle.""" + ) -> None: + """Write the output for the current forecast cycle. + + Warnings + -------- + Modifies mutable arguments in-place. + """ # If user requests output for given domain, then call # the I/O module to update opened netcdf file with forcing fields if ( @@ -743,12 +696,6 @@ def write_output( output_obj.gather_global_outputs( config_options, wrf_hydro_geo_meta, mpi_config ) - return ( - config_options, - wrf_hydro_geo_meta, - mpi_config, - output_obj, - ) """##################Step 6: flatten and update dict##########################################################################""" @@ -759,8 +706,13 @@ def update_dict( config_options: ConfigOptions, wrf_hydro_geo_meta: GeoMeta, output_obj: OutputObj, - ): - """Flatten the Forcings Engine output object and update the BMI dictionary.""" + ) -> None: + """Flatten the Forcings Engine output object and update the BMI dictionary. + + Warnings + -------- + Modifies mutable arguments in-place. + """ # Now loop through Forcings Engine output object # and flatten the 2D forcing array and append to # the BMI object to advertise to BMIinterface @@ -813,10 +765,4 @@ def update_dict( model[variable + "_ELEMENT"] = output_obj.output_global[ count, : ].flatten() - - return ( - model, - config_options, - wrf_hydro_geo_meta, - output_obj, - ) + model["CAT-ID"] = wrf_hydro_geo_meta.element_ids_global diff --git a/tests/test_utils.py b/tests/test_utils.py index e21a9d5c..049578e1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -673,43 +673,13 @@ def pre_regrid(self) -> None: ) model = self.bmi_model._model - ### NOTE with the exception of setting the skip flag, the below - ### block is copied verbatim from NWMv3ForcingEngineModel.run() - ( - future_time, - config_options, - ) = model.determine_forecast( - future_time, - config_options, - ) - ( - config_options, - input_forcing_mod, - mpi_config, - ) = model.adjust_precip( - config_options, - input_forcing_mod, - mpi_config, - ) - ( - config_options, - mpi_config, - ) = model.log_forecast( - config_options, - mpi_config, - ) + ### NOTE this should mimic NWMv3ForcingEngineModel.run() with the exception of setting the skip flag + model.determine_forecast(future_time, config_options) + model.adjust_precip(config_options, input_forcing_mod, mpi_config) + model.log_forecast(config_options, mpi_config) ### NOTE setting the flag causes the regrid step to be skipped self.set_input_forcings_skip_flags() - ( - future_time, - config_options, - geo_meta, - input_forcing_mod, - supp_pcp_mod, - mpi_config, - output_obj, - input_forcings, - ) = model.loop_through_forcing_products( + model.loop_through_forcing_products( future_time, config_options, geo_meta, From 7eb4f5a6bed22657e97ff05e19bd28d9a5109237 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 10:10:43 -0400 Subject: [PATCH 18/71] Raise error on unexpected grid_type --- .../NextGen_Forcings_Engine/model.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 4fde3687..ed8fec99 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -320,6 +320,10 @@ def loop_through_forcing_products( elif config_options.grid_type == "hydrofabric": # Reset out final grids to missing values. output_obj.output_local[:, :] = config_options.globalNdv + else: + raise ValueError( + f"Unexpected grid_type: {repr(config_options.grid_type)}" + ) # Increment or initialize output step count if config_options.current_output_step is None: @@ -496,6 +500,10 @@ def loop_through_forcing_products( input_forcings.regridded_forcings1[:, :] = ( input_forcings.regridded_forcings2[:, :] ) + else: + raise ValueError( + f"Unexpected grid_type: {repr(config_options.grid_type)}" + ) # Re-calculate the neighbor files. input_forcings.calc_neighbor_files( config_options, output_obj.outDate, mpi_config @@ -766,3 +774,5 @@ def update_dict( count, : ].flatten() model["CAT-ID"] = wrf_hydro_geo_meta.element_ids_global + else: + raise ValueError(f"Unexpected grid_type: {repr(config_options.grid_type)}") From b47e4c9513820ba04e7807491b7d7a8e5ea7f792 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 12:10:35 -0400 Subject: [PATCH 19/71] Use `time.perf_counter` instead of `time.time` --- .../NextGen_Forcings_Engine/model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index ed8fec99..229fe863 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -2,7 +2,7 @@ import logging import os from contextlib import contextmanager -from time import time +from time import time, perf_counter import numpy as np import pandas as pd @@ -48,9 +48,9 @@ def timing_block(step_str: str): step_str: Description of the step being timed. """ - start = time() + start = perf_counter() yield - end = time() + end = perf_counter() LOG.debug(f" Execution time for {step_str}: {round(end - start, 2)} seconds") From 8341ef874264f12062941caaf3b70eb1af385167 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 13:37:59 -0400 Subject: [PATCH 20/71] Start encapsulating BMI model into model.py NWMv3ForcingEngineModel starting with _values dict --- .../NextGen_Forcings_Engine/bmi_model.py | 2 -- .../NextGen_Forcings_Engine/model.py | 36 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index da812bab..c7e7aaee 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -516,7 +516,6 @@ def update_until(self, future_time: float) -> None: == self.cfg_bmi["initial_time"] ): self._model.run( - self._values, future_time, self._job_meta, self.geo_meta, @@ -533,7 +532,6 @@ def update_until(self, future_time: float) -> None: self._values["current_model_time"] += self._values["time_step_size"] # Run the model for the new current time and update the state. self._model.run( - self._values, self._values["current_model_time"], self._job_meta, self.geo_meta, diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 229fe863..575221f1 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -1,8 +1,11 @@ +from __future__ import annotations + import datetime import logging import os from contextlib import contextmanager -from time import time, perf_counter +from time import perf_counter, time +from typing import TYPE_CHECKING import numpy as np import pandas as pd @@ -35,6 +38,12 @@ NWMV3PuertoRicoProcessor, ) +if TYPE_CHECKING: + # To allow type hint without circular import error + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.bmi_model import ( + NWMv3_Forcing_Engine_BMI_model_Base, + ) + LOG = logging.getLogger("FORCING") MODNM = ModuleKey.FORCING.value @@ -68,9 +77,10 @@ def wrapper(*args, **kwargs): class NWMv3ForcingEngineModel: """NextGen Forcings Engine BMI model class for NWMv3 forcings.""" - def __init__(self): + def __init__(self, bmi_model: NWMv3_Forcing_Engine_BMI_model_Base): """Initialize the NWMv3 Forcing Engine Model.""" self.source_data_processor = None + self._bmi = bmi_model # TODO: refactor the bmi_model.py file and this to have this type maintain its own state. # def __init__(self): @@ -83,7 +93,6 @@ def __init__(self): def run( self, - model: dict, future_time: float, config_options: ConfigOptions, wrf_hydro_geo_meta: GeoMeta, @@ -94,10 +103,10 @@ def run( ) -> None: """Execute the full forcings engine BMI pipeline for a given future timestep. - This method updates the `model` state dictionary with atmospheric forcings computed from + This method updates the `self._bmi._values` state dictionary with atmospheric forcings computed from available input datasets. It handles initialization, AWS Zarr loading, regridding, temporal interpolation, bias correction, downscaling, supplemental precipitation processing, and output - population into the model structure. + population into the self._bmi._values structure. The following steps are performed: @@ -116,10 +125,9 @@ def run( b. Disaggregate and interpolate. c. Layer into the final output. 5. Write output to NetCDF forcing files if requested. - 6. Update the model state dictionary with flattened arrays. + 6. Update the self._bmi._values state dictionary with flattened arrays. 7. Advance the BMI time index. - :param model: The model state dictionary that will be updated with new forcing data. :param future_time: The number of seconds into the future to advance the model. :param config_options: Configuration object containing all model options, flags, and paths. :param wrf_hydro_geo_meta: Geospatial metadata needed for regridding and interpolation. @@ -159,7 +167,6 @@ def run( output_obj, ) self.update_dict( - model, config_options, wrf_hydro_geo_meta, output_obj, @@ -710,7 +717,6 @@ def write_output( @time_function def update_dict( self, - model: dict, config_options: ConfigOptions, wrf_hydro_geo_meta: GeoMeta, output_obj: OutputObj, @@ -759,20 +765,22 @@ def update_dict( ] if config_options.grid_type == "gridded": for count, variable in enumerate(variables): - model[variable + "_ELEMENT"] = output_obj.output_local[ + self._bmi._values[variable + "_ELEMENT"] = output_obj.output_local[ count, :, : ].flatten() elif config_options.grid_type == "unstructured": for count, variable in enumerate(variables): - model[variable + "_ELEMENT"] = output_obj.output_local_elem[ + self._bmi._values[variable + "_ELEMENT"] = output_obj.output_local_elem[ + count, : + ].flatten() + self._bmi._values[variable + "_NODE"] = output_obj.output_local[ count, : ].flatten() - model[variable + "_NODE"] = output_obj.output_local[count, :].flatten() elif config_options.grid_type == "hydrofabric": for count, variable in enumerate(variables): - model[variable + "_ELEMENT"] = output_obj.output_global[ + self._bmi._values[variable + "_ELEMENT"] = output_obj.output_global[ count, : ].flatten() - model["CAT-ID"] = wrf_hydro_geo_meta.element_ids_global + self._bmi._values["CAT-ID"] = wrf_hydro_geo_meta.element_ids_global else: raise ValueError(f"Unexpected grid_type: {repr(config_options.grid_type)}") From d0b6c054b9790e2e34f4153d6d694925740dbeb5 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 14:34:31 -0400 Subject: [PATCH 21/71] Encapsulate ConfigOptions instance --- .../NextGen_Forcings_Engine/bmi_model.py | 2 - .../NextGen_Forcings_Engine/model.py | 397 ++++++++++-------- tests/test_utils.py | 8 +- 3 files changed, 218 insertions(+), 189 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index c7e7aaee..606a06af 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -517,7 +517,6 @@ def update_until(self, future_time: float) -> None: ): self._model.run( future_time, - self._job_meta, self.geo_meta, self._input_forcing_mod, self._supp_pcp_mod, @@ -533,7 +532,6 @@ def update_until(self, future_time: float) -> None: # Run the model for the new current time and update the state. self._model.run( self._values["current_model_time"], - self._job_meta, self.geo_meta, self._input_forcing_mod, self._supp_pcp_mod, diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 575221f1..6a045262 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -94,7 +94,6 @@ def __init__(self, bmi_model: NWMv3_Forcing_Engine_BMI_model_Base): def run( self, future_time: float, - config_options: ConfigOptions, wrf_hydro_geo_meta: GeoMeta, input_forcing_mod: dict, supp_pcp_mod: dict, @@ -108,6 +107,8 @@ def run( interpolation, bias correction, downscaling, supplemental precipitation processing, and output population into the self._bmi._values structure. + `self._bmi._job_meta`, an instance of ConfigOptions is also updated in-place, for example for time handling. + The following steps are performed: 1. Determine the current forecast and output times based on the future timestamp @@ -129,7 +130,6 @@ def run( 7. Advance the BMI time index. :param future_time: The number of seconds into the future to advance the model. - :param config_options: Configuration object containing all model options, flags, and paths. :param wrf_hydro_geo_meta: Geospatial metadata needed for regridding and interpolation. :param input_forcing_mod: Dictionary of initialized input forcing modules indexed by forcing key. :param supp_pcp_mod: Dictionary of supplemental precipitation modules indexed by key. @@ -139,13 +139,12 @@ def run( :raises RuntimeError: If the model fails to initialize or if required arguments are missing. """ - self.determine_forecast(future_time, config_options) - self.adjust_precip(config_options, input_forcing_mod, mpi_config) - self.log_forecast(config_options, mpi_config) + self.determine_forecast(future_time) + self.adjust_precip(input_forcing_mod, mpi_config) + self.log_forecast(mpi_config) # TODO look into input_forcings usage in `process_suplemental_precip` and in `loop_through_forcing_products` at `disaggregate_fun`. input_forcings = self.loop_through_forcing_products( future_time, - config_options, wrf_hydro_geo_meta, input_forcing_mod, supp_pcp_mod, @@ -153,7 +152,6 @@ def run( output_obj, ) self.process_suplemental_precip( - config_options, wrf_hydro_geo_meta, supp_pcp_mod, mpi_config, @@ -161,25 +159,22 @@ def run( input_forcings, ) self.write_output( - config_options, wrf_hydro_geo_meta, mpi_config, output_obj, ) self.update_dict( - config_options, wrf_hydro_geo_meta, output_obj, ) ## Update BMI model time index to next iteration - config_options.bmi_time_index += 1 + self._bmi._job_meta.bmi_time_index += 1 @time_function def determine_forecast( self, future_time: float, - config_options: ConfigOptions, ) -> None: """Determine the forecast for the given future time and configuration. @@ -188,64 +183,67 @@ def determine_forecast( Modifies mutable arguments in-place. """ # Assign the future time to the configuration - config_options.bmi_time = future_time - self.disaggregate_fun = disaggregateMod.disaggregate_factory(config_options) + self._bmi._job_meta.bmi_time = future_time + self.disaggregate_fun = disaggregateMod.disaggregate_factory( + self._bmi._job_meta + ) # Calculate current time stamp based on operational configuration - if config_options.ana_flag: + if self._bmi._job_meta.ana_flag: # If we're in an AnA configuration, then must offset the BMI future # timestamp to account for the "lookback" period being properly iterated # over between 3-28 hour look back time period and operation configuration - - # if config_options.input_forcings[0] in [20, 22]: - # config_options.current_fcst_cycle = ( - # config_options.b_date_proc - # + pd.TimedeltaIndex( - # np.array([future_time - 7200.0], dtype=float), "s" - # )[0] - # ) - # config_options.current_time = ( - # config_options.b_date_proc - # + pd.TimedeltaIndex( - # np.array([future_time - 7200.0], dtype=float), "s" - # )[0] - # ) - # config_options.future_time = future_time - # else: - - # Puerto Rico / Hawaii AnA: 1-hour lookback (based on 6-hourly forecast cycles) - config_options.current_fcst_cycle = ( - config_options.b_date_proc - + pd.TimedeltaIndex(np.array([future_time - 3600.0], dtype=float), "s")[ - 0 - ] - ) - config_options.current_time = ( - config_options.b_date_proc - + pd.TimedeltaIndex(np.array([future_time - 3600.0], dtype=float), "s")[ - 0 - ] - ) + if self._bmi._job_meta.input_forcings[0] in [20, 22]: + self._bmi._job_meta.current_fcst_cycle = ( + self._bmi._job_meta.b_date_proc + + pd.TimedeltaIndex( + np.array([future_time - 7200.0], dtype=float), "s" + )[0] + ) + self._bmi._job_meta.current_time = ( + self._bmi._job_meta.b_date_proc + + pd.TimedeltaIndex( + np.array([future_time - 7200.0], dtype=float), "s" + )[0] + ) + self._bmi._job_meta.future_time = future_time + else: + # Puerto Rico / Hawaii AnA: 1-hour lookback (based on 6-hourly forecast cycles) + self._bmi._job_meta.current_fcst_cycle = ( + self._bmi._job_meta.b_date_proc + + pd.TimedeltaIndex( + np.array([future_time - 3600.0], dtype=float), "s" + )[0] + ) + self._bmi._job_meta.current_time = ( + self._bmi._job_meta.b_date_proc + + pd.TimedeltaIndex( + np.array([future_time - 3600.0], dtype=float), "s" + )[0] + ) else: # Forecast-only mode — use BMI timestamp as-is - config_options.current_fcst_cycle = config_options.b_date_proc - config_options.current_time = pd.Timestamp( - config_options.b_date_proc + self._bmi._job_meta.current_fcst_cycle = self._bmi._job_meta.b_date_proc + self._bmi._job_meta.current_time = pd.Timestamp( + self._bmi._job_meta.b_date_proc ) + pd.to_timedelta(future_time, unit="s") LOG.debug( "NextGen Forcings Engine processing meteorological forcings for BMI timestamp" ) - LOG.debug(f"Model.py current time: {config_options.current_time}") - LOG.debug(f"Model.py current fcst cycle: {config_options.current_fcst_cycle}") + LOG.debug(f"Model.py current time: {self._bmi._job_meta.current_time}") + LOG.debug( + f"Model.py current fcst cycle: {self._bmi._job_meta.current_fcst_cycle}" + ) - if config_options.first_fcst_cycle is None: - config_options.first_fcst_cycle = config_options.current_fcst_cycle + if self._bmi._job_meta.first_fcst_cycle is None: + self._bmi._job_meta.first_fcst_cycle = ( + self._bmi._job_meta.current_fcst_cycle + ) @time_function def adjust_precip( self, - config_options: ConfigOptions, input_forcing_mod: dict, mpi_config: MpiConfig, ) -> None: @@ -255,17 +253,16 @@ def adjust_precip( -------- Modifies mutable arguments in-place. """ - if not config_options.precip_only_flag: + if not self._bmi._job_meta.precip_only_flag: # reset skips if present - for force_key in config_options.input_forcings: + for force_key in self._bmi._job_meta.input_forcings: input_forcing_mod[force_key].skip = False - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status(self._bmi._job_meta, mpi_config) @time_function def log_forecast( self, - config_options: ConfigOptions, mpi_config: MpiConfig, ) -> None: """Log information about the current forecast cycle. @@ -276,26 +273,25 @@ def log_forecast( """ # Log information about this forecast cycle if mpi_config.rank == 0: - config_options.statusMsg = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - err_handler.log_msg(config_options, mpi_config, True) - config_options.statusMsg = ( + self._bmi._job_meta.statusMsg = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + err_handler.log_msg(self._bmi._job_meta, mpi_config, True) + self._bmi._job_meta.statusMsg = ( "Processing Forecast Cycle: " - + config_options.current_fcst_cycle.strftime("%Y-%m-%d %H:%M") + + self._bmi._job_meta.current_fcst_cycle.strftime("%Y-%m-%d %H:%M") ) - err_handler.log_msg(config_options, mpi_config, True) - config_options.statusMsg = ( + err_handler.log_msg(self._bmi._job_meta, mpi_config, True) + self._bmi._job_meta.statusMsg = ( "Forecast Cycle Length is: " - + str(config_options.cycle_length_minutes) + + str(self._bmi._job_meta.cycle_length_minutes) + " minutes" ) - err_handler.log_msg(config_options, mpi_config, True) + err_handler.log_msg(self._bmi._job_meta, mpi_config, True) # mpi_config.comm.barrier() @time_function def loop_through_forcing_products( self, future_time: float, - config_options: ConfigOptions, wrf_hydro_geo_meta: GeoMeta, input_forcing_mod: dict, supp_pcp_mod: dict, @@ -314,93 +310,99 @@ def loop_through_forcing_products( # 3.) Regrid the forcings, and temporally interpolate. # 4.) Downscale. # 5.) Layer, and output as necessary. - ana_factor = 1 if config_options.ana_flag is False else 0 + ana_factor = 1 if self._bmi._job_meta.ana_flag is False else 0 show_message = True - if not config_options.precip_only_flag: - if config_options.grid_type == "gridded": + if not self._bmi._job_meta.precip_only_flag: + if self._bmi._job_meta.grid_type == "gridded": # Reset out final grids to missing values. - output_obj.output_local[:, :, :] = config_options.globalNdv - elif config_options.grid_type == "unstructured": + output_obj.output_local[:, :, :] = self._bmi._job_meta.globalNdv + elif self._bmi._job_meta.grid_type == "unstructured": # Reset out final grids to missing values. - output_obj.output_local[:, :] = config_options.globalNdv - output_obj.output_local_elem[:, :] = config_options.globalNdv - elif config_options.grid_type == "hydrofabric": + output_obj.output_local[:, :] = self._bmi._job_meta.globalNdv + output_obj.output_local_elem[:, :] = self._bmi._job_meta.globalNdv + elif self._bmi._job_meta.grid_type == "hydrofabric": # Reset out final grids to missing values. - output_obj.output_local[:, :] = config_options.globalNdv + output_obj.output_local[:, :] = self._bmi._job_meta.globalNdv else: raise ValueError( - f"Unexpected grid_type: {repr(config_options.grid_type)}" + f"Unexpected grid_type: {repr(self._bmi._job_meta.grid_type)}" ) # Increment or initialize output step count - if config_options.current_output_step is None: - config_options.current_output_step = 1 + if self._bmi._job_meta.current_output_step is None: + self._bmi._job_meta.current_output_step = 1 else: - config_options.current_output_step += 1 + self._bmi._job_meta.current_output_step += 1 # Optional sub-output timestamp - if config_options.sub_output_hour is not None: + if self._bmi._job_meta.sub_output_hour is not None: # TODO This is not used - subOutDate = config_options.first_fcst_cycle + datetime.timedelta( - hours=config_options.sub_output_hour + subOutDate = self._bmi._job_meta.first_fcst_cycle + datetime.timedelta( + hours=self._bmi._job_meta.sub_output_hour ) # Compute the output timestamp for this step - if config_options.ana_flag: + if self._bmi._job_meta.ana_flag: output_obj.outDate = ( - config_options.current_fcst_cycle - + datetime.timedelta(seconds=config_options.output_freq * 60) + self._bmi._job_meta.current_fcst_cycle + + datetime.timedelta(seconds=self._bmi._job_meta.output_freq * 60) ) else: output_obj.outDate = ( - config_options.current_fcst_cycle + self._bmi._job_meta.current_fcst_cycle + datetime.timedelta(seconds=future_time) ) - config_options.current_output_date = output_obj.outDate + self._bmi._job_meta.current_output_date = output_obj.outDate # Adjust file_date for AnA if needed file_date = ( output_obj.outDate - - datetime.timedelta(seconds=config_options.output_freq * 60) - if config_options.ana_flag + - datetime.timedelta(seconds=self._bmi._job_meta.output_freq * 60) + if self._bmi._job_meta.ana_flag else output_obj.outDate ) # Compute previous output date (used for downscaling logic) - if config_options.current_output_step == ana_factor: - config_options.prev_output_date = config_options.current_output_date + if self._bmi._job_meta.current_output_step == ana_factor: + self._bmi._job_meta.prev_output_date = ( + self._bmi._job_meta.current_output_date + ) else: - config_options.prev_output_date = ( - config_options.current_output_date + self._bmi._job_meta.prev_output_date = ( + self._bmi._job_meta.current_output_date - datetime.timedelta(seconds=future_time) ) # Print message on log file indicating the timestamp # we are currently processing for forcings if mpi_config.rank == 0 and show_message: - config_options.statusMsg = "=========================================" - err_handler.log_msg(config_options, mpi_config, True) - config_options.statusMsg = f"Processing for output timestep: {file_date.strftime('%Y-%m-%d %H:%M')}" - err_handler.log_msg(config_options, mpi_config, True) - - config_options.currentForceNum = 0 - config_options.currentCustomForceNum = 0 - LOG.debug(f"config_options.input_forcings: {config_options.input_forcings}") + self._bmi._job_meta.statusMsg = ( + "=========================================" + ) + err_handler.log_msg(self._bmi._job_meta, mpi_config, True) + self._bmi._job_meta.statusMsg = f"Processing for output timestep: {file_date.strftime('%Y-%m-%d %H:%M')}" + err_handler.log_msg(self._bmi._job_meta, mpi_config, True) + + self._bmi._job_meta.currentForceNum = 0 + self._bmi._job_meta.currentCustomForceNum = 0 + LOG.debug( + f"config_options.input_forcings: {self._bmi._job_meta.input_forcings}" + ) # Loop over each of the input forcings specified. LOG.debug( - f"Model.py forcing loop: {len(config_options.input_forcings)} forcings configured: {config_options.input_forcings}" + f"Model.py forcing loop: {len(self._bmi._job_meta.input_forcings)} forcings configured: {self._bmi._job_meta.input_forcings}" ) - for force_key in config_options.input_forcings: + for force_key in self._bmi._job_meta.input_forcings: LOG.debug(f"force_key: {force_key}") - LOG.debug(f"config_options.aws: {config_options.aws}") + LOG.debug(f"config_options.aws: {self._bmi._job_meta.aws}") # Pass these methods for AORC data is ERA5-Interim blend is requested # so we can finish filling in the missing gaps if ( force_key == 23 - and 12 in config_options.input_forcings - and 21 in config_options.input_forcings + and 12 in self._bmi._job_meta.input_forcings + and 21 in self._bmi._job_meta.input_forcings ): input_forcings = input_forcing_mod[force_key] @@ -410,35 +412,39 @@ def loop_through_forcing_products( else: input_forcings = input_forcing_mod[force_key] input_forcings.calc_neighbor_files( - config_options, output_obj.outDate, mpi_config + self._bmi._job_meta, output_obj.outDate, mpi_config ) if force_key in [12, 21, 27]: - if config_options.aws is None: + if self._bmi._job_meta.aws is None: # Calculate the previous and next input cycle files from the inputs. input_forcings.calc_neighbor_files( - config_options, output_obj.outDate, mpi_config + self._bmi._job_meta, output_obj.outDate, mpi_config + ) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) else: # Flag to indicate the AWS .zarr AORC method if force_key == 12: if self.source_data_processor is None: self.source_data_processor = AORCConusProcessor( - config_options, mpi_config, wrf_hydro_geo_meta + self._bmi._job_meta, mpi_config, wrf_hydro_geo_meta ) elif force_key == 21: if self.source_data_processor is None: self.source_data_processor = AORCAlaskaProcessor( - config_options, mpi_config, wrf_hydro_geo_meta + self._bmi._job_meta, mpi_config, wrf_hydro_geo_meta ) # Flag to indicate the AWS .zarr NWMv3 Forcing file method elif force_key == 27: if self.source_data_processor is None: - if config_options.nwm_domain == "CONUS": + if self._bmi._job_meta.nwm_domain == "CONUS": self.source_data_processor = NWMV3ConusProcessor( - config_options, mpi_config, wrf_hydro_geo_meta + self._bmi._job_meta, + mpi_config, + wrf_hydro_geo_meta, ) elif config_options.nwm_domain == "Hawaii": self.source_data_processor = NWMV3HawaiiProcessor( @@ -455,16 +461,18 @@ def loop_through_forcing_products( ) elif config_options.nwm_domain == "Alaska": self.source_data_processor = NWMV3AlaskaProcessor( - config_options, mpi_config, wrf_hydro_geo_meta + self._bmi._job_meta, + mpi_config, + wrf_hydro_geo_meta, ) else: raise ValueError( - f"Unsupported domain type ({config_options.nwm_domain} for forcing type: {force_key} )" + f"Unsupported domain type ({self._bmi._job_meta.nwm_domain} for forcing type: {force_key} )" ) - config_options.aws_obj = ( + self._bmi._job_meta.aws_obj = ( self.source_data_processor.process_historical_data( - config_options.current_time + self._bmi._job_meta.current_time ) ) @@ -474,15 +482,15 @@ def loop_through_forcing_products( break # Regrid forcings. input_forcings.regrid_inputs( - config_options, wrf_hydro_geo_meta, mpi_config + self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status(self._bmi._job_meta, mpi_config) # Run check on regridded fields for reasonable values that are not missing values. err_handler.check_forcing_bounds( - config_options, input_forcings, mpi_config + self._bmi._job_meta, input_forcings, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status(self._bmi._job_meta, mpi_config) # If we are restarting a forecast cycle, re-calculate the neighboring files, and regrid the # next set of forcings as the previous step just regridded the previous forcing. @@ -492,83 +500,89 @@ def loop_through_forcing_products( and input_forcings.regridded_forcings2 is not None ): # Set the forcings back to reflect we just regridded the previous set of inputs, not the next. - if config_options.grid_type == "gridded": + if self._bmi._job_meta.grid_type == "gridded": input_forcings.regridded_forcings1[:, :, :] = ( input_forcings.regridded_forcings2[:, :, :] ) - elif config_options.grid_type == "unstructured": + elif self._bmi._job_meta.grid_type == "unstructured": input_forcings.regridded_forcings1[:, :] = ( input_forcings.regridded_forcings2[:, :] ) input_forcings.regridded_forcings1_elem[:, :] = ( input_forcings.regridded_forcings2_elem[:, :] ) - elif config_options.grid_type == "hydrofabric": + elif self._bmi._job_meta.grid_type == "hydrofabric": input_forcings.regridded_forcings1[:, :] = ( input_forcings.regridded_forcings2[:, :] ) else: raise ValueError( - f"Unexpected grid_type: {repr(config_options.grid_type)}" + f"Unexpected grid_type: {repr(self._bmi._job_meta.grid_type)}" ) # Re-calculate the neighbor files. input_forcings.calc_neighbor_files( - config_options, output_obj.outDate, mpi_config + self._bmi._job_meta, output_obj.outDate, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status(self._bmi._job_meta, mpi_config) # Regrid the forcings for the end of the window. input_forcings.regrid_inputs( - config_options, wrf_hydro_geo_meta, mpi_config + self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status(self._bmi._job_meta, mpi_config) input_forcings.rstFlag = 0 # Run temporal interpolation on the grids. - input_forcings.temporal_interpolate_inputs(config_options, mpi_config) - err_handler.check_program_status(config_options, mpi_config) + input_forcings.temporal_interpolate_inputs( + self._bmi._job_meta, mpi_config + ) + err_handler.check_program_status(self._bmi._job_meta, mpi_config) # Run bias correction. bias_correction.run_bias_correction( - input_forcings, config_options, wrf_hydro_geo_meta, mpi_config + input_forcings, self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status(self._bmi._job_meta, mpi_config) # Run downscaling on grids for this output timestep. downscale.run_downscaling( - input_forcings, config_options, wrf_hydro_geo_meta, mpi_config + input_forcings, self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status(self._bmi._job_meta, mpi_config) # Layer in forcings from this product. layeringMod.layer_final_forcings( - output_obj, input_forcings, config_options, mpi_config + output_obj, input_forcings, self._bmi._job_meta, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status(self._bmi._job_meta, mpi_config) - config_options.currentForceNum += 1 + self._bmi._job_meta.currentForceNum += 1 if force_key == 10: - config_options.currentCustomForceNum += 1 + self._bmi._job_meta.currentCustomForceNum += 1 LOG.debug(f"End of loop for force_key {force_key}") # Process supplemental precipitation if we specified in the configuration file. - if config_options.number_supp_pcp > 0: - for supp_pcp_key in config_options.supp_precip_forcings: + if self._bmi._job_meta.number_supp_pcp > 0: + for supp_pcp_key in self._bmi._job_meta.supp_precip_forcings: if supp_pcp_key != 13: # Like with input forcings, calculate the neighboring files to use. supp_pcp_mod[supp_pcp_key].calc_neighbor_files( - config_options, output_obj.outDate, mpi_config + self._bmi._job_meta, output_obj.outDate, mpi_config + ) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) # Regrid the supplemental precipitation. supp_pcp_mod[supp_pcp_key].regrid_inputs( - config_options, wrf_hydro_geo_meta, mpi_config + self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config + ) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) if ( supp_pcp_mod[supp_pcp_key].regridded_precip1 is not None @@ -576,45 +590,53 @@ def loop_through_forcing_products( ): # Run check on regridded fields for reasonable values that are not missing values. err_handler.check_supp_pcp_bounds( - config_options, + self._bmi._job_meta, supp_pcp_mod[supp_pcp_key], mpi_config, wrf_hydro_geo_meta, ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config + ) # TODO input_forcings has not yet been initialized, so this is a bug waiting to happen self.disaggregate_fun( input_forcings, supp_pcp_mod[supp_pcp_key], - config_options, + self._bmi._job_meta, mpi_config, ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config + ) # Run temporal interpolation on the grids. supp_pcp_mod[supp_pcp_key].temporal_interpolate_inputs( - config_options, mpi_config + self._bmi._job_meta, mpi_config + ) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) # Layer in the supplemental precipitation into the current output object. layeringMod.layer_supplemental_forcing( output_obj, supp_pcp_mod[supp_pcp_key], - config_options, + self._bmi._job_meta, mpi_config, ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config + ) # Call the output routines # adjust date for AnA if necessary - if config_options.ana_flag: + if self._bmi._job_meta.ana_flag: output_obj.outDate = file_date ################ Commenting this out to bypass NWM forcing file output functionality ######### - # output_obj.output_final_ldasin(config_options, wrf_hydro_geo_meta, mpi_config) - # err_handler.check_program_status(config_options, mpi_config) + # output_obj.output_final_ldasin(self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config) + # err_handler.check_program_status(self._bmi._job_meta, mpi_config) ############################################################################################## return input_forcings @@ -622,7 +644,6 @@ def loop_through_forcing_products( @time_function def process_suplemental_precip( self, - config_options: ConfigOptions, wrf_hydro_geo_meta: GeoMeta, supp_pcp_mod: dict, mpi_config: MpiConfig, @@ -635,22 +656,26 @@ def process_suplemental_precip( -------- Modifies mutable arguments in-place. """ - if config_options.customSuppPcpFreq is not None: + if self._bmi._job_meta.customSuppPcpFreq is not None: # Process supplemental precipitation if we specified in the configuration file. - if config_options.number_supp_pcp > 0: - for supp_pcp_key in config_options.supp_precip_forcings: + if self._bmi._job_meta.number_supp_pcp > 0: + for supp_pcp_key in self._bmi._job_meta.supp_precip_forcings: if supp_pcp_key == 14: # Like with input forcings, calculate the neighboring files to use. supp_pcp_mod[supp_pcp_key].calc_neighbor_files( - config_options, output_obj.outDate, mpi_config + self._bmi._job_meta, output_obj.outDate, mpi_config + ) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) # Regrid the supplemental precipitation. supp_pcp_mod[supp_pcp_key].regrid_inputs( - config_options, wrf_hydro_geo_meta, mpi_config + self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config + ) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) if ( supp_pcp_mod[supp_pcp_key].regridded_precip1 is not None @@ -658,40 +683,47 @@ def process_suplemental_precip( ): # Run check on regridded fields for reasonable values that are not missing values. err_handler.check_supp_pcp_bounds( - config_options, + self._bmi._job_meta, supp_pcp_mod[supp_pcp_key], mpi_config, wrf_hydro_geo_meta, ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config + ) self.disaggregate_fun( input_forcings, supp_pcp_mod[supp_pcp_key], - config_options, + self._bmi._job_meta, mpi_config, ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config + ) # Run temporal interpolation on the grids. supp_pcp_mod[supp_pcp_key].temporal_interpolate_inputs( - config_options, mpi_config + self._bmi._job_meta, mpi_config + ) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config ) - err_handler.check_program_status(config_options, mpi_config) # Layer in the supplemental precipitation into the current output object. layeringMod.layer_supplemental_forcing( output_obj, supp_pcp_mod[supp_pcp_key], - config_options, + self._bmi._job_meta, mpi_config, ) - err_handler.check_program_status(config_options, mpi_config) + err_handler.check_program_status( + self._bmi._job_meta, mpi_config + ) @time_function def write_output( self, - config_options: ConfigOptions, wrf_hydro_geo_meta: GeoMeta, mpi_config: MpiConfig, output_obj: OutputObj, @@ -705,11 +737,11 @@ def write_output( # If user requests output for given domain, then call # the I/O module to update opened netcdf file with forcing fields if ( - config_options.forcing_output == 1 - or config_options.grid_type == "hydrofabric" + self._bmi._job_meta.forcing_output == 1 + or self._bmi._job_meta.grid_type == "hydrofabric" ): output_obj.gather_global_outputs( - config_options, wrf_hydro_geo_meta, mpi_config + self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config ) """##################Step 6: flatten and update dict##########################################################################""" @@ -717,7 +749,6 @@ def write_output( @time_function def update_dict( self, - config_options: ConfigOptions, wrf_hydro_geo_meta: GeoMeta, output_obj: OutputObj, ) -> None: @@ -740,7 +771,7 @@ def update_dict( # 7.) Surface incoming shortwave radiation flux (W/m^2) # 8.) Liquid Precipitation Fraction (%), Only available in certain operational configurations - if config_options.include_lqfrac == 1: + if self._bmi._job_meta.include_lqfrac == 1: variables = [ "U2D", "V2D", @@ -763,12 +794,12 @@ def update_dict( "PSFC", "SWDOWN", ] - if config_options.grid_type == "gridded": + if self._bmi._job_meta.grid_type == "gridded": for count, variable in enumerate(variables): self._bmi._values[variable + "_ELEMENT"] = output_obj.output_local[ count, :, : ].flatten() - elif config_options.grid_type == "unstructured": + elif self._bmi._job_meta.grid_type == "unstructured": for count, variable in enumerate(variables): self._bmi._values[variable + "_ELEMENT"] = output_obj.output_local_elem[ count, : @@ -776,11 +807,13 @@ def update_dict( self._bmi._values[variable + "_NODE"] = output_obj.output_local[ count, : ].flatten() - elif config_options.grid_type == "hydrofabric": + elif self._bmi._job_meta.grid_type == "hydrofabric": for count, variable in enumerate(variables): self._bmi._values[variable + "_ELEMENT"] = output_obj.output_global[ count, : ].flatten() self._bmi._values["CAT-ID"] = wrf_hydro_geo_meta.element_ids_global else: - raise ValueError(f"Unexpected grid_type: {repr(config_options.grid_type)}") + raise ValueError( + f"Unexpected grid_type: {repr(self._bmi._job_meta.grid_type)}" + ) diff --git a/tests/test_utils.py b/tests/test_utils.py index 049578e1..b86ad8a1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -660,7 +660,6 @@ def pre_regrid(self) -> None: f"In pre_regrid, expected state to be either None or 'post_ran' but got {repr(self._state)}. The test is set up incorrectly." ) - config_options = self.config_options mpi_config = self.mpi_config geo_meta = self.geo_meta supp_pcp_mod = self.bmi_model._supp_pcp_mod @@ -674,14 +673,13 @@ def pre_regrid(self) -> None: model = self.bmi_model._model ### NOTE this should mimic NWMv3ForcingEngineModel.run() with the exception of setting the skip flag - model.determine_forecast(future_time, config_options) - model.adjust_precip(config_options, input_forcing_mod, mpi_config) - model.log_forecast(config_options, mpi_config) + model.determine_forecast(future_time) + model.adjust_precip(input_forcing_mod, mpi_config) + model.log_forecast(mpi_config) ### NOTE setting the flag causes the regrid step to be skipped self.set_input_forcings_skip_flags() model.loop_through_forcing_products( future_time, - config_options, geo_meta, input_forcing_mod, supp_pcp_mod, From 11732970ab6d55072f7e2a1fb6d6cadcc49a4ded Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 14:53:12 -0400 Subject: [PATCH 22/71] Encapsulate GeoMeta instance --- .../NextGen_Forcings_Engine/bmi_model.py | 2 - .../NextGen_Forcings_Engine/model.py | 51 +++++++++---------- tests/test_utils.py | 2 - 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index 606a06af..2c890f97 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -517,7 +517,6 @@ def update_until(self, future_time: float) -> None: ): self._model.run( future_time, - self.geo_meta, self._input_forcing_mod, self._supp_pcp_mod, self._mpi_meta, @@ -532,7 +531,6 @@ def update_until(self, future_time: float) -> None: # Run the model for the new current time and update the state. self._model.run( self._values["current_model_time"], - self.geo_meta, self._input_forcing_mod, self._supp_pcp_mod, self._mpi_meta, diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 6a045262..633886fe 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -94,7 +94,6 @@ def __init__(self, bmi_model: NWMv3_Forcing_Engine_BMI_model_Base): def run( self, future_time: float, - wrf_hydro_geo_meta: GeoMeta, input_forcing_mod: dict, supp_pcp_mod: dict, mpi_config: MpiConfig, @@ -130,7 +129,6 @@ def run( 7. Advance the BMI time index. :param future_time: The number of seconds into the future to advance the model. - :param wrf_hydro_geo_meta: Geospatial metadata needed for regridding and interpolation. :param input_forcing_mod: Dictionary of initialized input forcing modules indexed by forcing key. :param supp_pcp_mod: Dictionary of supplemental precipitation modules indexed by key. :param mpi_config: Object containing MPI communication settings such as rank and communicator. @@ -145,26 +143,22 @@ def run( # TODO look into input_forcings usage in `process_suplemental_precip` and in `loop_through_forcing_products` at `disaggregate_fun`. input_forcings = self.loop_through_forcing_products( future_time, - wrf_hydro_geo_meta, input_forcing_mod, supp_pcp_mod, mpi_config, output_obj, ) self.process_suplemental_precip( - wrf_hydro_geo_meta, supp_pcp_mod, mpi_config, output_obj, input_forcings, ) self.write_output( - wrf_hydro_geo_meta, mpi_config, output_obj, ) self.update_dict( - wrf_hydro_geo_meta, output_obj, ) @@ -292,7 +286,6 @@ def log_forecast( def loop_through_forcing_products( self, future_time: float, - wrf_hydro_geo_meta: GeoMeta, input_forcing_mod: dict, supp_pcp_mod: dict, mpi_config: MpiConfig, @@ -429,12 +422,16 @@ def loop_through_forcing_products( if force_key == 12: if self.source_data_processor is None: self.source_data_processor = AORCConusProcessor( - self._bmi._job_meta, mpi_config, wrf_hydro_geo_meta + self._bmi._job_meta, + mpi_config, + self._bmi.geo_meta, ) elif force_key == 21: if self.source_data_processor is None: self.source_data_processor = AORCAlaskaProcessor( - self._bmi._job_meta, mpi_config, wrf_hydro_geo_meta + self._bmi._job_meta, + mpi_config, + self._bmi.geo_meta, ) # Flag to indicate the AWS .zarr NWMv3 Forcing file method @@ -444,13 +441,12 @@ def loop_through_forcing_products( self.source_data_processor = NWMV3ConusProcessor( self._bmi._job_meta, mpi_config, - wrf_hydro_geo_meta, + self._bmi.geo_meta, ) elif config_options.nwm_domain == "Hawaii": self.source_data_processor = NWMV3HawaiiProcessor( config_options, mpi_config, wrf_hydro_geo_meta ) - elif config_options.nwm_domain == "PR": self.source_data_processor = ( NWMV3PuertoRicoProcessor( @@ -463,7 +459,7 @@ def loop_through_forcing_products( self.source_data_processor = NWMV3AlaskaProcessor( self._bmi._job_meta, mpi_config, - wrf_hydro_geo_meta, + self._bmi.geo_meta, ) else: raise ValueError( @@ -482,7 +478,7 @@ def loop_through_forcing_products( break # Regrid forcings. input_forcings.regrid_inputs( - self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config + self._bmi._job_meta, self._bmi.geo_meta, mpi_config ) err_handler.check_program_status(self._bmi._job_meta, mpi_config) @@ -527,7 +523,7 @@ def loop_through_forcing_products( # Regrid the forcings for the end of the window. input_forcings.regrid_inputs( - self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config + self._bmi._job_meta, self._bmi.geo_meta, mpi_config ) err_handler.check_program_status(self._bmi._job_meta, mpi_config) @@ -541,13 +537,19 @@ def loop_through_forcing_products( # Run bias correction. bias_correction.run_bias_correction( - input_forcings, self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config + input_forcings, + self._bmi._job_meta, + self._bmi.geo_meta, + mpi_config, ) err_handler.check_program_status(self._bmi._job_meta, mpi_config) # Run downscaling on grids for this output timestep. downscale.run_downscaling( - input_forcings, self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config + input_forcings, + self._bmi._job_meta, + self._bmi.geo_meta, + mpi_config, ) err_handler.check_program_status(self._bmi._job_meta, mpi_config) @@ -578,7 +580,7 @@ def loop_through_forcing_products( # Regrid the supplemental precipitation. supp_pcp_mod[supp_pcp_key].regrid_inputs( - self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config + self._bmi._job_meta, self._bmi.geo_meta, mpi_config ) err_handler.check_program_status( self._bmi._job_meta, mpi_config @@ -593,7 +595,7 @@ def loop_through_forcing_products( self._bmi._job_meta, supp_pcp_mod[supp_pcp_key], mpi_config, - wrf_hydro_geo_meta, + self._bmi.geo_meta, ) err_handler.check_program_status( self._bmi._job_meta, mpi_config @@ -635,7 +637,7 @@ def loop_through_forcing_products( output_obj.outDate = file_date ################ Commenting this out to bypass NWM forcing file output functionality ######### - # output_obj.output_final_ldasin(self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config) + # output_obj.output_final_ldasin(self._bmi._job_meta, self._bmi.geo_meta, mpi_config) # err_handler.check_program_status(self._bmi._job_meta, mpi_config) ############################################################################################## @@ -644,7 +646,6 @@ def loop_through_forcing_products( @time_function def process_suplemental_precip( self, - wrf_hydro_geo_meta: GeoMeta, supp_pcp_mod: dict, mpi_config: MpiConfig, output_obj: OutputObj, @@ -671,7 +672,7 @@ def process_suplemental_precip( # Regrid the supplemental precipitation. supp_pcp_mod[supp_pcp_key].regrid_inputs( - self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config + self._bmi._job_meta, self._bmi.geo_meta, mpi_config ) err_handler.check_program_status( self._bmi._job_meta, mpi_config @@ -686,7 +687,7 @@ def process_suplemental_precip( self._bmi._job_meta, supp_pcp_mod[supp_pcp_key], mpi_config, - wrf_hydro_geo_meta, + self._bmi.geo_meta, ) err_handler.check_program_status( self._bmi._job_meta, mpi_config @@ -724,7 +725,6 @@ def process_suplemental_precip( @time_function def write_output( self, - wrf_hydro_geo_meta: GeoMeta, mpi_config: MpiConfig, output_obj: OutputObj, ) -> None: @@ -741,7 +741,7 @@ def write_output( or self._bmi._job_meta.grid_type == "hydrofabric" ): output_obj.gather_global_outputs( - self._bmi._job_meta, wrf_hydro_geo_meta, mpi_config + self._bmi._job_meta, self._bmi.geo_meta, mpi_config ) """##################Step 6: flatten and update dict##########################################################################""" @@ -749,7 +749,6 @@ def write_output( @time_function def update_dict( self, - wrf_hydro_geo_meta: GeoMeta, output_obj: OutputObj, ) -> None: """Flatten the Forcings Engine output object and update the BMI dictionary. @@ -812,7 +811,7 @@ def update_dict( self._bmi._values[variable + "_ELEMENT"] = output_obj.output_global[ count, : ].flatten() - self._bmi._values["CAT-ID"] = wrf_hydro_geo_meta.element_ids_global + self._bmi._values["CAT-ID"] = self._bmi.geo_meta.element_ids_global else: raise ValueError( f"Unexpected grid_type: {repr(self._bmi._job_meta.grid_type)}" diff --git a/tests/test_utils.py b/tests/test_utils.py index b86ad8a1..81a92fd7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -661,7 +661,6 @@ def pre_regrid(self) -> None: ) mpi_config = self.mpi_config - geo_meta = self.geo_meta supp_pcp_mod = self.bmi_model._supp_pcp_mod output_obj = self.bmi_model._output_obj input_forcing_mod = self.bmi_model._input_forcing_mod @@ -680,7 +679,6 @@ def pre_regrid(self) -> None: self.set_input_forcings_skip_flags() model.loop_through_forcing_products( future_time, - geo_meta, input_forcing_mod, supp_pcp_mod, mpi_config, From f6ebd7b7d1292c65f04e097d7776c44128145dac Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 15:36:11 -0400 Subject: [PATCH 23/71] Encapsulate input forcing mod dict --- .../NextGen_Forcings_Engine/bmi_model.py | 2 -- .../NextGen_Forcings_Engine/model.py | 13 ++++--------- tests/test_utils.py | 6 ++---- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index 2c890f97..9365226a 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -517,7 +517,6 @@ def update_until(self, future_time: float) -> None: ): self._model.run( future_time, - self._input_forcing_mod, self._supp_pcp_mod, self._mpi_meta, self._output_obj, @@ -531,7 +530,6 @@ def update_until(self, future_time: float) -> None: # Run the model for the new current time and update the state. self._model.run( self._values["current_model_time"], - self._input_forcing_mod, self._supp_pcp_mod, self._mpi_meta, self._output_obj, diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 633886fe..2a0ea617 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -94,7 +94,6 @@ def __init__(self, bmi_model: NWMv3_Forcing_Engine_BMI_model_Base): def run( self, future_time: float, - input_forcing_mod: dict, supp_pcp_mod: dict, mpi_config: MpiConfig, output_obj: OutputObj, @@ -129,7 +128,6 @@ def run( 7. Advance the BMI time index. :param future_time: The number of seconds into the future to advance the model. - :param input_forcing_mod: Dictionary of initialized input forcing modules indexed by forcing key. :param supp_pcp_mod: Dictionary of supplemental precipitation modules indexed by key. :param mpi_config: Object containing MPI communication settings such as rank and communicator. :param output_obj: Output object that stores the generated atmospheric forcing arrays. @@ -138,12 +136,11 @@ def run( """ self.determine_forecast(future_time) - self.adjust_precip(input_forcing_mod, mpi_config) + self.adjust_precip(mpi_config) self.log_forecast(mpi_config) # TODO look into input_forcings usage in `process_suplemental_precip` and in `loop_through_forcing_products` at `disaggregate_fun`. input_forcings = self.loop_through_forcing_products( future_time, - input_forcing_mod, supp_pcp_mod, mpi_config, output_obj, @@ -238,7 +235,6 @@ def determine_forecast( @time_function def adjust_precip( self, - input_forcing_mod: dict, mpi_config: MpiConfig, ) -> None: """Adjust precipitation for the given forecast cycle. @@ -250,7 +246,7 @@ def adjust_precip( if not self._bmi._job_meta.precip_only_flag: # reset skips if present for force_key in self._bmi._job_meta.input_forcings: - input_forcing_mod[force_key].skip = False + self._bmi._input_forcing_mod[force_key].skip = False err_handler.check_program_status(self._bmi._job_meta, mpi_config) @@ -286,7 +282,6 @@ def log_forecast( def loop_through_forcing_products( self, future_time: float, - input_forcing_mod: dict, supp_pcp_mod: dict, mpi_config: MpiConfig, output_obj: OutputObj, @@ -397,13 +392,13 @@ def loop_through_forcing_products( and 12 in self._bmi._job_meta.input_forcings and 21 in self._bmi._job_meta.input_forcings ): - input_forcings = input_forcing_mod[force_key] + input_forcings = self._bmi._input_forcing_mod[force_key] # These are not used # AORC_mask = input_forcings.regridded_mask_AORC # AORC_elem_mask = input_forcings.regridded_mask_elem_AORC else: - input_forcings = input_forcing_mod[force_key] + input_forcings = self._bmi._input_forcing_mod[force_key] input_forcings.calc_neighbor_files( self._bmi._job_meta, output_obj.outDate, mpi_config ) diff --git a/tests/test_utils.py b/tests/test_utils.py index 81a92fd7..8186c0dc 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -663,7 +663,6 @@ def pre_regrid(self) -> None: mpi_config = self.mpi_config supp_pcp_mod = self.bmi_model._supp_pcp_mod output_obj = self.bmi_model._output_obj - input_forcing_mod = self.bmi_model._input_forcing_mod future_time = ( self.bmi_model._values["current_model_time"] @@ -673,13 +672,12 @@ def pre_regrid(self) -> None: ### NOTE this should mimic NWMv3ForcingEngineModel.run() with the exception of setting the skip flag model.determine_forecast(future_time) - model.adjust_precip(input_forcing_mod, mpi_config) + model.adjust_precip(mpi_config) model.log_forecast(mpi_config) ### NOTE setting the flag causes the regrid step to be skipped self.set_input_forcings_skip_flags() model.loop_through_forcing_products( future_time, - input_forcing_mod, supp_pcp_mod, mpi_config, output_obj, @@ -691,7 +689,7 @@ def pre_regrid(self) -> None: def set_input_forcings_skip_flags(self) -> None: """Set the `skip` flag on the InputForcings object so that forcing regrid will not occur during loop_through_forcing_products().""" logging.debug( - "Setting input_forcing.skip = True for each value in dict self.input_forcing_mod" + "Setting input_forcing.skip = True for each value in dict self.bmi_model._input_forcing_mod" ) for force_key, input_forcing in self.bmi_model._input_forcing_mod.items(): input_forcing.skip = True From 104d1ab04e51ac4a1e209df111d040b37cea6ee3 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 15:43:48 -0400 Subject: [PATCH 24/71] Encapsulate supp pcp mod --- .../NextGen_Forcings_Engine/bmi_model.py | 2 - .../NextGen_Forcings_Engine/model.py | 46 ++++++++++--------- tests/test_utils.py | 2 - 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index 9365226a..7204df83 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -517,7 +517,6 @@ def update_until(self, future_time: float) -> None: ): self._model.run( future_time, - self._supp_pcp_mod, self._mpi_meta, self._output_obj, ) @@ -530,7 +529,6 @@ def update_until(self, future_time: float) -> None: # Run the model for the new current time and update the state. self._model.run( self._values["current_model_time"], - self._supp_pcp_mod, self._mpi_meta, self._output_obj, ) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 2a0ea617..fd1bb0e2 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -94,7 +94,6 @@ def __init__(self, bmi_model: NWMv3_Forcing_Engine_BMI_model_Base): def run( self, future_time: float, - supp_pcp_mod: dict, mpi_config: MpiConfig, output_obj: OutputObj, ) -> None: @@ -128,7 +127,6 @@ def run( 7. Advance the BMI time index. :param future_time: The number of seconds into the future to advance the model. - :param supp_pcp_mod: Dictionary of supplemental precipitation modules indexed by key. :param mpi_config: Object containing MPI communication settings such as rank and communicator. :param output_obj: Output object that stores the generated atmospheric forcing arrays. @@ -141,12 +139,10 @@ def run( # TODO look into input_forcings usage in `process_suplemental_precip` and in `loop_through_forcing_products` at `disaggregate_fun`. input_forcings = self.loop_through_forcing_products( future_time, - supp_pcp_mod, mpi_config, output_obj, ) self.process_suplemental_precip( - supp_pcp_mod, mpi_config, output_obj, input_forcings, @@ -282,7 +278,6 @@ def log_forecast( def loop_through_forcing_products( self, future_time: float, - supp_pcp_mod: dict, mpi_config: MpiConfig, output_obj: OutputObj, ) -> forcingInputMod.InputForcingsHydrofabric: @@ -566,7 +561,7 @@ def loop_through_forcing_products( for supp_pcp_key in self._bmi._job_meta.supp_precip_forcings: if supp_pcp_key != 13: # Like with input forcings, calculate the neighboring files to use. - supp_pcp_mod[supp_pcp_key].calc_neighbor_files( + self._bmi._supp_pcp_mod[supp_pcp_key].calc_neighbor_files( self._bmi._job_meta, output_obj.outDate, mpi_config ) err_handler.check_program_status( @@ -574,7 +569,7 @@ def loop_through_forcing_products( ) # Regrid the supplemental precipitation. - supp_pcp_mod[supp_pcp_key].regrid_inputs( + self._bmi._supp_pcp_mod[supp_pcp_key].regrid_inputs( self._bmi._job_meta, self._bmi.geo_meta, mpi_config ) err_handler.check_program_status( @@ -582,13 +577,15 @@ def loop_through_forcing_products( ) if ( - supp_pcp_mod[supp_pcp_key].regridded_precip1 is not None - and supp_pcp_mod[supp_pcp_key].regridded_precip2 is not None + self._bmi._supp_pcp_mod[supp_pcp_key].regridded_precip1 + is not None + and self._bmi._supp_pcp_mod[supp_pcp_key].regridded_precip2 + is not None ): # Run check on regridded fields for reasonable values that are not missing values. err_handler.check_supp_pcp_bounds( self._bmi._job_meta, - supp_pcp_mod[supp_pcp_key], + self._bmi._supp_pcp_mod[supp_pcp_key], mpi_config, self._bmi.geo_meta, ) @@ -599,7 +596,7 @@ def loop_through_forcing_products( # TODO input_forcings has not yet been initialized, so this is a bug waiting to happen self.disaggregate_fun( input_forcings, - supp_pcp_mod[supp_pcp_key], + self._bmi._supp_pcp_mod[supp_pcp_key], self._bmi._job_meta, mpi_config, ) @@ -608,7 +605,9 @@ def loop_through_forcing_products( ) # Run temporal interpolation on the grids. - supp_pcp_mod[supp_pcp_key].temporal_interpolate_inputs( + self._bmi._supp_pcp_mod[ + supp_pcp_key + ].temporal_interpolate_inputs( self._bmi._job_meta, mpi_config ) err_handler.check_program_status( @@ -618,7 +617,7 @@ def loop_through_forcing_products( # Layer in the supplemental precipitation into the current output object. layeringMod.layer_supplemental_forcing( output_obj, - supp_pcp_mod[supp_pcp_key], + self._bmi._supp_pcp_mod[supp_pcp_key], self._bmi._job_meta, mpi_config, ) @@ -641,7 +640,6 @@ def loop_through_forcing_products( @time_function def process_suplemental_precip( self, - supp_pcp_mod: dict, mpi_config: MpiConfig, output_obj: OutputObj, input_forcings: dict, @@ -658,7 +656,7 @@ def process_suplemental_precip( for supp_pcp_key in self._bmi._job_meta.supp_precip_forcings: if supp_pcp_key == 14: # Like with input forcings, calculate the neighboring files to use. - supp_pcp_mod[supp_pcp_key].calc_neighbor_files( + self._bmi._supp_pcp_mod[supp_pcp_key].calc_neighbor_files( self._bmi._job_meta, output_obj.outDate, mpi_config ) err_handler.check_program_status( @@ -666,7 +664,7 @@ def process_suplemental_precip( ) # Regrid the supplemental precipitation. - supp_pcp_mod[supp_pcp_key].regrid_inputs( + self._bmi._supp_pcp_mod[supp_pcp_key].regrid_inputs( self._bmi._job_meta, self._bmi.geo_meta, mpi_config ) err_handler.check_program_status( @@ -674,13 +672,15 @@ def process_suplemental_precip( ) if ( - supp_pcp_mod[supp_pcp_key].regridded_precip1 is not None - and supp_pcp_mod[supp_pcp_key].regridded_precip2 is not None + self._bmi._supp_pcp_mod[supp_pcp_key].regridded_precip1 + is not None + and self._bmi._supp_pcp_mod[supp_pcp_key].regridded_precip2 + is not None ): # Run check on regridded fields for reasonable values that are not missing values. err_handler.check_supp_pcp_bounds( self._bmi._job_meta, - supp_pcp_mod[supp_pcp_key], + self._bmi._supp_pcp_mod[supp_pcp_key], mpi_config, self._bmi.geo_meta, ) @@ -690,7 +690,7 @@ def process_suplemental_precip( self.disaggregate_fun( input_forcings, - supp_pcp_mod[supp_pcp_key], + self._bmi._supp_pcp_mod[supp_pcp_key], self._bmi._job_meta, mpi_config, ) @@ -699,7 +699,9 @@ def process_suplemental_precip( ) # Run temporal interpolation on the grids. - supp_pcp_mod[supp_pcp_key].temporal_interpolate_inputs( + self._bmi._supp_pcp_mod[ + supp_pcp_key + ].temporal_interpolate_inputs( self._bmi._job_meta, mpi_config ) err_handler.check_program_status( @@ -709,7 +711,7 @@ def process_suplemental_precip( # Layer in the supplemental precipitation into the current output object. layeringMod.layer_supplemental_forcing( output_obj, - supp_pcp_mod[supp_pcp_key], + self._bmi._supp_pcp_mod[supp_pcp_key], self._bmi._job_meta, mpi_config, ) diff --git a/tests/test_utils.py b/tests/test_utils.py index 8186c0dc..dc53e411 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -661,7 +661,6 @@ def pre_regrid(self) -> None: ) mpi_config = self.mpi_config - supp_pcp_mod = self.bmi_model._supp_pcp_mod output_obj = self.bmi_model._output_obj future_time = ( @@ -678,7 +677,6 @@ def pre_regrid(self) -> None: self.set_input_forcings_skip_flags() model.loop_through_forcing_products( future_time, - supp_pcp_mod, mpi_config, output_obj, ) From 4fdf14124f84a085ee08dd421413280dbe07b57b Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 15:50:57 -0400 Subject: [PATCH 25/71] Encapsulate MpiConfig --- .../NextGen_Forcings_Engine/bmi_model.py | 2 - .../NextGen_Forcings_Engine/model.py | 160 +++++++++--------- tests/test_utils.py | 11 +- 3 files changed, 83 insertions(+), 90 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index 7204df83..a4a53cab 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -517,7 +517,6 @@ def update_until(self, future_time: float) -> None: ): self._model.run( future_time, - self._mpi_meta, self._output_obj, ) else: @@ -529,7 +528,6 @@ def update_until(self, future_time: float) -> None: # Run the model for the new current time and update the state. self._model.run( self._values["current_model_time"], - self._mpi_meta, self._output_obj, ) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index fd1bb0e2..1577688a 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -94,7 +94,6 @@ def __init__(self, bmi_model: NWMv3_Forcing_Engine_BMI_model_Base): def run( self, future_time: float, - mpi_config: MpiConfig, output_obj: OutputObj, ) -> None: """Execute the full forcings engine BMI pipeline for a given future timestep. @@ -127,28 +126,24 @@ def run( 7. Advance the BMI time index. :param future_time: The number of seconds into the future to advance the model. - :param mpi_config: Object containing MPI communication settings such as rank and communicator. :param output_obj: Output object that stores the generated atmospheric forcing arrays. :raises RuntimeError: If the model fails to initialize or if required arguments are missing. """ self.determine_forecast(future_time) - self.adjust_precip(mpi_config) - self.log_forecast(mpi_config) + self.adjust_precip() + self.log_forecast() # TODO look into input_forcings usage in `process_suplemental_precip` and in `loop_through_forcing_products` at `disaggregate_fun`. input_forcings = self.loop_through_forcing_products( future_time, - mpi_config, output_obj, ) self.process_suplemental_precip( - mpi_config, output_obj, input_forcings, ) self.write_output( - mpi_config, output_obj, ) self.update_dict( @@ -229,10 +224,7 @@ def determine_forecast( ) @time_function - def adjust_precip( - self, - mpi_config: MpiConfig, - ) -> None: + def adjust_precip(self) -> None: """Adjust precipitation for the given forecast cycle. Warnings @@ -244,13 +236,10 @@ def adjust_precip( for force_key in self._bmi._job_meta.input_forcings: self._bmi._input_forcing_mod[force_key].skip = False - err_handler.check_program_status(self._bmi._job_meta, mpi_config) + err_handler.check_program_status(self._bmi._job_meta, self._bmi._mpi_meta) @time_function - def log_forecast( - self, - mpi_config: MpiConfig, - ) -> None: + def log_forecast(self) -> None: """Log information about the current forecast cycle. Warnings @@ -258,28 +247,25 @@ def log_forecast( Modifies mutable arguments in-place. """ # Log information about this forecast cycle - if mpi_config.rank == 0: + if self._bmi._mpi_meta.rank == 0: self._bmi._job_meta.statusMsg = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - err_handler.log_msg(self._bmi._job_meta, mpi_config, True) + err_handler.log_msg(self._bmi._job_meta, self._bmi._mpi_meta, True) self._bmi._job_meta.statusMsg = ( "Processing Forecast Cycle: " + self._bmi._job_meta.current_fcst_cycle.strftime("%Y-%m-%d %H:%M") ) - err_handler.log_msg(self._bmi._job_meta, mpi_config, True) + err_handler.log_msg(self._bmi._job_meta, self._bmi._mpi_meta, True) self._bmi._job_meta.statusMsg = ( "Forecast Cycle Length is: " + str(self._bmi._job_meta.cycle_length_minutes) + " minutes" ) - err_handler.log_msg(self._bmi._job_meta, mpi_config, True) - # mpi_config.comm.barrier() + err_handler.log_msg(self._bmi._job_meta, self._bmi._mpi_meta, True) + # self._bmi._mpi_meta.comm.barrier() @time_function def loop_through_forcing_products( - self, - future_time: float, - mpi_config: MpiConfig, - output_obj: OutputObj, + self, future_time: float, output_obj: OutputObj ) -> forcingInputMod.InputForcingsHydrofabric: """Loop through each forcing product and process it for the current forecast cycle. @@ -359,13 +345,13 @@ def loop_through_forcing_products( # Print message on log file indicating the timestamp # we are currently processing for forcings - if mpi_config.rank == 0 and show_message: + if self._bmi._mpi_meta.rank == 0 and show_message: self._bmi._job_meta.statusMsg = ( "=========================================" ) - err_handler.log_msg(self._bmi._job_meta, mpi_config, True) + err_handler.log_msg(self._bmi._job_meta, self._bmi._mpi_meta, True) self._bmi._job_meta.statusMsg = f"Processing for output timestep: {file_date.strftime('%Y-%m-%d %H:%M')}" - err_handler.log_msg(self._bmi._job_meta, mpi_config, True) + err_handler.log_msg(self._bmi._job_meta, self._bmi._mpi_meta, True) self._bmi._job_meta.currentForceNum = 0 self._bmi._job_meta.currentCustomForceNum = 0 @@ -395,17 +381,17 @@ def loop_through_forcing_products( else: input_forcings = self._bmi._input_forcing_mod[force_key] input_forcings.calc_neighbor_files( - self._bmi._job_meta, output_obj.outDate, mpi_config + self._bmi._job_meta, output_obj.outDate, self._bmi._mpi_meta ) if force_key in [12, 21, 27]: if self._bmi._job_meta.aws is None: # Calculate the previous and next input cycle files from the inputs. input_forcings.calc_neighbor_files( - self._bmi._job_meta, output_obj.outDate, mpi_config + self._bmi._job_meta, output_obj.outDate, self._bmi._mpi_meta ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) else: # Flag to indicate the AWS .zarr AORC method @@ -413,14 +399,14 @@ def loop_through_forcing_products( if self.source_data_processor is None: self.source_data_processor = AORCConusProcessor( self._bmi._job_meta, - mpi_config, + self._bmi._mpi_meta, self._bmi.geo_meta, ) elif force_key == 21: if self.source_data_processor is None: self.source_data_processor = AORCAlaskaProcessor( self._bmi._job_meta, - mpi_config, + self._bmi._mpi_meta, self._bmi.geo_meta, ) @@ -430,7 +416,7 @@ def loop_through_forcing_products( if self._bmi._job_meta.nwm_domain == "CONUS": self.source_data_processor = NWMV3ConusProcessor( self._bmi._job_meta, - mpi_config, + self._bmi._mpi_meta, self._bmi.geo_meta, ) elif config_options.nwm_domain == "Hawaii": @@ -448,7 +434,7 @@ def loop_through_forcing_products( elif config_options.nwm_domain == "Alaska": self.source_data_processor = NWMV3AlaskaProcessor( self._bmi._job_meta, - mpi_config, + self._bmi._mpi_meta, self._bmi.geo_meta, ) else: @@ -468,15 +454,19 @@ def loop_through_forcing_products( break # Regrid forcings. input_forcings.regrid_inputs( - self._bmi._job_meta, self._bmi.geo_meta, mpi_config + self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta + ) + err_handler.check_program_status( + self._bmi._job_meta, self._bmi._mpi_meta ) - err_handler.check_program_status(self._bmi._job_meta, mpi_config) # Run check on regridded fields for reasonable values that are not missing values. err_handler.check_forcing_bounds( - self._bmi._job_meta, input_forcings, mpi_config + self._bmi._job_meta, input_forcings, self._bmi._mpi_meta + ) + err_handler.check_program_status( + self._bmi._job_meta, self._bmi._mpi_meta ) - err_handler.check_program_status(self._bmi._job_meta, mpi_config) # If we are restarting a forecast cycle, re-calculate the neighboring files, and regrid the # next set of forcings as the previous step just regridded the previous forcing. @@ -507,47 +497,59 @@ def loop_through_forcing_products( ) # Re-calculate the neighbor files. input_forcings.calc_neighbor_files( - self._bmi._job_meta, output_obj.outDate, mpi_config + self._bmi._job_meta, output_obj.outDate, self._bmi._mpi_meta + ) + err_handler.check_program_status( + self._bmi._job_meta, self._bmi._mpi_meta ) - err_handler.check_program_status(self._bmi._job_meta, mpi_config) # Regrid the forcings for the end of the window. input_forcings.regrid_inputs( - self._bmi._job_meta, self._bmi.geo_meta, mpi_config + self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta + ) + err_handler.check_program_status( + self._bmi._job_meta, self._bmi._mpi_meta ) - err_handler.check_program_status(self._bmi._job_meta, mpi_config) input_forcings.rstFlag = 0 # Run temporal interpolation on the grids. input_forcings.temporal_interpolate_inputs( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta + ) + err_handler.check_program_status( + self._bmi._job_meta, self._bmi._mpi_meta ) - err_handler.check_program_status(self._bmi._job_meta, mpi_config) # Run bias correction. bias_correction.run_bias_correction( input_forcings, self._bmi._job_meta, self._bmi.geo_meta, - mpi_config, + self._bmi._mpi_meta, + ) + err_handler.check_program_status( + self._bmi._job_meta, self._bmi._mpi_meta ) - err_handler.check_program_status(self._bmi._job_meta, mpi_config) # Run downscaling on grids for this output timestep. downscale.run_downscaling( input_forcings, self._bmi._job_meta, self._bmi.geo_meta, - mpi_config, + self._bmi._mpi_meta, + ) + err_handler.check_program_status( + self._bmi._job_meta, self._bmi._mpi_meta ) - err_handler.check_program_status(self._bmi._job_meta, mpi_config) # Layer in forcings from this product. layeringMod.layer_final_forcings( - output_obj, input_forcings, self._bmi._job_meta, mpi_config + output_obj, input_forcings, self._bmi._job_meta, self._bmi._mpi_meta + ) + err_handler.check_program_status( + self._bmi._job_meta, self._bmi._mpi_meta ) - err_handler.check_program_status(self._bmi._job_meta, mpi_config) self._bmi._job_meta.currentForceNum += 1 @@ -562,18 +564,18 @@ def loop_through_forcing_products( if supp_pcp_key != 13: # Like with input forcings, calculate the neighboring files to use. self._bmi._supp_pcp_mod[supp_pcp_key].calc_neighbor_files( - self._bmi._job_meta, output_obj.outDate, mpi_config + self._bmi._job_meta, output_obj.outDate, self._bmi._mpi_meta ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) # Regrid the supplemental precipitation. self._bmi._supp_pcp_mod[supp_pcp_key].regrid_inputs( - self._bmi._job_meta, self._bmi.geo_meta, mpi_config + self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) if ( @@ -586,11 +588,11 @@ def loop_through_forcing_products( err_handler.check_supp_pcp_bounds( self._bmi._job_meta, self._bmi._supp_pcp_mod[supp_pcp_key], - mpi_config, + self._bmi._mpi_meta, self._bmi.geo_meta, ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) # TODO input_forcings has not yet been initialized, so this is a bug waiting to happen @@ -598,20 +600,20 @@ def loop_through_forcing_products( input_forcings, self._bmi._supp_pcp_mod[supp_pcp_key], self._bmi._job_meta, - mpi_config, + self._bmi._mpi_meta, ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) # Run temporal interpolation on the grids. self._bmi._supp_pcp_mod[ supp_pcp_key ].temporal_interpolate_inputs( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) # Layer in the supplemental precipitation into the current output object. @@ -619,10 +621,10 @@ def loop_through_forcing_products( output_obj, self._bmi._supp_pcp_mod[supp_pcp_key], self._bmi._job_meta, - mpi_config, + self._bmi._mpi_meta, ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) # Call the output routines @@ -631,8 +633,8 @@ def loop_through_forcing_products( output_obj.outDate = file_date ################ Commenting this out to bypass NWM forcing file output functionality ######### - # output_obj.output_final_ldasin(self._bmi._job_meta, self._bmi.geo_meta, mpi_config) - # err_handler.check_program_status(self._bmi._job_meta, mpi_config) + # output_obj.output_final_ldasin(self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta) + # err_handler.check_program_status(self._bmi._job_meta, self._bmi._mpi_meta) ############################################################################################## return input_forcings @@ -640,7 +642,6 @@ def loop_through_forcing_products( @time_function def process_suplemental_precip( self, - mpi_config: MpiConfig, output_obj: OutputObj, input_forcings: dict, ) -> None: @@ -657,18 +658,18 @@ def process_suplemental_precip( if supp_pcp_key == 14: # Like with input forcings, calculate the neighboring files to use. self._bmi._supp_pcp_mod[supp_pcp_key].calc_neighbor_files( - self._bmi._job_meta, output_obj.outDate, mpi_config + self._bmi._job_meta, output_obj.outDate, self._bmi._mpi_meta ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) # Regrid the supplemental precipitation. self._bmi._supp_pcp_mod[supp_pcp_key].regrid_inputs( - self._bmi._job_meta, self._bmi.geo_meta, mpi_config + self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) if ( @@ -681,31 +682,31 @@ def process_suplemental_precip( err_handler.check_supp_pcp_bounds( self._bmi._job_meta, self._bmi._supp_pcp_mod[supp_pcp_key], - mpi_config, + self._bmi._mpi_meta, self._bmi.geo_meta, ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) self.disaggregate_fun( input_forcings, self._bmi._supp_pcp_mod[supp_pcp_key], self._bmi._job_meta, - mpi_config, + self._bmi._mpi_meta, ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) # Run temporal interpolation on the grids. self._bmi._supp_pcp_mod[ supp_pcp_key ].temporal_interpolate_inputs( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) # Layer in the supplemental precipitation into the current output object. @@ -713,16 +714,15 @@ def process_suplemental_precip( output_obj, self._bmi._supp_pcp_mod[supp_pcp_key], self._bmi._job_meta, - mpi_config, + self._bmi._mpi_meta, ) err_handler.check_program_status( - self._bmi._job_meta, mpi_config + self._bmi._job_meta, self._bmi._mpi_meta ) @time_function def write_output( self, - mpi_config: MpiConfig, output_obj: OutputObj, ) -> None: """Write the output for the current forecast cycle. @@ -738,7 +738,7 @@ def write_output( or self._bmi._job_meta.grid_type == "hydrofabric" ): output_obj.gather_global_outputs( - self._bmi._job_meta, self._bmi.geo_meta, mpi_config + self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta ) """##################Step 6: flatten and update dict##########################################################################""" diff --git a/tests/test_utils.py b/tests/test_utils.py index dc53e411..efba3ca9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -660,7 +660,6 @@ def pre_regrid(self) -> None: f"In pre_regrid, expected state to be either None or 'post_ran' but got {repr(self._state)}. The test is set up incorrectly." ) - mpi_config = self.mpi_config output_obj = self.bmi_model._output_obj future_time = ( @@ -671,15 +670,11 @@ def pre_regrid(self) -> None: ### NOTE this should mimic NWMv3ForcingEngineModel.run() with the exception of setting the skip flag model.determine_forecast(future_time) - model.adjust_precip(mpi_config) - model.log_forecast(mpi_config) + model.adjust_precip() + model.log_forecast() ### NOTE setting the flag causes the regrid step to be skipped self.set_input_forcings_skip_flags() - model.loop_through_forcing_products( - future_time, - mpi_config, - output_obj, - ) + model.loop_through_forcing_products(future_time, output_obj) # Update test fixture status self._state = "pre_ran" From 246f4e22f788b664375fb44f449c46cdadd892ec Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 16:01:33 -0400 Subject: [PATCH 26/71] Encapsulate OutputObj instance --- .../NextGen_Forcings_Engine/bmi_model.py | 10 +- .../NextGen_Forcings_Engine/model.py | 125 ++++++++---------- tests/test_utils.py | 4 +- 3 files changed, 61 insertions(+), 78 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index a4a53cab..a780e744 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -515,10 +515,7 @@ def update_until(self, future_time: float) -> None: == future_time == self.cfg_bmi["initial_time"] ): - self._model.run( - future_time, - self._output_obj, - ) + self._model.run(future_time) else: # Start a while loop to iterate the model time step by step until the # current model time reaches or exceeds the future_time. @@ -526,10 +523,7 @@ def update_until(self, future_time: float) -> None: # Advance the model time by the defined time step size. self._values["current_model_time"] += self._values["time_step_size"] # Run the model for the new current time and update the state. - self._model.run( - self._values["current_model_time"], - self._output_obj, - ) + self._model.run(self._values["current_model_time"]) def finalize(self) -> None: """Finalize the model, performing necessary cleanup tasks. diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 1577688a..2f101c34 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -91,11 +91,7 @@ def __init__(self, bmi_model: NWMv3_Forcing_Engine_BMI_model_Base): # def aws_obj(files): # return xr.open_mfdataset(files, engine="zarr", parallel=True, consolidated=True) - def run( - self, - future_time: float, - output_obj: OutputObj, - ) -> None: + def run(self, future_time: float) -> None: """Execute the full forcings engine BMI pipeline for a given future timestep. This method updates the `self._bmi._values` state dictionary with atmospheric forcings computed from @@ -126,7 +122,6 @@ def run( 7. Advance the BMI time index. :param future_time: The number of seconds into the future to advance the model. - :param output_obj: Output object that stores the generated atmospheric forcing arrays. :raises RuntimeError: If the model fails to initialize or if required arguments are missing. """ @@ -137,27 +132,16 @@ def run( # TODO look into input_forcings usage in `process_suplemental_precip` and in `loop_through_forcing_products` at `disaggregate_fun`. input_forcings = self.loop_through_forcing_products( future_time, - output_obj, - ) - self.process_suplemental_precip( - output_obj, - input_forcings, - ) - self.write_output( - output_obj, - ) - self.update_dict( - output_obj, ) + self.process_suplemental_precip(input_forcings) + self.write_output() + self.update_dict() ## Update BMI model time index to next iteration self._bmi._job_meta.bmi_time_index += 1 @time_function - def determine_forecast( - self, - future_time: float, - ) -> None: + def determine_forecast(self, future_time: float) -> None: """Determine the forecast for the given future time and configuration. Warnings @@ -265,7 +249,7 @@ def log_forecast(self) -> None: @time_function def loop_through_forcing_products( - self, future_time: float, output_obj: OutputObj + self, future_time: float ) -> forcingInputMod.InputForcingsHydrofabric: """Loop through each forcing product and process it for the current forecast cycle. @@ -284,14 +268,18 @@ def loop_through_forcing_products( if not self._bmi._job_meta.precip_only_flag: if self._bmi._job_meta.grid_type == "gridded": # Reset out final grids to missing values. - output_obj.output_local[:, :, :] = self._bmi._job_meta.globalNdv + self._bmi._output_obj.output_local[:, :, :] = ( + self._bmi._job_meta.globalNdv + ) elif self._bmi._job_meta.grid_type == "unstructured": # Reset out final grids to missing values. - output_obj.output_local[:, :] = self._bmi._job_meta.globalNdv - output_obj.output_local_elem[:, :] = self._bmi._job_meta.globalNdv + self._bmi._output_obj.output_local[:, :] = self._bmi._job_meta.globalNdv + self._bmi._output_obj.output_local_elem[:, :] = ( + self._bmi._job_meta.globalNdv + ) elif self._bmi._job_meta.grid_type == "hydrofabric": # Reset out final grids to missing values. - output_obj.output_local[:, :] = self._bmi._job_meta.globalNdv + self._bmi._output_obj.output_local[:, :] = self._bmi._job_meta.globalNdv else: raise ValueError( f"Unexpected grid_type: {repr(self._bmi._job_meta.grid_type)}" @@ -312,24 +300,24 @@ def loop_through_forcing_products( # Compute the output timestamp for this step if self._bmi._job_meta.ana_flag: - output_obj.outDate = ( + self._bmi._output_obj.outDate = ( self._bmi._job_meta.current_fcst_cycle + datetime.timedelta(seconds=self._bmi._job_meta.output_freq * 60) ) else: - output_obj.outDate = ( + self._bmi._output_obj.outDate = ( self._bmi._job_meta.current_fcst_cycle + datetime.timedelta(seconds=future_time) ) - self._bmi._job_meta.current_output_date = output_obj.outDate + self._bmi._job_meta.current_output_date = self._bmi._output_obj.outDate # Adjust file_date for AnA if needed file_date = ( - output_obj.outDate + self._bmi._output_obj.outDate - datetime.timedelta(seconds=self._bmi._job_meta.output_freq * 60) if self._bmi._job_meta.ana_flag - else output_obj.outDate + else self._bmi._output_obj.outDate ) # Compute previous output date (used for downscaling logic) @@ -381,14 +369,18 @@ def loop_through_forcing_products( else: input_forcings = self._bmi._input_forcing_mod[force_key] input_forcings.calc_neighbor_files( - self._bmi._job_meta, output_obj.outDate, self._bmi._mpi_meta + self._bmi._job_meta, + self._bmi._output_obj.outDate, + self._bmi._mpi_meta, ) if force_key in [12, 21, 27]: if self._bmi._job_meta.aws is None: # Calculate the previous and next input cycle files from the inputs. input_forcings.calc_neighbor_files( - self._bmi._job_meta, output_obj.outDate, self._bmi._mpi_meta + self._bmi._job_meta, + self._bmi._output_obj.outDate, + self._bmi._mpi_meta, ) err_handler.check_program_status( self._bmi._job_meta, self._bmi._mpi_meta @@ -497,7 +489,9 @@ def loop_through_forcing_products( ) # Re-calculate the neighbor files. input_forcings.calc_neighbor_files( - self._bmi._job_meta, output_obj.outDate, self._bmi._mpi_meta + self._bmi._job_meta, + self._bmi._output_obj.outDate, + self._bmi._mpi_meta, ) err_handler.check_program_status( self._bmi._job_meta, self._bmi._mpi_meta @@ -545,7 +539,10 @@ def loop_through_forcing_products( # Layer in forcings from this product. layeringMod.layer_final_forcings( - output_obj, input_forcings, self._bmi._job_meta, self._bmi._mpi_meta + self._bmi._output_obj, + input_forcings, + self._bmi._job_meta, + self._bmi._mpi_meta, ) err_handler.check_program_status( self._bmi._job_meta, self._bmi._mpi_meta @@ -564,7 +561,9 @@ def loop_through_forcing_products( if supp_pcp_key != 13: # Like with input forcings, calculate the neighboring files to use. self._bmi._supp_pcp_mod[supp_pcp_key].calc_neighbor_files( - self._bmi._job_meta, output_obj.outDate, self._bmi._mpi_meta + self._bmi._job_meta, + self._bmi._output_obj.outDate, + self._bmi._mpi_meta, ) err_handler.check_program_status( self._bmi._job_meta, self._bmi._mpi_meta @@ -618,7 +617,7 @@ def loop_through_forcing_products( # Layer in the supplemental precipitation into the current output object. layeringMod.layer_supplemental_forcing( - output_obj, + self._bmi._output_obj, self._bmi._supp_pcp_mod[supp_pcp_key], self._bmi._job_meta, self._bmi._mpi_meta, @@ -630,21 +629,17 @@ def loop_through_forcing_products( # Call the output routines # adjust date for AnA if necessary if self._bmi._job_meta.ana_flag: - output_obj.outDate = file_date + self._bmi._output_obj.outDate = file_date ################ Commenting this out to bypass NWM forcing file output functionality ######### - # output_obj.output_final_ldasin(self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta) + # self._bmi._output_obj.output_final_ldasin(self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta) # err_handler.check_program_status(self._bmi._job_meta, self._bmi._mpi_meta) ############################################################################################## return input_forcings @time_function - def process_suplemental_precip( - self, - output_obj: OutputObj, - input_forcings: dict, - ) -> None: + def process_suplemental_precip(self, input_forcings: dict) -> None: """Process supplemental precipitation for the current forecast cycle. Warnings @@ -658,7 +653,9 @@ def process_suplemental_precip( if supp_pcp_key == 14: # Like with input forcings, calculate the neighboring files to use. self._bmi._supp_pcp_mod[supp_pcp_key].calc_neighbor_files( - self._bmi._job_meta, output_obj.outDate, self._bmi._mpi_meta + self._bmi._job_meta, + self._bmi._output_obj.outDate, + self._bmi._mpi_meta, ) err_handler.check_program_status( self._bmi._job_meta, self._bmi._mpi_meta @@ -711,7 +708,7 @@ def process_suplemental_precip( # Layer in the supplemental precipitation into the current output object. layeringMod.layer_supplemental_forcing( - output_obj, + self._bmi._output_obj, self._bmi._supp_pcp_mod[supp_pcp_key], self._bmi._job_meta, self._bmi._mpi_meta, @@ -721,10 +718,7 @@ def process_suplemental_precip( ) @time_function - def write_output( - self, - output_obj: OutputObj, - ) -> None: + def write_output(self) -> None: """Write the output for the current forecast cycle. Warnings @@ -737,17 +731,14 @@ def write_output( self._bmi._job_meta.forcing_output == 1 or self._bmi._job_meta.grid_type == "hydrofabric" ): - output_obj.gather_global_outputs( + self._bmi._output_obj.gather_global_outputs( self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta ) """##################Step 6: flatten and update dict##########################################################################""" @time_function - def update_dict( - self, - output_obj: OutputObj, - ) -> None: + def update_dict(self) -> None: """Flatten the Forcings Engine output object and update the BMI dictionary. Warnings @@ -792,22 +783,22 @@ def update_dict( ] if self._bmi._job_meta.grid_type == "gridded": for count, variable in enumerate(variables): - self._bmi._values[variable + "_ELEMENT"] = output_obj.output_local[ - count, :, : - ].flatten() + self._bmi._values[variable + "_ELEMENT"] = ( + self._bmi._output_obj.output_local[count, :, :].flatten() + ) elif self._bmi._job_meta.grid_type == "unstructured": for count, variable in enumerate(variables): - self._bmi._values[variable + "_ELEMENT"] = output_obj.output_local_elem[ - count, : - ].flatten() - self._bmi._values[variable + "_NODE"] = output_obj.output_local[ - count, : - ].flatten() + self._bmi._values[variable + "_ELEMENT"] = ( + self._bmi._output_obj.output_local_elem[count, :].flatten() + ) + self._bmi._values[variable + "_NODE"] = ( + self._bmi._output_obj.output_local[count, :].flatten() + ) elif self._bmi._job_meta.grid_type == "hydrofabric": for count, variable in enumerate(variables): - self._bmi._values[variable + "_ELEMENT"] = output_obj.output_global[ - count, : - ].flatten() + self._bmi._values[variable + "_ELEMENT"] = ( + self._bmi._output_obj.output_global[count, :].flatten() + ) self._bmi._values["CAT-ID"] = self._bmi.geo_meta.element_ids_global else: raise ValueError( diff --git a/tests/test_utils.py b/tests/test_utils.py index efba3ca9..56accdd5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -660,8 +660,6 @@ def pre_regrid(self) -> None: f"In pre_regrid, expected state to be either None or 'post_ran' but got {repr(self._state)}. The test is set up incorrectly." ) - output_obj = self.bmi_model._output_obj - future_time = ( self.bmi_model._values["current_model_time"] + self.bmi_model._values["time_step_size"] @@ -674,7 +672,7 @@ def pre_regrid(self) -> None: model.log_forecast() ### NOTE setting the flag causes the regrid step to be skipped self.set_input_forcings_skip_flags() - model.loop_through_forcing_products(future_time, output_obj) + model.loop_through_forcing_products(future_time) # Update test fixture status self._state = "pre_ran" From 2abab0ead1016b0617b9de5344faaa7f4123a24b Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 16:03:13 -0400 Subject: [PATCH 27/71] Remove unused imports --- .../NextGen_Forcings_Engine/model.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 2f101c34..ad417d17 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -2,15 +2,12 @@ import datetime import logging -import os from contextlib import contextmanager -from time import perf_counter, time +from time import perf_counter from typing import TYPE_CHECKING import numpy as np import pandas as pd -from ewts import Payload as Pld -from ewts import Status as St from ewts.modules import ModuleKey from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core import ( @@ -21,14 +18,6 @@ forcingInputMod, layeringMod, ) -from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( - ConfigOptions, -) -from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.geoMod import ( - GeoMeta, -) -from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.ioMod import OutputObj -from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.parallel import MpiConfig from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.historical_forcing import ( AORCAlaskaProcessor, AORCConusProcessor, From 5eb4779294d5730d376fca9083a44c0748b50f2f Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 16:09:41 -0400 Subject: [PATCH 28/71] Remove hard-coded msg control --- NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index ad417d17..436a1510 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -253,7 +253,6 @@ def loop_through_forcing_products( # 4.) Downscale. # 5.) Layer, and output as necessary. ana_factor = 1 if self._bmi._job_meta.ana_flag is False else 0 - show_message = True if not self._bmi._job_meta.precip_only_flag: if self._bmi._job_meta.grid_type == "gridded": # Reset out final grids to missing values. @@ -322,7 +321,7 @@ def loop_through_forcing_products( # Print message on log file indicating the timestamp # we are currently processing for forcings - if self._bmi._mpi_meta.rank == 0 and show_message: + if self._bmi._mpi_meta.rank == 0: self._bmi._job_meta.statusMsg = ( "=========================================" ) From 7e746b35c6bd6c35cebe236d2094e719ff72b6cc Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 16:57:44 -0400 Subject: [PATCH 29/71] DRYify some AnA deltas --- .../NextGen_Forcings_Engine/model.py | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 436a1510..9fd5d3a0 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -148,33 +148,28 @@ def determine_forecast(self, future_time: float) -> None: # If we're in an AnA configuration, then must offset the BMI future # timestamp to account for the "lookback" period being properly iterated # over between 3-28 hour look back time period and operation configuration + # TODO confirm these codes, and should they consider all input_forcings not just [0]? if self._bmi._job_meta.input_forcings[0] in [20, 22]: + delta = pd.TimedeltaIndex( + np.array([future_time - 7200.0], dtype=float), "s" + )[0] self._bmi._job_meta.current_fcst_cycle = ( - self._bmi._job_meta.b_date_proc - + pd.TimedeltaIndex( - np.array([future_time - 7200.0], dtype=float), "s" - )[0] + self._bmi._job_meta.b_date_proc + delta ) self._bmi._job_meta.current_time = ( - self._bmi._job_meta.b_date_proc - + pd.TimedeltaIndex( - np.array([future_time - 7200.0], dtype=float), "s" - )[0] + self._bmi._job_meta.b_date_proc + delta ) self._bmi._job_meta.future_time = future_time else: # Puerto Rico / Hawaii AnA: 1-hour lookback (based on 6-hourly forecast cycles) + delta = pd.TimedeltaIndex( + np.array([future_time - 3600.0], dtype=float), "s" + )[0] self._bmi._job_meta.current_fcst_cycle = ( - self._bmi._job_meta.b_date_proc - + pd.TimedeltaIndex( - np.array([future_time - 3600.0], dtype=float), "s" - )[0] + self._bmi._job_meta.b_date_proc + delta ) self._bmi._job_meta.current_time = ( - self._bmi._job_meta.b_date_proc - + pd.TimedeltaIndex( - np.array([future_time - 3600.0], dtype=float), "s" - )[0] + self._bmi._job_meta.b_date_proc + delta ) else: # Forecast-only mode — use BMI timestamp as-is From 34827a3ed0930354a7c8909e2b44068afe2b9e18 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 17:25:16 -0400 Subject: [PATCH 30/71] DRYify calls to check_program_status --- .../NextGen_Forcings_Engine/model.py | 92 ++++++------------- 1 file changed, 27 insertions(+), 65 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 9fd5d3a0..1b328fd2 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -80,6 +80,10 @@ def __init__(self, bmi_model: NWMv3_Forcing_Engine_BMI_model_Base): # def aws_obj(files): # return xr.open_mfdataset(files, engine="zarr", parallel=True, consolidated=True) + def check_program_status(self) -> None: + """Call err_handler.check_program_status""" + err_handler.check_program_status(self._bmi._job_meta, self._bmi._mpi_meta) + def run(self, future_time: float) -> None: """Execute the full forcings engine BMI pipeline for a given future timestep. @@ -204,7 +208,7 @@ def adjust_precip(self) -> None: for force_key in self._bmi._job_meta.input_forcings: self._bmi._input_forcing_mod[force_key].skip = False - err_handler.check_program_status(self._bmi._job_meta, self._bmi._mpi_meta) + self.check_program_status() @time_function def log_forecast(self) -> None: @@ -365,9 +369,7 @@ def loop_through_forcing_products( self._bmi._output_obj.outDate, self._bmi._mpi_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() else: # Flag to indicate the AWS .zarr AORC method if force_key == 12: @@ -431,17 +433,13 @@ def loop_through_forcing_products( input_forcings.regrid_inputs( self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # Run check on regridded fields for reasonable values that are not missing values. err_handler.check_forcing_bounds( self._bmi._job_meta, input_forcings, self._bmi._mpi_meta ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # If we are restarting a forecast cycle, re-calculate the neighboring files, and regrid the # next set of forcings as the previous step just regridded the previous forcing. @@ -476,17 +474,13 @@ def loop_through_forcing_products( self._bmi._output_obj.outDate, self._bmi._mpi_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # Regrid the forcings for the end of the window. input_forcings.regrid_inputs( self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() input_forcings.rstFlag = 0 @@ -494,9 +488,7 @@ def loop_through_forcing_products( input_forcings.temporal_interpolate_inputs( self._bmi._job_meta, self._bmi._mpi_meta ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # Run bias correction. bias_correction.run_bias_correction( @@ -505,9 +497,7 @@ def loop_through_forcing_products( self._bmi.geo_meta, self._bmi._mpi_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # Run downscaling on grids for this output timestep. downscale.run_downscaling( @@ -516,9 +506,7 @@ def loop_through_forcing_products( self._bmi.geo_meta, self._bmi._mpi_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # Layer in forcings from this product. layeringMod.layer_final_forcings( @@ -527,9 +515,7 @@ def loop_through_forcing_products( self._bmi._job_meta, self._bmi._mpi_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() self._bmi._job_meta.currentForceNum += 1 @@ -548,17 +534,13 @@ def loop_through_forcing_products( self._bmi._output_obj.outDate, self._bmi._mpi_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # Regrid the supplemental precipitation. self._bmi._supp_pcp_mod[supp_pcp_key].regrid_inputs( self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() if ( self._bmi._supp_pcp_mod[supp_pcp_key].regridded_precip1 @@ -573,9 +555,7 @@ def loop_through_forcing_products( self._bmi._mpi_meta, self._bmi.geo_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # TODO input_forcings has not yet been initialized, so this is a bug waiting to happen self.disaggregate_fun( @@ -584,9 +564,7 @@ def loop_through_forcing_products( self._bmi._job_meta, self._bmi._mpi_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # Run temporal interpolation on the grids. self._bmi._supp_pcp_mod[ @@ -594,9 +572,7 @@ def loop_through_forcing_products( ].temporal_interpolate_inputs( self._bmi._job_meta, self._bmi._mpi_meta ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # Layer in the supplemental precipitation into the current output object. layeringMod.layer_supplemental_forcing( @@ -605,9 +581,7 @@ def loop_through_forcing_products( self._bmi._job_meta, self._bmi._mpi_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # Call the output routines # adjust date for AnA if necessary @@ -616,7 +590,7 @@ def loop_through_forcing_products( ################ Commenting this out to bypass NWM forcing file output functionality ######### # self._bmi._output_obj.output_final_ldasin(self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta) - # err_handler.check_program_status(self._bmi._job_meta, self._bmi._mpi_meta) + # self.check_program_status() ############################################################################################## return input_forcings @@ -640,17 +614,13 @@ def process_suplemental_precip(self, input_forcings: dict) -> None: self._bmi._output_obj.outDate, self._bmi._mpi_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # Regrid the supplemental precipitation. self._bmi._supp_pcp_mod[supp_pcp_key].regrid_inputs( self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() if ( self._bmi._supp_pcp_mod[supp_pcp_key].regridded_precip1 @@ -665,9 +635,7 @@ def process_suplemental_precip(self, input_forcings: dict) -> None: self._bmi._mpi_meta, self._bmi.geo_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() self.disaggregate_fun( input_forcings, @@ -675,9 +643,7 @@ def process_suplemental_precip(self, input_forcings: dict) -> None: self._bmi._job_meta, self._bmi._mpi_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # Run temporal interpolation on the grids. self._bmi._supp_pcp_mod[ @@ -685,9 +651,7 @@ def process_suplemental_precip(self, input_forcings: dict) -> None: ].temporal_interpolate_inputs( self._bmi._job_meta, self._bmi._mpi_meta ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() # Layer in the supplemental precipitation into the current output object. layeringMod.layer_supplemental_forcing( @@ -696,9 +660,7 @@ def process_suplemental_precip(self, input_forcings: dict) -> None: self._bmi._job_meta, self._bmi._mpi_meta, ) - err_handler.check_program_status( - self._bmi._job_meta, self._bmi._mpi_meta - ) + self.check_program_status() @time_function def write_output(self) -> None: From f5bc953ee448fe1b79d3f7f62435bc5ddac42483 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 27 Apr 2026 17:32:54 -0400 Subject: [PATCH 31/71] Clean up comments and docstrings --- .../NextGen_Forcings_Engine/model.py | 63 +++++++++---------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 1b328fd2..28c68c61 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -1,3 +1,5 @@ +"""NWMv3ForcingEngineModel, to be constructed and managed by inheritors of NWMv3_Forcing_Engine_BMI_model_Base from bmi_model.py""" + from __future__ import annotations import datetime @@ -28,7 +30,6 @@ ) if TYPE_CHECKING: - # To allow type hint without circular import error from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.bmi_model import ( NWMv3_Forcing_Engine_BMI_model_Base, ) @@ -64,22 +65,15 @@ def wrapper(*args, **kwargs): class NWMv3ForcingEngineModel: - """NextGen Forcings Engine BMI model class for NWMv3 forcings.""" + """NextGen Forcings Engine BMI model class for NWMv3 forcings. + To be constructed and managed by inheritors of NWMv3_Forcing_Engine_BMI_model_Base from bmi_model.py. + """ def __init__(self, bmi_model: NWMv3_Forcing_Engine_BMI_model_Base): """Initialize the NWMv3 Forcing Engine Model.""" self.source_data_processor = None self._bmi = bmi_model - # TODO: refactor the bmi_model.py file and this to have this type maintain its own state. - # def __init__(self): - # super(ngen_model, self).__init__() - # #self._model = model - - # @dask.delayed - # def aws_obj(files): - # return xr.open_mfdataset(files, engine="zarr", parallel=True, consolidated=True) - def check_program_status(self) -> None: """Call err_handler.check_program_status""" err_handler.check_program_status(self._bmi._job_meta, self._bmi._mpi_meta) @@ -218,7 +212,6 @@ def log_forecast(self) -> None: -------- Modifies mutable arguments in-place. """ - # Log information about this forecast cycle if self._bmi._mpi_meta.rank == 0: self._bmi._job_meta.statusMsg = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" err_handler.log_msg(self._bmi._job_meta, self._bmi._mpi_meta, True) @@ -241,16 +234,17 @@ def loop_through_forcing_products( ) -> forcingInputMod.InputForcingsHydrofabric: """Loop through each forcing product and process it for the current forecast cycle. + Loop through each output timestep. Perform the following functions: + 1.) Calculate all necessary input files per user options. + 2.) Read in input forcings from GRIB/NetCDF files. + 3.) Regrid the forcings, and temporally interpolate. + 4.) Downscale. + 5.) Layer, and output as necessary. + Warnings -------- Modifies mutable arguments in-place. """ - # Loop through each output timestep. Perform the following functions: - # 1.) Calculate all necessary input files per user options. - # 2.) Read in input forcings from GRIB/NetCDF files. - # 3.) Regrid the forcings, and temporally interpolate. - # 4.) Downscale. - # 5.) Layer, and output as necessary. ana_factor = 1 if self._bmi._job_meta.ana_flag is False else 0 if not self._bmi._job_meta.precip_only_flag: if self._bmi._job_meta.grid_type == "gridded": @@ -371,6 +365,7 @@ def loop_through_forcing_products( ) self.check_program_status() else: + # TODO assert one force_key? # Flag to indicate the AWS .zarr AORC method if force_key == 12: if self.source_data_processor is None: @@ -519,6 +514,7 @@ def loop_through_forcing_products( self._bmi._job_meta.currentForceNum += 1 + # TODO what is this? if force_key == 10: self._bmi._job_meta.currentCustomForceNum += 1 @@ -665,13 +661,13 @@ def process_suplemental_precip(self, input_forcings: dict) -> None: @time_function def write_output(self) -> None: """Write the output for the current forecast cycle. + If user requests output for given domain, then call + the I/O module to update opened netcdf file with forcing fields. Warnings -------- Modifies mutable arguments in-place. """ - # If user requests output for given domain, then call - # the I/O module to update opened netcdf file with forcing fields if ( self._bmi._job_meta.forcing_output == 1 or self._bmi._job_meta.grid_type == "hydrofabric" @@ -680,28 +676,27 @@ def write_output(self) -> None: self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta ) - """##################Step 6: flatten and update dict##########################################################################""" - @time_function def update_dict(self) -> None: """Flatten the Forcings Engine output object and update the BMI dictionary. + Loop through Forcings Engine output object + and flatten the 2D forcing array and append to + the BMI object to advertise to BMIinterface. + 0.) U-Wind (m/s) + 1.) V-Wind (m/s) + 2.) Surface incoming longwave radiation flux (W/m^2) + 3.) Precipitation rate (mm/s) + 4.) 2-meter temperature (K) + 5.) 2-meter specific humidity (kg/kg) + 6.) Surface pressure (Pa) + 7.) Surface incoming shortwave radiation flux (W/m^2) + 8.) Liquid Precipitation Fraction (%), Only available in certain operational configurations + Warnings -------- Modifies mutable arguments in-place. """ - # Now loop through Forcings Engine output object - # and flatten the 2D forcing array and append to - # the BMI object to advertise to BMIinterface - # 0.) U-Wind (m/s) - # 1.) V-Wind (m/s) - # 2.) Surface incoming longwave radiation flux (W/m^2) - # 3.) Precipitation rate (mm/s) - # 4.) 2-meter temperature (K) - # 5.) 2-meter specific humidity (kg/kg) - # 6.) Surface pressure (Pa) - # 7.) Surface incoming shortwave radiation flux (W/m^2) - # 8.) Liquid Precipitation Fraction (%), Only available in certain operational configurations if self._bmi._job_meta.include_lqfrac == 1: variables = [ From 584afe3bcd96a0487ff9b6b25ac7edaab8e95d0d Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Wed, 29 Apr 2026 07:30:16 -0400 Subject: [PATCH 32/71] Add forcing key count assertion --- NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 28c68c61..4438e287 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -365,7 +365,10 @@ def loop_through_forcing_products( ) self.check_program_status() else: - # TODO assert one force_key? + if len(self._bmi._job_meta.input_forcings) != 1: + raise ValueError( + f"Expected to have 1 forcing key, but have {len(self._bmi._job_meta.input_forcings)}: {list(self._bmi._job_meta.input_forcings)}" + ) # Flag to indicate the AWS .zarr AORC method if force_key == 12: if self.source_data_processor is None: From d65927a72d558fe8933f1840e9ceb9083bec3ef2 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Wed, 29 Apr 2026 07:32:27 -0400 Subject: [PATCH 33/71] Update docstrings --- .../NextGen_Forcings_Engine/model.py | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 4438e287..8a788e8c 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -191,12 +191,7 @@ def determine_forecast(self, future_time: float) -> None: @time_function def adjust_precip(self) -> None: - """Adjust precipitation for the given forecast cycle. - - Warnings - -------- - Modifies mutable arguments in-place. - """ + """Adjust precipitation for the given forecast cycle.""" if not self._bmi._job_meta.precip_only_flag: # reset skips if present for force_key in self._bmi._job_meta.input_forcings: @@ -206,12 +201,7 @@ def adjust_precip(self) -> None: @time_function def log_forecast(self) -> None: - """Log information about the current forecast cycle. - - Warnings - -------- - Modifies mutable arguments in-place. - """ + """Log information about the current forecast cycle.""" if self._bmi._mpi_meta.rank == 0: self._bmi._job_meta.statusMsg = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" err_handler.log_msg(self._bmi._job_meta, self._bmi._mpi_meta, True) @@ -240,10 +230,6 @@ def loop_through_forcing_products( 3.) Regrid the forcings, and temporally interpolate. 4.) Downscale. 5.) Layer, and output as necessary. - - Warnings - -------- - Modifies mutable arguments in-place. """ ana_factor = 1 if self._bmi._job_meta.ana_flag is False else 0 if not self._bmi._job_meta.precip_only_flag: @@ -666,10 +652,6 @@ def write_output(self) -> None: """Write the output for the current forecast cycle. If user requests output for given domain, then call the I/O module to update opened netcdf file with forcing fields. - - Warnings - -------- - Modifies mutable arguments in-place. """ if ( self._bmi._job_meta.forcing_output == 1 @@ -695,10 +677,6 @@ def update_dict(self) -> None: 6.) Surface pressure (Pa) 7.) Surface incoming shortwave radiation flux (W/m^2) 8.) Liquid Precipitation Fraction (%), Only available in certain operational configurations - - Warnings - -------- - Modifies mutable arguments in-place. """ if self._bmi._job_meta.include_lqfrac == 1: From cf65ff40467deba6278aeb147f98349a70eb2566 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Wed, 29 Apr 2026 07:48:47 -0400 Subject: [PATCH 34/71] Move block using `rstFlag` to new private method --- .../NextGen_Forcings_Engine/model.py | 89 ++++++++++--------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 8a788e8c..9f90d7de 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -427,46 +427,7 @@ def loop_through_forcing_products( # If we are restarting a forecast cycle, re-calculate the neighboring files, and regrid the # next set of forcings as the previous step just regridded the previous forcing. - if input_forcings.rstFlag == 1: - if ( - input_forcings.regridded_forcings1 is not None - and input_forcings.regridded_forcings2 is not None - ): - # Set the forcings back to reflect we just regridded the previous set of inputs, not the next. - if self._bmi._job_meta.grid_type == "gridded": - input_forcings.regridded_forcings1[:, :, :] = ( - input_forcings.regridded_forcings2[:, :, :] - ) - elif self._bmi._job_meta.grid_type == "unstructured": - input_forcings.regridded_forcings1[:, :] = ( - input_forcings.regridded_forcings2[:, :] - ) - input_forcings.regridded_forcings1_elem[:, :] = ( - input_forcings.regridded_forcings2_elem[:, :] - ) - elif self._bmi._job_meta.grid_type == "hydrofabric": - input_forcings.regridded_forcings1[:, :] = ( - input_forcings.regridded_forcings2[:, :] - ) - else: - raise ValueError( - f"Unexpected grid_type: {repr(self._bmi._job_meta.grid_type)}" - ) - # Re-calculate the neighbor files. - input_forcings.calc_neighbor_files( - self._bmi._job_meta, - self._bmi._output_obj.outDate, - self._bmi._mpi_meta, - ) - self.check_program_status() - - # Regrid the forcings for the end of the window. - input_forcings.regrid_inputs( - self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta - ) - self.check_program_status() - - input_forcings.rstFlag = 0 + self.__use_rstFlag(input_forcings) # Run temporal interpolation on the grids. input_forcings.temporal_interpolate_inputs( @@ -580,6 +541,54 @@ def loop_through_forcing_products( return input_forcings + def __use_rstFlag(self, input_forcings): + """ + If we are restarting a forecast cycle, re-calculate the neighboring files, and regrid the + next set of forcings as the previous step just regridded the previous forcing. + + This code block was cut and pasted from method `loop_through_forcing_products` during refactor. + """ + if input_forcings.rstFlag == 1: + if ( + input_forcings.regridded_forcings1 is not None + and input_forcings.regridded_forcings2 is not None + ): + # Set the forcings back to reflect we just regridded the previous set of inputs, not the next. + if self._bmi._job_meta.grid_type == "gridded": + input_forcings.regridded_forcings1[:, :, :] = ( + input_forcings.regridded_forcings2[:, :, :] + ) + elif self._bmi._job_meta.grid_type == "unstructured": + input_forcings.regridded_forcings1[:, :] = ( + input_forcings.regridded_forcings2[:, :] + ) + input_forcings.regridded_forcings1_elem[:, :] = ( + input_forcings.regridded_forcings2_elem[:, :] + ) + elif self._bmi._job_meta.grid_type == "hydrofabric": + input_forcings.regridded_forcings1[:, :] = ( + input_forcings.regridded_forcings2[:, :] + ) + else: + raise ValueError( + f"Unexpected grid_type: {repr(self._bmi._job_meta.grid_type)}" + ) + # Re-calculate the neighbor files. + input_forcings.calc_neighbor_files( + self._bmi._job_meta, + self._bmi._output_obj.outDate, + self._bmi._mpi_meta, + ) + self.check_program_status() + + # Regrid the forcings for the end of the window. + input_forcings.regrid_inputs( + self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta + ) + self.check_program_status() + + input_forcings.rstFlag = 0 + @time_function def process_suplemental_precip(self, input_forcings: dict) -> None: """Process supplemental precipitation for the current forecast cycle. From 6749d011a1cd5b63cd5b96f9c600f2aee5f5303b Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Wed, 29 Apr 2026 08:25:03 -0400 Subject: [PATCH 35/71] Move block for supplemental precip handling to new private method --- .../NextGen_Forcings_Engine/model.py | 166 +++++++----------- 1 file changed, 59 insertions(+), 107 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 9f90d7de..9bfa401f 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -474,60 +474,9 @@ def loop_through_forcing_products( if self._bmi._job_meta.number_supp_pcp > 0: for supp_pcp_key in self._bmi._job_meta.supp_precip_forcings: if supp_pcp_key != 13: - # Like with input forcings, calculate the neighboring files to use. - self._bmi._supp_pcp_mod[supp_pcp_key].calc_neighbor_files( - self._bmi._job_meta, - self._bmi._output_obj.outDate, - self._bmi._mpi_meta, - ) - self.check_program_status() - - # Regrid the supplemental precipitation. - self._bmi._supp_pcp_mod[supp_pcp_key].regrid_inputs( - self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta - ) - self.check_program_status() - - if ( - self._bmi._supp_pcp_mod[supp_pcp_key].regridded_precip1 - is not None - and self._bmi._supp_pcp_mod[supp_pcp_key].regridded_precip2 - is not None - ): - # Run check on regridded fields for reasonable values that are not missing values. - err_handler.check_supp_pcp_bounds( - self._bmi._job_meta, - self._bmi._supp_pcp_mod[supp_pcp_key], - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) - self.check_program_status() - - # TODO input_forcings has not yet been initialized, so this is a bug waiting to happen - self.disaggregate_fun( - input_forcings, - self._bmi._supp_pcp_mod[supp_pcp_key], - self._bmi._job_meta, - self._bmi._mpi_meta, - ) - self.check_program_status() - - # Run temporal interpolation on the grids. - self._bmi._supp_pcp_mod[ - supp_pcp_key - ].temporal_interpolate_inputs( - self._bmi._job_meta, self._bmi._mpi_meta - ) - self.check_program_status() - - # Layer in the supplemental precipitation into the current output object. - layeringMod.layer_supplemental_forcing( - self._bmi._output_obj, - self._bmi._supp_pcp_mod[supp_pcp_key], - self._bmi._job_meta, - self._bmi._mpi_meta, - ) - self.check_program_status() + # Below comment copied from earlier code, the comment had been just above the call to `disaggregate_fun`. + # TODO input_forcings has not yet been initialized, so this is a bug waiting to happen + self.__process_supp_precip_key(input_forcings, supp_pcp_key) # Call the output routines # adjust date for AnA if necessary @@ -541,6 +490,61 @@ def loop_through_forcing_products( return input_forcings + def __process_supp_precip_key(self, input_forcings: dict, supp_pcp_key: int): + """Process supplemental precipitation for one supplemental precipitation key. + + This code block was cut and pasted from methods `loop_through_forcing_products` and `process_suplemental_precip` during refactor. + """ + # Like with input forcings, calculate the neighboring files to use. + self._bmi._supp_pcp_mod[supp_pcp_key].calc_neighbor_files( + self._bmi._job_meta, + self._bmi._output_obj.outDate, + self._bmi._mpi_meta, + ) + self.check_program_status() + + # Regrid the supplemental precipitation. + self._bmi._supp_pcp_mod[supp_pcp_key].regrid_inputs( + self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta + ) + self.check_program_status() + + if ( + self._bmi._supp_pcp_mod[supp_pcp_key].regridded_precip1 is not None + and self._bmi._supp_pcp_mod[supp_pcp_key].regridded_precip2 is not None + ): + # Run check on regridded fields for reasonable values that are not missing values. + err_handler.check_supp_pcp_bounds( + self._bmi._job_meta, + self._bmi._supp_pcp_mod[supp_pcp_key], + self._bmi._mpi_meta, + self._bmi.geo_meta, + ) + self.check_program_status() + + self.disaggregate_fun( + input_forcings, + self._bmi._supp_pcp_mod[supp_pcp_key], + self._bmi._job_meta, + self._bmi._mpi_meta, + ) + self.check_program_status() + + # Run temporal interpolation on the grids. + self._bmi._supp_pcp_mod[supp_pcp_key].temporal_interpolate_inputs( + self._bmi._job_meta, self._bmi._mpi_meta + ) + self.check_program_status() + + # Layer in the supplemental precipitation into the current output object. + layeringMod.layer_supplemental_forcing( + self._bmi._output_obj, + self._bmi._supp_pcp_mod[supp_pcp_key], + self._bmi._job_meta, + self._bmi._mpi_meta, + ) + self.check_program_status() + def __use_rstFlag(self, input_forcings): """ If we are restarting a forecast cycle, re-calculate the neighboring files, and regrid the @@ -602,59 +606,7 @@ def process_suplemental_precip(self, input_forcings: dict) -> None: if self._bmi._job_meta.number_supp_pcp > 0: for supp_pcp_key in self._bmi._job_meta.supp_precip_forcings: if supp_pcp_key == 14: - # Like with input forcings, calculate the neighboring files to use. - self._bmi._supp_pcp_mod[supp_pcp_key].calc_neighbor_files( - self._bmi._job_meta, - self._bmi._output_obj.outDate, - self._bmi._mpi_meta, - ) - self.check_program_status() - - # Regrid the supplemental precipitation. - self._bmi._supp_pcp_mod[supp_pcp_key].regrid_inputs( - self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta - ) - self.check_program_status() - - if ( - self._bmi._supp_pcp_mod[supp_pcp_key].regridded_precip1 - is not None - and self._bmi._supp_pcp_mod[supp_pcp_key].regridded_precip2 - is not None - ): - # Run check on regridded fields for reasonable values that are not missing values. - err_handler.check_supp_pcp_bounds( - self._bmi._job_meta, - self._bmi._supp_pcp_mod[supp_pcp_key], - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) - self.check_program_status() - - self.disaggregate_fun( - input_forcings, - self._bmi._supp_pcp_mod[supp_pcp_key], - self._bmi._job_meta, - self._bmi._mpi_meta, - ) - self.check_program_status() - - # Run temporal interpolation on the grids. - self._bmi._supp_pcp_mod[ - supp_pcp_key - ].temporal_interpolate_inputs( - self._bmi._job_meta, self._bmi._mpi_meta - ) - self.check_program_status() - - # Layer in the supplemental precipitation into the current output object. - layeringMod.layer_supplemental_forcing( - self._bmi._output_obj, - self._bmi._supp_pcp_mod[supp_pcp_key], - self._bmi._job_meta, - self._bmi._mpi_meta, - ) - self.check_program_status() + self.__process_supp_precip_key(input_forcings, supp_pcp_key) @time_function def write_output(self) -> None: From fb16a97428300ac9e898451fca651c535bf46fff Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Wed, 29 Apr 2026 08:28:11 -0400 Subject: [PATCH 36/71] docstrings and type hints --- .../NextGen_Forcings_Engine/model.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 9bfa401f..3cb1d814 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -490,10 +490,16 @@ def loop_through_forcing_products( return input_forcings - def __process_supp_precip_key(self, input_forcings: dict, supp_pcp_key: int): + def __process_supp_precip_key( + self, input_forcings: dict, supp_pcp_key: int + ) -> None: """Process supplemental precipitation for one supplemental precipitation key. This code block was cut and pasted from methods `loop_through_forcing_products` and `process_suplemental_precip` during refactor. + + Warnings + -------- + Modifies mutable arguments in-place. """ # Like with input forcings, calculate the neighboring files to use. self._bmi._supp_pcp_mod[supp_pcp_key].calc_neighbor_files( @@ -545,12 +551,16 @@ def __process_supp_precip_key(self, input_forcings: dict, supp_pcp_key: int): ) self.check_program_status() - def __use_rstFlag(self, input_forcings): + def __use_rstFlag(self, input_forcings: dict) -> None: """ If we are restarting a forecast cycle, re-calculate the neighboring files, and regrid the next set of forcings as the previous step just regridded the previous forcing. This code block was cut and pasted from method `loop_through_forcing_products` during refactor. + + Warnings + -------- + Modifies mutable arguments in-place. """ if input_forcings.rstFlag == 1: if ( From ff6443968b00148a7e6d350e48373bfff6a758eb Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Wed, 29 Apr 2026 08:42:10 -0400 Subject: [PATCH 37/71] Move block for AORC and NWM handling to new private method --- .../NextGen_Forcings_Engine/core/parallel.py | 7 +- .../NextGen_Forcings_Engine/model.py | 148 ++++++++++-------- 2 files changed, 85 insertions(+), 70 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py index dee8126c..dd87f7e3 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py @@ -5,11 +5,13 @@ import signal import sys from functools import partial -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, TypeVar import mpi4py import numpy as np +from . import err_handler, mpi_utils + mpi4py.rc.threads = False from mpi4py import MPI # noqa: E402 @@ -18,7 +20,6 @@ from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( ConfigOptions, ) -from . import err_handler, mpi_utils # If MPI was initialized outside of python, # disable initialization/finalization behavior @@ -26,7 +27,7 @@ mpi4py.rc.initialize = False mpi4py.rc.finalize = False -if typing.TYPE_CHECKING: +if TYPE_CHECKING: from .config import ConfigOptions from .geoMod import GriddedGeoMeta diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 3cb1d814..829f7968 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -341,73 +341,8 @@ def loop_through_forcing_products( self._bmi._mpi_meta, ) - if force_key in [12, 21, 27]: - if self._bmi._job_meta.aws is None: - # Calculate the previous and next input cycle files from the inputs. - input_forcings.calc_neighbor_files( - self._bmi._job_meta, - self._bmi._output_obj.outDate, - self._bmi._mpi_meta, - ) - self.check_program_status() - else: - if len(self._bmi._job_meta.input_forcings) != 1: - raise ValueError( - f"Expected to have 1 forcing key, but have {len(self._bmi._job_meta.input_forcings)}: {list(self._bmi._job_meta.input_forcings)}" - ) - # Flag to indicate the AWS .zarr AORC method - if force_key == 12: - if self.source_data_processor is None: - self.source_data_processor = AORCConusProcessor( - self._bmi._job_meta, - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) - elif force_key == 21: - if self.source_data_processor is None: - self.source_data_processor = AORCAlaskaProcessor( - self._bmi._job_meta, - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) - - # Flag to indicate the AWS .zarr NWMv3 Forcing file method - elif force_key == 27: - if self.source_data_processor is None: - if self._bmi._job_meta.nwm_domain == "CONUS": - self.source_data_processor = NWMV3ConusProcessor( - self._bmi._job_meta, - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) - elif config_options.nwm_domain == "Hawaii": - self.source_data_processor = NWMV3HawaiiProcessor( - config_options, mpi_config, wrf_hydro_geo_meta - ) - elif config_options.nwm_domain == "PR": - self.source_data_processor = ( - NWMV3PuertoRicoProcessor( - config_options, - mpi_config, - wrf_hydro_geo_meta, - ) - ) - elif config_options.nwm_domain == "Alaska": - self.source_data_processor = NWMV3AlaskaProcessor( - self._bmi._job_meta, - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) - else: - raise ValueError( - f"Unsupported domain type ({self._bmi._job_meta.nwm_domain} for forcing type: {force_key} )" - ) - - self._bmi._job_meta.aws_obj = ( - self.source_data_processor.process_historical_data( - self._bmi._job_meta.current_time - ) - ) + # Handle AORC and NWM force keys + self.__handle_aorc_and_nwm_force_keys(input_forcings, force_key) # If skipping this forcing, continue early if input_forcings.skip is True: @@ -490,6 +425,85 @@ def loop_through_forcing_products( return input_forcings + def __handle_aorc_and_nwm_force_keys(self, input_forcings, force_key: int) -> None: + """During `loop_through_forcing_products`, handle the case of the force key being AORC or NWM. + + This code block was cut and pasted from methods `loop_through_forcing_products` during refactor. + + Warnings + -------- + Modifies mutable arguments in-place. + """ + if force_key in [12, 21, 27]: + if self._bmi._job_meta.aws is None: + # Calculate the previous and next input cycle files from the inputs. + input_forcings.calc_neighbor_files( + self._bmi._job_meta, + self._bmi._output_obj.outDate, + self._bmi._mpi_meta, + ) + self.check_program_status() + else: + if len(self._bmi._job_meta.input_forcings) != 1: + raise ValueError( + f"Expected to have 1 forcing key, but have {len(self._bmi._job_meta.input_forcings)}: {list(self._bmi._job_meta.input_forcings)}" + ) + # Flag to indicate the AWS .zarr AORC method + if force_key == 12: + if self.source_data_processor is None: + self.source_data_processor = AORCConusProcessor( + self._bmi._job_meta, + self._bmi._mpi_meta, + self._bmi.geo_meta, + ) + elif force_key == 21: + if self.source_data_processor is None: + self.source_data_processor = AORCAlaskaProcessor( + self._bmi._job_meta, + self._bmi._mpi_meta, + self._bmi.geo_meta, + ) + + # Flag to indicate the AWS .zarr NWMv3 Forcing file method + elif force_key == 27: + if self.source_data_processor is None: + if self._bmi._job_meta.nwm_domain == "CONUS": + self.source_data_processor = NWMV3ConusProcessor( + self._bmi._job_meta, + self._bmi._mpi_meta, + self._bmi.geo_meta, + ) + elif self._bmi._job_meta.nwm_domain == "Hawaii": + self.source_data_processor = NWMV3HawaiiProcessor( + self._bmi._job_meta, + self._bmi._mpi_meta, + self._bmi.geo_meta, + ) + elif self._bmi._job_meta.nwm_domain == "PR": + self.source_data_processor = ( + NWMV3PuertoRicoProcessor( + self._bmi._job_meta, + self._bmi._mpi_meta, + self._bmi.geo_meta, + ) + ) + elif self._bmi._job_meta.nwm_domain == "Alaska": + self.source_data_processor = NWMV3AlaskaProcessor( + self._bmi._job_meta, + self._bmi._mpi_meta, + self._bmi.geo_meta, + ) + else: + raise ValueError( + f"Unsupported domain type ({self._bmi._job_meta.nwm_domain} for forcing type: {force_key} )" + ) + + self._bmi._job_meta.aws_obj = ( + self.source_data_processor.process_historical_data( + self._bmi._job_meta.current_time + ) + ) + def __process_supp_precip_key( self, input_forcings: dict, supp_pcp_key: int ) -> None: From fde1d4a360dbf4b3c02368ff6b15047f0d9a4202 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Wed, 29 Apr 2026 08:46:40 -0400 Subject: [PATCH 38/71] Comments and type hints --- .../NextGen_Forcings_Engine/model.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 829f7968..52e70650 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -345,9 +345,11 @@ def loop_through_forcing_products( self.__handle_aorc_and_nwm_force_keys(input_forcings, force_key) # If skipping this forcing, continue early + # NOTE this is used by the esmf regrid pytests, to halt the loop before "manually" calling a particular regrid function. if input_forcings.skip is True: LOG.debug(f"Breaking loop for force_key {force_key}") break + # Regrid forcings. input_forcings.regrid_inputs( self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta @@ -505,7 +507,7 @@ def __handle_aorc_and_nwm_force_keys(self, input_forcings, force_key: int) -> No ) def __process_supp_precip_key( - self, input_forcings: dict, supp_pcp_key: int + self, input_forcings: forcingInputMod.InputForcings, supp_pcp_key: int ) -> None: """Process supplemental precipitation for one supplemental precipitation key. @@ -565,7 +567,7 @@ def __process_supp_precip_key( ) self.check_program_status() - def __use_rstFlag(self, input_forcings: dict) -> None: + def __use_rstFlag(self, input_forcings: forcingInputMod.InputForcings) -> None: """ If we are restarting a forecast cycle, re-calculate the neighboring files, and regrid the next set of forcings as the previous step just regridded the previous forcing. @@ -618,7 +620,9 @@ def __use_rstFlag(self, input_forcings: dict) -> None: input_forcings.rstFlag = 0 @time_function - def process_suplemental_precip(self, input_forcings: dict) -> None: + def process_suplemental_precip( + self, input_forcings: forcingInputMod.InputForcings + ) -> None: """Process supplemental precipitation for the current forecast cycle. Warnings From 5b91132ff87c33eb511ed6f2437b2692e5aec58f Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Wed, 29 Apr 2026 08:59:01 -0400 Subject: [PATCH 39/71] Move model.py BMI variables to consts.py --- .../NextGen_Forcings_Engine/core/consts.py | 17 ++++++++++- .../NextGen_Forcings_Engine/model.py | 28 ++++--------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py index 4420e8cb..104a012d 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py @@ -1245,7 +1245,22 @@ 0: timeInterpMod.no_interpolation_supp_pcp, 1: timeInterpMod.nearest_neighbor_supp_pcp, 2: timeInterpMod.weighted_average_supp_pcp, - }, + } +} + +MODEL = { + # Used by method `model.NWMv3ForcingEngineModel.update_dict` + "update_dict_base_vars": [ + "U2D", + "V2D", + "LWDOWN", + "RAINRATE", + "T2D", + "Q2D", + "PSFC", + "SWDOWN", + ], + "update_dict_var_include_lqfraq": "LQFRAC", } TEST_UTILS = { diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 52e70650..4df95802 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -20,6 +20,9 @@ forcingInputMod, layeringMod, ) +from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.consts import ( + MODEL as model_consts, +) from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.historical_forcing import ( AORCAlaskaProcessor, AORCConusProcessor, @@ -668,29 +671,10 @@ def update_dict(self) -> None: 8.) Liquid Precipitation Fraction (%), Only available in certain operational configurations """ + variables = model_consts["update_dict_base_vars"] if self._bmi._job_meta.include_lqfrac == 1: - variables = [ - "U2D", - "V2D", - "LWDOWN", - "RAINRATE", - "T2D", - "Q2D", - "PSFC", - "SWDOWN", - "LQFRAC", - ] - else: - variables = [ - "U2D", - "V2D", - "LWDOWN", - "RAINRATE", - "T2D", - "Q2D", - "PSFC", - "SWDOWN", - ] + variables.append(model_consts["update_dict_var_include_lqfraq"]) + if self._bmi._job_meta.grid_type == "gridded": for count, variable in enumerate(variables): self._bmi._values[variable + "_ELEMENT"] = ( From d757f9575d13557af0bebed341fe430a611c4dff Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Wed, 29 Apr 2026 09:17:45 -0400 Subject: [PATCH 40/71] Fix usage of new consts.MODEL list --- NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 4df95802..5fb826a8 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -2,6 +2,7 @@ from __future__ import annotations +import copy import datetime import logging from contextlib import contextmanager @@ -671,7 +672,7 @@ def update_dict(self) -> None: 8.) Liquid Precipitation Fraction (%), Only available in certain operational configurations """ - variables = model_consts["update_dict_base_vars"] + variables = copy.deepcopy(model_consts["update_dict_base_vars"]) if self._bmi._job_meta.include_lqfrac == 1: variables.append(model_consts["update_dict_var_include_lqfraq"]) From d041997af317449be6d411a1071dccb39e46f336 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Wed, 29 Apr 2026 13:24:28 -0400 Subject: [PATCH 41/71] Comments --- NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 5fb826a8..c2a8046a 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -152,6 +152,7 @@ def determine_forecast(self, future_time: float) -> None: # over between 3-28 hour look back time period and operation configuration # TODO confirm these codes, and should they consider all input_forcings not just [0]? if self._bmi._job_meta.input_forcings[0] in [20, 22]: + # NOTE This appears to be intending to operate on Alaska-only AnA. delta = pd.TimedeltaIndex( np.array([future_time - 7200.0], dtype=float), "s" )[0] @@ -163,6 +164,7 @@ def determine_forecast(self, future_time: float) -> None: ) self._bmi._job_meta.future_time = future_time else: + # NOTE below comment was original, but this appears to be operating on all non-Alaska AnA, not just Puerto Rico / Hawaii AnA. # Puerto Rico / Hawaii AnA: 1-hour lookback (based on 6-hourly forecast cycles) delta = pd.TimedeltaIndex( np.array([future_time - 3600.0], dtype=float), "s" From 561cb91f89d0902cbe1bd3d7097186ac680b9fc8 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Thu, 30 Apr 2026 16:19:38 -0400 Subject: [PATCH 42/71] Add NotImplementedError for SubOutputHour --- NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index c2a8046a..00895b6d 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -266,6 +266,9 @@ def loop_through_forcing_products( # Optional sub-output timestamp if self._bmi._job_meta.sub_output_hour is not None: + raise NotImplementedError( + f"sub_output_hour (config SubOutputHour) is {repr(self._bmi._job_meta.sub_output_hour)} (not None) but is not used." + ) # TODO This is not used subOutDate = self._bmi._job_meta.first_fcst_cycle + datetime.timedelta( hours=self._bmi._job_meta.sub_output_hour From 422e8e973a220e90db2388c139fc3d846b9cd6f7 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Fri, 1 May 2026 14:04:18 -0400 Subject: [PATCH 43/71] Type hints and docstrings --- .../NextGen_Forcings_Engine/model.py | 75 +++++++++++++++---- 1 file changed, 60 insertions(+), 15 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 00895b6d..00cb9417 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -45,11 +45,12 @@ @contextmanager def timing_block(step_str: str): - """Context manager for timing code execution. - - Args: - step_str: Description of the step being timed. + """Context manager for timing code execution. Used by decorator `time_function`. + Parameters + ---------- + step_str : str + Description of the step being timed. """ start = perf_counter() yield @@ -58,7 +59,7 @@ def timing_block(step_str: str): def time_function(func): - """Measure the execution time of a function.""" + """Decorator for measuring the execution time of a function.""" def wrapper(*args, **kwargs): with timing_block(f"Executing {func.__name__}"): @@ -70,11 +71,17 @@ def wrapper(*args, **kwargs): class NWMv3ForcingEngineModel: """NextGen Forcings Engine BMI model class for NWMv3 forcings. + To be constructed and managed by inheritors of NWMv3_Forcing_Engine_BMI_model_Base from bmi_model.py. """ def __init__(self, bmi_model: NWMv3_Forcing_Engine_BMI_model_Base): - """Initialize the NWMv3 Forcing Engine Model.""" + """Initialize the NWMv3 Forcing Engine Model. + + Parameters + ---------- + bmi_model : NWMv3_Forcing_Engine_BMI_model_Base + """ self.source_data_processor = None self._bmi = bmi_model @@ -112,9 +119,17 @@ def run(self, future_time: float) -> None: 6. Update the self._bmi._values state dictionary with flattened arrays. 7. Advance the BMI time index. - :param future_time: The number of seconds into the future to advance the model. - - :raises RuntimeError: If the model fails to initialize or if required arguments are missing. + Parameters + ---------- + future_time : float + Timestamp, represented as *seconds relative to overall start time*, to advance to before returning. + Since this is relative to overall start time, it is unaware of the actual UTC datetimestamp of the start. + For example, since 1-hour timesteps are typical, the first value of this would typically be 3600, the second value 7200, etc. + + Raises + ------ + RuntimeError + If the model fails to initialize or if required arguments are missing. """ self.determine_forecast(future_time) @@ -137,7 +152,7 @@ def determine_forecast(self, future_time: float) -> None: Warnings -------- - Modifies mutable arguments in-place. + Modifies mutable arguments in-place. """ # Assign the future time to the configuration self._bmi._job_meta.bmi_time = future_time @@ -236,6 +251,15 @@ def loop_through_forcing_products( 3.) Regrid the forcings, and temporally interpolate. 4.) Downscale. 5.) Layer, and output as necessary. + + Parameters + ---------- + future_time : float + See description in `self.run`. + + Returns + ---------- + input_forcings: forcingInputMod.InputForcings """ ana_factor = 1 if self._bmi._job_meta.ana_flag is False else 0 if not self._bmi._job_meta.precip_only_flag: @@ -436,14 +460,21 @@ def loop_through_forcing_products( return input_forcings - def __handle_aorc_and_nwm_force_keys(self, input_forcings, force_key: int) -> None: + def __handle_aorc_and_nwm_force_keys( + self, input_forcings: forcingInputMod.InputForcings, force_key: int + ) -> None: """During `loop_through_forcing_products`, handle the case of the force key being AORC or NWM. This code block was cut and pasted from methods `loop_through_forcing_products` during refactor. + Parameters + ---------- + input_forcings : forcingInputMod.InputForcings + force_key : int + Warnings -------- - Modifies mutable arguments in-place. + Modifies mutable arguments in-place. """ if force_key in [12, 21, 27]: if self._bmi._job_meta.aws is None: @@ -522,9 +553,14 @@ def __process_supp_precip_key( This code block was cut and pasted from methods `loop_through_forcing_products` and `process_suplemental_precip` during refactor. + Parameters + ---------- + input_forcings : forcingInputMod.InputForcings + supp_pcp_key : int + Warnings -------- - Modifies mutable arguments in-place. + Modifies mutable arguments in-place. """ # Like with input forcings, calculate the neighboring files to use. self._bmi._supp_pcp_mod[supp_pcp_key].calc_neighbor_files( @@ -583,9 +619,13 @@ def __use_rstFlag(self, input_forcings: forcingInputMod.InputForcings) -> None: This code block was cut and pasted from method `loop_through_forcing_products` during refactor. + Parameters + ---------- + input_forcings : forcingInputMod.InputForcings + Warnings -------- - Modifies mutable arguments in-place. + Modifies mutable arguments in-place. """ if input_forcings.rstFlag == 1: if ( @@ -634,9 +674,13 @@ def process_suplemental_precip( ) -> None: """Process supplemental precipitation for the current forecast cycle. + Parameters + ---------- + input_forcings : forcingInputMod.InputForcings + Warnings -------- - Modifies mutable arguments in-place. + Modifies mutable arguments in-place. """ if self._bmi._job_meta.customSuppPcpFreq is not None: # Process supplemental precipitation if we specified in the configuration file. @@ -648,6 +692,7 @@ def process_suplemental_precip( @time_function def write_output(self) -> None: """Write the output for the current forecast cycle. + If user requests output for given domain, then call the I/O module to update opened netcdf file with forcing fields. """ From 722f0ceaa2c5d07334bb915cad7c9373dcaf5309 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Fri, 1 May 2026 19:42:16 -0400 Subject: [PATCH 44/71] Rename methods --- .../NextGen_Forcings_Engine/core/consts.py | 2 +- .../NextGen_Forcings_Engine/model.py | 23 ++++++++----------- tests/test_utils.py | 9 ++++---- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py index 104a012d..077048b3 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/consts.py @@ -1249,7 +1249,7 @@ } MODEL = { - # Used by method `model.NWMv3ForcingEngineModel.update_dict` + # Used by method `model.NWMv3ForcingEngineModel.update_bmi_output_dict` "update_dict_base_vars": [ "U2D", "V2D", diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 00cb9417..ba2a8df9 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -132,22 +132,19 @@ def run(self, future_time: float) -> None: If the model fails to initialize or if required arguments are missing. """ - self.determine_forecast(future_time) - self.adjust_precip() - self.log_forecast() - # TODO look into input_forcings usage in `process_suplemental_precip` and in `loop_through_forcing_products` at `disaggregate_fun`. - input_forcings = self.loop_through_forcing_products( - future_time, - ) + self.set_cycle_timing_attrs(future_time) + self.set_skip_flags() + self.log_cycle() + input_forcings = self.loop_through_forcing_products(future_time) self.process_suplemental_precip(input_forcings) self.write_output() - self.update_dict() + self.update_bmi_output_dict() ## Update BMI model time index to next iteration self._bmi._job_meta.bmi_time_index += 1 @time_function - def determine_forecast(self, future_time: float) -> None: + def set_cycle_timing_attrs(self, future_time: float) -> None: """Determine the forecast for the given future time and configuration. Warnings @@ -211,7 +208,7 @@ def determine_forecast(self, future_time: float) -> None: ) @time_function - def adjust_precip(self) -> None: + def set_skip_flags(self) -> None: """Adjust precipitation for the given forecast cycle.""" if not self._bmi._job_meta.precip_only_flag: # reset skips if present @@ -221,7 +218,7 @@ def adjust_precip(self) -> None: self.check_program_status() @time_function - def log_forecast(self) -> None: + def log_cycle(self) -> None: """Log information about the current forecast cycle.""" if self._bmi._mpi_meta.rank == 0: self._bmi._job_meta.statusMsg = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -259,7 +256,7 @@ def loop_through_forcing_products( Returns ---------- - input_forcings: forcingInputMod.InputForcings + input_forcings: forcingInputMod.InputForcings | None """ ana_factor = 1 if self._bmi._job_meta.ana_flag is False else 0 if not self._bmi._job_meta.precip_only_flag: @@ -705,7 +702,7 @@ def write_output(self) -> None: ) @time_function - def update_dict(self) -> None: + def update_bmi_output_dict(self) -> None: """Flatten the Forcings Engine output object and update the BMI dictionary. Loop through Forcings Engine output object diff --git a/tests/test_utils.py b/tests/test_utils.py index 56accdd5..2b0d4a68 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -666,10 +666,11 @@ def pre_regrid(self) -> None: ) model = self.bmi_model._model - ### NOTE this should mimic NWMv3ForcingEngineModel.run() with the exception of setting the skip flag - model.determine_forecast(future_time) - model.adjust_precip() - model.log_forecast() + # NOTE this should mimic NWMv3ForcingEngineModel.run() + # with the exception of externally setting the skip flags within this class. + model.set_cycle_timing_attrs(future_time) + model.set_skip_flags() + model.log_cycle() ### NOTE setting the flag causes the regrid step to be skipped self.set_input_forcings_skip_flags() model.loop_through_forcing_products(future_time) From 4d452895868932099b513506cec7d3a2c892efb4 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Fri, 1 May 2026 19:43:47 -0400 Subject: [PATCH 45/71] Fix input_forcings reference (return None conditionally) --- NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index ba2a8df9..bf1797b2 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -239,7 +239,7 @@ def log_cycle(self) -> None: @time_function def loop_through_forcing_products( self, future_time: float - ) -> forcingInputMod.InputForcingsHydrofabric: + ) -> forcingInputMod.InputForcingsHydrofabric | None: """Loop through each forcing product and process it for the current forecast cycle. Loop through each output timestep. Perform the following functions: @@ -454,6 +454,8 @@ def loop_through_forcing_products( # self._bmi._output_obj.output_final_ldasin(self._bmi._job_meta, self._bmi.geo_meta, self._bmi._mpi_meta) # self.check_program_status() ############################################################################################## + else: + input_forcings = None return input_forcings From dc6493d56bfd305164ae75159d8cd28f2e2729c9 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Fri, 1 May 2026 20:02:45 -0400 Subject: [PATCH 46/71] Use partials for log calls and use MPI-aware log methods --- .../NextGen_Forcings_Engine/model.py | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index bf1797b2..b565fb82 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -6,6 +6,7 @@ import datetime import logging from contextlib import contextmanager +from functools import partial from time import perf_counter from typing import TYPE_CHECKING @@ -55,7 +56,7 @@ def timing_block(step_str: str): start = perf_counter() yield end = perf_counter() - LOG.debug(f" Execution time for {step_str}: {round(end - start, 2)} seconds") + LOG.debug(msg=f" Execution time for {step_str}: {round(end - start, 2)} seconds") def time_function(func): @@ -84,6 +85,13 @@ def __init__(self, bmi_model: NWMv3_Forcing_Engine_BMI_model_Base): """ self.source_data_processor = None self._bmi = bmi_model + # Partials + self.log_info = partial( + err_handler.log_msg, self._bmi._job_meta, self._bmi._mpi_meta, False + ) + self.log_debug = partial( + err_handler.log_msg, self._bmi._job_meta, self._bmi._mpi_meta, True + ) def check_program_status(self) -> None: """Call err_handler.check_program_status""" @@ -194,12 +202,12 @@ def set_cycle_timing_attrs(self, future_time: float) -> None: self._bmi._job_meta.b_date_proc ) + pd.to_timedelta(future_time, unit="s") - LOG.debug( - "NextGen Forcings Engine processing meteorological forcings for BMI timestamp" + self.log_debug( + msg="NextGen Forcings Engine processing meteorological forcings for BMI timestamp" ) - LOG.debug(f"Model.py current time: {self._bmi._job_meta.current_time}") - LOG.debug( - f"Model.py current fcst cycle: {self._bmi._job_meta.current_fcst_cycle}" + self.log_debug(msg=f"Model.py current time: {self._bmi._job_meta.current_time}") + self.log_debug( + msg=f"Model.py current fcst cycle: {self._bmi._job_meta.current_fcst_cycle}" ) if self._bmi._job_meta.first_fcst_cycle is None: @@ -221,19 +229,13 @@ def set_skip_flags(self) -> None: def log_cycle(self) -> None: """Log information about the current forecast cycle.""" if self._bmi._mpi_meta.rank == 0: - self._bmi._job_meta.statusMsg = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - err_handler.log_msg(self._bmi._job_meta, self._bmi._mpi_meta, True) - self._bmi._job_meta.statusMsg = ( - "Processing Forecast Cycle: " - + self._bmi._job_meta.current_fcst_cycle.strftime("%Y-%m-%d %H:%M") + self.log_debug(msg="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") + self.log_debug( + msg=f"Processing Forecast Cycle: {self._bmi._job_meta.current_fcst_cycle.strftime('%Y-%m-%d %H:%M')}" ) - err_handler.log_msg(self._bmi._job_meta, self._bmi._mpi_meta, True) - self._bmi._job_meta.statusMsg = ( - "Forecast Cycle Length is: " - + str(self._bmi._job_meta.cycle_length_minutes) - + " minutes" + self.log_debug( + msg=f"Forecast Cycle Length is: {self._bmi._job_meta.cycle_length_minutes!s} minutes" ) - err_handler.log_msg(self._bmi._job_meta, self._bmi._mpi_meta, True) # self._bmi._mpi_meta.comm.barrier() @time_function @@ -331,26 +333,24 @@ def loop_through_forcing_products( # Print message on log file indicating the timestamp # we are currently processing for forcings if self._bmi._mpi_meta.rank == 0: - self._bmi._job_meta.statusMsg = ( - "=========================================" + self.log_debug(msg="=========================================") + self.log_debug( + msg=f"Processing for output timestep: {file_date.strftime('%Y-%m-%d %H:%M')}" ) - err_handler.log_msg(self._bmi._job_meta, self._bmi._mpi_meta, True) - self._bmi._job_meta.statusMsg = f"Processing for output timestep: {file_date.strftime('%Y-%m-%d %H:%M')}" - err_handler.log_msg(self._bmi._job_meta, self._bmi._mpi_meta, True) self._bmi._job_meta.currentForceNum = 0 self._bmi._job_meta.currentCustomForceNum = 0 - LOG.debug( - f"config_options.input_forcings: {self._bmi._job_meta.input_forcings}" + self.log_debug( + msg=f"config_options.input_forcings: {self._bmi._job_meta.input_forcings}" ) # Loop over each of the input forcings specified. - LOG.debug( - f"Model.py forcing loop: {len(self._bmi._job_meta.input_forcings)} forcings configured: {self._bmi._job_meta.input_forcings}" + self.log_debug( + msg=f"Model.py forcing loop: {len(self._bmi._job_meta.input_forcings)} forcings configured: {self._bmi._job_meta.input_forcings}" ) for force_key in self._bmi._job_meta.input_forcings: - LOG.debug(f"force_key: {force_key}") - LOG.debug(f"config_options.aws: {self._bmi._job_meta.aws}") + self.log_debug(msg=f"force_key: {force_key}") + self.log_debug(msg=f"config_options.aws: {self._bmi._job_meta.aws}") # Pass these methods for AORC data is ERA5-Interim blend is requested # so we can finish filling in the missing gaps if ( @@ -377,7 +377,7 @@ def loop_through_forcing_products( # If skipping this forcing, continue early # NOTE this is used by the esmf regrid pytests, to halt the loop before "manually" calling a particular regrid function. if input_forcings.skip is True: - LOG.debug(f"Breaking loop for force_key {force_key}") + self.log_debug(msg=f"Breaking loop for force_key {force_key}") break # Regrid forcings. @@ -435,7 +435,7 @@ def loop_through_forcing_products( if force_key == 10: self._bmi._job_meta.currentCustomForceNum += 1 - LOG.debug(f"End of loop for force_key {force_key}") + self.log_debug(msg=f"End of loop for force_key {force_key}") # Process supplemental precipitation if we specified in the configuration file. if self._bmi._job_meta.number_supp_pcp > 0: From 1228f087d35453c56c9535d6ea4e95607b341499 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Fri, 1 May 2026 20:03:09 -0400 Subject: [PATCH 47/71] Run flynt -tc -ll 9999 --- .../NextGen_Forcings_Engine/model.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index b565fb82..01555f1d 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -727,20 +727,20 @@ def update_bmi_output_dict(self) -> None: if self._bmi._job_meta.grid_type == "gridded": for count, variable in enumerate(variables): - self._bmi._values[variable + "_ELEMENT"] = ( + self._bmi._values[f"{variable}_ELEMENT"] = ( self._bmi._output_obj.output_local[count, :, :].flatten() ) elif self._bmi._job_meta.grid_type == "unstructured": for count, variable in enumerate(variables): - self._bmi._values[variable + "_ELEMENT"] = ( + self._bmi._values[f"{variable}_ELEMENT"] = ( self._bmi._output_obj.output_local_elem[count, :].flatten() ) - self._bmi._values[variable + "_NODE"] = ( + self._bmi._values[f"{variable}_NODE"] = ( self._bmi._output_obj.output_local[count, :].flatten() ) elif self._bmi._job_meta.grid_type == "hydrofabric": for count, variable in enumerate(variables): - self._bmi._values[variable + "_ELEMENT"] = ( + self._bmi._values[f"{variable}_ELEMENT"] = ( self._bmi._output_obj.output_global[count, :].flatten() ) self._bmi._values["CAT-ID"] = self._bmi.geo_meta.element_ids_global From ab7866b003e6cdde02839bb50b62f97a29cb5ca1 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Fri, 1 May 2026 20:19:10 -0400 Subject: [PATCH 48/71] Format docstrings to reST --- .../NextGen_Forcings_Engine/model.py | 180 ++++++++---------- 1 file changed, 79 insertions(+), 101 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 01555f1d..5fc169b8 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -46,12 +46,9 @@ @contextmanager def timing_block(step_str: str): - """Context manager for timing code execution. Used by decorator `time_function`. + """Context manager for timing code execution. Used by the decorator ``time_function``. - Parameters - ---------- - step_str : str - Description of the step being timed. + :param str step_str: Description of the step being timed. """ start = perf_counter() yield @@ -77,11 +74,9 @@ class NWMv3ForcingEngineModel: """ def __init__(self, bmi_model: NWMv3_Forcing_Engine_BMI_model_Base): - """Initialize the NWMv3 Forcing Engine Model. + """Initialize the NWMv3 Forcing Engine model. - Parameters - ---------- - bmi_model : NWMv3_Forcing_Engine_BMI_model_Base + :param bmi_model NWMv3_Forcing_Engine_BMI_model_Base: BMI model instance to initialize. """ self.source_data_processor = None self._bmi = bmi_model @@ -100,44 +95,47 @@ def check_program_status(self) -> None: def run(self, future_time: float) -> None: """Execute the full forcings engine BMI pipeline for a given future timestep. - This method updates the `self._bmi._values` state dictionary with atmospheric forcings computed from - available input datasets. It handles initialization, AWS Zarr loading, regridding, temporal - interpolation, bias correction, downscaling, supplemental precipitation processing, and output - population into the self._bmi._values structure. + This method updates the ``self._bmi._values`` state dictionary with atmospheric + forcings computed from available input datasets. It handles initialization, + AWS Zarr loading, regridding, temporal interpolation, bias correction, + downscaling, supplemental precipitation processing, and output population into + the ``self._bmi._values`` structure. - `self._bmi._job_meta`, an instance of ConfigOptions is also updated in-place, for example for time handling. + ``self._bmi._job_meta``, an instance of ``ConfigOptions``, is also updated + in-place, for example for forecast time handling. The following steps are performed: 1. Determine the current forecast and output times based on the future timestamp - and analysis mode (AnA or forecast). + and analysis mode (AnA or forecast). 2. Initialize or reset output grids and step counters. 3. Loop over each input forcing product: - a. Calculate neighboring input files. - b. Load AWS-hosted Zarr datasets if needed. - c. Regrid input forcings to the model grid. - d. Perform temporal interpolation. - e. Apply bias correction and downscaling. - f. Layer final forcings into the output object. + + a. Calculate neighboring input files. + b. Load AWS-hosted Zarr datasets if needed. + c. Regrid input forcings to the model grid. + d. Perform temporal interpolation. + e. Apply bias correction and downscaling. + f. Layer final forcings into the output object. + 4. Optionally process supplemental precipitation forcings: - a. Regrid and validate. - b. Disaggregate and interpolate. - c. Layer into the final output. + + a. Regrid and validate. + b. Disaggregate and interpolate. + c. Layer into the final output. + 5. Write output to NetCDF forcing files if requested. - 6. Update the self._bmi._values state dictionary with flattened arrays. + 6. Update the ``self._bmi._values`` state dictionary with flattened arrays. 7. Advance the BMI time index. - Parameters - ---------- - future_time : float - Timestamp, represented as *seconds relative to overall start time*, to advance to before returning. - Since this is relative to overall start time, it is unaware of the actual UTC datetimestamp of the start. - For example, since 1-hour timesteps are typical, the first value of this would typically be 3600, the second value 7200, etc. - - Raises - ------ - RuntimeError - If the model fails to initialize or if required arguments are missing. + :param float future_time: Timestamp, represented as *seconds relative to overall + start time*, to advance to before returning. Since this value is relative + to the overall start time, it is unaware of the actual UTC datetimestamp of + the start. For example, since 1-hour timesteps are typical, the first value + would typically be 3600, the second value 7200, etc. + + :raises RuntimeError: If the model fails to initialize or if required arguments + are missing. """ self.set_cycle_timing_attrs(future_time) @@ -155,9 +153,7 @@ def run(self, future_time: float) -> None: def set_cycle_timing_attrs(self, future_time: float) -> None: """Determine the forecast for the given future time and configuration. - Warnings - -------- - Modifies mutable arguments in-place. + :warning: Modifies mutable arguments in-place """ # Assign the future time to the configuration self._bmi._job_meta.bmi_time = future_time @@ -244,21 +240,17 @@ def loop_through_forcing_products( ) -> forcingInputMod.InputForcingsHydrofabric | None: """Loop through each forcing product and process it for the current forecast cycle. - Loop through each output timestep. Perform the following functions: - 1.) Calculate all necessary input files per user options. - 2.) Read in input forcings from GRIB/NetCDF files. - 3.) Regrid the forcings, and temporally interpolate. - 4.) Downscale. - 5.) Layer, and output as necessary. - - Parameters - ---------- - future_time : float - See description in `self.run`. - - Returns - ---------- - input_forcings: forcingInputMod.InputForcings | None + Loop through each output timestep and perform the following steps: + + 1. Calculate all necessary input files per user options. + 2. Read input forcings from GRIB/NetCDF files. + 3. Regrid the forcings and perform temporal interpolation. + 4. Downscale. + 5. Layer and write output as necessary. + + :param float future_time: See description in ``self.run``. + :returns: Processed input forcings for the current timestep. + :rtype: forcingInputMod.InputForcings | None """ ana_factor = 1 if self._bmi._job_meta.ana_flag is False else 0 if not self._bmi._job_meta.precip_only_flag: @@ -462,18 +454,14 @@ def loop_through_forcing_products( def __handle_aorc_and_nwm_force_keys( self, input_forcings: forcingInputMod.InputForcings, force_key: int ) -> None: - """During `loop_through_forcing_products`, handle the case of the force key being AORC or NWM. + """During ``loop_through_forcing_products``, handle the case where the force key is AORC or NWM. - This code block was cut and pasted from methods `loop_through_forcing_products` during refactor. + This code block was cut and pasted from the method ``loop_through_forcing_products`` during refactor. - Parameters - ---------- - input_forcings : forcingInputMod.InputForcings - force_key : int + :param input_forcings forcingInputMod.InputForcings: Input forcings object to be modified. + :param int force_key: Identifier for the forcing type. - Warnings - -------- - Modifies mutable arguments in-place. + :warning: Modifies mutable arguments in-place. """ if force_key in [12, 21, 27]: if self._bmi._job_meta.aws is None: @@ -548,18 +536,15 @@ def __handle_aorc_and_nwm_force_keys( def __process_supp_precip_key( self, input_forcings: forcingInputMod.InputForcings, supp_pcp_key: int ) -> None: - """Process supplemental precipitation for one supplemental precipitation key. + """Process supplemental precipitation for a single supplemental precipitation key. - This code block was cut and pasted from methods `loop_through_forcing_products` and `process_suplemental_precip` during refactor. + This code block was cut and pasted from the methods + ``loop_through_forcing_products`` and ``process_suplemental_precip`` during refactor. - Parameters - ---------- - input_forcings : forcingInputMod.InputForcings - supp_pcp_key : int + :param input_forcings forcingInputMod.InputForcings: Input forcings object to be modified. + :param int supp_pcp_key: Identifier for the supplemental precipitation forcing. - Warnings - -------- - Modifies mutable arguments in-place. + :warning: Modifies mutable arguments in-place. """ # Like with input forcings, calculate the neighboring files to use. self._bmi._supp_pcp_mod[supp_pcp_key].calc_neighbor_files( @@ -612,19 +597,15 @@ def __process_supp_precip_key( self.check_program_status() def __use_rstFlag(self, input_forcings: forcingInputMod.InputForcings) -> None: - """ - If we are restarting a forecast cycle, re-calculate the neighboring files, and regrid the - next set of forcings as the previous step just regridded the previous forcing. + """If restarting a forecast cycle, re-calculate neighboring files and regrid the + next set of forcings, as the previous step regridded the prior forcing. - This code block was cut and pasted from method `loop_through_forcing_products` during refactor. + This code block was cut and pasted from the method + ``loop_through_forcing_products`` during refactor. - Parameters - ---------- - input_forcings : forcingInputMod.InputForcings + :param input_forcings forcingInputMod.InputForcings: Input forcings object to be modified. - Warnings - -------- - Modifies mutable arguments in-place. + :warning: Modifies mutable arguments in-place. """ if input_forcings.rstFlag == 1: if ( @@ -673,13 +654,9 @@ def process_suplemental_precip( ) -> None: """Process supplemental precipitation for the current forecast cycle. - Parameters - ---------- - input_forcings : forcingInputMod.InputForcings + :param input_forcings forcingInputMod.InputForcings: Input forcings object to be modified. - Warnings - -------- - Modifies mutable arguments in-place. + :warning: Modifies mutable arguments in-place. """ if self._bmi._job_meta.customSuppPcpFreq is not None: # Process supplemental precipitation if we specified in the configuration file. @@ -707,20 +684,21 @@ def write_output(self) -> None: def update_bmi_output_dict(self) -> None: """Flatten the Forcings Engine output object and update the BMI dictionary. - Loop through Forcings Engine output object - and flatten the 2D forcing array and append to - the BMI object to advertise to BMIinterface. - 0.) U-Wind (m/s) - 1.) V-Wind (m/s) - 2.) Surface incoming longwave radiation flux (W/m^2) - 3.) Precipitation rate (mm/s) - 4.) 2-meter temperature (K) - 5.) 2-meter specific humidity (kg/kg) - 6.) Surface pressure (Pa) - 7.) Surface incoming shortwave radiation flux (W/m^2) - 8.) Liquid Precipitation Fraction (%), Only available in certain operational configurations - """ + Loop through the Forcings Engine output object, flatten the 2D forcing arrays, + and append them to the BMI object for advertisement through the BMI interface. + The flattened variables are ordered as follows: + + 0. U-wind (m/s) + 1. V-wind (m/s) + 2. Surface incoming longwave radiation flux (W/m²) + 3. Precipitation rate (mm/s) + 4. 2-meter air temperature (K) + 5. 2-meter specific humidity (kg/kg) + 6. Surface pressure (Pa) + 7. Surface incoming shortwave radiation flux (W/m²) + 8. Liquid precipitation fraction (%), available only in certain operational configurations + """ variables = copy.deepcopy(model_consts["update_dict_base_vars"]) if self._bmi._job_meta.include_lqfrac == 1: variables.append(model_consts["update_dict_var_include_lqfraq"]) From 0ad06fa3248451870704ab33ffb0e637df2829f4 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Fri, 1 May 2026 20:35:50 -0400 Subject: [PATCH 49/71] DRYify --- .../NextGen_Forcings_Engine/model.py | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 5fc169b8..ac691d09 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -423,7 +423,7 @@ def loop_through_forcing_products( self._bmi._job_meta.currentForceNum += 1 - # TODO what is this? + # NOTE currentCustomForceNum does not appear to be used. if force_key == 10: self._bmi._job_meta.currentCustomForceNum += 1 @@ -463,6 +463,8 @@ def __handle_aorc_and_nwm_force_keys( :warning: Modifies mutable arguments in-place. """ + proc_args = (self._bmi._job_meta, self._bmi._mpi_meta, self._bmi.geo_meta) + if force_key in [12, 21, 27]: if self._bmi._job_meta.aws is None: # Calculate the previous and next input cycle files from the inputs. @@ -480,18 +482,10 @@ def __handle_aorc_and_nwm_force_keys( # Flag to indicate the AWS .zarr AORC method if force_key == 12: if self.source_data_processor is None: - self.source_data_processor = AORCConusProcessor( - self._bmi._job_meta, - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) + proc_cls = AORCConusProcessor elif force_key == 21: if self.source_data_processor is None: - self.source_data_processor = AORCAlaskaProcessor( - self._bmi._job_meta, - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) + proc_cls = AORCAlaskaProcessor # Flag to indicate the AWS .zarr NWMv3 Forcing file method elif force_key == 27: @@ -517,16 +511,13 @@ def __handle_aorc_and_nwm_force_keys( ) ) elif self._bmi._job_meta.nwm_domain == "Alaska": - self.source_data_processor = NWMV3AlaskaProcessor( - self._bmi._job_meta, - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) + proc_cls = NWMV3AlaskaProcessor else: raise ValueError( f"Unsupported domain type ({self._bmi._job_meta.nwm_domain} for forcing type: {force_key} )" ) + self.source_data_processor = proc_cls(*proc_args) self._bmi._job_meta.aws_obj = ( self.source_data_processor.process_historical_data( self._bmi._job_meta.current_time From 4e027d6a9fd4174601a2e8a4d49d733b6a1a58b0 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Fri, 1 May 2026 20:36:50 -0400 Subject: [PATCH 50/71] Add assertion --- NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index ac691d09..843791d0 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -516,6 +516,8 @@ def __handle_aorc_and_nwm_force_keys( raise ValueError( f"Unsupported domain type ({self._bmi._job_meta.nwm_domain} for forcing type: {force_key} )" ) + else: + raise ValueError(f"Unexpected force_key: {force_key}") self.source_data_processor = proc_cls(*proc_args) self._bmi._job_meta.aws_obj = ( From 9f4f2a71c97b6417a7b4be30f29b80ac2af003cc Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Fri, 1 May 2026 21:04:34 -0400 Subject: [PATCH 51/71] Fix source_data_processor sets --- .../NextGen_Forcings_Engine/model.py | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 843791d0..567c5b87 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -479,17 +479,14 @@ def __handle_aorc_and_nwm_force_keys( raise ValueError( f"Expected to have 1 forcing key, but have {len(self._bmi._job_meta.input_forcings)}: {list(self._bmi._job_meta.input_forcings)}" ) - # Flag to indicate the AWS .zarr AORC method - if force_key == 12: - if self.source_data_processor is None: + if self.source_data_processor is None: + # Flag to indicate the AWS .zarr AORC method + if force_key == 12: proc_cls = AORCConusProcessor - elif force_key == 21: - if self.source_data_processor is None: + elif force_key == 21: proc_cls = AORCAlaskaProcessor - - # Flag to indicate the AWS .zarr NWMv3 Forcing file method - elif force_key == 27: - if self.source_data_processor is None: + # Flag to indicate the AWS .zarr NWMv3 Forcing file method + elif force_key == 27: if self._bmi._job_meta.nwm_domain == "CONUS": self.source_data_processor = NWMV3ConusProcessor( self._bmi._job_meta, @@ -516,10 +513,10 @@ def __handle_aorc_and_nwm_force_keys( raise ValueError( f"Unsupported domain type ({self._bmi._job_meta.nwm_domain} for forcing type: {force_key} )" ) - else: - raise ValueError(f"Unexpected force_key: {force_key}") + else: + raise ValueError(f"Unexpected force_key: {force_key}") + self.source_data_processor = proc_cls(*proc_args) - self.source_data_processor = proc_cls(*proc_args) self._bmi._job_meta.aws_obj = ( self.source_data_processor.process_historical_data( self._bmi._job_meta.current_time From 99f932d4264f15e4daebf3148a3ef77b1c556467 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Fri, 1 May 2026 21:07:30 -0400 Subject: [PATCH 52/71] Docstrings --- .../NextGen_Forcings_Engine/model.py | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 567c5b87..b72e3e2f 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -110,20 +110,16 @@ def run(self, future_time: float) -> None: and analysis mode (AnA or forecast). 2. Initialize or reset output grids and step counters. 3. Loop over each input forcing product: - - a. Calculate neighboring input files. - b. Load AWS-hosted Zarr datasets if needed. - c. Regrid input forcings to the model grid. - d. Perform temporal interpolation. - e. Apply bias correction and downscaling. - f. Layer final forcings into the output object. - + a. Calculate neighboring input files. + b. Load AWS-hosted Zarr datasets if needed. + c. Regrid input forcings to the model grid. + d. Perform temporal interpolation. + e. Apply bias correction and downscaling. + f. Layer final forcings into the output object. 4. Optionally process supplemental precipitation forcings: - - a. Regrid and validate. - b. Disaggregate and interpolate. - c. Layer into the final output. - + a. Regrid and validate. + b. Disaggregate and interpolate. + c. Layer into the final output. 5. Write output to NetCDF forcing files if requested. 6. Update the ``self._bmi._values`` state dictionary with flattened arrays. 7. Advance the BMI time index. @@ -433,7 +429,7 @@ def loop_through_forcing_products( if self._bmi._job_meta.number_supp_pcp > 0: for supp_pcp_key in self._bmi._job_meta.supp_precip_forcings: if supp_pcp_key != 13: - # Below comment copied from earlier code, the comment had been just above the call to `disaggregate_fun`. + # Below comment copied from earlier code, the comment had been just above the call to ``disaggregate_fun``. # TODO input_forcings has not yet been initialized, so this is a bug waiting to happen self.__process_supp_precip_key(input_forcings, supp_pcp_key) From f58cd4223642a0ceaa2e1af54f55886f868657ac Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Mon, 13 Jul 2026 10:05:59 -0500 Subject: [PATCH 53/71] comment out not implemented error. --- .../NextGen_Forcings_Engine/model.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index b72e3e2f..9e5a9a36 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -276,14 +276,18 @@ def loop_through_forcing_products( self._bmi._job_meta.current_output_step += 1 # Optional sub-output timestamp - if self._bmi._job_meta.sub_output_hour is not None: - raise NotImplementedError( - f"sub_output_hour (config SubOutputHour) is {repr(self._bmi._job_meta.sub_output_hour)} (not None) but is not used." - ) - # TODO This is not used - subOutDate = self._bmi._job_meta.first_fcst_cycle + datetime.timedelta( - hours=self._bmi._job_meta.sub_output_hour - ) + # if self._bmi._job_meta.sub_output_hour is not None: + # raise NotImplementedError( + # f"sub_output_hour (config SubOutputHour) is {repr(self._bmi._job_meta.sub_output_hour)} (not None) but is not used." + # ) + # # TODO This is not used. The raise not implemented error causes a fail on medium range blen due to the sub_output_hour being + # specified in the config file. Testing was performed and not specifying sub_output_hour produces the same results for medium range blend + # as of 7/13/2026. Not sure what this was intended to do but it is not used/effective at this time. Commenting it out to ensure medium range blend completes + # and it is retained in case the intent is realized and it should be resurrected. + + # subOutDate = self._bmi._job_meta.first_fcst_cycle + datetime.timedelta( + # hours=self._bmi._job_meta.sub_output_hour + # ) # Compute the output timestamp for this step if self._bmi._job_meta.ana_flag: From 28454cf0821cc7422619d8b3aebf6708a4736099 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Thu, 13 Aug 2026 14:03:08 -0400 Subject: [PATCH 54/71] Remove duplicate method --- .../NextGen_Forcings_Engine/core/config.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py index 3bc060a3..8f03e093 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py @@ -157,11 +157,6 @@ def supp_precip_count(self) -> int: # return len(SUPPPRECIPMOD["suppPrecipMod"]["PRODUCT_NAMES"]) return 15 - @property - def number_supp_pcp(self) -> int: - """Calculate the number of supplemental precip forcings specified by the user in the configuration file.""" - return len(self.supp_precip_forcings) - @property def precip_only_flag(self) -> bool: """Flag to indicate whether the user has chosen to run the supplemental precip forcings module only, which will trigger some different processing pathways and error checking for certain configuration options.""" From 2535bcc03c7641abfdaf531d8f0bed26b61ec8ac Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 17 Aug 2026 08:47:32 -0400 Subject: [PATCH 55/71] Following refactor+rebase: update CAT-ID assignments and init calls, fix namespace error, remove call to `validate_config` (validation occurs automatically in new design) --- .../NextGen_Forcings_Engine/bmi_model.py | 21 ++++++++----------- .../NextGen_Forcings_Engine/model.py | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index a780e744..c63d0afa 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -223,11 +223,10 @@ def _job_meta(self) -> ConfigOptions: def _job_meta(self, value: ConfigOptions) -> None: """Set the job metadata object.""" if value is None: - value = ConfigOptions( - self.cfg_bmi, b_date=self._b_date, geogrid_arg=self._geogrid - ) try: - value.validate_config(self.cfg_bmi) + value = ConfigOptions( + self.cfg_bmi, b_date=self._b_date, geogrid=self._geogrid + ) except KeyboardInterrupt as e: err_handler.err_out_screen("User keyboard interrupt", e) except ImportError as e: @@ -281,7 +280,7 @@ def init_scratch_dir(self) -> None: self._job_meta.uniquefy_scratch_dir_as_child(self._mpi_meta.uid64) def create_esmf_mesh(self) -> None: - """Create the ESMF mesh for the model.""" + """Create the ESMF mesh for the model and set ``self._cat_ids`` (later used as BMI variable "CAT-ID").""" if self._mpi_meta.rank == 0: cat_ids = esmf_creation.create_mesh(self._job_meta) cat_count = np.array([ @@ -291,6 +290,7 @@ def create_esmf_mesh(self) -> None: if self._mpi_meta.rank != 0: cat_ids = np.empty(cat_count[0], dtype=np.int64) self._mpi_meta.comm.Bcast(cat_ids, root=0) + self._cat_ids = cat_ids def fetch_raw_forcing_data(self) -> None: """Fetch raw forcing data for the model. @@ -411,12 +411,11 @@ def set_initial_time_and_step(self) -> None: """Set the initial time and time step size for the model.""" self._values["current_model_time"] = self.cfg_bmi["initial_time"] self._values["time_step_size"] = self.cfg_bmi["time_step_seconds"] - self._values["CAT-ID"] = cat_ids def set_catchment_ids(self) -> None: """Set catchment ids if using hydrofabric.""" if self._grid_type == "hydrofabric": - self._values["CAT-ID"] = self.geo_meta.element_ids_global + self._values["CAT-ID"] = self._cat_ids def initialize(self, config_file: str) -> None: """Initialize the model using a configuration file. @@ -435,7 +434,7 @@ def initialize(self, config_file: str) -> None: self._config_file = config_file for attr in BMI_MODEL[self.__class__.__base__.__name__]: setattr(self, attr, None) - self._model = NWMv3ForcingEngineModel() + self._model = NWMv3ForcingEngineModel(self) self.init_log() self.init_mpi() self.init_scratch_dir() @@ -1540,7 +1539,6 @@ class NWMv3_Forcing_Engine_BMI_model_Gridded(NWMv3_Forcing_Engine_BMI_model_Base def __init__( self, - config_file: str, b_date: str = None, geogrid: str = None, output_path: str = None, @@ -1549,7 +1547,7 @@ def __init__( Initializes the model with default values for time, variables, and grid types. """ - super().__init__(config_file, b_date, geogrid, output_path) + super().__init__(b_date, geogrid, output_path) self.GeoMeta = GriddedGeoMeta def grid_ranks(self) -> list[int]: @@ -1679,7 +1677,6 @@ class NWMv3_Forcing_Engine_BMI_model_Unstructured(NWMv3_Forcing_Engine_BMI_model def __init__( self, - config_file: str, b_date: str = None, geogrid: str = None, output_path: str = None, @@ -1688,7 +1685,7 @@ def __init__( Initializes the model with default values for time, variables, and grid types. """ - super().__init__(config_file, b_date, geogrid, output_path) + super().__init__(b_date, geogrid, output_path) self.GeoMeta = UnstructuredGeoMeta def grid_ranks(self) -> list[int]: diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 9e5a9a36..41fad2b9 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -711,7 +711,7 @@ def update_bmi_output_dict(self) -> None: self._bmi._values[f"{variable}_ELEMENT"] = ( self._bmi._output_obj.output_global[count, :].flatten() ) - self._bmi._values["CAT-ID"] = self._bmi.geo_meta.element_ids_global + self._bmi._values["CAT-ID"] = self._bmi._cat_ids else: raise ValueError( f"Unexpected grid_type: {repr(self._bmi._job_meta.grid_type)}" From 800d3e897a5674d344398ea7420afac7f3c04c65 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 17 Aug 2026 18:13:32 -0400 Subject: [PATCH 56/71] Ruff reorder imports --- tests/test_utils.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 2b0d4a68..e50aac9e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -12,17 +12,6 @@ import test_config_classes # noqa: F401 # Used by test implementations, more convenient to have it in here rather than using more importlib import test_consts # noqa: F401 # Used by test implementations, more convenient to have it in here rather than using more importlib import xarray as xr -from test_config_classes import ( - TestConfig_AnA, - TestConfig_Base, - TestConfig_BmiModel, - TestConfig_ConfigOptions, - TestConfig_GeoMod, - TestConfig_InputForcing, - TestConfig_Regrid, - TestConfig_SuppPrecip, -) - from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.bmi_model import ( BMIMODEL, NWMv3_Forcing_Engine_BMI_model_Base, @@ -44,6 +33,16 @@ assert_equal_with_tol, serialize_to_json, ) +from test_config_classes import ( + TestConfig_AnA, + TestConfig_Base, + TestConfig_BmiModel, + TestConfig_ConfigOptions, + TestConfig_GeoMod, + TestConfig_InputForcing, + TestConfig_Regrid, + TestConfig_SuppPrecip, +) OS_VAR__CREATE_TEST_EXPECT_DATA = "FORCING_PYTEST_WRITE_TEST_EXPECTED_DATA" From 4451dad7122c0b38e19a69e99cd4e25271222ea1 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 17 Aug 2026 18:14:36 -0400 Subject: [PATCH 57/71] Tests: update for new BMI forcing initialization method --- tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index e50aac9e..23233fe6 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -284,7 +284,7 @@ class BMIForcingFixture: def __init__(self, cfg: TestConfig_Base) -> None: """Initialize BMIForcingFixture.""" self.bmi_model: NWMv3_Forcing_Engine_BMI_model_Base = BMIMODEL[cfg.grid_type]() - self.bmi_model.initialize_with_params(config_file=cfg.config_file) + self.bmi_model.initialize(cfg.config_file) self.bmi_model_values = self.bmi_model._values self.mpi_config: MpiConfig = self.bmi_model._mpi_meta From 759d7431c4f4a3e564fcfe21e2560d6a75bb3ce0 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 17 Aug 2026 18:15:25 -0400 Subject: [PATCH 58/71] Tests: improve test data serialization/deserialization logic --- tests/test_utils.py | 76 +++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 23233fe6..43012925 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -386,40 +386,35 @@ def deserial_expected(self, suffix: str, current_output_step: str = "") -> dict: """Get the expected metadata results as a deserialized dictionary.""" file_path = self.expected_results_file_path(suffix, current_output_step) - if os.environ.get(OS_VAR__CREATE_TEST_EXPECT_DATA, "").lower() == "true": - # Dump current results to disk, to save it as "expected" results for later test runs. - # Should only be used when committing new test results to the repository. - logging.warning(f"Writing test data: {file_path}") - deserial_expected = self.deserial_actual( - suffix, current_output_step, write_to_file=False - ) - with open(file_path, "w") as f: - f.write(serialize_to_json(deserial_expected, sort_keys=True)) - # Remove keys that should be excluded from comparison (match read-exclusion) - deserial_expected = remove_key(deserial_expected, self.keys_to_exclude) + try: + with open(file_path) as f: + deserial_expected = json.load(f) if self.map_old_to_new_var_names: deserial_expected = self.map_old_to_new_variable_names( deserial_expected ) self._trim_arrays_to_input_map_output(deserial_expected) - return deserial_expected - else: - try: - with open(file_path) as f: - deserial_expected = json.load(f) - if self.map_old_to_new_var_names: - deserial_expected = self.map_old_to_new_variable_names( - deserial_expected - ) - self._trim_arrays_to_input_map_output(deserial_expected) - # Remove keys that should be excluded from comparison (match write-exclusion) - deserial_expected = remove_key(deserial_expected, self.keys_to_exclude) - # order and reverse so private attributes are last - return OrderedDict(reversed(list(deserial_expected.items()))) - except FileNotFoundError as e: - raise FileNotFoundError( - f"Could not find {file_path}. Try running the test using OS var {OS_VAR__CREATE_TEST_EXPECT_DATA}=true first to set up the test results expected data." - ) from e + # Remove keys that should be excluded from comparison + deserial_expected = remove_key(deserial_expected, self.keys_to_exclude) + # order and reverse so private attributes are last + return OrderedDict(reversed(list(deserial_expected.items()))) + except FileNotFoundError as e: + raise FileNotFoundError( + f"Could not find {file_path}. Try running the test using OS var {OS_VAR__CREATE_TEST_EXPECT_DATA}=true first to set up the test results expected data." + ) from e + + def _write_expected_file(self, actual_data: dict, suffix: str, current_output_step: str = "") -> None: + """Write actual data to expected results file for test data generation. + + This is a separate explicit step in the workflow to avoid confusion between + expected and actual data. Should only be called when FORCING_PYTEST_WRITE_TEST_EXPECTED_DATA=true. + """ + file_path = self.expected_results_file_path(suffix, current_output_step) + # Remove excluded keys before writing + data_to_write = remove_key(dict(actual_data), self.keys_to_exclude) + logging.warning(f"Writing test data: {file_path}") + with open(file_path, "w") as f: + f.write(serialize_to_json(data_to_write, sort_keys=True)) def map_old_to_new_variable_names(self, data: dict) -> dict: """Map old variable names to new variable names in the expected results data.""" @@ -440,7 +435,11 @@ def after_intitialization_check(self) -> None: orig = self.keys_to_exclude self.keys_to_exclude = orig + self.keys_to_exclude_at_init try: - self.compare(self.deserial_actual("init"), self.deserial_expected("init")) + actual = self.deserial_actual("init") + if os.environ.get(OS_VAR__CREATE_TEST_EXPECT_DATA, "").lower() == "true": + self._write_expected_file(actual, "init") + expected = self.deserial_expected("init") + self.compare(actual, expected) finally: self.keys_to_exclude = orig @@ -474,17 +473,20 @@ def after_bmi_model_update(self, current_output_step: int) -> None: """ logging.info("Starting after_bmi_model_update()...") - self.compare( - self.deserial_actual("after_update", f"_step_{current_output_step}"), - self.deserial_expected("after_update", f"_step_{current_output_step}"), - ) + actual = self.deserial_actual("after_update", f"_step_{current_output_step}") + if os.environ.get(OS_VAR__CREATE_TEST_EXPECT_DATA, "").lower() == "true": + self._write_expected_file(actual, "after_update", f"_step_{current_output_step}") + expected = self.deserial_expected("after_update", f"_step_{current_output_step}") + self.compare(actual, expected) def after_finalize(self) -> None: """Run checks after bmi_model.finalize() has been called.""" logging.info("Starting after_finalize()...") - self.compare( - self.deserial_actual("finalize"), self.deserial_expected("finalize") - ) + actual = self.deserial_actual("finalize") + if os.environ.get(OS_VAR__CREATE_TEST_EXPECT_DATA, "").lower() == "true": + self._write_expected_file(actual, "finalize") + expected = self.deserial_expected("finalize") + self.compare(actual, expected) def actual_results_file_path( self, suffix: str, current_output_step: str = "" From 6e5855111827f91e008deb0bdfc9fb2d905d0f2c Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 17 Aug 2026 18:16:11 -0400 Subject: [PATCH 59/71] Tests: bmi_model: exclude more keys --- tests/bmi_model/test_bmi_model.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/bmi_model/test_bmi_model.py b/tests/bmi_model/test_bmi_model.py index 274d1795..80461061 100644 --- a/tests/bmi_model/test_bmi_model.py +++ b/tests/bmi_model/test_bmi_model.py @@ -21,7 +21,12 @@ config_file=consts.RETRO_FORCING_CONFIG_FILE__AORC_CONUS, keys_to_check=(), keys_to_exclude=tuple( - set(consts.KEYS_TO_EXCLUDE) | {"d_program_init", "geogrid", "scratch_dir", "Element_Elevation", "Element_Slope", "Element_Slope_Azmuith"} + set(consts.KEYS_TO_EXCLUDE) | { + "d_program_init", "geogrid", "scratch_dir", "Element_Elevation", "Element_Slope", "Element_Slope_Azmuith", + "geo_meta.config_options.cfg_bmi", + "geo_meta.mpi_config.config_options", + "mpi_config.config_options", + } ), grid_type=consts.GRID_TYPE, test_file_name_prefix="bmi_model", From c46eb32a41d350be3f7a77121b37ca7ee1897454 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 17 Aug 2026 21:19:32 -0400 Subject: [PATCH 60/71] Fix various config handling issues following refactor + rebase. Notably if rqiMethod is 0 (unused) then rqiThresh property now resolves to None regardless of the value of the RqiThresh key in the config file. --- .../NextGen_Forcings_Engine/core/config.py | 174 ++++++++++++------ 1 file changed, 120 insertions(+), 54 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py index 8f03e093..868d7d1c 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py @@ -46,6 +46,14 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No else: self.user_provided_geogrid_flag = False + # If b_date not provided, try to read from config file + if b_date is None: + b_date = cfg_bmi.get("RefcstBDateProc", None) + if b_date is None: + err_out_screen( + "RefcstBDateProc is either missing or None in configuration file." + ) + self.b_date_proc = b_date self.cfg_bmi = cfg_bmi self.geogrid = geogrid @@ -63,19 +71,44 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No self.nwm_source = "s3://noaa-nwm-retrospective-3-0-pds" self._scratch_dir_has_been_uniquefied = False - self.supp_precip_forcings = self.extract_input_variable("SuppPcp") - if not self.precip_only_flag: - self.input_forcings = self.extract_input_variable("InputForcings") - - # Create temporary array to hold flags if we need input parameter files. - self.param_flag = np.zeros([len(self.input_forcings)], int) - - # set list of attibutes from consts.py to None. - # These are indexed from the consts dictionary using the class name + + # These must exist (as None) before the properties are accessed + self._supp_precip_forcings = None + self._b_date_proc = None + self._input_forcings = None + self._nwm_geogrid = None + self._output_freq = None + self._sub_output_hour = None + self._sub_output_freq = None + self._scratch_dir = None + self._useCompression = None + self._ana_flag = None + self._look_back = None + self._fcst_freq = None + self._spatial_meta = None + self._geopackage = None + self._geogrid = None + self._grid_type = None + + # set list of attributes from consts.py to None early on in the init process. + # These are indexed from the consts dictionary. + # This must happen before accessing properties like precip_only_flag for attr in CONFIGOPTIONS[self.__class__.__name__]: setattr(self, attr, None) self.broadcast_new_64bit_uid() + # Extract optional forcing inputs (SuppPcp, InputForcings) from config; default to empty lists if not provided since code assumes these are always iterable + supp_pcp = self.extract_input_variable("SuppPcp") + self.supp_precip_forcings = supp_pcp if supp_pcp is not None else [] + if not self.precip_only_flag: + input_forc = self.extract_input_variable("InputForcings") + self.input_forcings = input_forc if input_forc is not None else [] + # Create temporary array to hold flags if we need input parameter files. + self.param_flag = np.zeros([len(self.input_forcings)], int) + else: + self.input_forcings = [] + self.param_flag = np.array([], int) + for ( cfg_bmi_attr, config_options_attr, @@ -107,6 +140,11 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No self.set_attrs(CONFIGOPTIONS["downscaling_attrs_map"]) if self.grid_type == "unstructured": self.set_attrs(CONFIGOPTIONS["downscaling_unstructred_attrs_map"]) + else: + # Initialize downscaling attributes to None even if downscaling is not performed + self.set_attrs(CONFIGOPTIONS["downscaling_attrs_map"], set_none=True) + if self.grid_type == "unstructured": + self.set_attrs(CONFIGOPTIONS["downscaling_unstructred_attrs_map"], set_none=True) for cfg_bmi_attr, config_options_attr in CONFIGOPTIONS[ "extract_input_variable_set_default_attrs_map" @@ -121,10 +159,28 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No self.extract_input_variable_set_default(cfg_bmi_attr, default), ) + # Call post_init to perform any calculations that depend on multiple attributes + self.post_init() + + def post_init(self) -> None: + """Attr setting/calculating operations that depend on others already being set. + + This method is called at the end of __init__ to perform any side-effect calculations + that require multiple attributes to be initialized. This ensures independence of initialization order + and matches the original pre-refactored code behavior, where calculations + were performed after all attrs were read. + """ + # Calculate the beginning/ending processing dates if we are running realtime or if look_back != -9999 + if self.look_back is not None and self.look_back != -9999: + calculate_lookback_window(self) + elif self.realtime_flag: + calculate_lookback_window(self) + @property def try_config_get_except_attr_map(self) -> dict: """Get the mapping of configuration variable names to class attribute names for variables that are extracted directly from the configuration file without any additional processing. This is used to control how variables are extracted from the configuration file and assigned to class attributes in a consistent way based on the mapping specified in the consts.py file.""" - dict_map = CONFIGOPTIONS["try_config_get_except_attr_map"] + # Don't mutate the module-level CONFIGOPTIONS object. Operate on a copy instead (and return that modified copy). + dict_map = CONFIGOPTIONS["try_config_get_except_attr_map"].copy() if self._b_date_proc is not None and "RefcstBDateProc" in dict_map: dict_map.pop("RefcstBDateProc") if self.geogrid is not None and "GeogridIn" in dict_map: @@ -161,7 +217,7 @@ def supp_precip_count(self) -> int: def precip_only_flag(self) -> bool: """Flag to indicate whether the user has chosen to run the supplemental precip forcings module only, which will trigger some different processing pathways and error checking for certain configuration options.""" precip_only = False - if self.number_supp_pcp == 1: + if self.supp_precip_forcings is not None and len(self.supp_precip_forcings) > 0: if int(self.supp_precip_forcings[0]) == 14: precip_only = True return precip_only @@ -337,7 +393,7 @@ def supp_precip_forcings(self): @supp_precip_forcings.setter def supp_precip_forcings(self, value: list) -> None: """Set the list of supplemental precip forcing options specified by the user in the configuration file. This is used to control which supplemental precip forcings are processed and how they are processed based on the other configuration options specified for each supplemental precip forcing.""" - if len(value) > 0: + if value is not None and len(value) > 0: self.check_input_values_in_range( [int(i) for i in value], "SuppPcp", @@ -456,8 +512,7 @@ def look_back(self, value: int) -> None: """Set the look back window in hours specified by the user in the configuration file. This is used to calculate the processing window for reforecast simulations, and is only necessary if the user is running a reforecast simulation with a specified processing window rather than a realtime simulation.""" if value <= 0 and value != -9999: err_out_screen("Please specify a positive LookBack or -9999 for realtime.") - if value != -9999: - calculate_lookback_window(self) + # NOTE: Side effect (calculate_lookback_window) removed - now called in post_init() self._look_back = value @property @@ -510,8 +565,12 @@ def b_date_proc(self) -> str: @b_date_proc.setter def b_date_proc(self, value: str | datetime) -> None: """Set the beginning date of processing for reforecast simulations. This is used to calculate the processing window for reforecast simulations.""" + if value is None: + self._b_date_proc = None + return if isinstance(value, datetime): self._b_date_proc = value + return if value != -9999: if isinstance(value, str) and len(value) != 12: err_out_screen( @@ -537,9 +596,7 @@ def realtime_flag(self) -> bool: value = True else: value = False - # Calculate the beginning/ending processing dates if we are running realtime - if value: - calculate_lookback_window(self) + # NOTE: Side effect (calculate_lookback_window) removed from property getter - now called in post_init() return value @property @@ -573,11 +630,13 @@ def geogrid(self) -> str: @geogrid.setter def geogrid(self, value: str) -> None: """Set the pathway to the geogrid file to be used for processing. This is used to specify the grid information for regridding input forcings, and is only necessary if the user is running a simulation that requires regridding of input forcings.""" + # If user provided geogrid, use it as-is if self.user_provided_geogrid_flag: self._geogrid = value - if value is None: + # If value is None, just set to None + elif value is None: self._geogrid = value - # err_out_screen("Unable to locate GeogridIn in the configuration file.") + # Otherwise, process the path value from config with uid prefix else: geogrid_parent = os.path.dirname(value) geogrid_filename = os.path.basename(value) @@ -607,7 +666,7 @@ def input_forcings(self) -> list: @input_forcings.setter def input_forcings(self, value: list) -> None: """Set the list of input forcing options specified by the user in the configuration file. This is used to control which input forcings are processed and how they are processed based on the other configuration options specified for each input forcing.""" - if not self.precip_only_flag: + if value is not None and not self.precip_only_flag: self.check_input_values_in_range( value, "InputForcings", list(range(1, self.force_count + 1)) ) @@ -616,12 +675,15 @@ def input_forcings(self, value: list) -> None: @property def number_inputs(self) -> int: """Calculate the number of input forcing options specified by the user in the configuration file. This is used for error checking to ensure users specify valid input forcing options in the configuration file, and to control the flow of the program based on how many input forcings are being processed.""" + if self.input_forcings is None: + return 0 if not self.precip_only_flag: if len(self.input_forcings) == 0: err_out_screen( "Please choose at least one InputForcings dataset to process" ) return len(self.input_forcings) + return 0 @property def number_custom_inputs(self) -> int: @@ -635,6 +697,11 @@ def number_custom_inputs(self) -> int: else: return 0 + @number_custom_inputs.setter + def number_custom_inputs(self, value: int) -> None: + """This is a read-only computed property based on input_forcings.""" + raise AttributeError(f"number_custom_inputs is read-only (tried to set to: {value})") + @property def nwm_geogrid(self) -> str: """Only for the NWM v3 retorspective forcing module option (27) that requires the geo_em_NWM_DOMAIN.nc file as input for the NextGen Forcings Engine to properly setup up the ESMF grid object for the NWM forcing files since that information is not readily available in the NWM v3 retrospective forcing files.""" @@ -643,7 +710,7 @@ def nwm_geogrid(self) -> str: @nwm_geogrid.setter def nwm_geogrid(self, value: str) -> None: """Set the pathway to the NWM geogrid file specified by the user in the configuration file. This is used to specify the grid information for regridding NWM input forcings, and is only necessary if the user has chosen to regrid NWM input forcings in the configuration file.""" - if not self.precip_only_flag and 27 in self.input_forcings: + if not self.precip_only_flag and self.input_forcings is not None and 27 in self.input_forcings: self._nwm_geogrid = value else: self._nwm_geogrid = None @@ -746,9 +813,7 @@ def fcst_shift(self) -> int: def fcst_shift(self, value: int) -> None: if True: # was: self.realtime_flag: self.check_input_values_non_negative([value], "ForecastShift") - # Calculate the beginning/ending processing dates if we are running realtime - if self.realtime_flag: - calculate_lookback_window(self) + # NOTE: Side effect (calculate_lookback_window) removed - now called in post_init() self._fcst_shift = value # NOTE this commented out code copied from pre-refactored code on 5/6/2026 @@ -1284,6 +1349,8 @@ def runCfsNldasBiasCorrect(self) -> bool: @property def number_supp_pcp(self) -> int: """Get the number of supplemental precipitation input forcings specified by the user in the configuration file. This is used to control how many supplemental precipitation input forcings are processed based on the number of supplemental precipitation input forcings specified in the configuration file.""" + if self.supp_precip_forcings is None: + return 0 return len(self.supp_precip_forcings) @property @@ -1312,7 +1379,7 @@ def supplemental_precip_file_type_options(self) -> list: return ["GRIB1", "GRIB2", "NETCDF"] @property - def rqiMethod(self) -> list: + def rqiMethod(self) -> int | list[int] | None: """Optional RQI method for radar-based data. 0 - Do not use any RQI filtering. Use all radar-based estimates. 1 - Use hourly MRMS Radar Quality Index grids, 2 - Use NWM monthly climatology grids (NWM only!!!!). Example- RqiMethod: 2 @@ -1322,46 +1389,45 @@ def rqiMethod(self) -> list: for suppOpt in self.supp_precip_forcings: # Read in RQI threshold to apply to radar products. if suppOpt in (1, 2, 7, 10, 11, 12): - value = self.extract_input_variable("RqiMethod") - - # Check that if we have more than one RqiMethod, it's the correct number - if type(value) is list: - self.check_number_of_inputs_supp_pcp(value, "RqiMethod") - elif type(value) is int: - # Support 'classic' mode of single method - value = [value] * self.number_supp_pcp - - # Make sure the RqiMethod(s) makes sense. - for method in value: - self.check_input_values_in_range(method, "RqiMethod", [0, 1, 2]) + # Returns None if key missing (not configured for this product) + value = self.cfg_bmi.get("RqiMethod") + if value is not None: + # Validate + if type(value) is list: + self.check_number_of_inputs_supp_pcp(value, "RqiMethod") + elif type(value) in (int, type(None)): + # Support configuration file representing this with a single scalar value, apply to all + value = [value] * self.number_supp_pcp + + self.check_input_values_in_range(value, "RqiMethod", [0, 1, 2]) return value @property - def rqiThresh(self): + def rqiThresh(self) -> float | list[float] | None: """Optional RQI threshold to be used to mask out. Currently used for MRMS products. Please choose a value from 0.0-1.0. Associated radar quality index files will be expected from MRMS data. Example- RqiThreshold: 0.9 """ - value = 1.0 + value = None if self.number_supp_pcp > 0: for supp_opt in self.supp_precip_forcings: # Read in RQI threshold to apply to radar products. if supp_opt in (1, 2, 7, 10, 11, 12): - value = self.extract_input_variable("RqiThresh") - - # Check that if we have more than one RqiThresh, it's the correct number - if type(value) is list: - self.check_number_of_inputs_supp_pcp(value, "RqiThresh") - elif type(value) is (int, float): - # Support 'classic' mode of single threshold - value = [value] * self.number_supp_pcp - - # Make sure the RqiThresh(es) makes sense. - for threshold in value: - if threshold < 0.0 or threshold > 1.0: - err_out_screen( - "Please specify RqiThresholds between 0.0 and 1.0." - ) + # Returns None if key missing (not configured for this product) + value = self.cfg_bmi.get("RqiThresh") + if value is not None: + # Validate + if type(value) is list: + self.check_number_of_inputs_supp_pcp(value, "RqiThresh") + elif type(value) in (int, float, type(None)): + # Support configuration file representing this with a single scalar value, apply to all + value = [value] * self.number_supp_pcp + + for threshold in value: + if threshold < 0.0 or threshold > 1.0: + err_out_screen( + "Please specify RqiThresholds between 0.0 and 1.0." + ) return value @property From 8b40324b9e44ab8a52f152c2f410de093b65ba71 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Mon, 17 Aug 2026 21:21:43 -0400 Subject: [PATCH 61/71] Test data: update expected json files for bmi_model and config_options tests relative to refactored class structures and new key exclusions in test utils --- ...i_model_after_update_n1_rank0__step_1.json | 405 ++-------- ...i_model_after_update_n1_rank0__step_2.json | 405 ++-------- ...i_model_after_update_n1_rank0__step_3.json | 405 ++-------- ...i_model_after_update_n2_rank0__step_1.json | 409 ++--------- ...i_model_after_update_n2_rank0__step_2.json | 409 ++--------- ...i_model_after_update_n2_rank0__step_3.json | 409 ++--------- ...i_model_after_update_n2_rank1__step_1.json | 407 ++--------- ...i_model_after_update_n2_rank1__step_2.json | 407 ++--------- ...i_model_after_update_n2_rank1__step_3.json | 407 ++--------- ...expected_bmi_model_finalize_n1_rank0_.json | 690 +++++++++++++++++- ...expected_bmi_model_finalize_n2_rank0_.json | 669 ++++++++++++++++- ...expected_bmi_model_finalize_n2_rank1_.json | 662 ++++++++++++++++- ...est_expected_bmi_model_init_n1_rank0_.json | 213 ++---- ...est_expected_bmi_model_init_n2_rank0_.json | 217 ++---- ...est_expected_bmi_model_init_n2_rank1_.json | 215 ++---- ...options_after_update_n1_rank0__step_1.json | 162 +++- ...options_after_update_n1_rank0__step_2.json | 162 +++- ...options_after_update_n1_rank0__step_3.json | 162 +++- ...options_after_update_n2_rank0__step_1.json | 162 +++- ...options_after_update_n2_rank0__step_2.json | 162 +++- ...options_after_update_n2_rank0__step_3.json | 162 +++- ...options_after_update_n2_rank1__step_1.json | 162 +++- ...options_after_update_n2_rank1__step_2.json | 162 +++- ...options_after_update_n2_rank1__step_3.json | 162 +++- ...ted_config_options_finalize_n1_rank0_.json | 160 +++- ...ted_config_options_finalize_n2_rank0_.json | 160 +++- ...ted_config_options_finalize_n2_rank1_.json | 160 +++- ...xpected_config_options_init_n1_rank0_.json | 160 +++- ...xpected_config_options_init_n2_rank0_.json | 160 +++- ...xpected_config_options_init_n2_rank1_.json | 160 +++- 30 files changed, 4961 insertions(+), 3786 deletions(-) diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_1.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_1.json index 40136e80..283f9511 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_1.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_1.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,6 +118,7 @@ "initial_time": 0, "time_step_seconds": 3600 }, + "dimensionality": 1, "geo_meta": { "approx_centroid_global_xy": [ -72.05503025291092, @@ -323,10 +325,29 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_time": 3600, "bmi_time_index": 1, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -354,17 +375,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -406,6 +435,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -434,24 +467,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -464,9 +502,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 @@ -723,355 +766,6 @@ "mesh_inds_elem": null, "mpi_config": { "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "config_options": { - "ExactExtract": null, - "actual_output_steps": 71, - "ana_flag": 0, - "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", - "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", - "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", - "aorc_conus_year_url": "{source}/{year}.zarr", - "aws": true, - "aws_obj": { - "attrs": {}, - "coords": { - "spatial_ref": { - "attrs": { - "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]", - "geographic_crs_name": "WGS 84", - "grid_mapping_name": "latitude_longitude", - "horizontal_datum_name": "World Geodetic System 1984", - "inverse_flattening": 298.257223563, - "longitude_of_prime_meridian": 0.0, - "prime_meridian_name": "Greenwich", - "reference_ellipsoid_name": "WGS 84", - "semi_major_axis": 6378137.0, - "semi_minor_axis": 6356752.314245179, - "spatial_ref": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" - }, - "data": 0, - "dims": [] - }, - "time": { - "attrs": { - "long_name": "verification time generated by wgrib2 function verftime()", - "reference_date": "2013.01.01 00:00:00 UTC", - "reference_time": 1356998400.0, - "reference_time_description": "kind of product unclear, reference date is variable, min found reference date is given", - "reference_time_type": 0, - "time_step": 0.0, - "time_step_setting": "auto" - }, - "data": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "dims": [] - }, - "x": { - "attrs": { - "long_name": "longitude", - "units": "degrees_east" - }, - "data": "hash_-5399622063019475031_len_28", - "dims": [ - "x" - ] - }, - "y": { - "attrs": { - "long_name": "latitude", - "units": "degrees_north" - }, - "data": "hash_-1457289664996315734_len_37", - "dims": [ - "y" - ] - } - }, - "data_vars": { - "APCP_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Total Precipitation", - "short_name": "APCP_surface", - "units": "kg/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DLWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Long-Wave Rad. Flux", - "short_name": "DLWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DSWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Short-Wave Rad. Flux", - "short_name": "DSWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "PRES_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Pressure", - "short_name": "PRES_surface", - "units": "Pa" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "SPFH_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Specific Humidity", - "short_name": "SPFH_2maboveground", - "units": "kg/kg" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "TMP_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Temperature", - "short_name": "TMP_2maboveground", - "units": "K" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "UGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "U-Component of Wind", - "short_name": "UGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "VGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "V-Component of Wind", - "short_name": "VGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - } - }, - "dims": { - "x": 28, - "y": 37 - } - }, - "aws_time": null, - "b_date_proc": "2013-07-01T00:00:00", - "bmi_time": 3600, - "bmi_time_index": 1, - "cfsv2EnsMember": null, - "config_path": null, - "cosalpha_var": null, - "currentCustomForceNum": 0, - "currentForceNum": 1, - "current_fcst_cycle": "2013-07-01T00:00:00", - "current_output_date": "2013-07-01T01:00:00", - "current_output_step": 1, - "current_time": "2013-07-01T01:00:00", - "customFcstFreq": [], - "customSuppPcpFreq": null, - "cycle_length_minutes": 4260, - "dScaleParamDirs": [ - "/ngen-app/data" - ], - "e_date_proc": null, - "elemconn_var": "elementConn", - "elemcoords_var": "centerCoords", - "element_id_var": "element_id", - "errFlag": 0, - "errMsg": null, - "fcst_freq": 60, - "fcst_input_horizons": [ - 4260 - ], - "fcst_input_offsets": [ - 0 - ], - "fcst_shift": 0, - "first_fcst_cycle": "2013-07-01T00:00:00", - "forceTemoralInterp": [ - 0 - ], - "forcing_output": 0, - "future_time": null, - "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", - "globalNdv": -9999.0, - "grid_meta": null, - "grid_type": "hydrofabric", - "hgt_elem_var": null, - "hgt_var": null, - "ignored_border_widths": [ - 0 - ], - "include_lqfrac": 1, - "input_force_dirs": [ - "s3://null" - ], - "input_force_mandatory": [ - 0 - ], - "input_force_types": [ - "GRIB2" - ], - "input_forcings": [ - 12 - ], - "lat_var": null, - "logFile": null, - "logHandle": null, - "lon_var": null, - "look_back": -9999, - "lwBiasCorrectOpt": [ - 0 - ], - "nFcsts": 1, - "nodecoords_var": "nodeCoords", - "num_output_steps": 71, - "num_supp_output_steps": null, - "number_custom_inputs": 0, - "number_inputs": 1, - "number_supp_pcp": 0, - "numelemconn_var": "numElementConn", - "nwmConfig": "AORC", - "nwmVersion": 4.0, - "nwm_domain": null, - "nwm_geogrid": null, - "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", - "nwm_url": null, - "output_freq": 60, - "paramFlagArray": null, - "precipBiasCorrectOpt": [ - 0 - ], - "precipDownscaleOpt": [ - 0 - ], - "precip_only_flag": false, - "prev_output_date": "2013-07-01T00:00:00", - "process_window": null, - "psfcBiasCorrectOpt": [ - 0 - ], - "psfcDownscaleOpt": [ - 0 - ], - "q2BiasCorrectOpt": [ - 0 - ], - "q2dDownscaleOpt": [ - 0 - ], - "realtime_flag": false, - "refcst_flag": true, - "regrid_opt": [ - 1 - ], - "regrid_opt_supp_pcp": null, - "rqiMethod": null, - "rqiThresh": 1.0, - "runCfsNldasBiasCorrect": false, - "sinalpha_var": null, - "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, - "slope_var": null, - "slope_var_elem": null, - "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", - "sub_output_freq": null, - "sub_output_hour": null, - "suppTemporalInterp": null, - "supp_pcp_max_hours": null, - "supp_precip_dirs": null, - "supp_precip_file_types": [], - "supp_precip_forcings": [], - "supp_precip_mandatory": null, - "supp_precip_param_dir": null, - "swBiasCorrectOpt": [ - 0 - ], - "swDownscaleOpt": [ - 0 - ], - "t2BiasCorrectOpt": [ - 0 - ], - "t2dDownscaleOpt": [ - 0 - ], - "useCompression": 0, - "useFloats": 0, - "use_data_at_current_time": true, - "weightsDir": null, - "windBiasCorrect": [ - 0 - ] - }, "rank": 0, "size": 1 }, @@ -1152,5 +846,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_2.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_2.json index b495ac2e..26e1450f 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_2.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_2.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,6 +118,7 @@ "initial_time": 0, "time_step_seconds": 3600 }, + "dimensionality": 1, "geo_meta": { "approx_centroid_global_xy": [ -72.05503025291092, @@ -323,10 +325,29 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_time": 7200, "bmi_time_index": 2, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -354,17 +375,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -406,6 +435,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -434,24 +467,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -464,9 +502,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 @@ -723,355 +766,6 @@ "mesh_inds_elem": null, "mpi_config": { "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "config_options": { - "ExactExtract": null, - "actual_output_steps": 71, - "ana_flag": 0, - "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", - "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", - "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", - "aorc_conus_year_url": "{source}/{year}.zarr", - "aws": true, - "aws_obj": { - "attrs": {}, - "coords": { - "spatial_ref": { - "attrs": { - "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]", - "geographic_crs_name": "WGS 84", - "grid_mapping_name": "latitude_longitude", - "horizontal_datum_name": "World Geodetic System 1984", - "inverse_flattening": 298.257223563, - "longitude_of_prime_meridian": 0.0, - "prime_meridian_name": "Greenwich", - "reference_ellipsoid_name": "WGS 84", - "semi_major_axis": 6378137.0, - "semi_minor_axis": 6356752.314245179, - "spatial_ref": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" - }, - "data": 0, - "dims": [] - }, - "time": { - "attrs": { - "long_name": "verification time generated by wgrib2 function verftime()", - "reference_date": "2013.01.01 00:00:00 UTC", - "reference_time": 1356998400.0, - "reference_time_description": "kind of product unclear, reference date is variable, min found reference date is given", - "reference_time_type": 0, - "time_step": 0.0, - "time_step_setting": "auto" - }, - "data": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "dims": [] - }, - "x": { - "attrs": { - "long_name": "longitude", - "units": "degrees_east" - }, - "data": "hash_-5399622063019475031_len_28", - "dims": [ - "x" - ] - }, - "y": { - "attrs": { - "long_name": "latitude", - "units": "degrees_north" - }, - "data": "hash_-1457289664996315734_len_37", - "dims": [ - "y" - ] - } - }, - "data_vars": { - "APCP_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Total Precipitation", - "short_name": "APCP_surface", - "units": "kg/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DLWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Long-Wave Rad. Flux", - "short_name": "DLWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DSWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Short-Wave Rad. Flux", - "short_name": "DSWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "PRES_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Pressure", - "short_name": "PRES_surface", - "units": "Pa" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "SPFH_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Specific Humidity", - "short_name": "SPFH_2maboveground", - "units": "kg/kg" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "TMP_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Temperature", - "short_name": "TMP_2maboveground", - "units": "K" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "UGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "U-Component of Wind", - "short_name": "UGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "VGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "V-Component of Wind", - "short_name": "VGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - } - }, - "dims": { - "x": 28, - "y": 37 - } - }, - "aws_time": null, - "b_date_proc": "2013-07-01T00:00:00", - "bmi_time": 7200, - "bmi_time_index": 2, - "cfsv2EnsMember": null, - "config_path": null, - "cosalpha_var": null, - "currentCustomForceNum": 0, - "currentForceNum": 1, - "current_fcst_cycle": "2013-07-01T00:00:00", - "current_output_date": "2013-07-01T02:00:00", - "current_output_step": 2, - "current_time": "2013-07-01T02:00:00", - "customFcstFreq": [], - "customSuppPcpFreq": null, - "cycle_length_minutes": 4260, - "dScaleParamDirs": [ - "/ngen-app/data" - ], - "e_date_proc": null, - "elemconn_var": "elementConn", - "elemcoords_var": "centerCoords", - "element_id_var": "element_id", - "errFlag": 0, - "errMsg": null, - "fcst_freq": 60, - "fcst_input_horizons": [ - 4260 - ], - "fcst_input_offsets": [ - 0 - ], - "fcst_shift": 0, - "first_fcst_cycle": "2013-07-01T00:00:00", - "forceTemoralInterp": [ - 0 - ], - "forcing_output": 0, - "future_time": null, - "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", - "globalNdv": -9999.0, - "grid_meta": null, - "grid_type": "hydrofabric", - "hgt_elem_var": null, - "hgt_var": null, - "ignored_border_widths": [ - 0 - ], - "include_lqfrac": 1, - "input_force_dirs": [ - "s3://null" - ], - "input_force_mandatory": [ - 0 - ], - "input_force_types": [ - "GRIB2" - ], - "input_forcings": [ - 12 - ], - "lat_var": null, - "logFile": null, - "logHandle": null, - "lon_var": null, - "look_back": -9999, - "lwBiasCorrectOpt": [ - 0 - ], - "nFcsts": 1, - "nodecoords_var": "nodeCoords", - "num_output_steps": 71, - "num_supp_output_steps": null, - "number_custom_inputs": 0, - "number_inputs": 1, - "number_supp_pcp": 0, - "numelemconn_var": "numElementConn", - "nwmConfig": "AORC", - "nwmVersion": 4.0, - "nwm_domain": null, - "nwm_geogrid": null, - "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", - "nwm_url": null, - "output_freq": 60, - "paramFlagArray": null, - "precipBiasCorrectOpt": [ - 0 - ], - "precipDownscaleOpt": [ - 0 - ], - "precip_only_flag": false, - "prev_output_date": "2013-07-01T00:00:00", - "process_window": null, - "psfcBiasCorrectOpt": [ - 0 - ], - "psfcDownscaleOpt": [ - 0 - ], - "q2BiasCorrectOpt": [ - 0 - ], - "q2dDownscaleOpt": [ - 0 - ], - "realtime_flag": false, - "refcst_flag": true, - "regrid_opt": [ - 1 - ], - "regrid_opt_supp_pcp": null, - "rqiMethod": null, - "rqiThresh": 1.0, - "runCfsNldasBiasCorrect": false, - "sinalpha_var": null, - "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, - "slope_var": null, - "slope_var_elem": null, - "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", - "sub_output_freq": null, - "sub_output_hour": null, - "suppTemporalInterp": null, - "supp_pcp_max_hours": null, - "supp_precip_dirs": null, - "supp_precip_file_types": [], - "supp_precip_forcings": [], - "supp_precip_mandatory": null, - "supp_precip_param_dir": null, - "swBiasCorrectOpt": [ - 0 - ], - "swDownscaleOpt": [ - 0 - ], - "t2BiasCorrectOpt": [ - 0 - ], - "t2dDownscaleOpt": [ - 0 - ], - "useCompression": 0, - "useFloats": 0, - "use_data_at_current_time": true, - "weightsDir": null, - "windBiasCorrect": [ - 0 - ] - }, "rank": 0, "size": 1 }, @@ -1152,5 +846,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_3.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_3.json index f7a6b582..78e899a3 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_3.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_3.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,6 +118,7 @@ "initial_time": 0, "time_step_seconds": 3600 }, + "dimensionality": 1, "geo_meta": { "approx_centroid_global_xy": [ -72.05503025291092, @@ -323,10 +325,29 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_time": 10800, "bmi_time_index": 3, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -354,17 +375,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -406,6 +435,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -434,24 +467,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -464,9 +502,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 @@ -723,355 +766,6 @@ "mesh_inds_elem": null, "mpi_config": { "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "config_options": { - "ExactExtract": null, - "actual_output_steps": 71, - "ana_flag": 0, - "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", - "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", - "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", - "aorc_conus_year_url": "{source}/{year}.zarr", - "aws": true, - "aws_obj": { - "attrs": {}, - "coords": { - "spatial_ref": { - "attrs": { - "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]", - "geographic_crs_name": "WGS 84", - "grid_mapping_name": "latitude_longitude", - "horizontal_datum_name": "World Geodetic System 1984", - "inverse_flattening": 298.257223563, - "longitude_of_prime_meridian": 0.0, - "prime_meridian_name": "Greenwich", - "reference_ellipsoid_name": "WGS 84", - "semi_major_axis": 6378137.0, - "semi_minor_axis": 6356752.314245179, - "spatial_ref": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" - }, - "data": 0, - "dims": [] - }, - "time": { - "attrs": { - "long_name": "verification time generated by wgrib2 function verftime()", - "reference_date": "2013.01.01 00:00:00 UTC", - "reference_time": 1356998400.0, - "reference_time_description": "kind of product unclear, reference date is variable, min found reference date is given", - "reference_time_type": 0, - "time_step": 0.0, - "time_step_setting": "auto" - }, - "data": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "dims": [] - }, - "x": { - "attrs": { - "long_name": "longitude", - "units": "degrees_east" - }, - "data": "hash_-5399622063019475031_len_28", - "dims": [ - "x" - ] - }, - "y": { - "attrs": { - "long_name": "latitude", - "units": "degrees_north" - }, - "data": "hash_-1457289664996315734_len_37", - "dims": [ - "y" - ] - } - }, - "data_vars": { - "APCP_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Total Precipitation", - "short_name": "APCP_surface", - "units": "kg/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DLWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Long-Wave Rad. Flux", - "short_name": "DLWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DSWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Short-Wave Rad. Flux", - "short_name": "DSWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "PRES_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Pressure", - "short_name": "PRES_surface", - "units": "Pa" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "SPFH_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Specific Humidity", - "short_name": "SPFH_2maboveground", - "units": "kg/kg" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "TMP_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Temperature", - "short_name": "TMP_2maboveground", - "units": "K" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "UGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "U-Component of Wind", - "short_name": "UGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "VGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "V-Component of Wind", - "short_name": "VGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - } - }, - "dims": { - "x": 28, - "y": 37 - } - }, - "aws_time": null, - "b_date_proc": "2013-07-01T00:00:00", - "bmi_time": 10800, - "bmi_time_index": 3, - "cfsv2EnsMember": null, - "config_path": null, - "cosalpha_var": null, - "currentCustomForceNum": 0, - "currentForceNum": 1, - "current_fcst_cycle": "2013-07-01T00:00:00", - "current_output_date": "2013-07-01T03:00:00", - "current_output_step": 3, - "current_time": "2013-07-01T03:00:00", - "customFcstFreq": [], - "customSuppPcpFreq": null, - "cycle_length_minutes": 4260, - "dScaleParamDirs": [ - "/ngen-app/data" - ], - "e_date_proc": null, - "elemconn_var": "elementConn", - "elemcoords_var": "centerCoords", - "element_id_var": "element_id", - "errFlag": 0, - "errMsg": null, - "fcst_freq": 60, - "fcst_input_horizons": [ - 4260 - ], - "fcst_input_offsets": [ - 0 - ], - "fcst_shift": 0, - "first_fcst_cycle": "2013-07-01T00:00:00", - "forceTemoralInterp": [ - 0 - ], - "forcing_output": 0, - "future_time": null, - "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", - "globalNdv": -9999.0, - "grid_meta": null, - "grid_type": "hydrofabric", - "hgt_elem_var": null, - "hgt_var": null, - "ignored_border_widths": [ - 0 - ], - "include_lqfrac": 1, - "input_force_dirs": [ - "s3://null" - ], - "input_force_mandatory": [ - 0 - ], - "input_force_types": [ - "GRIB2" - ], - "input_forcings": [ - 12 - ], - "lat_var": null, - "logFile": null, - "logHandle": null, - "lon_var": null, - "look_back": -9999, - "lwBiasCorrectOpt": [ - 0 - ], - "nFcsts": 1, - "nodecoords_var": "nodeCoords", - "num_output_steps": 71, - "num_supp_output_steps": null, - "number_custom_inputs": 0, - "number_inputs": 1, - "number_supp_pcp": 0, - "numelemconn_var": "numElementConn", - "nwmConfig": "AORC", - "nwmVersion": 4.0, - "nwm_domain": null, - "nwm_geogrid": null, - "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", - "nwm_url": null, - "output_freq": 60, - "paramFlagArray": null, - "precipBiasCorrectOpt": [ - 0 - ], - "precipDownscaleOpt": [ - 0 - ], - "precip_only_flag": false, - "prev_output_date": "2013-07-01T00:00:00", - "process_window": null, - "psfcBiasCorrectOpt": [ - 0 - ], - "psfcDownscaleOpt": [ - 0 - ], - "q2BiasCorrectOpt": [ - 0 - ], - "q2dDownscaleOpt": [ - 0 - ], - "realtime_flag": false, - "refcst_flag": true, - "regrid_opt": [ - 1 - ], - "regrid_opt_supp_pcp": null, - "rqiMethod": null, - "rqiThresh": 1.0, - "runCfsNldasBiasCorrect": false, - "sinalpha_var": null, - "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, - "slope_var": null, - "slope_var_elem": null, - "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", - "sub_output_freq": null, - "sub_output_hour": null, - "suppTemporalInterp": null, - "supp_pcp_max_hours": null, - "supp_precip_dirs": null, - "supp_precip_file_types": [], - "supp_precip_forcings": [], - "supp_precip_mandatory": null, - "supp_precip_param_dir": null, - "swBiasCorrectOpt": [ - 0 - ], - "swDownscaleOpt": [ - 0 - ], - "t2BiasCorrectOpt": [ - 0 - ], - "t2dDownscaleOpt": [ - 0 - ], - "useCompression": 0, - "useFloats": 0, - "use_data_at_current_time": true, - "weightsDir": null, - "windBiasCorrect": [ - 0 - ] - }, "rank": 0, "size": 1 }, @@ -1152,5 +846,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_1.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_1.json index b07e8be3..93fc260a 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_1.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_1.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,6 +118,7 @@ "initial_time": 0, "time_step_seconds": 3600 }, + "dimensionality": 1, "geo_meta": { "approx_centroid_global_xy": [ -72.05503025291092, @@ -323,10 +325,29 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_time": 3600, "bmi_time_index": 1, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -354,17 +375,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -406,6 +435,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -434,24 +467,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -464,9 +502,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 @@ -531,7 +574,7 @@ "_coords": [ [ "hash_351698735832278484_len_364", - "hash_1673925891551318769_len_364" + "hash_-6066707896656524608_len_364" ], [ [ @@ -680,7 +723,7 @@ "height_elem": null, "heights_global": null, "inds": null, - "lat_bounds": "hash_2117205719057770460_len_582", + "lat_bounds": "hash_902249663378761532_len_582", "latitude_grid": [ 41.67904491423198, 41.73961258049449, @@ -705,355 +748,6 @@ "mesh_inds_elem": null, "mpi_config": { "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "config_options": { - "ExactExtract": null, - "actual_output_steps": 71, - "ana_flag": 0, - "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", - "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", - "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", - "aorc_conus_year_url": "{source}/{year}.zarr", - "aws": true, - "aws_obj": { - "attrs": {}, - "coords": { - "spatial_ref": { - "attrs": { - "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]", - "geographic_crs_name": "WGS 84", - "grid_mapping_name": "latitude_longitude", - "horizontal_datum_name": "World Geodetic System 1984", - "inverse_flattening": 298.257223563, - "longitude_of_prime_meridian": 0.0, - "prime_meridian_name": "Greenwich", - "reference_ellipsoid_name": "WGS 84", - "semi_major_axis": 6378137.0, - "semi_minor_axis": 6356752.314245179, - "spatial_ref": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" - }, - "data": 0, - "dims": [] - }, - "time": { - "attrs": { - "long_name": "verification time generated by wgrib2 function verftime()", - "reference_date": "2013.01.01 00:00:00 UTC", - "reference_time": 1356998400.0, - "reference_time_description": "kind of product unclear, reference date is variable, min found reference date is given", - "reference_time_type": 0, - "time_step": 0.0, - "time_step_setting": "auto" - }, - "data": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "dims": [] - }, - "x": { - "attrs": { - "long_name": "longitude", - "units": "degrees_east" - }, - "data": "hash_-5399622063019475031_len_28", - "dims": [ - "x" - ] - }, - "y": { - "attrs": { - "long_name": "latitude", - "units": "degrees_north" - }, - "data": "hash_-1457289664996315734_len_37", - "dims": [ - "y" - ] - } - }, - "data_vars": { - "APCP_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Total Precipitation", - "short_name": "APCP_surface", - "units": "kg/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DLWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Long-Wave Rad. Flux", - "short_name": "DLWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DSWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Short-Wave Rad. Flux", - "short_name": "DSWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "PRES_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Pressure", - "short_name": "PRES_surface", - "units": "Pa" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "SPFH_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Specific Humidity", - "short_name": "SPFH_2maboveground", - "units": "kg/kg" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "TMP_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Temperature", - "short_name": "TMP_2maboveground", - "units": "K" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "UGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "U-Component of Wind", - "short_name": "UGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "VGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "V-Component of Wind", - "short_name": "VGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - } - }, - "dims": { - "x": 28, - "y": 37 - } - }, - "aws_time": null, - "b_date_proc": "2013-07-01T00:00:00", - "bmi_time": 3600, - "bmi_time_index": 1, - "cfsv2EnsMember": null, - "config_path": null, - "cosalpha_var": null, - "currentCustomForceNum": 0, - "currentForceNum": 1, - "current_fcst_cycle": "2013-07-01T00:00:00", - "current_output_date": "2013-07-01T01:00:00", - "current_output_step": 1, - "current_time": "2013-07-01T01:00:00", - "customFcstFreq": [], - "customSuppPcpFreq": null, - "cycle_length_minutes": 4260, - "dScaleParamDirs": [ - "/ngen-app/data" - ], - "e_date_proc": null, - "elemconn_var": "elementConn", - "elemcoords_var": "centerCoords", - "element_id_var": "element_id", - "errFlag": 0, - "errMsg": null, - "fcst_freq": 60, - "fcst_input_horizons": [ - 4260 - ], - "fcst_input_offsets": [ - 0 - ], - "fcst_shift": 0, - "first_fcst_cycle": "2013-07-01T00:00:00", - "forceTemoralInterp": [ - 0 - ], - "forcing_output": 0, - "future_time": null, - "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", - "globalNdv": -9999.0, - "grid_meta": null, - "grid_type": "hydrofabric", - "hgt_elem_var": null, - "hgt_var": null, - "ignored_border_widths": [ - 0 - ], - "include_lqfrac": 1, - "input_force_dirs": [ - "s3://null" - ], - "input_force_mandatory": [ - 0 - ], - "input_force_types": [ - "GRIB2" - ], - "input_forcings": [ - 12 - ], - "lat_var": null, - "logFile": null, - "logHandle": null, - "lon_var": null, - "look_back": -9999, - "lwBiasCorrectOpt": [ - 0 - ], - "nFcsts": 1, - "nodecoords_var": "nodeCoords", - "num_output_steps": 71, - "num_supp_output_steps": null, - "number_custom_inputs": 0, - "number_inputs": 1, - "number_supp_pcp": 0, - "numelemconn_var": "numElementConn", - "nwmConfig": "AORC", - "nwmVersion": 4.0, - "nwm_domain": null, - "nwm_geogrid": null, - "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", - "nwm_url": null, - "output_freq": 60, - "paramFlagArray": null, - "precipBiasCorrectOpt": [ - 0 - ], - "precipDownscaleOpt": [ - 0 - ], - "precip_only_flag": false, - "prev_output_date": "2013-07-01T00:00:00", - "process_window": null, - "psfcBiasCorrectOpt": [ - 0 - ], - "psfcDownscaleOpt": [ - 0 - ], - "q2BiasCorrectOpt": [ - 0 - ], - "q2dDownscaleOpt": [ - 0 - ], - "realtime_flag": false, - "refcst_flag": true, - "regrid_opt": [ - 1 - ], - "regrid_opt_supp_pcp": null, - "rqiMethod": null, - "rqiThresh": 1.0, - "runCfsNldasBiasCorrect": false, - "sinalpha_var": null, - "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, - "slope_var": null, - "slope_var_elem": null, - "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", - "sub_output_freq": null, - "sub_output_hour": null, - "suppTemporalInterp": null, - "supp_pcp_max_hours": null, - "supp_precip_dirs": null, - "supp_precip_file_types": [], - "supp_precip_forcings": [], - "supp_precip_mandatory": null, - "supp_precip_param_dir": null, - "swBiasCorrectOpt": [ - 0 - ], - "swDownscaleOpt": [ - 0 - ], - "t2BiasCorrectOpt": [ - 0 - ], - "t2dDownscaleOpt": [ - 0 - ], - "useCompression": 0, - "useFloats": 0, - "use_data_at_current_time": true, - "weightsDir": null, - "windBiasCorrect": [ - 0 - ] - }, "rank": 0, "size": 2 }, @@ -1125,5 +819,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_2.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_2.json index 26be099a..50cf0d86 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_2.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_2.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,6 +118,7 @@ "initial_time": 0, "time_step_seconds": 3600 }, + "dimensionality": 1, "geo_meta": { "approx_centroid_global_xy": [ -72.05503025291092, @@ -323,10 +325,29 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_time": 7200, "bmi_time_index": 2, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -354,17 +375,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -406,6 +435,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -434,24 +467,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -464,9 +502,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 @@ -531,7 +574,7 @@ "_coords": [ [ "hash_351698735832278484_len_364", - "hash_1673925891551318769_len_364" + "hash_-6066707896656524608_len_364" ], [ [ @@ -680,7 +723,7 @@ "height_elem": null, "heights_global": null, "inds": null, - "lat_bounds": "hash_2117205719057770460_len_582", + "lat_bounds": "hash_902249663378761532_len_582", "latitude_grid": [ 41.67904491423198, 41.73961258049449, @@ -705,355 +748,6 @@ "mesh_inds_elem": null, "mpi_config": { "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "config_options": { - "ExactExtract": null, - "actual_output_steps": 71, - "ana_flag": 0, - "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", - "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", - "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", - "aorc_conus_year_url": "{source}/{year}.zarr", - "aws": true, - "aws_obj": { - "attrs": {}, - "coords": { - "spatial_ref": { - "attrs": { - "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]", - "geographic_crs_name": "WGS 84", - "grid_mapping_name": "latitude_longitude", - "horizontal_datum_name": "World Geodetic System 1984", - "inverse_flattening": 298.257223563, - "longitude_of_prime_meridian": 0.0, - "prime_meridian_name": "Greenwich", - "reference_ellipsoid_name": "WGS 84", - "semi_major_axis": 6378137.0, - "semi_minor_axis": 6356752.314245179, - "spatial_ref": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" - }, - "data": 0, - "dims": [] - }, - "time": { - "attrs": { - "long_name": "verification time generated by wgrib2 function verftime()", - "reference_date": "2013.01.01 00:00:00 UTC", - "reference_time": 1356998400.0, - "reference_time_description": "kind of product unclear, reference date is variable, min found reference date is given", - "reference_time_type": 0, - "time_step": 0.0, - "time_step_setting": "auto" - }, - "data": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "dims": [] - }, - "x": { - "attrs": { - "long_name": "longitude", - "units": "degrees_east" - }, - "data": "hash_-5399622063019475031_len_28", - "dims": [ - "x" - ] - }, - "y": { - "attrs": { - "long_name": "latitude", - "units": "degrees_north" - }, - "data": "hash_-1457289664996315734_len_37", - "dims": [ - "y" - ] - } - }, - "data_vars": { - "APCP_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Total Precipitation", - "short_name": "APCP_surface", - "units": "kg/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DLWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Long-Wave Rad. Flux", - "short_name": "DLWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DSWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Short-Wave Rad. Flux", - "short_name": "DSWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "PRES_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Pressure", - "short_name": "PRES_surface", - "units": "Pa" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "SPFH_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Specific Humidity", - "short_name": "SPFH_2maboveground", - "units": "kg/kg" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "TMP_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Temperature", - "short_name": "TMP_2maboveground", - "units": "K" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "UGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "U-Component of Wind", - "short_name": "UGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "VGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "V-Component of Wind", - "short_name": "VGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - } - }, - "dims": { - "x": 28, - "y": 37 - } - }, - "aws_time": null, - "b_date_proc": "2013-07-01T00:00:00", - "bmi_time": 7200, - "bmi_time_index": 2, - "cfsv2EnsMember": null, - "config_path": null, - "cosalpha_var": null, - "currentCustomForceNum": 0, - "currentForceNum": 1, - "current_fcst_cycle": "2013-07-01T00:00:00", - "current_output_date": "2013-07-01T02:00:00", - "current_output_step": 2, - "current_time": "2013-07-01T02:00:00", - "customFcstFreq": [], - "customSuppPcpFreq": null, - "cycle_length_minutes": 4260, - "dScaleParamDirs": [ - "/ngen-app/data" - ], - "e_date_proc": null, - "elemconn_var": "elementConn", - "elemcoords_var": "centerCoords", - "element_id_var": "element_id", - "errFlag": 0, - "errMsg": null, - "fcst_freq": 60, - "fcst_input_horizons": [ - 4260 - ], - "fcst_input_offsets": [ - 0 - ], - "fcst_shift": 0, - "first_fcst_cycle": "2013-07-01T00:00:00", - "forceTemoralInterp": [ - 0 - ], - "forcing_output": 0, - "future_time": null, - "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", - "globalNdv": -9999.0, - "grid_meta": null, - "grid_type": "hydrofabric", - "hgt_elem_var": null, - "hgt_var": null, - "ignored_border_widths": [ - 0 - ], - "include_lqfrac": 1, - "input_force_dirs": [ - "s3://null" - ], - "input_force_mandatory": [ - 0 - ], - "input_force_types": [ - "GRIB2" - ], - "input_forcings": [ - 12 - ], - "lat_var": null, - "logFile": null, - "logHandle": null, - "lon_var": null, - "look_back": -9999, - "lwBiasCorrectOpt": [ - 0 - ], - "nFcsts": 1, - "nodecoords_var": "nodeCoords", - "num_output_steps": 71, - "num_supp_output_steps": null, - "number_custom_inputs": 0, - "number_inputs": 1, - "number_supp_pcp": 0, - "numelemconn_var": "numElementConn", - "nwmConfig": "AORC", - "nwmVersion": 4.0, - "nwm_domain": null, - "nwm_geogrid": null, - "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", - "nwm_url": null, - "output_freq": 60, - "paramFlagArray": null, - "precipBiasCorrectOpt": [ - 0 - ], - "precipDownscaleOpt": [ - 0 - ], - "precip_only_flag": false, - "prev_output_date": "2013-07-01T00:00:00", - "process_window": null, - "psfcBiasCorrectOpt": [ - 0 - ], - "psfcDownscaleOpt": [ - 0 - ], - "q2BiasCorrectOpt": [ - 0 - ], - "q2dDownscaleOpt": [ - 0 - ], - "realtime_flag": false, - "refcst_flag": true, - "regrid_opt": [ - 1 - ], - "regrid_opt_supp_pcp": null, - "rqiMethod": null, - "rqiThresh": 1.0, - "runCfsNldasBiasCorrect": false, - "sinalpha_var": null, - "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, - "slope_var": null, - "slope_var_elem": null, - "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", - "sub_output_freq": null, - "sub_output_hour": null, - "suppTemporalInterp": null, - "supp_pcp_max_hours": null, - "supp_precip_dirs": null, - "supp_precip_file_types": [], - "supp_precip_forcings": [], - "supp_precip_mandatory": null, - "supp_precip_param_dir": null, - "swBiasCorrectOpt": [ - 0 - ], - "swDownscaleOpt": [ - 0 - ], - "t2BiasCorrectOpt": [ - 0 - ], - "t2dDownscaleOpt": [ - 0 - ], - "useCompression": 0, - "useFloats": 0, - "use_data_at_current_time": true, - "weightsDir": null, - "windBiasCorrect": [ - 0 - ] - }, "rank": 0, "size": 2 }, @@ -1125,5 +819,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_3.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_3.json index 211cc8ad..fe18aacb 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_3.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_3.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,6 +118,7 @@ "initial_time": 0, "time_step_seconds": 3600 }, + "dimensionality": 1, "geo_meta": { "approx_centroid_global_xy": [ -72.05503025291092, @@ -323,10 +325,29 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_time": 10800, "bmi_time_index": 3, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -354,17 +375,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -406,6 +435,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -434,24 +467,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -464,9 +502,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 @@ -531,7 +574,7 @@ "_coords": [ [ "hash_351698735832278484_len_364", - "hash_1673925891551318769_len_364" + "hash_-6066707896656524608_len_364" ], [ [ @@ -680,7 +723,7 @@ "height_elem": null, "heights_global": null, "inds": null, - "lat_bounds": "hash_2117205719057770460_len_582", + "lat_bounds": "hash_902249663378761532_len_582", "latitude_grid": [ 41.67904491423198, 41.73961258049449, @@ -705,355 +748,6 @@ "mesh_inds_elem": null, "mpi_config": { "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "config_options": { - "ExactExtract": null, - "actual_output_steps": 71, - "ana_flag": 0, - "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", - "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", - "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", - "aorc_conus_year_url": "{source}/{year}.zarr", - "aws": true, - "aws_obj": { - "attrs": {}, - "coords": { - "spatial_ref": { - "attrs": { - "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]", - "geographic_crs_name": "WGS 84", - "grid_mapping_name": "latitude_longitude", - "horizontal_datum_name": "World Geodetic System 1984", - "inverse_flattening": 298.257223563, - "longitude_of_prime_meridian": 0.0, - "prime_meridian_name": "Greenwich", - "reference_ellipsoid_name": "WGS 84", - "semi_major_axis": 6378137.0, - "semi_minor_axis": 6356752.314245179, - "spatial_ref": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" - }, - "data": 0, - "dims": [] - }, - "time": { - "attrs": { - "long_name": "verification time generated by wgrib2 function verftime()", - "reference_date": "2013.01.01 00:00:00 UTC", - "reference_time": 1356998400.0, - "reference_time_description": "kind of product unclear, reference date is variable, min found reference date is given", - "reference_time_type": 0, - "time_step": 0.0, - "time_step_setting": "auto" - }, - "data": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "dims": [] - }, - "x": { - "attrs": { - "long_name": "longitude", - "units": "degrees_east" - }, - "data": "hash_-5399622063019475031_len_28", - "dims": [ - "x" - ] - }, - "y": { - "attrs": { - "long_name": "latitude", - "units": "degrees_north" - }, - "data": "hash_-1457289664996315734_len_37", - "dims": [ - "y" - ] - } - }, - "data_vars": { - "APCP_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Total Precipitation", - "short_name": "APCP_surface", - "units": "kg/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DLWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Long-Wave Rad. Flux", - "short_name": "DLWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DSWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Short-Wave Rad. Flux", - "short_name": "DSWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "PRES_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Pressure", - "short_name": "PRES_surface", - "units": "Pa" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "SPFH_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Specific Humidity", - "short_name": "SPFH_2maboveground", - "units": "kg/kg" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "TMP_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Temperature", - "short_name": "TMP_2maboveground", - "units": "K" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "UGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "U-Component of Wind", - "short_name": "UGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "VGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "V-Component of Wind", - "short_name": "VGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - } - }, - "dims": { - "x": 28, - "y": 37 - } - }, - "aws_time": null, - "b_date_proc": "2013-07-01T00:00:00", - "bmi_time": 10800, - "bmi_time_index": 3, - "cfsv2EnsMember": null, - "config_path": null, - "cosalpha_var": null, - "currentCustomForceNum": 0, - "currentForceNum": 1, - "current_fcst_cycle": "2013-07-01T00:00:00", - "current_output_date": "2013-07-01T03:00:00", - "current_output_step": 3, - "current_time": "2013-07-01T03:00:00", - "customFcstFreq": [], - "customSuppPcpFreq": null, - "cycle_length_minutes": 4260, - "dScaleParamDirs": [ - "/ngen-app/data" - ], - "e_date_proc": null, - "elemconn_var": "elementConn", - "elemcoords_var": "centerCoords", - "element_id_var": "element_id", - "errFlag": 0, - "errMsg": null, - "fcst_freq": 60, - "fcst_input_horizons": [ - 4260 - ], - "fcst_input_offsets": [ - 0 - ], - "fcst_shift": 0, - "first_fcst_cycle": "2013-07-01T00:00:00", - "forceTemoralInterp": [ - 0 - ], - "forcing_output": 0, - "future_time": null, - "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", - "globalNdv": -9999.0, - "grid_meta": null, - "grid_type": "hydrofabric", - "hgt_elem_var": null, - "hgt_var": null, - "ignored_border_widths": [ - 0 - ], - "include_lqfrac": 1, - "input_force_dirs": [ - "s3://null" - ], - "input_force_mandatory": [ - 0 - ], - "input_force_types": [ - "GRIB2" - ], - "input_forcings": [ - 12 - ], - "lat_var": null, - "logFile": null, - "logHandle": null, - "lon_var": null, - "look_back": -9999, - "lwBiasCorrectOpt": [ - 0 - ], - "nFcsts": 1, - "nodecoords_var": "nodeCoords", - "num_output_steps": 71, - "num_supp_output_steps": null, - "number_custom_inputs": 0, - "number_inputs": 1, - "number_supp_pcp": 0, - "numelemconn_var": "numElementConn", - "nwmConfig": "AORC", - "nwmVersion": 4.0, - "nwm_domain": null, - "nwm_geogrid": null, - "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", - "nwm_url": null, - "output_freq": 60, - "paramFlagArray": null, - "precipBiasCorrectOpt": [ - 0 - ], - "precipDownscaleOpt": [ - 0 - ], - "precip_only_flag": false, - "prev_output_date": "2013-07-01T00:00:00", - "process_window": null, - "psfcBiasCorrectOpt": [ - 0 - ], - "psfcDownscaleOpt": [ - 0 - ], - "q2BiasCorrectOpt": [ - 0 - ], - "q2dDownscaleOpt": [ - 0 - ], - "realtime_flag": false, - "refcst_flag": true, - "regrid_opt": [ - 1 - ], - "regrid_opt_supp_pcp": null, - "rqiMethod": null, - "rqiThresh": 1.0, - "runCfsNldasBiasCorrect": false, - "sinalpha_var": null, - "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, - "slope_var": null, - "slope_var_elem": null, - "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", - "sub_output_freq": null, - "sub_output_hour": null, - "suppTemporalInterp": null, - "supp_pcp_max_hours": null, - "supp_precip_dirs": null, - "supp_precip_file_types": [], - "supp_precip_forcings": [], - "supp_precip_mandatory": null, - "supp_precip_param_dir": null, - "swBiasCorrectOpt": [ - 0 - ], - "swDownscaleOpt": [ - 0 - ], - "t2BiasCorrectOpt": [ - 0 - ], - "t2dDownscaleOpt": [ - 0 - ], - "useCompression": 0, - "useFloats": 0, - "use_data_at_current_time": true, - "weightsDir": null, - "windBiasCorrect": [ - 0 - ] - }, "rank": 0, "size": 2 }, @@ -1125,5 +819,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_1.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_1.json index 0669c8f9..5f28473b 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_1.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_1.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,6 +118,7 @@ "initial_time": 0, "time_step_seconds": 3600 }, + "dimensionality": 1, "geo_meta": { "approx_centroid_global_xy": [ -72.05503025291092, @@ -323,10 +325,29 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_time": 3600, "bmi_time_index": 1, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -354,17 +375,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -406,6 +435,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -434,24 +467,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -464,9 +502,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 @@ -530,7 +573,7 @@ "_coords": [ [ "hash_7545881362083397004_len_218", - "hash_6855503821947747755_len_218" + "hash_-1022784215004640784_len_218" ], [ [ @@ -699,355 +742,6 @@ "mesh_inds_elem": null, "mpi_config": { "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "config_options": { - "ExactExtract": null, - "actual_output_steps": 71, - "ana_flag": 0, - "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", - "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", - "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", - "aorc_conus_year_url": "{source}/{year}.zarr", - "aws": true, - "aws_obj": { - "attrs": {}, - "coords": { - "spatial_ref": { - "attrs": { - "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]", - "geographic_crs_name": "WGS 84", - "grid_mapping_name": "latitude_longitude", - "horizontal_datum_name": "World Geodetic System 1984", - "inverse_flattening": 298.257223563, - "longitude_of_prime_meridian": 0.0, - "prime_meridian_name": "Greenwich", - "reference_ellipsoid_name": "WGS 84", - "semi_major_axis": 6378137.0, - "semi_minor_axis": 6356752.314245179, - "spatial_ref": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" - }, - "data": 0, - "dims": [] - }, - "time": { - "attrs": { - "long_name": "verification time generated by wgrib2 function verftime()", - "reference_date": "2013.01.01 00:00:00 UTC", - "reference_time": 1356998400.0, - "reference_time_description": "kind of product unclear, reference date is variable, min found reference date is given", - "reference_time_type": 0, - "time_step": 0.0, - "time_step_setting": "auto" - }, - "data": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "dims": [] - }, - "x": { - "attrs": { - "long_name": "longitude", - "units": "degrees_east" - }, - "data": "hash_-5399622063019475031_len_28", - "dims": [ - "x" - ] - }, - "y": { - "attrs": { - "long_name": "latitude", - "units": "degrees_north" - }, - "data": "hash_-1457289664996315734_len_37", - "dims": [ - "y" - ] - } - }, - "data_vars": { - "APCP_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Total Precipitation", - "short_name": "APCP_surface", - "units": "kg/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DLWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Long-Wave Rad. Flux", - "short_name": "DLWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DSWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Short-Wave Rad. Flux", - "short_name": "DSWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "PRES_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Pressure", - "short_name": "PRES_surface", - "units": "Pa" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "SPFH_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Specific Humidity", - "short_name": "SPFH_2maboveground", - "units": "kg/kg" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "TMP_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Temperature", - "short_name": "TMP_2maboveground", - "units": "K" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "UGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "U-Component of Wind", - "short_name": "UGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "VGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "V-Component of Wind", - "short_name": "VGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - } - }, - "dims": { - "x": 28, - "y": 37 - } - }, - "aws_time": null, - "b_date_proc": "2013-07-01T00:00:00", - "bmi_time": 3600, - "bmi_time_index": 1, - "cfsv2EnsMember": null, - "config_path": null, - "cosalpha_var": null, - "currentCustomForceNum": 0, - "currentForceNum": 1, - "current_fcst_cycle": "2013-07-01T00:00:00", - "current_output_date": "2013-07-01T01:00:00", - "current_output_step": 1, - "current_time": "2013-07-01T01:00:00", - "customFcstFreq": [], - "customSuppPcpFreq": null, - "cycle_length_minutes": 4260, - "dScaleParamDirs": [ - "/ngen-app/data" - ], - "e_date_proc": null, - "elemconn_var": "elementConn", - "elemcoords_var": "centerCoords", - "element_id_var": "element_id", - "errFlag": 0, - "errMsg": null, - "fcst_freq": 60, - "fcst_input_horizons": [ - 4260 - ], - "fcst_input_offsets": [ - 0 - ], - "fcst_shift": 0, - "first_fcst_cycle": "2013-07-01T00:00:00", - "forceTemoralInterp": [ - 0 - ], - "forcing_output": 0, - "future_time": null, - "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", - "globalNdv": -9999.0, - "grid_meta": null, - "grid_type": "hydrofabric", - "hgt_elem_var": null, - "hgt_var": null, - "ignored_border_widths": [ - 0 - ], - "include_lqfrac": 1, - "input_force_dirs": [ - "s3://null" - ], - "input_force_mandatory": [ - 0 - ], - "input_force_types": [ - "GRIB2" - ], - "input_forcings": [ - 12 - ], - "lat_var": null, - "logFile": null, - "logHandle": null, - "lon_var": null, - "look_back": -9999, - "lwBiasCorrectOpt": [ - 0 - ], - "nFcsts": 1, - "nodecoords_var": "nodeCoords", - "num_output_steps": 71, - "num_supp_output_steps": null, - "number_custom_inputs": 0, - "number_inputs": 1, - "number_supp_pcp": 0, - "numelemconn_var": "numElementConn", - "nwmConfig": "AORC", - "nwmVersion": 4.0, - "nwm_domain": null, - "nwm_geogrid": null, - "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", - "nwm_url": null, - "output_freq": 60, - "paramFlagArray": null, - "precipBiasCorrectOpt": [ - 0 - ], - "precipDownscaleOpt": [ - 0 - ], - "precip_only_flag": false, - "prev_output_date": "2013-07-01T00:00:00", - "process_window": null, - "psfcBiasCorrectOpt": [ - 0 - ], - "psfcDownscaleOpt": [ - 0 - ], - "q2BiasCorrectOpt": [ - 0 - ], - "q2dDownscaleOpt": [ - 0 - ], - "realtime_flag": false, - "refcst_flag": true, - "regrid_opt": [ - 1 - ], - "regrid_opt_supp_pcp": null, - "rqiMethod": null, - "rqiThresh": 1.0, - "runCfsNldasBiasCorrect": false, - "sinalpha_var": null, - "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, - "slope_var": null, - "slope_var_elem": null, - "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", - "sub_output_freq": null, - "sub_output_hour": null, - "suppTemporalInterp": null, - "supp_pcp_max_hours": null, - "supp_precip_dirs": null, - "supp_precip_file_types": [], - "supp_precip_forcings": [], - "supp_precip_mandatory": null, - "supp_precip_param_dir": null, - "swBiasCorrectOpt": [ - 0 - ], - "swDownscaleOpt": [ - 0 - ], - "t2BiasCorrectOpt": [ - 0 - ], - "t2dDownscaleOpt": [ - 0 - ], - "useCompression": 0, - "useFloats": 0, - "use_data_at_current_time": true, - "weightsDir": null, - "windBiasCorrect": [ - 0 - ] - }, "rank": 1, "size": 2 }, @@ -1116,5 +810,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_2.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_2.json index 49febe29..65e8fc17 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_2.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_2.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,6 +118,7 @@ "initial_time": 0, "time_step_seconds": 3600 }, + "dimensionality": 1, "geo_meta": { "approx_centroid_global_xy": [ -72.05503025291092, @@ -323,10 +325,29 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_time": 7200, "bmi_time_index": 2, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -354,17 +375,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -406,6 +435,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -434,24 +467,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -464,9 +502,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 @@ -530,7 +573,7 @@ "_coords": [ [ "hash_7545881362083397004_len_218", - "hash_6855503821947747755_len_218" + "hash_-1022784215004640784_len_218" ], [ [ @@ -699,355 +742,6 @@ "mesh_inds_elem": null, "mpi_config": { "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "config_options": { - "ExactExtract": null, - "actual_output_steps": 71, - "ana_flag": 0, - "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", - "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", - "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", - "aorc_conus_year_url": "{source}/{year}.zarr", - "aws": true, - "aws_obj": { - "attrs": {}, - "coords": { - "spatial_ref": { - "attrs": { - "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]", - "geographic_crs_name": "WGS 84", - "grid_mapping_name": "latitude_longitude", - "horizontal_datum_name": "World Geodetic System 1984", - "inverse_flattening": 298.257223563, - "longitude_of_prime_meridian": 0.0, - "prime_meridian_name": "Greenwich", - "reference_ellipsoid_name": "WGS 84", - "semi_major_axis": 6378137.0, - "semi_minor_axis": 6356752.314245179, - "spatial_ref": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" - }, - "data": 0, - "dims": [] - }, - "time": { - "attrs": { - "long_name": "verification time generated by wgrib2 function verftime()", - "reference_date": "2013.01.01 00:00:00 UTC", - "reference_time": 1356998400.0, - "reference_time_description": "kind of product unclear, reference date is variable, min found reference date is given", - "reference_time_type": 0, - "time_step": 0.0, - "time_step_setting": "auto" - }, - "data": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "dims": [] - }, - "x": { - "attrs": { - "long_name": "longitude", - "units": "degrees_east" - }, - "data": "hash_-5399622063019475031_len_28", - "dims": [ - "x" - ] - }, - "y": { - "attrs": { - "long_name": "latitude", - "units": "degrees_north" - }, - "data": "hash_-1457289664996315734_len_37", - "dims": [ - "y" - ] - } - }, - "data_vars": { - "APCP_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Total Precipitation", - "short_name": "APCP_surface", - "units": "kg/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DLWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Long-Wave Rad. Flux", - "short_name": "DLWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DSWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Short-Wave Rad. Flux", - "short_name": "DSWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "PRES_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Pressure", - "short_name": "PRES_surface", - "units": "Pa" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "SPFH_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Specific Humidity", - "short_name": "SPFH_2maboveground", - "units": "kg/kg" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "TMP_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Temperature", - "short_name": "TMP_2maboveground", - "units": "K" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "UGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "U-Component of Wind", - "short_name": "UGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "VGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "V-Component of Wind", - "short_name": "VGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - } - }, - "dims": { - "x": 28, - "y": 37 - } - }, - "aws_time": null, - "b_date_proc": "2013-07-01T00:00:00", - "bmi_time": 7200, - "bmi_time_index": 2, - "cfsv2EnsMember": null, - "config_path": null, - "cosalpha_var": null, - "currentCustomForceNum": 0, - "currentForceNum": 1, - "current_fcst_cycle": "2013-07-01T00:00:00", - "current_output_date": "2013-07-01T02:00:00", - "current_output_step": 2, - "current_time": "2013-07-01T02:00:00", - "customFcstFreq": [], - "customSuppPcpFreq": null, - "cycle_length_minutes": 4260, - "dScaleParamDirs": [ - "/ngen-app/data" - ], - "e_date_proc": null, - "elemconn_var": "elementConn", - "elemcoords_var": "centerCoords", - "element_id_var": "element_id", - "errFlag": 0, - "errMsg": null, - "fcst_freq": 60, - "fcst_input_horizons": [ - 4260 - ], - "fcst_input_offsets": [ - 0 - ], - "fcst_shift": 0, - "first_fcst_cycle": "2013-07-01T00:00:00", - "forceTemoralInterp": [ - 0 - ], - "forcing_output": 0, - "future_time": null, - "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", - "globalNdv": -9999.0, - "grid_meta": null, - "grid_type": "hydrofabric", - "hgt_elem_var": null, - "hgt_var": null, - "ignored_border_widths": [ - 0 - ], - "include_lqfrac": 1, - "input_force_dirs": [ - "s3://null" - ], - "input_force_mandatory": [ - 0 - ], - "input_force_types": [ - "GRIB2" - ], - "input_forcings": [ - 12 - ], - "lat_var": null, - "logFile": null, - "logHandle": null, - "lon_var": null, - "look_back": -9999, - "lwBiasCorrectOpt": [ - 0 - ], - "nFcsts": 1, - "nodecoords_var": "nodeCoords", - "num_output_steps": 71, - "num_supp_output_steps": null, - "number_custom_inputs": 0, - "number_inputs": 1, - "number_supp_pcp": 0, - "numelemconn_var": "numElementConn", - "nwmConfig": "AORC", - "nwmVersion": 4.0, - "nwm_domain": null, - "nwm_geogrid": null, - "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", - "nwm_url": null, - "output_freq": 60, - "paramFlagArray": null, - "precipBiasCorrectOpt": [ - 0 - ], - "precipDownscaleOpt": [ - 0 - ], - "precip_only_flag": false, - "prev_output_date": "2013-07-01T00:00:00", - "process_window": null, - "psfcBiasCorrectOpt": [ - 0 - ], - "psfcDownscaleOpt": [ - 0 - ], - "q2BiasCorrectOpt": [ - 0 - ], - "q2dDownscaleOpt": [ - 0 - ], - "realtime_flag": false, - "refcst_flag": true, - "regrid_opt": [ - 1 - ], - "regrid_opt_supp_pcp": null, - "rqiMethod": null, - "rqiThresh": 1.0, - "runCfsNldasBiasCorrect": false, - "sinalpha_var": null, - "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, - "slope_var": null, - "slope_var_elem": null, - "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", - "sub_output_freq": null, - "sub_output_hour": null, - "suppTemporalInterp": null, - "supp_pcp_max_hours": null, - "supp_precip_dirs": null, - "supp_precip_file_types": [], - "supp_precip_forcings": [], - "supp_precip_mandatory": null, - "supp_precip_param_dir": null, - "swBiasCorrectOpt": [ - 0 - ], - "swDownscaleOpt": [ - 0 - ], - "t2BiasCorrectOpt": [ - 0 - ], - "t2dDownscaleOpt": [ - 0 - ], - "useCompression": 0, - "useFloats": 0, - "use_data_at_current_time": true, - "weightsDir": null, - "windBiasCorrect": [ - 0 - ] - }, "rank": 1, "size": 2 }, @@ -1116,5 +810,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_3.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_3.json index 9fbaea9a..ca8f708a 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_3.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_3.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,6 +118,7 @@ "initial_time": 0, "time_step_seconds": 3600 }, + "dimensionality": 1, "geo_meta": { "approx_centroid_global_xy": [ -72.05503025291092, @@ -323,10 +325,29 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_time": 10800, "bmi_time_index": 3, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -354,17 +375,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -406,6 +435,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -434,24 +467,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -464,9 +502,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 @@ -530,7 +573,7 @@ "_coords": [ [ "hash_7545881362083397004_len_218", - "hash_6855503821947747755_len_218" + "hash_-1022784215004640784_len_218" ], [ [ @@ -699,355 +742,6 @@ "mesh_inds_elem": null, "mpi_config": { "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "config_options": { - "ExactExtract": null, - "actual_output_steps": 71, - "ana_flag": 0, - "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", - "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", - "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", - "aorc_conus_year_url": "{source}/{year}.zarr", - "aws": true, - "aws_obj": { - "attrs": {}, - "coords": { - "spatial_ref": { - "attrs": { - "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]", - "geographic_crs_name": "WGS 84", - "grid_mapping_name": "latitude_longitude", - "horizontal_datum_name": "World Geodetic System 1984", - "inverse_flattening": 298.257223563, - "longitude_of_prime_meridian": 0.0, - "prime_meridian_name": "Greenwich", - "reference_ellipsoid_name": "WGS 84", - "semi_major_axis": 6378137.0, - "semi_minor_axis": 6356752.314245179, - "spatial_ref": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" - }, - "data": 0, - "dims": [] - }, - "time": { - "attrs": { - "long_name": "verification time generated by wgrib2 function verftime()", - "reference_date": "2013.01.01 00:00:00 UTC", - "reference_time": 1356998400.0, - "reference_time_description": "kind of product unclear, reference date is variable, min found reference date is given", - "reference_time_type": 0, - "time_step": 0.0, - "time_step_setting": "auto" - }, - "data": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "dims": [] - }, - "x": { - "attrs": { - "long_name": "longitude", - "units": "degrees_east" - }, - "data": "hash_-5399622063019475031_len_28", - "dims": [ - "x" - ] - }, - "y": { - "attrs": { - "long_name": "latitude", - "units": "degrees_north" - }, - "data": "hash_-1457289664996315734_len_37", - "dims": [ - "y" - ] - } - }, - "data_vars": { - "APCP_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Total Precipitation", - "short_name": "APCP_surface", - "units": "kg/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DLWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Long-Wave Rad. Flux", - "short_name": "DLWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "DSWRF_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Downward Short-Wave Rad. Flux", - "short_name": "DSWRF_surface", - "units": "W/m^2" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "PRES_surface": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "surface", - "long_name": "Pressure", - "short_name": "PRES_surface", - "units": "Pa" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "SPFH_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Specific Humidity", - "short_name": "SPFH_2maboveground", - "units": "kg/kg" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "TMP_2maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "2 m above ground", - "long_name": "Temperature", - "short_name": "TMP_2maboveground", - "units": "K" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "UGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "U-Component of Wind", - "short_name": "UGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - }, - "VGRD_10maboveground": { - "attrs": { - "AORC_Contact": "aorc.info@noaa.gov", - "aorc_version": "v1.1", - "crs": "EPSG:4326", - "level": "10 m above ground", - "long_name": "V-Component of Wind", - "short_name": "VGRD_10maboveground", - "units": "m/s" - }, - "data": null, - "dims": [ - "y", - "x" - ] - } - }, - "dims": { - "x": 28, - "y": 37 - } - }, - "aws_time": null, - "b_date_proc": "2013-07-01T00:00:00", - "bmi_time": 10800, - "bmi_time_index": 3, - "cfsv2EnsMember": null, - "config_path": null, - "cosalpha_var": null, - "currentCustomForceNum": 0, - "currentForceNum": 1, - "current_fcst_cycle": "2013-07-01T00:00:00", - "current_output_date": "2013-07-01T03:00:00", - "current_output_step": 3, - "current_time": "2013-07-01T03:00:00", - "customFcstFreq": [], - "customSuppPcpFreq": null, - "cycle_length_minutes": 4260, - "dScaleParamDirs": [ - "/ngen-app/data" - ], - "e_date_proc": null, - "elemconn_var": "elementConn", - "elemcoords_var": "centerCoords", - "element_id_var": "element_id", - "errFlag": 0, - "errMsg": null, - "fcst_freq": 60, - "fcst_input_horizons": [ - 4260 - ], - "fcst_input_offsets": [ - 0 - ], - "fcst_shift": 0, - "first_fcst_cycle": "2013-07-01T00:00:00", - "forceTemoralInterp": [ - 0 - ], - "forcing_output": 0, - "future_time": null, - "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", - "globalNdv": -9999.0, - "grid_meta": null, - "grid_type": "hydrofabric", - "hgt_elem_var": null, - "hgt_var": null, - "ignored_border_widths": [ - 0 - ], - "include_lqfrac": 1, - "input_force_dirs": [ - "s3://null" - ], - "input_force_mandatory": [ - 0 - ], - "input_force_types": [ - "GRIB2" - ], - "input_forcings": [ - 12 - ], - "lat_var": null, - "logFile": null, - "logHandle": null, - "lon_var": null, - "look_back": -9999, - "lwBiasCorrectOpt": [ - 0 - ], - "nFcsts": 1, - "nodecoords_var": "nodeCoords", - "num_output_steps": 71, - "num_supp_output_steps": null, - "number_custom_inputs": 0, - "number_inputs": 1, - "number_supp_pcp": 0, - "numelemconn_var": "numElementConn", - "nwmConfig": "AORC", - "nwmVersion": 4.0, - "nwm_domain": null, - "nwm_geogrid": null, - "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", - "nwm_url": null, - "output_freq": 60, - "paramFlagArray": null, - "precipBiasCorrectOpt": [ - 0 - ], - "precipDownscaleOpt": [ - 0 - ], - "precip_only_flag": false, - "prev_output_date": "2013-07-01T00:00:00", - "process_window": null, - "psfcBiasCorrectOpt": [ - 0 - ], - "psfcDownscaleOpt": [ - 0 - ], - "q2BiasCorrectOpt": [ - 0 - ], - "q2dDownscaleOpt": [ - 0 - ], - "realtime_flag": false, - "refcst_flag": true, - "regrid_opt": [ - 1 - ], - "regrid_opt_supp_pcp": null, - "rqiMethod": null, - "rqiThresh": 1.0, - "runCfsNldasBiasCorrect": false, - "sinalpha_var": null, - "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, - "slope_var": null, - "slope_var_elem": null, - "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", - "sub_output_freq": null, - "sub_output_hour": null, - "suppTemporalInterp": null, - "supp_pcp_max_hours": null, - "supp_precip_dirs": null, - "supp_precip_file_types": [], - "supp_precip_forcings": [], - "supp_precip_mandatory": null, - "supp_precip_param_dir": null, - "swBiasCorrectOpt": [ - 0 - ], - "swDownscaleOpt": [ - 0 - ], - "t2BiasCorrectOpt": [ - 0 - ], - "t2dDownscaleOpt": [ - 0 - ], - "useCompression": 0, - "useFloats": 0, - "use_data_at_current_time": true, - "weightsDir": null, - "windBiasCorrect": [ - 0 - ] - }, "rank": 1, "size": 2 }, @@ -1116,5 +810,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_finalize_n1_rank0_.json b/tests/test_data/expected_results/test_expected_bmi_model_finalize_n1_rank0_.json index f82eb7a5..5086d888 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_finalize_n1_rank0_.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_finalize_n1_rank0_.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,7 +118,693 @@ "initial_time": 0, "time_step_seconds": 3600 }, - "geo_meta": null, + "dimensionality": 1, + "geo_meta": { + "approx_centroid_global_xy": [ + -72.05503025291092, + 41.7594933573475 + ], + "centerCoords": null, + "config_options": { + "ExactExtract": null, + "actual_output_steps": 71, + "ana_flag": 0, + "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", + "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", + "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", + "aorc_conus_year_url": "{source}/{year}.zarr", + "aws": true, + "aws_obj": { + "attrs": {}, + "coords": { + "spatial_ref": { + "attrs": { + "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]", + "geographic_crs_name": "WGS 84", + "grid_mapping_name": "latitude_longitude", + "horizontal_datum_name": "World Geodetic System 1984", + "inverse_flattening": 298.257223563, + "longitude_of_prime_meridian": 0.0, + "prime_meridian_name": "Greenwich", + "reference_ellipsoid_name": "WGS 84", + "semi_major_axis": 6378137.0, + "semi_minor_axis": 6356752.314245179, + "spatial_ref": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" + }, + "data": 0, + "dims": [] + }, + "time": { + "attrs": { + "long_name": "verification time generated by wgrib2 function verftime()", + "reference_date": "2013.01.01 00:00:00 UTC", + "reference_time": 1356998400.0, + "reference_time_description": "kind of product unclear, reference date is variable, min found reference date is given", + "reference_time_type": 0, + "time_step": 0.0, + "time_step_setting": "auto" + }, + "data": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", + "dims": [] + }, + "x": { + "attrs": { + "long_name": "longitude", + "units": "degrees_east" + }, + "data": "hash_-5399622063019475031_len_28", + "dims": [ + "x" + ] + }, + "y": { + "attrs": { + "long_name": "latitude", + "units": "degrees_north" + }, + "data": "hash_-1457289664996315734_len_37", + "dims": [ + "y" + ] + } + }, + "data_vars": { + "APCP_surface": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "surface", + "long_name": "Total Precipitation", + "short_name": "APCP_surface", + "units": "kg/m^2" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "DLWRF_surface": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "surface", + "long_name": "Downward Long-Wave Rad. Flux", + "short_name": "DLWRF_surface", + "units": "W/m^2" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "DSWRF_surface": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "surface", + "long_name": "Downward Short-Wave Rad. Flux", + "short_name": "DSWRF_surface", + "units": "W/m^2" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "PRES_surface": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "surface", + "long_name": "Pressure", + "short_name": "PRES_surface", + "units": "Pa" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "SPFH_2maboveground": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "2 m above ground", + "long_name": "Specific Humidity", + "short_name": "SPFH_2maboveground", + "units": "kg/kg" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "TMP_2maboveground": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "2 m above ground", + "long_name": "Temperature", + "short_name": "TMP_2maboveground", + "units": "K" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "UGRD_10maboveground": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "10 m above ground", + "long_name": "U-Component of Wind", + "short_name": "UGRD_10maboveground", + "units": "m/s" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "VGRD_10maboveground": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "10 m above ground", + "long_name": "V-Component of Wind", + "short_name": "VGRD_10maboveground", + "units": "m/s" + }, + "data": null, + "dims": [ + "y", + "x" + ] + } + }, + "dims": { + "x": 28, + "y": 37 + } + }, + "aws_time": null, + "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, + "bmi_time": 10800, + "bmi_time_index": 3, + "cfsv2EnsMember": null, + "cosalpha_var": null, + "currentCustomForceNum": 0, + "currentForceNum": 1, + "current_fcst_cycle": "2013-07-01T00:00:00", + "current_output_date": "2013-07-01T03:00:00", + "current_output_step": 3, + "current_time": "2013-07-01T03:00:00", + "customFcstFreq": [], + "customSuppPcpFreq": null, + "cycle_length_minutes": 4260, + "dScaleParamDirs": [ + "/ngen-app/data" + ], + "e_date_proc": null, + "elemconn_var": "elementConn", + "elemcoords_var": "centerCoords", + "element_id_var": "element_id", + "errFlag": 0, + "errMsg": null, + "fcst_freq": 60, + "fcst_input_horizons": [ + 4260 + ], + "fcst_input_offsets": [ + 0 + ], + "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], + "first_fcst_cycle": "2013-07-01T00:00:00", + "forceTemoralInterp": [ + 0 + ], + "force_count": 27, + "forcing_output": 0, + "future_time": null, + "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "globalNdv": -9999.0, + "grid_meta": null, + "grid_type": "hydrofabric", + "hgt_var": null, + "ignored_border_widths": [ + 0 + ], + "include_lqfrac": 1, + "input_force_dirs": [ + "s3://null" + ], + "input_force_mandatory": [ + 0 + ], + "input_force_types": [ + "GRIB2" + ], + "input_forcings": [ + 12 + ], + "lat_var": null, + "logFile": null, + "logHandle": null, + "lon_var": null, + "look_back": -9999, + "lwBiasCorrectOpt": [ + 0 + ], + "nFcsts": 1, + "nodecoords_var": "nodeCoords", + "num_output_steps": 71, + "num_supp_output_steps": null, + "number_custom_inputs": 0, + "number_inputs": 1, + "number_supp_pcp": 0, + "numelemconn_var": "numElementConn", + "nwmConfig": "AORC", + "nwmVersion": 4.0, + "nwm_domain": null, + "nwm_geogrid": null, + "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", + "nwm_url": null, + "output_freq": 60, + "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, + "precipBiasCorrectOpt": [ + 0 + ], + "precipDownscaleOpt": [ + 0 + ], + "precip_only_flag": false, + "prev_output_date": "2013-07-01T00:00:00", + "process_window": null, + "psfcBiasCorrectOpt": [ + 0 + ], + "psfcDownscaleOpt": [ + 0 + ], + "q2BiasCorrectOpt": [ + 0 + ], + "q2dDownscaleOpt": [ + 0 + ], + "realtime_flag": false, + "refcst_flag": true, + "regrid_opt": [ + 1 + ], + "regrid_opt_supp_pcp": null, + "rqiMethod": null, + "rqiThresh": null, + "runCfsNldasBiasCorrect": false, + "sinalpha_var": null, + "slope_azimuth_var": null, + "slope_var": null, + "spatial_meta": null, + "statusMsg": "Starting BMI finalize()", + "sub_output_freq": null, + "sub_output_hour": null, + "suppTemporalInterp": null, + "supp_input_offsets": null, + "supp_pcp_max_hours": null, + "supp_precip_count": 15, + "supp_precip_dirs": null, + "supp_precip_file_types": [], + "supp_precip_forcings": [], + "supp_precip_mandatory": null, + "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], + "swBiasCorrectOpt": [ + 0 + ], + "swDownscaleOpt": [ + 0 + ], + "t2BiasCorrectOpt": [ + 0 + ], + "t2dDownscaleOpt": [ + 0 + ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, + "useCompression": 0, + "useFloats": 0, + "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, + "weightsDir": null, + "windBiasCorrect": [ + 0 + ] + }, + "cosa_grid": null, + "crs_atts": null, + "dx_meters": null, + "dy_meters": null, + "element_ids": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ], + "element_ids_global": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ], + "elementcoords_global": [ + [ + -72.05141087733058, + 41.67904491423198 + ], + [ + -72.05118973471748, + 41.739612580494466 + ], + [ + -72.0334056658147, + 41.72174218772185 + ], + [ + -72.06530692999942, + 41.77071194478257 + ], + [ + -72.08488656934233, + 41.78930917764987 + ], + [ + -72.04984213921676, + 41.79151575447281 + ], + [ + -72.04916985395522, + 41.82451694207896 + ] + ], + "esmf_ds": null, + "esmf_grid": { + "_area": [ + null, + null + ], + "_coord_sys": null, + "_coords": [ + [ + "hash_2904886930620536845_len_582", + "hash_902249663378761532_len_582" + ], + [ + [ + -72.05141087733058, + -72.05118973471748, + -72.0334056658147, + -72.06530692999942, + -72.08488656934233, + -72.04984213921676, + -72.04916985395522 + ], + [ + 41.67904491423198, + 41.739612580494466, + 41.72174218772185, + 41.77071194478257, + 41.78930917764987, + 41.79151575447281, + 41.82451694207896 + ] + ] + ], + "_finalized": false, + "_mask": [ + null, + null + ], + "_meta": {}, + "_parametric_dim": 2, + "_rank": 1, + "_size": [ + 582, + 7 + ], + "_size_owned": [ + 582, + 7 + ], + "_spatial_dim": null, + "_struct": {} + }, + "esmf_lat": null, + "esmf_lon": null, + "geogrid_ds": { + "attrs": { + "gridType": "unstructured", + "version": "0.9" + }, + "coords": {}, + "data_vars": { + "centerCoords": { + "attrs": { + "units": "degrees" + }, + "data": [ + [ + -72.05141087733058, + 41.67904491423198 + ], + [ + -72.05118973471748, + 41.739612580494466 + ], + [ + -72.0334056658147, + 41.72174218772185 + ], + [ + -72.06530692999942, + 41.77071194478257 + ], + [ + -72.08488656934233, + 41.78930917764987 + ], + [ + -72.04984213921676, + 41.79151575447281 + ], + [ + -72.04916985395522, + 41.82451694207896 + ] + ], + "dims": [ + "elementCount", + "coordDim" + ] + }, + "elementConn": { + "attrs": { + "long_name": "Node Indices that define the element connectivity" + }, + "data": "hash_5853656558824341831_len_781", + "dims": [ + "connectionCount" + ] + }, + "element_id": { + "attrs": { + "long_name": "False 32-bit catchment IDs use for ESMF mesh generation" + }, + "data": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ], + "dims": [ + "elementCount" + ] + }, + "nodeCoords": { + "attrs": { + "units": "degrees" + }, + "data": null, + "dims": [ + "nodeCount", + "coordDim" + ] + }, + "numElementConn": { + "attrs": { + "long_name": "Number of nodes per element" + }, + "data": [ + 160, + 119, + 95, + 68, + 69, + 173, + 97 + ], + "dims": [ + "elementCount" + ] + } + }, + "dims": { + "connectionCount": 781, + "coordDim": 2, + "elementCount": 7, + "nodeCount": 582 + } + }, + "height": null, + "height_elem": null, + "heights_global": null, + "inds": null, + "lat_bounds": "hash_902249663378761532_len_582", + "latitude_grid": [ + 41.67904491423198, + 41.739612580494466, + 41.72174218772185, + 41.77071194478257, + 41.78930917764987, + 41.79151575447281, + 41.82451694207896 + ], + "latitude_grid_elem": null, + "lon_bounds": "hash_2904886930620536845_len_582", + "longitude_grid": [ + -72.05141087733058, + -72.05118973471748, + -72.0334056658147, + -72.06530692999942, + -72.08488656934233, + -72.04984213921676, + -72.04916985395522 + ], + "longitude_grid_elem": null, + "mesh_inds": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ], + "mesh_inds_elem": null, + "mpi_config": { + "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", + "rank": 0, + "size": 1 + }, + "nodeCoords": null, + "nx_global": 7, + "nx_global_elem": null, + "nx_local": 7, + "nx_local_elem": null, + "ny_global": 7, + "ny_global_elem": null, + "ny_local": 7, + "ny_local_elem": null, + "pet_element_inds": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ], + "sina_grid": null, + "slope": null, + "slope_elem": null, + "slopes_global": null, + "slp_azi": null, + "slp_azi_elem": null, + "slp_azi_global": null, + "spatial_global_atts": null, + "spatial_metadata_exists": false, + "x_coord_atts": null, + "x_coords": null, + "x_lower_bound": null, + "x_upper_bound": null, + "y_coord_atts": null, + "y_coords": null, + "y_lower_bound": null, + "y_upper_bound": null + }, "grid_4": { "_grid_x": [ -72.05141087733057, @@ -159,5 +846,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank0_.json b/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank0_.json index f856bf7f..fdcd8db2 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank0_.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank0_.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,7 +118,672 @@ "initial_time": 0, "time_step_seconds": 3600 }, - "geo_meta": null, + "dimensionality": 1, + "geo_meta": { + "approx_centroid_global_xy": [ + -72.05503025291092, + 41.7594933573475 + ], + "centerCoords": null, + "config_options": { + "ExactExtract": null, + "actual_output_steps": 71, + "ana_flag": 0, + "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", + "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", + "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", + "aorc_conus_year_url": "{source}/{year}.zarr", + "aws": true, + "aws_obj": { + "attrs": {}, + "coords": { + "spatial_ref": { + "attrs": { + "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]", + "geographic_crs_name": "WGS 84", + "grid_mapping_name": "latitude_longitude", + "horizontal_datum_name": "World Geodetic System 1984", + "inverse_flattening": 298.257223563, + "longitude_of_prime_meridian": 0.0, + "prime_meridian_name": "Greenwich", + "reference_ellipsoid_name": "WGS 84", + "semi_major_axis": 6378137.0, + "semi_minor_axis": 6356752.314245179, + "spatial_ref": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" + }, + "data": 0, + "dims": [] + }, + "time": { + "attrs": { + "long_name": "verification time generated by wgrib2 function verftime()", + "reference_date": "2013.01.01 00:00:00 UTC", + "reference_time": 1356998400.0, + "reference_time_description": "kind of product unclear, reference date is variable, min found reference date is given", + "reference_time_type": 0, + "time_step": 0.0, + "time_step_setting": "auto" + }, + "data": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", + "dims": [] + }, + "x": { + "attrs": { + "long_name": "longitude", + "units": "degrees_east" + }, + "data": "hash_-5399622063019475031_len_28", + "dims": [ + "x" + ] + }, + "y": { + "attrs": { + "long_name": "latitude", + "units": "degrees_north" + }, + "data": "hash_-1457289664996315734_len_37", + "dims": [ + "y" + ] + } + }, + "data_vars": { + "APCP_surface": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "surface", + "long_name": "Total Precipitation", + "short_name": "APCP_surface", + "units": "kg/m^2" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "DLWRF_surface": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "surface", + "long_name": "Downward Long-Wave Rad. Flux", + "short_name": "DLWRF_surface", + "units": "W/m^2" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "DSWRF_surface": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "surface", + "long_name": "Downward Short-Wave Rad. Flux", + "short_name": "DSWRF_surface", + "units": "W/m^2" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "PRES_surface": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "surface", + "long_name": "Pressure", + "short_name": "PRES_surface", + "units": "Pa" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "SPFH_2maboveground": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "2 m above ground", + "long_name": "Specific Humidity", + "short_name": "SPFH_2maboveground", + "units": "kg/kg" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "TMP_2maboveground": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "2 m above ground", + "long_name": "Temperature", + "short_name": "TMP_2maboveground", + "units": "K" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "UGRD_10maboveground": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "10 m above ground", + "long_name": "U-Component of Wind", + "short_name": "UGRD_10maboveground", + "units": "m/s" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "VGRD_10maboveground": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "10 m above ground", + "long_name": "V-Component of Wind", + "short_name": "VGRD_10maboveground", + "units": "m/s" + }, + "data": null, + "dims": [ + "y", + "x" + ] + } + }, + "dims": { + "x": 28, + "y": 37 + } + }, + "aws_time": null, + "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, + "bmi_time": 10800, + "bmi_time_index": 3, + "cfsv2EnsMember": null, + "cosalpha_var": null, + "currentCustomForceNum": 0, + "currentForceNum": 1, + "current_fcst_cycle": "2013-07-01T00:00:00", + "current_output_date": "2013-07-01T03:00:00", + "current_output_step": 3, + "current_time": "2013-07-01T03:00:00", + "customFcstFreq": [], + "customSuppPcpFreq": null, + "cycle_length_minutes": 4260, + "dScaleParamDirs": [ + "/ngen-app/data" + ], + "e_date_proc": null, + "elemconn_var": "elementConn", + "elemcoords_var": "centerCoords", + "element_id_var": "element_id", + "errFlag": 0, + "errMsg": null, + "fcst_freq": 60, + "fcst_input_horizons": [ + 4260 + ], + "fcst_input_offsets": [ + 0 + ], + "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], + "first_fcst_cycle": "2013-07-01T00:00:00", + "forceTemoralInterp": [ + 0 + ], + "force_count": 27, + "forcing_output": 0, + "future_time": null, + "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "globalNdv": -9999.0, + "grid_meta": null, + "grid_type": "hydrofabric", + "hgt_var": null, + "ignored_border_widths": [ + 0 + ], + "include_lqfrac": 1, + "input_force_dirs": [ + "s3://null" + ], + "input_force_mandatory": [ + 0 + ], + "input_force_types": [ + "GRIB2" + ], + "input_forcings": [ + 12 + ], + "lat_var": null, + "logFile": null, + "logHandle": null, + "lon_var": null, + "look_back": -9999, + "lwBiasCorrectOpt": [ + 0 + ], + "nFcsts": 1, + "nodecoords_var": "nodeCoords", + "num_output_steps": 71, + "num_supp_output_steps": null, + "number_custom_inputs": 0, + "number_inputs": 1, + "number_supp_pcp": 0, + "numelemconn_var": "numElementConn", + "nwmConfig": "AORC", + "nwmVersion": 4.0, + "nwm_domain": null, + "nwm_geogrid": null, + "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", + "nwm_url": null, + "output_freq": 60, + "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, + "precipBiasCorrectOpt": [ + 0 + ], + "precipDownscaleOpt": [ + 0 + ], + "precip_only_flag": false, + "prev_output_date": "2013-07-01T00:00:00", + "process_window": null, + "psfcBiasCorrectOpt": [ + 0 + ], + "psfcDownscaleOpt": [ + 0 + ], + "q2BiasCorrectOpt": [ + 0 + ], + "q2dDownscaleOpt": [ + 0 + ], + "realtime_flag": false, + "refcst_flag": true, + "regrid_opt": [ + 1 + ], + "regrid_opt_supp_pcp": null, + "rqiMethod": null, + "rqiThresh": null, + "runCfsNldasBiasCorrect": false, + "sinalpha_var": null, + "slope_azimuth_var": null, + "slope_var": null, + "spatial_meta": null, + "statusMsg": "Starting BMI finalize()", + "sub_output_freq": null, + "sub_output_hour": null, + "suppTemporalInterp": null, + "supp_input_offsets": null, + "supp_pcp_max_hours": null, + "supp_precip_count": 15, + "supp_precip_dirs": null, + "supp_precip_file_types": [], + "supp_precip_forcings": [], + "supp_precip_mandatory": null, + "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], + "swBiasCorrectOpt": [ + 0 + ], + "swDownscaleOpt": [ + 0 + ], + "t2BiasCorrectOpt": [ + 0 + ], + "t2dDownscaleOpt": [ + 0 + ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, + "useCompression": 0, + "useFloats": 0, + "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, + "weightsDir": null, + "windBiasCorrect": [ + 0 + ] + }, + "cosa_grid": null, + "crs_atts": null, + "dx_meters": null, + "dy_meters": null, + "element_ids": [ + 0, + 1, + 2, + 3 + ], + "element_ids_global": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ], + "elementcoords_global": [ + [ + -72.05141087733058, + 41.67904491423198 + ], + [ + -72.05118973471748, + 41.739612580494466 + ], + [ + -72.0334056658147, + 41.72174218772185 + ], + [ + -72.06530692999942, + 41.77071194478257 + ], + [ + -72.08488656934233, + 41.78930917764987 + ], + [ + -72.04984213921676, + 41.79151575447281 + ], + [ + -72.04916985395522, + 41.82451694207896 + ] + ], + "esmf_ds": null, + "esmf_grid": { + "_area": [ + null, + null + ], + "_coord_sys": null, + "_coords": [ + [ + "hash_351698735832278484_len_364", + "hash_-6066707896656524608_len_364" + ], + [ + [ + -72.05141087733058, + -72.05118973471748, + -72.0334056658147, + -72.06530692999942 + ], + [ + 41.67904491423198, + 41.739612580494466, + 41.72174218772185, + 41.77071194478257 + ] + ] + ], + "_finalized": false, + "_mask": [ + null, + null + ], + "_meta": {}, + "_parametric_dim": 2, + "_rank": 1, + "_size": [ + 364, + 4 + ], + "_size_owned": [ + 364, + 4 + ], + "_spatial_dim": null, + "_struct": {} + }, + "esmf_lat": null, + "esmf_lon": null, + "geogrid_ds": { + "attrs": { + "gridType": "unstructured", + "version": "0.9" + }, + "coords": {}, + "data_vars": { + "centerCoords": { + "attrs": { + "units": "degrees" + }, + "data": [ + [ + -72.05141087733058, + 41.67904491423198 + ], + [ + -72.05118973471748, + 41.739612580494466 + ], + [ + -72.0334056658147, + 41.72174218772185 + ], + [ + -72.06530692999942, + 41.77071194478257 + ], + [ + -72.08488656934233, + 41.78930917764987 + ], + [ + -72.04984213921676, + 41.79151575447281 + ], + [ + -72.04916985395522, + 41.82451694207896 + ] + ], + "dims": [ + "elementCount", + "coordDim" + ] + }, + "elementConn": { + "attrs": { + "long_name": "Node Indices that define the element connectivity" + }, + "data": "hash_5853656558824341831_len_781", + "dims": [ + "connectionCount" + ] + }, + "element_id": { + "attrs": { + "long_name": "False 32-bit catchment IDs use for ESMF mesh generation" + }, + "data": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ], + "dims": [ + "elementCount" + ] + }, + "nodeCoords": { + "attrs": { + "units": "degrees" + }, + "data": null, + "dims": [ + "nodeCount", + "coordDim" + ] + }, + "numElementConn": { + "attrs": { + "long_name": "Number of nodes per element" + }, + "data": [ + 160, + 119, + 95, + 68, + 69, + 173, + 97 + ], + "dims": [ + "elementCount" + ] + } + }, + "dims": { + "connectionCount": 781, + "coordDim": 2, + "elementCount": 7, + "nodeCount": 582 + } + }, + "height": null, + "height_elem": null, + "heights_global": null, + "inds": null, + "lat_bounds": "hash_902249663378761532_len_582", + "latitude_grid": [ + 41.67904491423198, + 41.739612580494466, + 41.72174218772185, + 41.77071194478257 + ], + "latitude_grid_elem": null, + "lon_bounds": "hash_2904886930620536845_len_582", + "longitude_grid": [ + -72.05141087733058, + -72.05118973471748, + -72.0334056658147, + -72.06530692999942 + ], + "longitude_grid_elem": null, + "mesh_inds": [ + 0, + 1, + 2, + 3 + ], + "mesh_inds_elem": null, + "mpi_config": { + "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", + "rank": 0, + "size": 2 + }, + "nodeCoords": null, + "nx_global": 7, + "nx_global_elem": null, + "nx_local": 4, + "nx_local_elem": null, + "ny_global": 7, + "ny_global_elem": null, + "ny_local": 4, + "ny_local_elem": null, + "pet_element_inds": [ + 0, + 1, + 2, + 3 + ], + "sina_grid": null, + "slope": null, + "slope_elem": null, + "slopes_global": null, + "slp_azi": null, + "slp_azi_elem": null, + "slp_azi_global": null, + "spatial_global_atts": null, + "spatial_metadata_exists": false, + "x_coord_atts": null, + "x_coords": null, + "x_lower_bound": null, + "x_upper_bound": null, + "y_coord_atts": null, + "y_coords": null, + "y_lower_bound": null, + "y_upper_bound": null + }, "grid_4": { "_grid_x": [ -72.05141087733057, @@ -153,5 +819,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank1_.json b/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank1_.json index e15a50a2..4339fbe6 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank1_.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank1_.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,7 +118,665 @@ "initial_time": 0, "time_step_seconds": 3600 }, - "geo_meta": null, + "dimensionality": 1, + "geo_meta": { + "approx_centroid_global_xy": [ + -72.05503025291092, + 41.7594933573475 + ], + "centerCoords": null, + "config_options": { + "ExactExtract": null, + "actual_output_steps": 71, + "ana_flag": 0, + "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", + "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", + "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", + "aorc_conus_year_url": "{source}/{year}.zarr", + "aws": true, + "aws_obj": { + "attrs": {}, + "coords": { + "spatial_ref": { + "attrs": { + "crs_wkt": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]", + "geographic_crs_name": "WGS 84", + "grid_mapping_name": "latitude_longitude", + "horizontal_datum_name": "World Geodetic System 1984", + "inverse_flattening": 298.257223563, + "longitude_of_prime_meridian": 0.0, + "prime_meridian_name": "Greenwich", + "reference_ellipsoid_name": "WGS 84", + "semi_major_axis": 6378137.0, + "semi_minor_axis": 6356752.314245179, + "spatial_ref": "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" + }, + "data": 0, + "dims": [] + }, + "time": { + "attrs": { + "long_name": "verification time generated by wgrib2 function verftime()", + "reference_date": "2013.01.01 00:00:00 UTC", + "reference_time": 1356998400.0, + "reference_time_description": "kind of product unclear, reference date is variable, min found reference date is given", + "reference_time_type": 0, + "time_step": 0.0, + "time_step_setting": "auto" + }, + "data": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", + "dims": [] + }, + "x": { + "attrs": { + "long_name": "longitude", + "units": "degrees_east" + }, + "data": "hash_-5399622063019475031_len_28", + "dims": [ + "x" + ] + }, + "y": { + "attrs": { + "long_name": "latitude", + "units": "degrees_north" + }, + "data": "hash_-1457289664996315734_len_37", + "dims": [ + "y" + ] + } + }, + "data_vars": { + "APCP_surface": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "surface", + "long_name": "Total Precipitation", + "short_name": "APCP_surface", + "units": "kg/m^2" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "DLWRF_surface": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "surface", + "long_name": "Downward Long-Wave Rad. Flux", + "short_name": "DLWRF_surface", + "units": "W/m^2" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "DSWRF_surface": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "surface", + "long_name": "Downward Short-Wave Rad. Flux", + "short_name": "DSWRF_surface", + "units": "W/m^2" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "PRES_surface": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "surface", + "long_name": "Pressure", + "short_name": "PRES_surface", + "units": "Pa" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "SPFH_2maboveground": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "2 m above ground", + "long_name": "Specific Humidity", + "short_name": "SPFH_2maboveground", + "units": "kg/kg" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "TMP_2maboveground": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "2 m above ground", + "long_name": "Temperature", + "short_name": "TMP_2maboveground", + "units": "K" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "UGRD_10maboveground": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "10 m above ground", + "long_name": "U-Component of Wind", + "short_name": "UGRD_10maboveground", + "units": "m/s" + }, + "data": null, + "dims": [ + "y", + "x" + ] + }, + "VGRD_10maboveground": { + "attrs": { + "AORC_Contact": "aorc.info@noaa.gov", + "aorc_version": "v1.1", + "crs": "EPSG:4326", + "level": "10 m above ground", + "long_name": "V-Component of Wind", + "short_name": "VGRD_10maboveground", + "units": "m/s" + }, + "data": null, + "dims": [ + "y", + "x" + ] + } + }, + "dims": { + "x": 28, + "y": 37 + } + }, + "aws_time": null, + "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, + "bmi_time": 10800, + "bmi_time_index": 3, + "cfsv2EnsMember": null, + "cosalpha_var": null, + "currentCustomForceNum": 0, + "currentForceNum": 1, + "current_fcst_cycle": "2013-07-01T00:00:00", + "current_output_date": "2013-07-01T03:00:00", + "current_output_step": 3, + "current_time": "2013-07-01T03:00:00", + "customFcstFreq": [], + "customSuppPcpFreq": null, + "cycle_length_minutes": 4260, + "dScaleParamDirs": [ + "/ngen-app/data" + ], + "e_date_proc": null, + "elemconn_var": "elementConn", + "elemcoords_var": "centerCoords", + "element_id_var": "element_id", + "errFlag": 0, + "errMsg": null, + "fcst_freq": 60, + "fcst_input_horizons": [ + 4260 + ], + "fcst_input_offsets": [ + 0 + ], + "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], + "first_fcst_cycle": "2013-07-01T00:00:00", + "forceTemoralInterp": [ + 0 + ], + "force_count": 27, + "forcing_output": 0, + "future_time": null, + "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "globalNdv": -9999.0, + "grid_meta": null, + "grid_type": "hydrofabric", + "hgt_var": null, + "ignored_border_widths": [ + 0 + ], + "include_lqfrac": 1, + "input_force_dirs": [ + "s3://null" + ], + "input_force_mandatory": [ + 0 + ], + "input_force_types": [ + "GRIB2" + ], + "input_forcings": [ + 12 + ], + "lat_var": null, + "logFile": null, + "logHandle": null, + "lon_var": null, + "look_back": -9999, + "lwBiasCorrectOpt": [ + 0 + ], + "nFcsts": 1, + "nodecoords_var": "nodeCoords", + "num_output_steps": 71, + "num_supp_output_steps": null, + "number_custom_inputs": 0, + "number_inputs": 1, + "number_supp_pcp": 0, + "numelemconn_var": "numElementConn", + "nwmConfig": "AORC", + "nwmVersion": 4.0, + "nwm_domain": null, + "nwm_geogrid": null, + "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", + "nwm_url": null, + "output_freq": 60, + "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, + "precipBiasCorrectOpt": [ + 0 + ], + "precipDownscaleOpt": [ + 0 + ], + "precip_only_flag": false, + "prev_output_date": "2013-07-01T00:00:00", + "process_window": null, + "psfcBiasCorrectOpt": [ + 0 + ], + "psfcDownscaleOpt": [ + 0 + ], + "q2BiasCorrectOpt": [ + 0 + ], + "q2dDownscaleOpt": [ + 0 + ], + "realtime_flag": false, + "refcst_flag": true, + "regrid_opt": [ + 1 + ], + "regrid_opt_supp_pcp": null, + "rqiMethod": null, + "rqiThresh": null, + "runCfsNldasBiasCorrect": false, + "sinalpha_var": null, + "slope_azimuth_var": null, + "slope_var": null, + "spatial_meta": null, + "statusMsg": "Starting BMI finalize()", + "sub_output_freq": null, + "sub_output_hour": null, + "suppTemporalInterp": null, + "supp_input_offsets": null, + "supp_pcp_max_hours": null, + "supp_precip_count": 15, + "supp_precip_dirs": null, + "supp_precip_file_types": [], + "supp_precip_forcings": [], + "supp_precip_mandatory": null, + "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], + "swBiasCorrectOpt": [ + 0 + ], + "swDownscaleOpt": [ + 0 + ], + "t2BiasCorrectOpt": [ + 0 + ], + "t2dDownscaleOpt": [ + 0 + ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, + "useCompression": 0, + "useFloats": 0, + "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, + "weightsDir": null, + "windBiasCorrect": [ + 0 + ] + }, + "cosa_grid": null, + "crs_atts": null, + "dx_meters": null, + "dy_meters": null, + "element_ids": [ + 4, + 5, + 6 + ], + "element_ids_global": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ], + "elementcoords_global": [ + [ + -72.05141087733058, + 41.67904491423198 + ], + [ + -72.05118973471748, + 41.739612580494466 + ], + [ + -72.0334056658147, + 41.72174218772185 + ], + [ + -72.06530692999942, + 41.77071194478257 + ], + [ + -72.08488656934233, + 41.78930917764987 + ], + [ + -72.04984213921676, + 41.79151575447281 + ], + [ + -72.04916985395522, + 41.82451694207896 + ] + ], + "esmf_ds": null, + "esmf_grid": { + "_area": [ + null, + null + ], + "_coord_sys": null, + "_coords": [ + [ + "hash_7545881362083397004_len_218", + "hash_-1022784215004640784_len_218" + ], + [ + [ + -72.08488656934233, + -72.04984213921676, + -72.04916985395522 + ], + [ + 41.78930917764987, + 41.79151575447281, + 41.82451694207896 + ] + ] + ], + "_finalized": false, + "_mask": [ + null, + null + ], + "_meta": {}, + "_parametric_dim": 2, + "_rank": 1, + "_size": [ + 278, + 3 + ], + "_size_owned": [ + 218, + 3 + ], + "_spatial_dim": null, + "_struct": {} + }, + "esmf_lat": null, + "esmf_lon": null, + "geogrid_ds": { + "attrs": { + "gridType": "unstructured", + "version": "0.9" + }, + "coords": {}, + "data_vars": { + "centerCoords": { + "attrs": { + "units": "degrees" + }, + "data": [ + [ + -72.05141087733058, + 41.67904491423198 + ], + [ + -72.05118973471748, + 41.739612580494466 + ], + [ + -72.0334056658147, + 41.72174218772185 + ], + [ + -72.06530692999942, + 41.77071194478257 + ], + [ + -72.08488656934233, + 41.78930917764987 + ], + [ + -72.04984213921676, + 41.79151575447281 + ], + [ + -72.04916985395522, + 41.82451694207896 + ] + ], + "dims": [ + "elementCount", + "coordDim" + ] + }, + "elementConn": { + "attrs": { + "long_name": "Node Indices that define the element connectivity" + }, + "data": "hash_5853656558824341831_len_781", + "dims": [ + "connectionCount" + ] + }, + "element_id": { + "attrs": { + "long_name": "False 32-bit catchment IDs use for ESMF mesh generation" + }, + "data": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ], + "dims": [ + "elementCount" + ] + }, + "nodeCoords": { + "attrs": { + "units": "degrees" + }, + "data": null, + "dims": [ + "nodeCount", + "coordDim" + ] + }, + "numElementConn": { + "attrs": { + "long_name": "Number of nodes per element" + }, + "data": [ + 160, + 119, + 95, + 68, + 69, + 173, + 97 + ], + "dims": [ + "elementCount" + ] + } + }, + "dims": { + "connectionCount": 781, + "coordDim": 2, + "elementCount": 7, + "nodeCount": 582 + } + }, + "height": null, + "height_elem": null, + "heights_global": null, + "inds": null, + "lat_bounds": null, + "latitude_grid": [ + 41.78930917764987, + 41.79151575447281, + 41.82451694207896 + ], + "latitude_grid_elem": null, + "lon_bounds": null, + "longitude_grid": [ + -72.08488656934233, + -72.04984213921676, + -72.04916985395522 + ], + "longitude_grid_elem": null, + "mesh_inds": [ + 4, + 5, + 6 + ], + "mesh_inds_elem": null, + "mpi_config": { + "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", + "rank": 1, + "size": 2 + }, + "nodeCoords": null, + "nx_global": 7, + "nx_global_elem": null, + "nx_local": 3, + "nx_local_elem": null, + "ny_global": 7, + "ny_global_elem": null, + "ny_local": 3, + "ny_local_elem": null, + "pet_element_inds": [ + 4, + 5, + 6 + ], + "sina_grid": null, + "slope": null, + "slope_elem": null, + "slopes_global": null, + "slp_azi": null, + "slp_azi_elem": null, + "slp_azi_global": null, + "spatial_global_atts": null, + "spatial_metadata_exists": false, + "x_coord_atts": null, + "x_coords": null, + "x_lower_bound": null, + "x_upper_bound": null, + "y_coord_atts": null, + "y_coords": null, + "y_lower_bound": null, + "y_upper_bound": null + }, "grid_4": { "_grid_x": [ -72.08488656934233, @@ -151,5 +810,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_init_n1_rank0_.json b/tests/test_data/expected_results/test_expected_bmi_model_init_n1_rank0_.json index 15342a9c..0349bee9 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_init_n1_rank0_.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_init_n1_rank0_.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,6 +118,7 @@ "initial_time": 0, "time_step_seconds": 3600 }, + "dimensionality": 1, "geo_meta": { "approx_centroid_global_xy": [ -72.05503025291092, @@ -135,10 +137,29 @@ "aws_obj": null, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_time": null, "bmi_time_index": 0, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "current_fcst_cycle": null, "current_output_date": null, @@ -164,17 +185,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": null, "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -216,6 +245,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -244,24 +277,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, "statusMsg": "func esmf_mesh_retry finished after 1 attempts.", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -274,9 +312,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 @@ -533,165 +576,6 @@ "mesh_inds_elem": null, "mpi_config": { "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "config_options": { - "ExactExtract": null, - "actual_output_steps": 71, - "ana_flag": 0, - "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", - "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", - "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", - "aorc_conus_year_url": "{source}/{year}.zarr", - "aws": true, - "aws_obj": null, - "aws_time": null, - "b_date_proc": "2013-07-01T00:00:00", - "bmi_time": null, - "bmi_time_index": 0, - "cfsv2EnsMember": null, - "config_path": null, - "cosalpha_var": null, - "current_fcst_cycle": null, - "current_output_date": null, - "current_output_step": null, - "current_time": null, - "customFcstFreq": [], - "customSuppPcpFreq": null, - "cycle_length_minutes": 4260, - "dScaleParamDirs": [ - "/ngen-app/data" - ], - "e_date_proc": null, - "elemconn_var": "elementConn", - "elemcoords_var": "centerCoords", - "element_id_var": "element_id", - "errFlag": 0, - "errMsg": null, - "fcst_freq": 60, - "fcst_input_horizons": [ - 4260 - ], - "fcst_input_offsets": [ - 0 - ], - "fcst_shift": 0, - "first_fcst_cycle": null, - "forceTemoralInterp": [ - 0 - ], - "forcing_output": 0, - "future_time": null, - "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", - "globalNdv": -9999.0, - "grid_meta": null, - "grid_type": "hydrofabric", - "hgt_elem_var": null, - "hgt_var": null, - "ignored_border_widths": [ - 0 - ], - "include_lqfrac": 1, - "input_force_dirs": [ - "s3://null" - ], - "input_force_mandatory": [ - 0 - ], - "input_force_types": [ - "GRIB2" - ], - "input_forcings": [ - 12 - ], - "lat_var": null, - "logFile": null, - "logHandle": null, - "lon_var": null, - "look_back": -9999, - "lwBiasCorrectOpt": [ - 0 - ], - "nFcsts": 1, - "nodecoords_var": "nodeCoords", - "num_output_steps": 71, - "num_supp_output_steps": null, - "number_custom_inputs": 0, - "number_inputs": 1, - "number_supp_pcp": 0, - "numelemconn_var": "numElementConn", - "nwmConfig": "AORC", - "nwmVersion": 4.0, - "nwm_domain": null, - "nwm_geogrid": null, - "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", - "nwm_url": null, - "output_freq": 60, - "paramFlagArray": null, - "precipBiasCorrectOpt": [ - 0 - ], - "precipDownscaleOpt": [ - 0 - ], - "precip_only_flag": false, - "prev_output_date": null, - "process_window": null, - "psfcBiasCorrectOpt": [ - 0 - ], - "psfcDownscaleOpt": [ - 0 - ], - "q2BiasCorrectOpt": [ - 0 - ], - "q2dDownscaleOpt": [ - 0 - ], - "realtime_flag": false, - "refcst_flag": true, - "regrid_opt": [ - 1 - ], - "regrid_opt_supp_pcp": null, - "rqiMethod": null, - "rqiThresh": 1.0, - "runCfsNldasBiasCorrect": false, - "sinalpha_var": null, - "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, - "slope_var": null, - "slope_var_elem": null, - "spatial_meta": null, - "statusMsg": "func esmf_mesh_retry finished after 1 attempts.", - "sub_output_freq": null, - "sub_output_hour": null, - "suppTemporalInterp": null, - "supp_pcp_max_hours": null, - "supp_precip_dirs": null, - "supp_precip_file_types": [], - "supp_precip_forcings": [], - "supp_precip_mandatory": null, - "supp_precip_param_dir": null, - "swBiasCorrectOpt": [ - 0 - ], - "swDownscaleOpt": [ - 0 - ], - "t2BiasCorrectOpt": [ - 0 - ], - "t2dDownscaleOpt": [ - 0 - ], - "useCompression": 0, - "useFloats": 0, - "use_data_at_current_time": true, - "weightsDir": null, - "windBiasCorrect": [ - 0 - ] - }, "rank": 0, "size": 1 }, @@ -772,5 +656,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank0_.json b/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank0_.json index c3476459..1d8b1d20 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank0_.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank0_.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,6 +118,7 @@ "initial_time": 0, "time_step_seconds": 3600 }, + "dimensionality": 1, "geo_meta": { "approx_centroid_global_xy": [ -72.05503025291092, @@ -135,10 +137,29 @@ "aws_obj": null, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_time": null, "bmi_time_index": 0, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "current_fcst_cycle": null, "current_output_date": null, @@ -164,17 +185,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": null, "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -216,6 +245,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -244,24 +277,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, "statusMsg": "func esmf_mesh_retry finished after 1 attempts.", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -274,9 +312,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 @@ -341,7 +384,7 @@ "_coords": [ [ "hash_351698735832278484_len_364", - "hash_1673925891551318769_len_364" + "hash_-6066707896656524608_len_364" ], [ [ @@ -490,7 +533,7 @@ "height_elem": null, "heights_global": null, "inds": null, - "lat_bounds": "hash_2117205719057770460_len_582", + "lat_bounds": "hash_902249663378761532_len_582", "latitude_grid": [ 41.67904491423198, 41.73961258049449, @@ -515,165 +558,6 @@ "mesh_inds_elem": null, "mpi_config": { "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "config_options": { - "ExactExtract": null, - "actual_output_steps": 71, - "ana_flag": 0, - "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", - "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", - "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", - "aorc_conus_year_url": "{source}/{year}.zarr", - "aws": true, - "aws_obj": null, - "aws_time": null, - "b_date_proc": "2013-07-01T00:00:00", - "bmi_time": null, - "bmi_time_index": 0, - "cfsv2EnsMember": null, - "config_path": null, - "cosalpha_var": null, - "current_fcst_cycle": null, - "current_output_date": null, - "current_output_step": null, - "current_time": null, - "customFcstFreq": [], - "customSuppPcpFreq": null, - "cycle_length_minutes": 4260, - "dScaleParamDirs": [ - "/ngen-app/data" - ], - "e_date_proc": null, - "elemconn_var": "elementConn", - "elemcoords_var": "centerCoords", - "element_id_var": "element_id", - "errFlag": 0, - "errMsg": null, - "fcst_freq": 60, - "fcst_input_horizons": [ - 4260 - ], - "fcst_input_offsets": [ - 0 - ], - "fcst_shift": 0, - "first_fcst_cycle": null, - "forceTemoralInterp": [ - 0 - ], - "forcing_output": 0, - "future_time": null, - "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", - "globalNdv": -9999.0, - "grid_meta": null, - "grid_type": "hydrofabric", - "hgt_elem_var": null, - "hgt_var": null, - "ignored_border_widths": [ - 0 - ], - "include_lqfrac": 1, - "input_force_dirs": [ - "s3://null" - ], - "input_force_mandatory": [ - 0 - ], - "input_force_types": [ - "GRIB2" - ], - "input_forcings": [ - 12 - ], - "lat_var": null, - "logFile": null, - "logHandle": null, - "lon_var": null, - "look_back": -9999, - "lwBiasCorrectOpt": [ - 0 - ], - "nFcsts": 1, - "nodecoords_var": "nodeCoords", - "num_output_steps": 71, - "num_supp_output_steps": null, - "number_custom_inputs": 0, - "number_inputs": 1, - "number_supp_pcp": 0, - "numelemconn_var": "numElementConn", - "nwmConfig": "AORC", - "nwmVersion": 4.0, - "nwm_domain": null, - "nwm_geogrid": null, - "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", - "nwm_url": null, - "output_freq": 60, - "paramFlagArray": null, - "precipBiasCorrectOpt": [ - 0 - ], - "precipDownscaleOpt": [ - 0 - ], - "precip_only_flag": false, - "prev_output_date": null, - "process_window": null, - "psfcBiasCorrectOpt": [ - 0 - ], - "psfcDownscaleOpt": [ - 0 - ], - "q2BiasCorrectOpt": [ - 0 - ], - "q2dDownscaleOpt": [ - 0 - ], - "realtime_flag": false, - "refcst_flag": true, - "regrid_opt": [ - 1 - ], - "regrid_opt_supp_pcp": null, - "rqiMethod": null, - "rqiThresh": 1.0, - "runCfsNldasBiasCorrect": false, - "sinalpha_var": null, - "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, - "slope_var": null, - "slope_var_elem": null, - "spatial_meta": null, - "statusMsg": "func esmf_mesh_retry finished after 1 attempts.", - "sub_output_freq": null, - "sub_output_hour": null, - "suppTemporalInterp": null, - "supp_pcp_max_hours": null, - "supp_precip_dirs": null, - "supp_precip_file_types": [], - "supp_precip_forcings": [], - "supp_precip_mandatory": null, - "supp_precip_param_dir": null, - "swBiasCorrectOpt": [ - 0 - ], - "swDownscaleOpt": [ - 0 - ], - "t2BiasCorrectOpt": [ - 0 - ], - "t2dDownscaleOpt": [ - 0 - ], - "useCompression": 0, - "useFloats": 0, - "use_data_at_current_time": true, - "weightsDir": null, - "windBiasCorrect": [ - 0 - ] - }, "rank": 0, "size": 2 }, @@ -745,5 +629,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank1_.json b/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank1_.json index 18023934..e2b6c0df 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank1_.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank1_.json @@ -1,4 +1,5 @@ { + "bmi_cfg_file": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -117,6 +118,7 @@ "initial_time": 0, "time_step_seconds": 3600 }, + "dimensionality": 1, "geo_meta": { "approx_centroid_global_xy": [ -72.05503025291092, @@ -135,10 +137,29 @@ "aws_obj": null, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_time": null, "bmi_time_index": 0, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "current_fcst_cycle": null, "current_output_date": null, @@ -164,17 +185,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": null, "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -216,6 +245,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -244,24 +277,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, "statusMsg": "func esmf_mesh_retry finished after 1 attempts.", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -274,9 +312,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 @@ -340,7 +383,7 @@ "_coords": [ [ "hash_7545881362083397004_len_218", - "hash_6855503821947747755_len_218" + "hash_-1022784215004640784_len_218" ], [ [ @@ -509,165 +552,6 @@ "mesh_inds_elem": null, "mpi_config": { "comm": "ERR_NOT_JSON_SERIALIZABLE:TYPE:", - "config_options": { - "ExactExtract": null, - "actual_output_steps": 71, - "ana_flag": 0, - "aorc_alaska_source": "s3://ngwpc-data/AORC/Alaska", - "aorc_alaska_url": "{source}/{year}/{year}{month:02d}/AK_AORC-OWP_{date}.nc4", - "aorc_conus_source": "s3://noaa-nws-aorc-v1-1-1km", - "aorc_conus_year_url": "{source}/{year}.zarr", - "aws": true, - "aws_obj": null, - "aws_time": null, - "b_date_proc": "2013-07-01T00:00:00", - "bmi_time": null, - "bmi_time_index": 0, - "cfsv2EnsMember": null, - "config_path": null, - "cosalpha_var": null, - "current_fcst_cycle": null, - "current_output_date": null, - "current_output_step": null, - "current_time": null, - "customFcstFreq": [], - "customSuppPcpFreq": null, - "cycle_length_minutes": 4260, - "dScaleParamDirs": [ - "/ngen-app/data" - ], - "e_date_proc": null, - "elemconn_var": "elementConn", - "elemcoords_var": "centerCoords", - "element_id_var": "element_id", - "errFlag": 0, - "errMsg": null, - "fcst_freq": 60, - "fcst_input_horizons": [ - 4260 - ], - "fcst_input_offsets": [ - 0 - ], - "fcst_shift": 0, - "first_fcst_cycle": null, - "forceTemoralInterp": [ - 0 - ], - "forcing_output": 0, - "future_time": null, - "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", - "globalNdv": -9999.0, - "grid_meta": null, - "grid_type": "hydrofabric", - "hgt_elem_var": null, - "hgt_var": null, - "ignored_border_widths": [ - 0 - ], - "include_lqfrac": 1, - "input_force_dirs": [ - "s3://null" - ], - "input_force_mandatory": [ - 0 - ], - "input_force_types": [ - "GRIB2" - ], - "input_forcings": [ - 12 - ], - "lat_var": null, - "logFile": null, - "logHandle": null, - "lon_var": null, - "look_back": -9999, - "lwBiasCorrectOpt": [ - 0 - ], - "nFcsts": 1, - "nodecoords_var": "nodeCoords", - "num_output_steps": 71, - "num_supp_output_steps": null, - "number_custom_inputs": 0, - "number_inputs": 1, - "number_supp_pcp": 0, - "numelemconn_var": "numElementConn", - "nwmConfig": "AORC", - "nwmVersion": 4.0, - "nwm_domain": null, - "nwm_geogrid": null, - "nwm_source": "s3://noaa-nwm-retrospective-3-0-pds", - "nwm_url": null, - "output_freq": 60, - "paramFlagArray": null, - "precipBiasCorrectOpt": [ - 0 - ], - "precipDownscaleOpt": [ - 0 - ], - "precip_only_flag": false, - "prev_output_date": null, - "process_window": null, - "psfcBiasCorrectOpt": [ - 0 - ], - "psfcDownscaleOpt": [ - 0 - ], - "q2BiasCorrectOpt": [ - 0 - ], - "q2dDownscaleOpt": [ - 0 - ], - "realtime_flag": false, - "refcst_flag": true, - "regrid_opt": [ - 1 - ], - "regrid_opt_supp_pcp": null, - "rqiMethod": null, - "rqiThresh": 1.0, - "runCfsNldasBiasCorrect": false, - "sinalpha_var": null, - "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, - "slope_var": null, - "slope_var_elem": null, - "spatial_meta": null, - "statusMsg": "func esmf_mesh_retry finished after 1 attempts.", - "sub_output_freq": null, - "sub_output_hour": null, - "suppTemporalInterp": null, - "supp_pcp_max_hours": null, - "supp_precip_dirs": null, - "supp_precip_file_types": [], - "supp_precip_forcings": [], - "supp_precip_mandatory": null, - "supp_precip_param_dir": null, - "swBiasCorrectOpt": [ - 0 - ], - "swDownscaleOpt": [ - 0 - ], - "t2BiasCorrectOpt": [ - 0 - ], - "t2dDownscaleOpt": [ - 0 - ], - "useCompression": 0, - "useFloats": 0, - "use_data_at_current_time": true, - "weightsDir": null, - "windBiasCorrect": [ - 0 - ] - }, "rank": 1, "size": 2 }, @@ -736,5 +620,6 @@ -1 ] }, + "output_path": null, "var_array_lengths": 1 } \ No newline at end of file diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_1.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_1.json index bb89f16e..b2edf10e 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_1.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_1.json @@ -198,6 +198,26 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -209,8 +229,116 @@ ], "bmi_time": 3600, "bmi_time_index": 1, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -238,17 +366,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -290,6 +426,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -318,24 +458,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -348,9 +493,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_2.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_2.json index ed3c2aaa..33914021 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_2.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_2.json @@ -198,6 +198,26 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -209,8 +229,116 @@ ], "bmi_time": 7200, "bmi_time_index": 2, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -238,17 +366,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -290,6 +426,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -318,24 +458,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -348,9 +493,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_3.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_3.json index 20e3ce1c..d5781251 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_3.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_3.json @@ -198,6 +198,26 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -209,8 +229,116 @@ ], "bmi_time": 10800, "bmi_time_index": 3, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -238,17 +366,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -290,6 +426,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -318,24 +458,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -348,9 +493,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_1.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_1.json index bb89f16e..b2edf10e 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_1.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_1.json @@ -198,6 +198,26 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -209,8 +229,116 @@ ], "bmi_time": 3600, "bmi_time_index": 1, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -238,17 +366,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -290,6 +426,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -318,24 +458,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -348,9 +493,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_2.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_2.json index ed3c2aaa..33914021 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_2.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_2.json @@ -198,6 +198,26 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -209,8 +229,116 @@ ], "bmi_time": 7200, "bmi_time_index": 2, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -238,17 +366,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -290,6 +426,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -318,24 +458,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -348,9 +493,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_3.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_3.json index 20e3ce1c..d5781251 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_3.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_3.json @@ -198,6 +198,26 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -209,8 +229,116 @@ ], "bmi_time": 10800, "bmi_time_index": 3, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -238,17 +366,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -290,6 +426,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -318,24 +458,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -348,9 +493,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_1.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_1.json index bb89f16e..b2edf10e 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_1.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_1.json @@ -198,6 +198,26 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -209,8 +229,116 @@ ], "bmi_time": 3600, "bmi_time_index": 1, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -238,17 +366,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -290,6 +426,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -318,24 +458,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -348,9 +493,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_2.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_2.json index ed3c2aaa..33914021 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_2.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_2.json @@ -198,6 +198,26 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -209,8 +229,116 @@ ], "bmi_time": 7200, "bmi_time_index": 2, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -238,17 +366,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -290,6 +426,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -318,24 +458,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -348,9 +493,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_3.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_3.json index 20e3ce1c..d5781251 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_3.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_3.json @@ -198,6 +198,26 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -209,8 +229,116 @@ ], "bmi_time": 10800, "bmi_time_index": 3, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -238,17 +366,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -290,6 +426,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -318,24 +458,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, - "statusMsg": "func esmf_regridobj_call_retry finished after 1 attempts.", + "statusMsg": "End of loop for force_key 12", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -348,9 +493,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_finalize_n1_rank0_.json b/tests/test_data/expected_results/test_expected_config_options_finalize_n1_rank0_.json index 147309ce..35b7e0a4 100644 --- a/tests/test_data/expected_results/test_expected_config_options_finalize_n1_rank0_.json +++ b/tests/test_data/expected_results/test_expected_config_options_finalize_n1_rank0_.json @@ -198,6 +198,26 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -209,8 +229,116 @@ ], "bmi_time": 10800, "bmi_time_index": 3, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -238,17 +366,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -290,6 +426,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -318,24 +458,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, "statusMsg": "Starting BMI finalize()", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -348,9 +493,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank0_.json b/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank0_.json index 147309ce..35b7e0a4 100644 --- a/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank0_.json +++ b/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank0_.json @@ -198,6 +198,26 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -209,8 +229,116 @@ ], "bmi_time": 10800, "bmi_time_index": 3, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -238,17 +366,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -290,6 +426,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -318,24 +458,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, "statusMsg": "Starting BMI finalize()", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -348,9 +493,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank1_.json b/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank1_.json index 147309ce..35b7e0a4 100644 --- a/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank1_.json +++ b/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank1_.json @@ -198,6 +198,26 @@ }, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -209,8 +229,116 @@ ], "bmi_time": 10800, "bmi_time_index": 3, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "currentCustomForceNum": 0, "currentForceNum": 1, @@ -238,17 +366,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": "2013-07-01T00:00:00", "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -290,6 +426,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -318,24 +458,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, "statusMsg": "Starting BMI finalize()", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -348,9 +493,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_init_n1_rank0_.json b/tests/test_data/expected_results/test_expected_config_options_init_n1_rank0_.json index cb4682a4..115490a3 100644 --- a/tests/test_data/expected_results/test_expected_config_options_init_n1_rank0_.json +++ b/tests/test_data/expected_results/test_expected_config_options_init_n1_rank0_.json @@ -10,6 +10,26 @@ "aws_obj": null, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -21,8 +41,116 @@ ], "bmi_time": null, "bmi_time_index": 0, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "current_fcst_cycle": null, "current_output_date": null, @@ -48,17 +176,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": null, "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -100,6 +236,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -128,24 +268,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, "statusMsg": "func esmf_mesh_retry finished after 1 attempts.", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -158,9 +303,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_init_n2_rank0_.json b/tests/test_data/expected_results/test_expected_config_options_init_n2_rank0_.json index cb4682a4..115490a3 100644 --- a/tests/test_data/expected_results/test_expected_config_options_init_n2_rank0_.json +++ b/tests/test_data/expected_results/test_expected_config_options_init_n2_rank0_.json @@ -10,6 +10,26 @@ "aws_obj": null, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -21,8 +41,116 @@ ], "bmi_time": null, "bmi_time_index": 0, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "current_fcst_cycle": null, "current_output_date": null, @@ -48,17 +176,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": null, "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -100,6 +236,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -128,24 +268,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, "statusMsg": "func esmf_mesh_retry finished after 1 attempts.", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -158,9 +303,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 diff --git a/tests/test_data/expected_results/test_expected_config_options_init_n2_rank1_.json b/tests/test_data/expected_results/test_expected_config_options_init_n2_rank1_.json index cb4682a4..115490a3 100644 --- a/tests/test_data/expected_results/test_expected_config_options_init_n2_rank1_.json +++ b/tests/test_data/expected_results/test_expected_config_options_init_n2_rank1_.json @@ -10,6 +10,26 @@ "aws_obj": null, "aws_time": null, "b_date_proc": "2013-07-01T00:00:00", + "bias_correction_properties": { + "Precipitation": [ + 0 + ], + "long-wave radiation": [ + 0 + ], + "short-wave radiation": [ + 0 + ], + "specific humidity": [ + 0 + ], + "surface pressure": [ + 0 + ], + "wind forcings": [ + 0 + ] + }, "bmi_model_values__CAT-ID": [ 1285829030285639, 1285830316458152, @@ -21,8 +41,116 @@ ], "bmi_time": null, "bmi_time_index": 0, + "cfg_bmi": { + "AnAFlag": 0, + "DownscalingParamDirs": [ + "/ngen-app/data" + ], + "ElemConn": "elementConn", + "ElemCoords": "centerCoords", + "ElemID": "element_id", + "ForcingTemporalInterpolation": [ + 0 + ], + "ForecastFrequency": 60, + "ForecastInputHorizons": [ + 4260 + ], + "ForecastInputOffsets": [ + 0 + ], + "ForecastShift": 0, + "GRID_TYPE": "hydrofabric", + "GeogridIn": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/esmf_mesh/gauge_01123000_ESMF_Mesh.nc", + "Geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", + "HGTVAR": "Element_Elevation", + "HumidityBiasCorrection": [ + 0 + ], + "HumidityDownscaling": [ + 0 + ], + "IgnoredBorderWidths": [ + 0 + ], + "InputForcingDirectories": [ + "s3://null" + ], + "InputForcingTypes": [ + "GRIB2" + ], + "InputForcings": [ + 12 + ], + "InputMandatory": [ + 0 + ], + "LookBack": -9999, + "LwBiasCorrection": [ + 0 + ], + "NWM_CONFIG": "AORC", + "NWM_VERSION": 4.0, + "NodeCoords": "nodeCoords", + "NumElemConn": "numElementConn", + "Output": 0, + "OutputFrequency": 60, + "PrecipBiasCorrection": [ + 0 + ], + "PrecipDownscaling": [ + 0 + ], + "PressureBiasCorrection": [ + 0 + ], + "PressureDownscaling": [ + 0 + ], + "RefcstBDateProc": "201307010000", + "RegridOpt": [ + 1 + ], + "RegridOptSuppPcp": [], + "RqiMethod": 0, + "RqiThreshold": 0.9, + "SLOPE": "Element_Slope", + "SLOPE_AZIMUTH": "Element_Slope_Azmuith", + "ScratchDir": "/ngen-app/data/scratch/AORC/", + "ShortwaveDownscaling": [ + 0 + ], + "SpatialMetaIn": "", + "SubOutFreq": 0, + "SubOutputHour": 0, + "SuppPcp": [], + "SuppPcpDirectories": [], + "SuppPcpForcingTypes": [], + "SuppPcpInputOffsets": [], + "SuppPcpMandatory": [], + "SuppPcpParamDir": "", + "SuppPcpTemporalInterpolation": [], + "SwBiasCorrection": [ + 0 + ], + "TemperatureBiasCorrection": [ + 0 + ], + "TemperatureDownscaling": [ + 0 + ], + "WindBiasCorrection": [ + 0 + ], + "cfsEnsNumber": 1, + "compressOutput": 0, + "custom_input_fcst_freq": [], + "floatOutput": 0, + "includeLQFrac": 1, + "initial_time": 0, + "time_step_seconds": 3600 + }, "cfsv2EnsMember": null, - "config_path": null, "cosalpha_var": null, "current_fcst_cycle": null, "current_output_date": null, @@ -48,17 +176,25 @@ 0 ], "fcst_shift": 0, + "file_types": [ + "GRIB1", + "GRIB2", + "NETCDF", + "NETCDF4", + "NWM", + "ZARR" + ], "first_fcst_cycle": null, "forceTemoralInterp": [ 0 ], + "force_count": 27, "forcing_output": 0, "future_time": null, "geopackage": "/workspaces/nwm-rte/src/ngen-forcing/tests/test_data/gpkg/gauge_01123000.gpkg", "globalNdv": -9999.0, "grid_meta": null, "grid_type": "hydrofabric", - "hgt_elem_var": null, "hgt_var": null, "ignored_border_widths": [ 0 @@ -100,6 +236,10 @@ "nwm_url": null, "output_freq": 60, "paramFlagArray": null, + "param_flag": [ + 0 + ], + "perform_downscaling": false, "precipBiasCorrectOpt": [ 0 ], @@ -128,24 +268,29 @@ ], "regrid_opt_supp_pcp": null, "rqiMethod": null, - "rqiThresh": 1.0, + "rqiThresh": null, "runCfsNldasBiasCorrect": false, "sinalpha_var": null, "slope_azimuth_var": null, - "slope_azimuth_var_elem": null, "slope_var": null, - "slope_var_elem": null, "spatial_meta": null, "statusMsg": "func esmf_mesh_retry finished after 1 attempts.", "sub_output_freq": null, "sub_output_hour": null, "suppTemporalInterp": null, + "supp_input_offsets": null, "supp_pcp_max_hours": null, + "supp_precip_count": 15, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], "supp_precip_mandatory": null, "supp_precip_param_dir": null, + "supplemental_precip_file_type_options": [ + "GRIB1", + "GRIB2", + "NETCDF" + ], "swBiasCorrectOpt": [ 0 ], @@ -158,9 +303,14 @@ "t2dDownscaleOpt": [ 0 ], + "try_config_get_except_attr_map": { + "Geopackage": "geopackage", + "SpatialMetaIn": "spatial_meta" + }, "useCompression": 0, "useFloats": 0, "use_data_at_current_time": true, + "user_provided_geogrid_flag": false, "weightsDir": null, "windBiasCorrect": [ 0 From 308f1d3c48c8de53008916dee736ac94d2292490 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Tue, 18 Aug 2026 11:48:10 -0400 Subject: [PATCH 62/71] Bolster test utils handling of serialization and deserialization --- tests/test_utils.py | 74 ++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 43012925..c3cd2634 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -295,6 +295,7 @@ def __init__(self, cfg: TestConfig_Base) -> None: self.keys_to_check = cfg.keys_to_check self.keys_to_exclude = cfg.keys_to_exclude + self.keys_no_hash = cfg.keys_no_hash self.map_old_to_new_var_names = cfg.map_old_to_new_var_names self.test_file_name_prefix = cfg.test_file_name_prefix @@ -323,6 +324,46 @@ def _trim_arrays_to_input_map_output(data_dict: dict) -> None: ) data_dict[key] = value[: len(input_map_output)] + def _apply_transformations(self, data: dict, keys_to_exclude: tuple, keys_no_hash: tuple = (), apply_map: bool = True) -> dict: + """Apply transformations to live BMI data to produce its final JSON representation. + + Used only by deserial_actual() to transform raw BMI state. Expected result files are already + in their final form (transformed + extra_attrs added), so they are read directly without re-transformation. + + The processing order is: + 1. Re-order the keys + 2. Save raw values for keys_no_hash before hashing + 3. Convert long lists to hashes (except keys_no_hash which are excluded) + 4. Restore raw values for keys_no_hash + 5. Remove excluded keys + 6. Map old variable names to new (if apply_map=True and self.map_old_to_new_var_names) + + Args: + data: The deserialized data dictionary + keys_to_exclude: Tuple of keys to exclude from result + keys_no_hash: Tuple of keys that should NOT be hashed (preserved as raw values) + apply_map: Whether to apply variable name mapping (converting earlier pre-refactor namespace to later namespace) + + Returns: + Transformed dictionary + """ + # Order and reverse so private attributes are last + result = OrderedDict(reversed(list(data.items()))) + # Save raw values for keys that should not be hashed + raw_vals_no_hash = { + k: result[k] for k in keys_no_hash if k in result + } + # Convert long lists to hash strings (this may hash keys_no_hash too) + result = convert_long_lists(result, 10) + # Restore raw (unhashed) values for keys_no_hash + result.update(raw_vals_no_hash) + # Remove excluded keys + result = remove_key(dict(result), keys_to_exclude) + # Map old variable names to new if enabled + if apply_map and self.map_old_to_new_var_names: + result = self.map_old_to_new_variable_names(result) + return result + class BMIForcingFixture_Class(BMIForcingFixture): """Test fixture for Class-based tests.""" @@ -340,41 +381,32 @@ def __init__(self, cfg: TestConfig_Base) -> None: self.actual_sub_dir = "test_data/actual_results" self.test_dir = os.path.dirname(os.path.abspath(__file__)) self.extra_attrs: tuple[ClassAttrFetcher] = cfg.extra_attrs - self.keys_no_hash: tuple[str] = cfg.keys_no_hash self.keys_to_exclude_at_init: tuple[str] = cfg.keys_to_exclude_at_init def deserial_actual( self, suffix: str, current_output_step: str = "", write_to_file: bool = True ) -> dict: """Get the actual metadata results as a deserialized dictionary, including any extra_attrs.""" - deserial_actual = json.loads( + data = json.loads( serialize_to_json( copy_and_stringify_functions(self.test_class_as_dict), sort_keys=True ) ) - # order and reverse so private attributes are last - deserial_actual = OrderedDict(reversed(list(deserial_actual.items()))) - # Save raw values for keys that should not be hashed - raw_vals = { - k: deserial_actual[k] for k in self.keys_no_hash if k in deserial_actual - } - deserial_actual = convert_long_lists(deserial_actual, 10) - deserial_actual.update(raw_vals) - deserial_actual = remove_key(dict(deserial_actual), self.keys_to_exclude) + data = self._apply_transformations(data, self.keys_to_exclude, keys_no_hash=self.keys_no_hash, apply_map=True) # Add any extra attributes to the results for ea in self.extra_attrs: - deserial_actual[ea.results_key_name] = ea.get( + data[ea.results_key_name] = ea.get( self, serialize_and_deserialize=True ) - self._trim_arrays_to_input_map_output(deserial_actual) + self._trim_arrays_to_input_map_output(data) if write_to_file: self.write_json( - deserial_actual, + data, self.actual_results_file_path(suffix, current_output_step), ) - return deserial_actual + return data def write_json(self, dictionary_to_write: dict, json_path: str) -> None: """Write the deserialized results to a JSON file.""" @@ -388,16 +420,8 @@ def deserial_expected(self, suffix: str, current_output_step: str = "") -> dict: try: with open(file_path) as f: - deserial_expected = json.load(f) - if self.map_old_to_new_var_names: - deserial_expected = self.map_old_to_new_variable_names( - deserial_expected - ) - self._trim_arrays_to_input_map_output(deserial_expected) - # Remove keys that should be excluded from comparison - deserial_expected = remove_key(deserial_expected, self.keys_to_exclude) - # order and reverse so private attributes are last - return OrderedDict(reversed(list(deserial_expected.items()))) + # Files are already in their final representation (transformed + trimmed), do not re-transform. + return json.load(f) except FileNotFoundError as e: raise FileNotFoundError( f"Could not find {file_path}. Try running the test using OS var {OS_VAR__CREATE_TEST_EXPECT_DATA}=true first to set up the test results expected data." From ec8d6d6616287191519cdf742be673287888a96c Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Tue, 18 Aug 2026 12:57:27 -0400 Subject: [PATCH 63/71] Format with ruff default line length (88) --- .../NextGen_hyfab_to_ESMF_Mesh.py | 114 +++++++++++------- .../NextGen_Forcings_Engine/bmi_model.py | 22 ++-- .../NextGen_Forcings_Engine/core/config.py | 20 ++- .../core/forcingInputMod.py | 3 +- .../NextGen_Forcings_Engine/core/parallel.py | 8 +- .../NextGen_Forcings_Engine/core/regrid.py | 36 +++--- .../NextGen_Forcings_Engine/esmf_utils.py | 11 +- .../NextGen_Forcings_Engine/model.py | 10 +- tests/bmi_model/test_bmi_model.py | 12 +- tests/geomod/test_geomod.py | 4 +- tests/test_utils.py | 42 ++++--- 11 files changed, 177 insertions(+), 105 deletions(-) diff --git a/ESMF_Mesh_Domain_Configuration_Production/NextGen_hyfab_to_ESMF_Mesh.py b/ESMF_Mesh_Domain_Configuration_Production/NextGen_hyfab_to_ESMF_Mesh.py index c9426a94..b6c39859 100644 --- a/ESMF_Mesh_Domain_Configuration_Production/NextGen_hyfab_to_ESMF_Mesh.py +++ b/ESMF_Mesh_Domain_Configuration_Production/NextGen_hyfab_to_ESMF_Mesh.py @@ -34,7 +34,7 @@ def convert_hyfab_to_esmf(hyfab_gpkg: pathlib.Path, esmf_mesh_output: pathlib.Pa # for orientation properties since there are issues # with geopandas for converting crs and translating # orientation of polygon from original dataset - hyfab_cart = gpd.read_file(hyfab_gpkg, layer='divides') + hyfab_cart = gpd.read_file(hyfab_gpkg, layer="divides") hyfab_cart = hyfab_cart.sort_values(by=["div_id"]).reset_index(drop=True) hyfab = hyfab_cart.to_crs("WGS84") @@ -52,23 +52,25 @@ def convert_hyfab_to_esmf(hyfab_gpkg: pathlib.Path, esmf_mesh_output: pathlib.Pa hyfab_coords[:, 1] = false_ids # Sort data by feature id and reset index - hyfab['element_id'] = false_ids - hyfab_cart['element_id'] = false_ids + hyfab["element_id"] = false_ids + hyfab_cart["element_id"] = false_ids # Get element count element_count = len(hyfab.element_id) # find the number of nodes in first element # based on geometry type - if (hyfab.geometry[0].geom_type == "Polygon"): + if hyfab.geometry[0].geom_type == "Polygon": dup_df = pd.DataFrame([]) - dup_df['node_x'], dup_df['node_y'] = hyfab.geometry[0].exterior.coords.xy - dup_df = dup_df.drop_duplicates(subset=['node_x', 'node_y'], keep='first') + dup_df["node_x"], dup_df["node_y"] = hyfab.geometry[0].exterior.coords.xy + dup_df = dup_df.drop_duplicates(subset=["node_x", "node_y"], keep="first") elem_max_nodes = len(dup_df) else: dup_df = pd.DataFrame([]) - dup_df['node_x'], dup_df['node_y'] = hyfab.geometry[0].geoms._get_geom_item(0).exterior.xy - dup_df = dup_df.drop_duplicates(subset=['node_x', 'node_y'], keep='first') + dup_df["node_x"], dup_df["node_y"] = ( + hyfab.geometry[0].geoms._get_geom_item(0).exterior.xy + ) + dup_df = dup_df.drop_duplicates(subset=["node_x", "node_y"], keep="first") elem_max_nodes = len(dup_df) # Allocate element arrays for center point calculations @@ -85,15 +87,17 @@ def convert_hyfab_to_esmf(hyfab_gpkg: pathlib.Path, esmf_mesh_output: pathlib.Pa # based on geometry type total_num_nodes = 0 for i in range(element_count): - if (hyfab.geometry[i].geom_type == "Polygon"): + if hyfab.geometry[i].geom_type == "Polygon": dup_df = pd.DataFrame([]) - dup_df['node_x'], dup_df['node_y'] = hyfab.geometry[i].exterior.coords.xy - dup_df = dup_df.drop_duplicates(subset=['node_x', 'node_y'], keep='first') + dup_df["node_x"], dup_df["node_y"] = hyfab.geometry[i].exterior.coords.xy + dup_df = dup_df.drop_duplicates(subset=["node_x", "node_y"], keep="first") total_num_nodes += len(dup_df) else: dup_df = pd.DataFrame([]) - dup_df['node_x'], dup_df['node_y'] = hyfab.geometry[i].geoms._get_geom_item(0).exterior.xy - dup_df = dup_df.drop_duplicates(subset=['node_x', 'node_y'], keep='first') + dup_df["node_x"], dup_df["node_y"] = ( + hyfab.geometry[i].geoms._get_geom_item(0).exterior.xy + ) + dup_df = dup_df.drop_duplicates(subset=["node_x", "node_y"], keep="first") total_num_nodes += len(dup_df) # assign current node id and allocate node arrays to extract @@ -108,24 +112,26 @@ def convert_hyfab_to_esmf(hyfab_gpkg: pathlib.Path, esmf_mesh_output: pathlib.Pa # flip node coordinates based on orientation of polygons # from the original cartesian coordinate system for i in range(element_count): - if (hyfab.geometry[i].geom_type == "Polygon"): + if hyfab.geometry[i].geom_type == "Polygon": dup_df = pd.DataFrame([]) - dup_df['node_x'], dup_df['node_y'] = hyfab.geometry[i].exterior.coords.xy - dup_df = dup_df.drop_duplicates(subset=['node_x', 'node_y'], keep='first') + dup_df["node_x"], dup_df["node_y"] = hyfab.geometry[i].exterior.coords.xy + dup_df = dup_df.drop_duplicates(subset=["node_x", "node_y"], keep="first") node_x = dup_df.node_x.values node_y = dup_df.node_y.values ccw = hyfab_cart.geometry[i].exterior.is_ccw else: dup_df = pd.DataFrame([]) - dup_df['node_x'], dup_df['node_y'] = hyfab.geometry[i].geoms._get_geom_item(0).exterior.xy - dup_df = dup_df.drop_duplicates(subset=['node_x', 'node_y'], keep='first') + dup_df["node_x"], dup_df["node_y"] = ( + hyfab.geometry[i].geoms._get_geom_item(0).exterior.xy + ) + dup_df = dup_df.drop_duplicates(subset=["node_x", "node_y"], keep="first") node_x = dup_df.node_x.values node_y = dup_df.node_y.values ccw = hyfab_cart.geometry[i].geoms._get_geom_item(0).exterior.is_ccw num_nodes = len(node_x) element_num_nodes[i] = num_nodes - if (num_nodes > elem_max_nodes): + if num_nodes > elem_max_nodes: elem_max_nodes = num_nodes element_x_coord[i] = hyfab.geometry[i].centroid.coords.xy[0][0] @@ -133,24 +139,34 @@ def convert_hyfab_to_esmf(hyfab_gpkg: pathlib.Path, esmf_mesh_output: pathlib.Pa element_elevation[i] = hyfab.elevation_mean[i] element_slope[i] = hyfab.slope1km_mean[i] - element_slope_azmuith[i] = hyfab.aspect_circmean[i] # NHF aspect is currently in radians, may need to be converted to degrees - - if (ccw): - node_x_coord[node_start:node_start + num_nodes] = np.array(node_x, dtype=np.double) - node_y_coord[node_start:node_start + num_nodes] = np.array(node_y, dtype=np.double) + element_slope_azmuith[i] = hyfab.aspect_circmean[ + i + ] # NHF aspect is currently in radians, may need to be converted to degrees + + if ccw: + node_x_coord[node_start : node_start + num_nodes] = np.array( + node_x, dtype=np.double + ) + node_y_coord[node_start : node_start + num_nodes] = np.array( + node_y, dtype=np.double + ) else: - node_x_coord[node_start:node_start + num_nodes] = np.array(np.concatenate([[node_x[0]], np.flip(node_x[1:])]), dtype=np.double) - node_y_coord[node_start:node_start + num_nodes] = np.array(np.concatenate([[node_y[0]], np.flip(node_y[1:])]), dtype=np.double) + node_x_coord[node_start : node_start + num_nodes] = np.array( + np.concatenate([[node_x[0]], np.flip(node_x[1:])]), dtype=np.double + ) + node_y_coord[node_start : node_start + num_nodes] = np.array( + np.concatenate([[node_y[0]], np.flip(node_y[1:])]), dtype=np.double + ) node_start += num_nodes # Assign node data to pandas dataframe # and calculate the duplicate nodes throughout # the hydrofabric geometry network node_connectivity = pd.DataFrame([]) - node_connectivity['node_x'] = node_x_coord - node_connectivity['node_y'] = node_y_coord + node_connectivity["node_x"] = node_x_coord + node_connectivity["node_y"] = node_y_coord - duplicates = node_connectivity[node_connectivity.duplicated(keep='first')] + duplicates = node_connectivity[node_connectivity.duplicated(keep="first")] # Create array to assign duplicate nodes as # zeroes, while creating unique ids for only @@ -159,25 +175,27 @@ def convert_hyfab_to_esmf(hyfab_gpkg: pathlib.Path, esmf_mesh_output: pathlib.Pa node_id_connectivity = np.empty(len(node_id), dtype=np.int32) node_count = 1 for i in range(len(node_id)): - if (i in duplicates_index): + if i in duplicates_index: node_id_connectivity[i] = 0 else: node_id_connectivity[i] = node_count node_count += 1 # Assign new node id network to dataframe - node_connectivity['node_id'] = node_id_connectivity + node_connectivity["node_id"] = node_id_connectivity # calculate the node id network to include its duplicate ids # for each instance of the node coordinates - ESMF_node_id_connectivity = node_connectivity.groupby(['node_x', 'node_y']).node_id.transform('max') + ESMF_node_id_connectivity = node_connectivity.groupby( + ["node_x", "node_y"] + ).node_id.transform("max") - node_connectivity['node_id_connectivity'] = ESMF_node_id_connectivity.values + node_connectivity["node_id_connectivity"] = ESMF_node_id_connectivity.values node_connectivity_final = node_connectivity.node_id_connectivity.values # Extract only the unique node id network and respective coordinates - node_connectivity = node_connectivity.drop_duplicates('node_id_connectivity') + node_connectivity = node_connectivity.drop_duplicates("node_id_connectivity") node_count = len(node_connectivity) node_x_coord_final = node_connectivity.node_x.values node_y_coord_final = node_connectivity.node_y.values @@ -190,7 +208,9 @@ def convert_hyfab_to_esmf(hyfab_gpkg: pathlib.Path, esmf_mesh_output: pathlib.Pa end_index = 0 for i in range(element_count): end_index += element_num_nodes[i] - elementConn[i, 0:element_num_nodes[i]] = node_connectivity_final[start_index:end_index] + elementConn[i, 0 : element_num_nodes[i]] = node_connectivity_final[ + start_index:end_index + ] start_index = end_index out_dir = os.path.dirname(esmf_mesh_output) @@ -204,9 +224,11 @@ def convert_hyfab_to_esmf(hyfab_gpkg: pathlib.Path, esmf_mesh_output: pathlib.Pa nc = netCDF4.Dataset(temp_path, "w", format="NETCDF4") node_count_dim = nc.createDimension("nodeCount", node_count) elem_count_dim = nc.createDimension("elementCount", element_count) - elem_conn_count_dim = nc.createDimension("connectionCount", len(node_connectivity_final)) + elem_conn_count_dim = nc.createDimension( + "connectionCount", len(node_connectivity_final) + ) node_count_dim = nc.createDimension("coordDim", 2) - node_coords_var = nc.createVariable("nodeCoords", 'f8', ("nodeCount", "coordDim")) + node_coords_var = nc.createVariable("nodeCoords", "f8", ("nodeCount", "coordDim")) node_coords_var.units = "degrees" elem_id = nc.createVariable("element_id", "i4", "elementCount") elem_id.long_name = "False 32-bit catchment IDs use for ESMF mesh generation" @@ -214,7 +236,9 @@ def convert_hyfab_to_esmf(hyfab_gpkg: pathlib.Path, esmf_mesh_output: pathlib.Pa elem_conn_var.long_name = "Node Indices that define the element connectivity" num_elem_conn_var = nc.createVariable("numElementConn", "i", "elementCount") num_elem_conn_var.long_name = "Number of nodes per element" - center_coords_var = nc.createVariable("centerCoords", 'f8', ("elementCount", "coordDim")) + center_coords_var = nc.createVariable( + "centerCoords", "f8", ("elementCount", "coordDim") + ) center_coords_var.units = "degrees" nc.gridType = "unstructured" nc.version = "0.9" @@ -225,7 +249,9 @@ def convert_hyfab_to_esmf(hyfab_gpkg: pathlib.Path, esmf_mesh_output: pathlib.Pa slope_elem_var = nc.createVariable("Element_Slope", "f8", ("elementCount")) slope_elem_var.long_name = "Catchment slope" slope_elem_var.units = "meters" - slope_azi_elem_var = nc.createVariable("Element_Slope_Azmuith", "f8", ("elementCount")) + slope_azi_elem_var = nc.createVariable( + "Element_Slope_Azmuith", "f8", ("elementCount") + ) slope_azi_elem_var.long_name = "Catchment slope azmuith angle" slope_azi_elem_var.units = "Degrees" hgt_elem_var[:] = element_elevation @@ -259,8 +285,14 @@ def convert_hyfab_to_esmf(hyfab_gpkg: pathlib.Path, esmf_mesh_output: pathlib.Pa def get_options(): parser = argparse.ArgumentParser() - parser.add_argument('hyfab_gpkg', type=pathlib.Path, help="Hydrofabric geopackage file pathway") - parser.add_argument("esmf_mesh_output", type=pathlib.Path, help="File pathway to save ESMF netcdf mesh file for hydrofabric") + parser.add_argument( + "hyfab_gpkg", type=pathlib.Path, help="Hydrofabric geopackage file pathway" + ) + parser.add_argument( + "esmf_mesh_output", + type=pathlib.Path, + help="File pathway to save ESMF netcdf mesh file for hydrofabric", + ) return parser.parse_args() diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index c63d0afa..fe393c85 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -71,15 +71,14 @@ try: from ewts.helper import getenv_any from ewts.logger import configure_existing_logger + FORCING_USE_EWTS = True except ImportError: FORCING_USE_EWTS = False -class StdoutStyleFormatter(logging.Formatter): - INFO_FORMAT = ( - "%(asctime)s %(name)-8s %(levelname)-7s %(message)s" - ) +class StdoutStyleFormatter(logging.Formatter): + INFO_FORMAT = "%(asctime)s %(name)-8s %(levelname)-7s %(message)s" DETAILED_FORMAT = ( "%(asctime)s %(name)-8s %(levelname)-7s " @@ -94,7 +93,7 @@ def format(self, record): self._style._fmt = self.DETAILED_FORMAT return super().format(record) - + def formatTime(self, record, datefmt=None): dt = datetime.fromtimestamp(record.created, tz=timezone.utc) return dt.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z" @@ -111,6 +110,7 @@ def _configure_stdout_logging(): LOG.propagate = False + # If less than 0, then ESMF.__version__ is greater than 8.7.0 if ESMF.version_compare("8.7.0", ESMF.__version__) < 0: manager = ESMF.api.esmpymanager.Manager(endFlag=ESMF.constants.EndAction.KEEP_MPI) @@ -174,7 +174,9 @@ def init_log(self) -> None: configure_existing_logger(LOG) else: _configure_stdout_logging() - LOG.warning("ewts package installed but EWTS_USE_NGEN_BRIDGE not on. Falling back to default logging.") + LOG.warning( + "ewts package installed but EWTS_USE_NGEN_BRIDGE not on. Falling back to default logging." + ) else: _configure_stdout_logging() LOG.info("-" * 30) @@ -283,9 +285,9 @@ def create_esmf_mesh(self) -> None: """Create the ESMF mesh for the model and set ``self._cat_ids`` (later used as BMI variable "CAT-ID").""" if self._mpi_meta.rank == 0: cat_ids = esmf_creation.create_mesh(self._job_meta) - cat_count = np.array([ - len(cat_ids) if self._mpi_meta.rank == 0 else 0 - ], dtype=np.intc) + cat_count = np.array( + [len(cat_ids) if self._mpi_meta.rank == 0 else 0], dtype=np.intc + ) self._mpi_meta.comm.Bcast(cat_count, root=0) if self._mpi_meta.rank != 0: cat_ids = np.empty(cat_count[0], dtype=np.int64) @@ -735,7 +737,7 @@ def get_value_ptr(self, var_name: str) -> NDArray[Any]: # Ensure dtype is float64 (C double), except for CAT-ID if var_name == "CAT-ID": - return arr # allow CAT-ID to pass on whatever the dtype is based on the input data + return arr # allow CAT-ID to pass on whatever the dtype is based on the input data elif arr.dtype != np.float64: LOG.warning( f"[BMI] Array for '{var_name}' has dtype {arr.dtype}, expected float64; converting." diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py index 868d7d1c..cfdeee2a 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py @@ -71,7 +71,7 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No self.nwm_source = "s3://noaa-nwm-retrospective-3-0-pds" self._scratch_dir_has_been_uniquefied = False - + # These must exist (as None) before the properties are accessed self._supp_precip_forcings = None self._b_date_proc = None @@ -89,7 +89,7 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No self._geopackage = None self._geogrid = None self._grid_type = None - + # set list of attributes from consts.py to None early on in the init process. # These are indexed from the consts dictionary. # This must happen before accessing properties like precip_only_flag @@ -144,12 +144,14 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No # Initialize downscaling attributes to None even if downscaling is not performed self.set_attrs(CONFIGOPTIONS["downscaling_attrs_map"], set_none=True) if self.grid_type == "unstructured": - self.set_attrs(CONFIGOPTIONS["downscaling_unstructred_attrs_map"], set_none=True) + self.set_attrs( + CONFIGOPTIONS["downscaling_unstructred_attrs_map"], set_none=True + ) for cfg_bmi_attr, config_options_attr in CONFIGOPTIONS[ "extract_input_variable_set_default_attrs_map" ].items(): - if config_options_attr in ["supp_pcp_max_hours","weightsDir"]: + if config_options_attr in ["supp_pcp_max_hours", "weightsDir"]: default = None else: default = 0 @@ -700,7 +702,9 @@ def number_custom_inputs(self) -> int: @number_custom_inputs.setter def number_custom_inputs(self, value: int) -> None: """This is a read-only computed property based on input_forcings.""" - raise AttributeError(f"number_custom_inputs is read-only (tried to set to: {value})") + raise AttributeError( + f"number_custom_inputs is read-only (tried to set to: {value})" + ) @property def nwm_geogrid(self) -> str: @@ -710,7 +714,11 @@ def nwm_geogrid(self) -> str: @nwm_geogrid.setter def nwm_geogrid(self, value: str) -> None: """Set the pathway to the NWM geogrid file specified by the user in the configuration file. This is used to specify the grid information for regridding NWM input forcings, and is only necessary if the user has chosen to regrid NWM input forcings in the configuration file.""" - if not self.precip_only_flag and self.input_forcings is not None and 27 in self.input_forcings: + if ( + not self.precip_only_flag + and self.input_forcings is not None + and 27 in self.input_forcings + ): self._nwm_geogrid = value else: self._nwm_geogrid = None diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/forcingInputMod.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/forcingInputMod.py index 1cb97ef7..49dfef2f 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/forcingInputMod.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/forcingInputMod.py @@ -25,6 +25,7 @@ MpiConfig, ) import logging + LOG = logging.getLogger("FORCING") @@ -94,7 +95,7 @@ def _initialize_config_options(self) -> None: Check if the attibute allready exists before setting. """ for key in dir(self.config_options): - val=getattr(self.config_options,key) + val = getattr(self.config_options, key) if ( isinstance(val, list) and len(val) > 0 diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py index dd87f7e3..de27c74c 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py @@ -384,7 +384,9 @@ def merge_slabs_gatherv( try: self.comm.Allgather([shapes, MPI.INTEGER], [global_shapes, MPI.INTEGER]) except Exception: - self.config_options.errMsg = "Failed all gathering slab shapes at rank" + str(self.rank) + self.config_options.errMsg = ( + "Failed all gathering slab shapes at rank" + str(self.rank) + ) err_handler.log_critical(self.config_options, self) return None @@ -455,7 +457,9 @@ def merge_slabs_gatherv( root=0, ) except Exception: - self.config_options.errMsg = "Failed to Gatherv to rank 0 from rank " + str(self.rank) + self.config_options.errMsg = "Failed to Gatherv to rank 0 from rank " + str( + self.rank + ) err_handler.log_critical(self.config_options, self) return None diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/regrid.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/regrid.py index 92ff26d8..639904a4 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/regrid.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/regrid.py @@ -45,19 +45,20 @@ from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( ConfigOptions, ) - from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.geoMod import ( - GeoMeta, - ) - from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.suppPrecipMod import ( - supplemental_precip, - ) from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.forcingInputMod import ( InputForcings, ) + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.geoMod import ( + GeoMeta, + ) from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.parallel import ( MpiConfig, ) + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.suppPrecipMod import ( + supplemental_precip, + ) import logging + from ..esmf_utils import ( esmf_field_retry, esmf_grid_retry, @@ -9683,7 +9684,10 @@ def regrid_sbcv2_liquid_water_fraction( def regrid_hourly_nbm( - forcings_or_precip:supplemental_precip|InputForcings, config_options:ConfigOptions, wrf_hydro_geo_meta:GeoMeta, mpi_config:MpiConfig + forcings_or_precip: supplemental_precip | InputForcings, + config_options: ConfigOptions, + wrf_hydro_geo_meta: GeoMeta, + mpi_config: MpiConfig, ): """Regrid hourly NBM precipitation. @@ -9739,7 +9743,7 @@ def regrid_hourly_nbm( cmd = f'$WGRIB2 -match "({"|".join(fields)})" -not "prob" -not "ens" {forcings_or_precip.file_in1} -netcdf {nbm_tmp_nc}' else: # Perform a GRIB dump to NetCDF for the precip data. - time_str=f"{forcings_or_precip.fcst_hour1}-{forcings_or_precip.fcst_hour2} hour acc fcst" + time_str = f"{forcings_or_precip.fcst_hour1}-{forcings_or_precip.fcst_hour2} hour acc fcst" fieldnbm_match1 = f'":APCP:surface:{time_str}:"' fieldnbm_match2 = ( f'"{forcings_or_precip.fcst_hour1}-{forcings_or_precip.fcst_hour2}"' @@ -11357,10 +11361,14 @@ def check_regrid_status( ) elif config_options.grid_type == "hydrofabric": input_forcings.regridded_forcings1 = np.full( - [force_count, wrf_hydro_geo_meta.ny_local], np.nan,dtype=np.float32 #NOTE changed to np.full to be deterministic for unit tests. + [force_count, wrf_hydro_geo_meta.ny_local], + np.nan, + dtype=np.float32, # NOTE changed to np.full to be deterministic for unit tests. ) input_forcings.regridded_forcings2 = np.full( - [force_count, wrf_hydro_geo_meta.ny_local], np.nan,dtype=np.float32 #NOTE changed to np.full to be deterministic for unit tests. + [force_count, wrf_hydro_geo_meta.ny_local], + np.nan, + dtype=np.float32, # NOTE changed to np.full to be deterministic for unit tests. ) if mpi_config.rank == 0: @@ -11855,13 +11863,9 @@ def calculate_weights( err_handler.check_program_status(config_options, mpi_config) # Broadcast the forcing nx/ny values - input_forcings.ny_global = mpi_config.broadcast_parameter( - input_forcings.ny_global - ) + input_forcings.ny_global = mpi_config.broadcast_parameter(input_forcings.ny_global) err_handler.check_program_status(config_options, mpi_config) - input_forcings.nx_global = mpi_config.broadcast_parameter( - input_forcings.nx_global - ) + input_forcings.nx_global = mpi_config.broadcast_parameter(input_forcings.nx_global) err_handler.check_program_status(config_options, mpi_config) try: diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/esmf_utils.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/esmf_utils.py index f49b8960..9c0072eb 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/esmf_utils.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/esmf_utils.py @@ -1,7 +1,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any import types +from typing import TYPE_CHECKING, Any import esmpy as ESMF @@ -10,9 +10,14 @@ import shapely from . import retry_utils + if TYPE_CHECKING: - from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ConfigOptions - from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.parallel import MpiConfig + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( + ConfigOptions, + ) + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.parallel import ( + MpiConfig, + ) @retry_utils.retry_w_mpi_context( diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 41fad2b9..4335fea5 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -500,12 +500,10 @@ def __handle_aorc_and_nwm_force_keys( self._bmi.geo_meta, ) elif self._bmi._job_meta.nwm_domain == "PR": - self.source_data_processor = ( - NWMV3PuertoRicoProcessor( - self._bmi._job_meta, - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) + self.source_data_processor = NWMV3PuertoRicoProcessor( + self._bmi._job_meta, + self._bmi._mpi_meta, + self._bmi.geo_meta, ) elif self._bmi._job_meta.nwm_domain == "Alaska": proc_cls = NWMV3AlaskaProcessor diff --git a/tests/bmi_model/test_bmi_model.py b/tests/bmi_model/test_bmi_model.py index 80461061..dc17feb3 100644 --- a/tests/bmi_model/test_bmi_model.py +++ b/tests/bmi_model/test_bmi_model.py @@ -21,8 +21,14 @@ config_file=consts.RETRO_FORCING_CONFIG_FILE__AORC_CONUS, keys_to_check=(), keys_to_exclude=tuple( - set(consts.KEYS_TO_EXCLUDE) | { - "d_program_init", "geogrid", "scratch_dir", "Element_Elevation", "Element_Slope", "Element_Slope_Azmuith", + set(consts.KEYS_TO_EXCLUDE) + | { + "d_program_init", + "geogrid", + "scratch_dir", + "Element_Elevation", + "Element_Slope", + "Element_Slope_Azmuith", "geo_meta.config_options.cfg_bmi", "geo_meta.mpi_config.config_options", "mpi_config.config_options", @@ -30,7 +36,7 @@ ), grid_type=consts.GRID_TYPE, test_file_name_prefix="bmi_model", - extra_attrs=[ClassAttrFetcher("bmi_model_values", "CAT-ID")] + extra_attrs=[ClassAttrFetcher("bmi_model_values", "CAT-ID")], ), ] diff --git a/tests/geomod/test_geomod.py b/tests/geomod/test_geomod.py index 3cbc8b9a..e329be0c 100644 --- a/tests/geomod/test_geomod.py +++ b/tests/geomod/test_geomod.py @@ -27,7 +27,9 @@ ), grid_type=consts.GRID_TYPE, test_file_name_prefix=TEST_FILE_NAME_PREFIX, - extra_attrs=[ClassAttrFetcher("bmi_model_values", "CAT-ID"),] + extra_attrs=[ + ClassAttrFetcher("bmi_model_values", "CAT-ID"), + ], ), ] diff --git a/tests/test_utils.py b/tests/test_utils.py index c3cd2634..f561d65d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -324,12 +324,18 @@ def _trim_arrays_to_input_map_output(data_dict: dict) -> None: ) data_dict[key] = value[: len(input_map_output)] - def _apply_transformations(self, data: dict, keys_to_exclude: tuple, keys_no_hash: tuple = (), apply_map: bool = True) -> dict: + def _apply_transformations( + self, + data: dict, + keys_to_exclude: tuple, + keys_no_hash: tuple = (), + apply_map: bool = True, + ) -> dict: """Apply transformations to live BMI data to produce its final JSON representation. - + Used only by deserial_actual() to transform raw BMI state. Expected result files are already in their final form (transformed + extra_attrs added), so they are read directly without re-transformation. - + The processing order is: 1. Re-order the keys 2. Save raw values for keys_no_hash before hashing @@ -337,22 +343,20 @@ def _apply_transformations(self, data: dict, keys_to_exclude: tuple, keys_no_has 4. Restore raw values for keys_no_hash 5. Remove excluded keys 6. Map old variable names to new (if apply_map=True and self.map_old_to_new_var_names) - + Args: data: The deserialized data dictionary keys_to_exclude: Tuple of keys to exclude from result keys_no_hash: Tuple of keys that should NOT be hashed (preserved as raw values) apply_map: Whether to apply variable name mapping (converting earlier pre-refactor namespace to later namespace) - + Returns: Transformed dictionary """ # Order and reverse so private attributes are last result = OrderedDict(reversed(list(data.items()))) # Save raw values for keys that should not be hashed - raw_vals_no_hash = { - k: result[k] for k in keys_no_hash if k in result - } + raw_vals_no_hash = {k: result[k] for k in keys_no_hash if k in result} # Convert long lists to hash strings (this may hash keys_no_hash too) result = convert_long_lists(result, 10) # Restore raw (unhashed) values for keys_no_hash @@ -392,12 +396,12 @@ def deserial_actual( copy_and_stringify_functions(self.test_class_as_dict), sort_keys=True ) ) - data = self._apply_transformations(data, self.keys_to_exclude, keys_no_hash=self.keys_no_hash, apply_map=True) + data = self._apply_transformations( + data, self.keys_to_exclude, keys_no_hash=self.keys_no_hash, apply_map=True + ) # Add any extra attributes to the results for ea in self.extra_attrs: - data[ea.results_key_name] = ea.get( - self, serialize_and_deserialize=True - ) + data[ea.results_key_name] = ea.get(self, serialize_and_deserialize=True) self._trim_arrays_to_input_map_output(data) @@ -427,9 +431,11 @@ def deserial_expected(self, suffix: str, current_output_step: str = "") -> dict: f"Could not find {file_path}. Try running the test using OS var {OS_VAR__CREATE_TEST_EXPECT_DATA}=true first to set up the test results expected data." ) from e - def _write_expected_file(self, actual_data: dict, suffix: str, current_output_step: str = "") -> None: + def _write_expected_file( + self, actual_data: dict, suffix: str, current_output_step: str = "" + ) -> None: """Write actual data to expected results file for test data generation. - + This is a separate explicit step in the workflow to avoid confusion between expected and actual data. Should only be called when FORCING_PYTEST_WRITE_TEST_EXPECTED_DATA=true. """ @@ -499,8 +505,12 @@ def after_bmi_model_update(self, current_output_step: int) -> None: logging.info("Starting after_bmi_model_update()...") actual = self.deserial_actual("after_update", f"_step_{current_output_step}") if os.environ.get(OS_VAR__CREATE_TEST_EXPECT_DATA, "").lower() == "true": - self._write_expected_file(actual, "after_update", f"_step_{current_output_step}") - expected = self.deserial_expected("after_update", f"_step_{current_output_step}") + self._write_expected_file( + actual, "after_update", f"_step_{current_output_step}" + ) + expected = self.deserial_expected( + "after_update", f"_step_{current_output_step}" + ) self.compare(actual, expected) def after_finalize(self) -> None: From 79e10821cf19d6d4cd259f2b51945c3f79813f7c Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Tue, 18 Aug 2026 14:14:55 -0400 Subject: [PATCH 64/71] Adjustments following review --- .../NextGen_hyfab_to_ESMF_Mesh.py | 5 ++--- .../NextGen_Forcings_Engine/bmi_model.py | 4 ++-- .../NextGen_Forcings_Engine/core/parallel.py | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ESMF_Mesh_Domain_Configuration_Production/NextGen_hyfab_to_ESMF_Mesh.py b/ESMF_Mesh_Domain_Configuration_Production/NextGen_hyfab_to_ESMF_Mesh.py index b6c39859..4c6a7d9f 100644 --- a/ESMF_Mesh_Domain_Configuration_Production/NextGen_hyfab_to_ESMF_Mesh.py +++ b/ESMF_Mesh_Domain_Configuration_Production/NextGen_hyfab_to_ESMF_Mesh.py @@ -139,9 +139,8 @@ def convert_hyfab_to_esmf(hyfab_gpkg: pathlib.Path, esmf_mesh_output: pathlib.Pa element_elevation[i] = hyfab.elevation_mean[i] element_slope[i] = hyfab.slope1km_mean[i] - element_slope_azmuith[i] = hyfab.aspect_circmean[ - i - ] # NHF aspect is currently in radians, may need to be converted to degrees + # NHF aspect is currently in radians, may need to be converted to degrees + element_slope_azmuith[i] = hyfab.aspect_circmean[i] if ccw: node_x_coord[node_start : node_start + num_nodes] = np.array( diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index fe393c85..2b321d8c 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -423,8 +423,8 @@ def initialize(self, config_file: str) -> None: """Initialize the model using a configuration file. This function is part of the BMI (Basic Model Interface) specification and is automatically - invoked by the BMI system. When running standalone, call `initialize_with_params()` instead, - which sets additional parameters such as `b_date`, `geogrid`, and `output_path`. + invoked by the BMI system. To override parameters like `b_date`, `geogrid`, and `output_path` + (normally read from the config file), pass them to the constructor. This function is responsible for: - Setting up core model attributes, grids, and MPI communication. diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py index de27c74c..e221758a 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/parallel.py @@ -20,6 +20,9 @@ from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( ConfigOptions, ) + from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.geoMod import ( + GriddedGeoMeta, + ) # If MPI was initialized outside of python, # disable initialization/finalization behavior @@ -27,9 +30,6 @@ mpi4py.rc.initialize = False mpi4py.rc.finalize = False -if TYPE_CHECKING: - from .config import ConfigOptions - from .geoMod import GriddedGeoMeta _T = TypeVar("_T") From 2d5b441eb6c33dc14a5f144c831d58329dc0655b Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Tue, 25 Aug 2026 10:29:54 -0400 Subject: [PATCH 65/71] Fix NameError during handling of class init args introduced during refactor and/or rebasing --- .../NextGen_Forcings_Engine/model.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py index 4335fea5..66886ab9 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/model.py @@ -488,23 +488,11 @@ def __handle_aorc_and_nwm_force_keys( # Flag to indicate the AWS .zarr NWMv3 Forcing file method elif force_key == 27: if self._bmi._job_meta.nwm_domain == "CONUS": - self.source_data_processor = NWMV3ConusProcessor( - self._bmi._job_meta, - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) + proc_cls = NWMV3ConusProcessor elif self._bmi._job_meta.nwm_domain == "Hawaii": - self.source_data_processor = NWMV3HawaiiProcessor( - self._bmi._job_meta, - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) + proc_cls = NWMV3HawaiiProcessor elif self._bmi._job_meta.nwm_domain == "PR": - self.source_data_processor = NWMV3PuertoRicoProcessor( - self._bmi._job_meta, - self._bmi._mpi_meta, - self._bmi.geo_meta, - ) + proc_cls = NWMV3PuertoRicoProcessor elif self._bmi._job_meta.nwm_domain == "Alaska": proc_cls = NWMV3AlaskaProcessor else: From 0cb8b204d9e3655541f8ed7496f111c230b7d08c Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Tue, 25 Aug 2026 11:34:27 -0400 Subject: [PATCH 66/71] Add short-circuit guard for property perform_downscaling to return False when precip_only_flag is falsy. --- .../NextGen_Forcings_Engine/core/config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py index cfdeee2a..b5fe943e 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py @@ -1188,6 +1188,8 @@ def dScaleParamDirs(self, value: list) -> None: @property def perform_downscaling(self) -> bool: """Determine whether downscaling of input forcings is necessary based on the downscaling options specified by the user for each input forcing in the configuration file.""" + if self.precip_only_flag: + return False if ( 1 in self.q2dDownscaleOpt or 1 in self.swDownscaleOpt From cfa0d9693dcbb375e1a6f166e7b5f600fdbc5768 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Tue, 25 Aug 2026 11:45:38 -0400 Subject: [PATCH 67/71] Remove vestigial self.GeoMeta attribute --- .../NextGen_Forcings_Engine/bmi_model.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py index 2b321d8c..6f3256e0 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/bmi_model.py @@ -1550,7 +1550,6 @@ def __init__( Initializes the model with default values for time, variables, and grid types. """ super().__init__(b_date, geogrid, output_path) - self.GeoMeta = GriddedGeoMeta def grid_ranks(self) -> list[int]: """Get the grid ranks for the gridded domain.""" @@ -1621,7 +1620,6 @@ def __init__( Initializes the model with default values for time, variables, and grid types. """ super().__init__(b_date, geogrid, output_path) - self.GeoMeta = HydrofabricGeoMeta def grid_ranks(self) -> list[int]: """Get the grid ranks for the hydrofabric domain.""" @@ -1688,7 +1686,6 @@ def __init__( Initializes the model with default values for time, variables, and grid types. """ super().__init__(b_date, geogrid, output_path) - self.GeoMeta = UnstructuredGeoMeta def grid_ranks(self) -> list[int]: """Get the grid ranks for the unstructured domain.""" From 528c3e37d59464db1b9a13d9f7294641c930f595 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Tue, 25 Aug 2026 12:29:19 -0400 Subject: [PATCH 68/71] Add TODOs about potential bugs --- .../NextGen_Forcings_Engine/core/regrid.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/regrid.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/regrid.py index 639904a4..fa751dc9 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/regrid.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/regrid.py @@ -350,6 +350,8 @@ def regrid_ak_ext_ana(input_forcings, config_options, wrf_hydro_geo_meta, mpi_co input_forcings.regridded_forcings2_elem = np.empty( [9, wrf_hydro_geo_meta.ny_local_elem], np.float32 ) + # TODO likely a bug, should this be "hydrofabric"? + # Issue might be overridden for hydrofabric case in function `check_regrid_status`. elif config_options.grid_type == "unstructured": input_forcings.regridded_forcings1 = np.empty( [9, wrf_hydro_geo_meta.ny_local], np.float32 @@ -446,6 +448,9 @@ def regrid_ak_ext_ana(input_forcings, config_options, wrf_hydro_geo_meta, mpi_co ] = input_forcings.regridded_forcings2_elem[ input_forcings.input_map_output[force_count], : ] + # TODO likely a bug, "hydrofabric" slicing should access 1 dimension, not 2. + # See `regridded_forcings2 =` for hydrofabric case in function `check_regrid_status`. + # Is AK Extended AnA runnable like this? elif config_options.grid_type == "hydrofabric": try: input_forcings.regridded_forcings2[ From a0b009dc0b15c5e422234e9345945b4c7520273e Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Tue, 25 Aug 2026 17:26:37 -0400 Subject: [PATCH 69/71] Replace hard-coded supplemental precip count with dynamic length lookup of supp precip forcing list --- .../NextGen_Forcings_Engine/core/config.py | 13 ++++++++----- ...ted_bmi_model_after_update_n1_rank0__step_1.json | 2 +- ...ted_bmi_model_after_update_n1_rank0__step_2.json | 2 +- ...ted_bmi_model_after_update_n1_rank0__step_3.json | 2 +- ...ted_bmi_model_after_update_n2_rank0__step_1.json | 2 +- ...ted_bmi_model_after_update_n2_rank0__step_2.json | 2 +- ...ted_bmi_model_after_update_n2_rank0__step_3.json | 2 +- ...ted_bmi_model_after_update_n2_rank1__step_1.json | 2 +- ...ted_bmi_model_after_update_n2_rank1__step_2.json | 2 +- ...ted_bmi_model_after_update_n2_rank1__step_3.json | 2 +- .../test_expected_bmi_model_finalize_n1_rank0_.json | 2 +- .../test_expected_bmi_model_finalize_n2_rank0_.json | 2 +- .../test_expected_bmi_model_finalize_n2_rank1_.json | 2 +- .../test_expected_bmi_model_init_n1_rank0_.json | 2 +- .../test_expected_bmi_model_init_n2_rank0_.json | 2 +- .../test_expected_bmi_model_init_n2_rank1_.json | 2 +- ...onfig_options_after_update_n1_rank0__step_1.json | 2 +- ...onfig_options_after_update_n1_rank0__step_2.json | 2 +- ...onfig_options_after_update_n1_rank0__step_3.json | 2 +- ...onfig_options_after_update_n2_rank0__step_1.json | 2 +- ...onfig_options_after_update_n2_rank0__step_2.json | 2 +- ...onfig_options_after_update_n2_rank0__step_3.json | 2 +- ...onfig_options_after_update_n2_rank1__step_1.json | 2 +- ...onfig_options_after_update_n2_rank1__step_2.json | 2 +- ...onfig_options_after_update_n2_rank1__step_3.json | 2 +- ..._expected_config_options_finalize_n1_rank0_.json | 2 +- ..._expected_config_options_finalize_n2_rank0_.json | 2 +- ..._expected_config_options_finalize_n2_rank1_.json | 2 +- ...test_expected_config_options_init_n1_rank0_.json | 2 +- ...test_expected_config_options_init_n2_rank0_.json | 2 +- ...test_expected_config_options_init_n2_rank1_.json | 2 +- 31 files changed, 38 insertions(+), 35 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py index b5fe943e..d4bb52b2 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py @@ -16,6 +16,7 @@ from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.consts import ( CONFIGOPTIONS, FORCINGINPUTMOD, + SUPPPRECIPMOD, ) from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.err_handler import ( err_out_screen, @@ -205,15 +206,17 @@ def cfg_bmi(self, value: dict) -> None: @property def force_count(self) -> int: - """Calculate the number of total possible input forcing options based on the length of the InputForcings list in the consts.py file. This is used for error checking to ensure users specify valid input forcing options in the configuration file.""" + """Calculate the number of total possible input forcing options based on the length of the InputForcings list in consts.py. + This is used for error checking to ensure users specify valid input forcing options in the configuration file. + """ return len(FORCINGINPUTMOD["PRODUCT_NAME"]) @property def supp_precip_count(self) -> int: - """Calculate the number of total possible supplemental precip forcing options based on the length of the SuppPrecipForcings list in the consts.py file. This is used for error checking to ensure users specify valid supplemental precip forcing options in the configuration file.""" - # TODO make this dynamic based on the length of the SUPPPRECIPMOD list in consts.py, but for now hardcoding to 15 since that is the number of options currently available in consts.py and this will avoid any issues with the formatting of the consts.py file causing errors in the program. This is used for error checking to ensure users specify valid supplemental precip forcing options in the configuration file. - # return len(SUPPPRECIPMOD["suppPrecipMod"]["PRODUCT_NAMES"]) - return 15 + """Calculate the number of total possible supplemental precip forcing options based on the length of the Supplemental Precip PRODUCT_NAMES dict in consts.py. + This is used for error checking to ensure users specify valid supplemental precip forcing options in the configuration file. + """ + return len(SUPPPRECIPMOD["PRODUCT_NAMES"]) @property def precip_only_flag(self) -> bool: diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_1.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_1.json index 283f9511..8f7df495 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_1.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_1.json @@ -479,7 +479,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_2.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_2.json index 26e1450f..617df417 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_2.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_2.json @@ -479,7 +479,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_3.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_3.json index 78e899a3..0617ab38 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_3.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n1_rank0__step_3.json @@ -479,7 +479,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_1.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_1.json index 93fc260a..6b4e9f2c 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_1.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_1.json @@ -479,7 +479,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_2.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_2.json index 50cf0d86..d60330e1 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_2.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_2.json @@ -479,7 +479,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_3.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_3.json index fe18aacb..3f62699f 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_3.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank0__step_3.json @@ -479,7 +479,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_1.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_1.json index 5f28473b..6ce96b23 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_1.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_1.json @@ -479,7 +479,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_2.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_2.json index 65e8fc17..79bc3416 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_2.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_2.json @@ -479,7 +479,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_3.json b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_3.json index ca8f708a..ad066576 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_3.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_after_update_n2_rank1__step_3.json @@ -479,7 +479,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_finalize_n1_rank0_.json b/tests/test_data/expected_results/test_expected_bmi_model_finalize_n1_rank0_.json index 5086d888..2e13b37f 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_finalize_n1_rank0_.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_finalize_n1_rank0_.json @@ -479,7 +479,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank0_.json b/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank0_.json index fdcd8db2..c8c8115c 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank0_.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank0_.json @@ -479,7 +479,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank1_.json b/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank1_.json index 4339fbe6..10e05311 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank1_.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_finalize_n2_rank1_.json @@ -479,7 +479,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_init_n1_rank0_.json b/tests/test_data/expected_results/test_expected_bmi_model_init_n1_rank0_.json index 0349bee9..3a29d087 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_init_n1_rank0_.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_init_n1_rank0_.json @@ -289,7 +289,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank0_.json b/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank0_.json index 1d8b1d20..a4920c77 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank0_.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank0_.json @@ -289,7 +289,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank1_.json b/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank1_.json index e2b6c0df..074032c7 100644 --- a/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank1_.json +++ b/tests/test_data/expected_results/test_expected_bmi_model_init_n2_rank1_.json @@ -289,7 +289,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_1.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_1.json index b2edf10e..f4f6b99c 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_1.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_1.json @@ -470,7 +470,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_2.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_2.json index 33914021..8699d992 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_2.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_2.json @@ -470,7 +470,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_3.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_3.json index d5781251..58255f00 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_3.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n1_rank0__step_3.json @@ -470,7 +470,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_1.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_1.json index b2edf10e..f4f6b99c 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_1.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_1.json @@ -470,7 +470,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_2.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_2.json index 33914021..8699d992 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_2.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_2.json @@ -470,7 +470,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_3.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_3.json index d5781251..58255f00 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_3.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank0__step_3.json @@ -470,7 +470,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_1.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_1.json index b2edf10e..f4f6b99c 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_1.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_1.json @@ -470,7 +470,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_2.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_2.json index 33914021..8699d992 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_2.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_2.json @@ -470,7 +470,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_3.json b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_3.json index d5781251..58255f00 100644 --- a/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_3.json +++ b/tests/test_data/expected_results/test_expected_config_options_after_update_n2_rank1__step_3.json @@ -470,7 +470,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_finalize_n1_rank0_.json b/tests/test_data/expected_results/test_expected_config_options_finalize_n1_rank0_.json index 35b7e0a4..d0d21c4d 100644 --- a/tests/test_data/expected_results/test_expected_config_options_finalize_n1_rank0_.json +++ b/tests/test_data/expected_results/test_expected_config_options_finalize_n1_rank0_.json @@ -470,7 +470,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank0_.json b/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank0_.json index 35b7e0a4..d0d21c4d 100644 --- a/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank0_.json +++ b/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank0_.json @@ -470,7 +470,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank1_.json b/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank1_.json index 35b7e0a4..d0d21c4d 100644 --- a/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank1_.json +++ b/tests/test_data/expected_results/test_expected_config_options_finalize_n2_rank1_.json @@ -470,7 +470,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_init_n1_rank0_.json b/tests/test_data/expected_results/test_expected_config_options_init_n1_rank0_.json index 115490a3..99420727 100644 --- a/tests/test_data/expected_results/test_expected_config_options_init_n1_rank0_.json +++ b/tests/test_data/expected_results/test_expected_config_options_init_n1_rank0_.json @@ -280,7 +280,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_init_n2_rank0_.json b/tests/test_data/expected_results/test_expected_config_options_init_n2_rank0_.json index 115490a3..99420727 100644 --- a/tests/test_data/expected_results/test_expected_config_options_init_n2_rank0_.json +++ b/tests/test_data/expected_results/test_expected_config_options_init_n2_rank0_.json @@ -280,7 +280,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], diff --git a/tests/test_data/expected_results/test_expected_config_options_init_n2_rank1_.json b/tests/test_data/expected_results/test_expected_config_options_init_n2_rank1_.json index 115490a3..99420727 100644 --- a/tests/test_data/expected_results/test_expected_config_options_init_n2_rank1_.json +++ b/tests/test_data/expected_results/test_expected_config_options_init_n2_rank1_.json @@ -280,7 +280,7 @@ "suppTemporalInterp": null, "supp_input_offsets": null, "supp_pcp_max_hours": null, - "supp_precip_count": 15, + "supp_precip_count": 16, "supp_precip_dirs": null, "supp_precip_file_types": [], "supp_precip_forcings": [], From ebf1a5de9aba5911659826927397bac07eb7e25b Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Tue, 25 Aug 2026 18:07:19 -0400 Subject: [PATCH 70/71] Add targeted hardening of ConfigOptions attrs to address concerns documented in: https://github.com/NGWPC/ngen-forcing/pull/107 --- .../NextGen_Forcings_Engine/core/config.py | 23 +++++++++++++++- .../historical_forcing.py | 26 +++++++++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py index d4bb52b2..037eb3f8 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/config.py @@ -86,6 +86,7 @@ def __init__(self, cfg_bmi: dict, b_date: str = None, geogrid: str = None) -> No self._ana_flag = None self._look_back = None self._fcst_freq = None + self._fcst_input_horizons = None self._spatial_meta = None self._geopackage = None self._geogrid = None @@ -530,7 +531,18 @@ def fcst_freq(self) -> int: @fcst_freq.setter def fcst_freq(self, value: int) -> None: - """Set the forecast frequency in hours specified by the user in the configuration file. This is used to calculate the processing window for reforecast simulations, and is only necessary if the user is running a reforecast simulation with a specified processing window rather than a realtime simulation.""" + """Set the forecast frequency in hours specified by the user in the configuration file. + + This is used to calculate the processing window for reforecast simulations, and is only necessary + if the user is running a reforecast simulation with a specified processing window rather than a realtime simulation. + + NOTE: this property is hardened such that it allows being set one time, but may not be mutated after that initial set. + For rationale, see: https://github.com/NGWPC/ngen-forcing/pull/107 + """ + if self._fcst_freq is not None and self._fcst_freq != value: + raise ValueError( + f"fcst_freq is immutable after initialization. Current: {self._fcst_freq}, Attempted: {value}" + ) self.check_input_values_non_negative([value], "ForecastFrequency") if value > 1440: err_out_screen( @@ -864,6 +876,15 @@ def fcst_input_horizons(self) -> list: @fcst_input_horizons.setter def fcst_input_horizons(self, value: list) -> None: + """Setter for ``fcst_input_horizons``. + + NOTE: this property is hardened such that it allows being set one time, but may not be mutated after that initial set. + For rationale, see: https://github.com/NGWPC/ngen-forcing/pull/107 + """ + if self._fcst_input_horizons is not None and self._fcst_input_horizons != value: + raise ValueError( + f"fcst_input_horizons is immutable after initialization. Current: {self._fcst_input_horizons}, Attempted: {value}" + ) if not self.precip_only_flag: self.check_number_of_inputs_forcings(value, "ForecastInputHorizons") self.check_input_values_non_negative(value, "ForecastInputHorizons") diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/historical_forcing.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/historical_forcing.py index 5e802404..e6b3d3c6 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/historical_forcing.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/historical_forcing.py @@ -51,6 +51,20 @@ def __init__( self.config_options = config_options self.mpi_config = mpi_config self.wrf_hydro_geo_meta = wrf_hydro_geo_meta + self._b_date_proc_initial = None # Cached value to detect mutations + + def _get_b_date_proc_safe(self): + """Hardened accessor for ``config_options.b_date_proc`` which ensures that is does not get mutated. + + For rationale, see: https://github.com/NGWPC/ngen-forcing/pull/107 + """ + if self._b_date_proc_initial is None: + self._b_date_proc_initial = self.config_options.b_date_proc + elif self.config_options.b_date_proc != self._b_date_proc_initial: + raise ValueError( + "b_date_proc was modified after BaseProcessor was created, which is not allowed." + ) + return self.config_options.b_date_proc @cached_property def bounds(self) -> tuple[float, float, float, float]: @@ -114,7 +128,7 @@ def time_min(self) -> np.datetime64: :return: Minimum time as np.datetime64 """ - return np.datetime64(self.config_options.b_date_proc) + np.timedelta64(1, "h") + return np.datetime64(self._get_b_date_proc_safe()) + np.timedelta64(1, "h") @property def datetimes(self) -> pd.DatetimeIndex: @@ -196,10 +210,12 @@ def start_end_datetimes(self) -> dict[pd.Timestamp, pd.Timestamp]: start and end date pairs based on the cache size. :return: Dictionary of start and end dates as pd.Timestamp - TODO for lru_cache / cached_property safety, confirm or enforce that these are never mutated: - self.config_options.b_date_proc - self.config_options.fcst_input_horizons - self.config_options.fcst_freq + NOTE: + ``b_date_proc`` is protected by _get_``b_date_proc_safe()``. + ``fcst_input_horizons`` is protected by its own setter in ConfigOptions. + ``fcst_freq`` is protected by its own setter in ConfigOptions. + For rationale, see: https://github.com/NGWPC/ngen-forcing/pull/107 + """ start_end_datetimes = {} for start, end in self.year_start_stop_dict.values(): From b7456df8d13be402e0e1cfd68d2ad1669c756a90 Mon Sep 17 00:00:00 2001 From: Max Kipp Date: Tue, 25 Aug 2026 18:14:51 -0400 Subject: [PATCH 71/71] Remove unused variable --- .../NextGen_Forcings_Engine/historical_forcing.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/historical_forcing.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/historical_forcing.py index e6b3d3c6..380eb662 100644 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/historical_forcing.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/historical_forcing.py @@ -625,10 +625,6 @@ def sliced_ds(self) -> xr.Dataset: for var in self.vars: try: with self.timing_block(f"lazy loading {self.dataset_name} data"): - # TODO this object_store var is not used - object_store = obstore.store.from_url( - self.url(var), skip_signature=True - ) datasets.append(self.slice_ds(self.s3_lazy_ds[var])) except Exception as e: LOG.critical(