Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add LastObs reading and writing for command-line run of main_V04 with HYfeature hydrofabric #701

Conversation

kumdonoaa
Copy link
Contributor

@kumdonoaa kumdonoaa commented Nov 17, 2023

Currently, reading lastobs files to create lastobs Dataframe and then writing lastobs files from run_results with updated lastobs time and values from computing mc_reach.py is only available for BMI running and command-line run for NHD hydrofabric. This PR adds such capability as well for command-line run with HYfeature hydrofabric.

Additions

  • def _read_lastobs_file() from model_DAforcing.py to DataAssimilation.py
  • lastobs_output parameter under output_parameters in test_AnA_V4_HYFeatuere config file
  • output_parameter in input argument list of def init of class HYFeatureNetwork
  • if lastobs condition in output.py for activating writing lastobs files

Removals

Changes

Testing

  1. python3 -m nwm_routing -V4 -f test_AnA_V4_HYFeature.yaml

Screenshots

Notes

Todos

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Visually tested in supported browsers and devices (see checklist below 👇)
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

Testing checklist

Target Environment support

  • Windows
  • Linux
  • Browser

Accessibility

  • Keyboard friendly
  • Screen reader friendly

Other

  • Is useable without CSS
  • Is useable without JS
  • Flexible from small to large screens
  • No linting errors or warnings
  • JavaScript tests are passing

df_discharge.
apply(pd.Series.last_valid_index). # index of last non-nan value, each gage
to_numpy() # to numpy array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, last_obs_index returns all zeros for me (changing all discharge values to zero), however, df_discharge is not zero.

To find the last valid value, maybe consider something like this:

df_discharge = ds[obs_discharge_id].to_dataframe().replace(to_replace=discharge_nan, value=np.nan).reset_index(level='timeInd', drop=True).stack().dropna()
last_obs_value = df_discharge.iloc[-1]

And for the index of the last value:

last_obs_index = df_discharge[df_discharge == last_obs_value].idxmax()[0]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess last_obs_index is only used for row index of df_discharge, being nothing to do with make discharge zero. If you look into the final product, which is lastobs_df, the dataframe has non-zero lastobs_discharge values.

@AminTorabi-NOAA
Copy link
Contributor

HYFeature works but for NHD it gave me this error:

image

@kumdonoaa kumdonoaa merged commit 59f2b50 into NOAA-OWP:master Dec 6, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants