NOAA-OWP / t-route

Tree based hydrologic and hydraulic routing
Other
43 stars 48 forks source link

Inconsistency in expected config structure between troute-config and troute-network #719

Open robertbartel opened 9 months ago

robertbartel commented 9 months ago

The troute-network package (and possibly other places) expects compute_parameters.data_assimilation_parameters.reservoir_da to have subkeys reservoir_persistence_usace and reservoir_persistence_usgs. However, troute-config defines this property as an Optional[ReservoirDA]. As a result, if reservoir_persistence_usace and reservoir_persistence_usgs are present, we see this error:

terminate called after throwing an instance of 'pybind11::error_already_set'
  what():  ValidationError: 2 validation errors for Config
compute_parameters -> data_assimilation_parameters -> reservoir_da -> reservoir_persistence_usace
  extra fields not permitted (type=value_error.extra)
compute_parameters -> data_assimilation_parameters -> reservoir_da -> reservoir_persistence_usgs
  extra fields not permitted (type=value_error.extra)

During troubleshooting, it was suggested by @aaraney that, within the DataAssimilationParameters model, the reservoir_da attribute may need to be of type Optional[ReservoirPersistenceDA] rather than Optional[ReservoirDA].

Note that if we comment out reservoir_persistence_usace and reservoir_persistence_usgs from the config, then this error happens:

terminate called after throwing an instance of 'pybind11::error_already_set'
  what():  AttributeError: 'NoneType' object has no attribute 'get'

At:
  /usr/local/lib64/python3.9/site-packages/troute/HYFeaturesNetwork.py(32): read_geopkg
  /usr/local/lib64/python3.9/site-packages/troute/HYFeaturesNetwork.py(154): read_geo_file
  /usr/local/lib64/python3.9/site-packages/troute/HYFeaturesNetwork.py(253): __init__
  /usr/local/lib/python3.9/site-packages/nwm_routing/__main__.py(80): main_v04

Here are lines 31 and 32 of src/troute-network/troute/HYFeaturesNetwork.py:

    streamflow_nudging = data_assimilation_parameters.get('streamflow_da',{}).get('streamflow_nudging',False)
    usgs_da = data_assimilation_parameters.get('reservoir_da',{}).get('reservoir_persistence_usgs',False)
robertbartel commented 9 months ago

A note that I did attempt to change the reservoir_da property type from Optional[ReservoirDA] to Optional[ReservoirPersistenceDA], as @aaraney suggested and as was mentioned in the description, but that led to a different error during testing:

terminate called after throwing an instance of 'pybind11::error_already_set'
  what():  AttributeError: 'ReservoirPersistenceDA' object has no attribute 'reservoir_rfc_da'

At:
  /usr/local/lib/python3.9/site-packages/troute/config/config.py(118): check_rfc_parameters
  /usr/local/lib/python3.9/site-packages/nwm_routing/input.py(44): _input_handler_v04
  /usr/local/lib/python3.9/site-packages/nwm_routing/__main__.py(54): main_v04
shorvath-noaa commented 8 months ago

@robertbartel It looks like, for the original error listed here, you're missing a level in the config file. They way troute-config is setup, it should be compute_parameters -> data_assimilation_parameters -> reservoir_da -> reservoir_persistence_da -> reservoir_persistence_usace

shorvath-noaa commented 8 months ago

The two config files in /t-route/test/LowerColorado_TX_v4/ are the most recent examples that work with V4. You should be able to use these as guidelines for running the latest version of t-route.