hydrotools.nwm_client.utils module#

National Water Model File Utilities#

This module provides methods for handling common model parameter files that can be used in part with the other portions of this subpackage. One pragmatic use of this module is to extract nhdPlus links associated with usgs sites to filter stations of interest.

hydrotools.nwm_client.utils.crosswalk(usgs_site_codes: str | List[str] | None = None, nwm_feature_ids: str | List[str] | None = None) DataFrame#

Return the nwm_feature_id(s) OR usgs_site_codes for one or more provided usgs_sites_codes or nwm_feature_ids.

Parameters:
  • usgs_site_codes (Union[str, List[str]], either usgs_site_codes or nwm_feature_ids) – USGS site code as string, string seperated by commas, or list of strings

  • nwm_feature_ids (Union[str, List[str]], either usgs_site_codes or nwm_feature_ids) – NWM feature id(s) as string, string seperated by commas, or list of strings

Returns:

df of nwm_feature_id and usgs_site_code cols

Return type:

pd.DataFrame

Examples

>>> from hydrotool.nwm_client import utils
>>> cribbs_creek = "02465292"
>>> crx_walk = utils.crosswalk(usgs_site_codes=cribbs_creek)
>>> sites = ["02465292", "04234000"]
>>> crx_walk = utils.crosswalk(usgs_site_codes=sites)
>>> sites = "02465292,04234000"
>>> crx_walk = utils.crosswalk(usgs_site_codes=sites)
>>> nwm_feature = 18206880
>>> crx_walk = utils.crosswalk(nwm_feature_ids=nwm_feature)

From a NWM routelink file, extract nwm_feature_id’s that have associated USGS NWIS Stations, returning a df with cols nwm_feature_id and usgs_site_code.

Routelink files can be obtained from nomads production server: https://www.nco.ncep.noaa.gov/pmb/codes/nwprod/

Under ./nwm.v*/parm/domain/RouteLink*.nc

Parameters:

routelink_file_or_url (Union[ str, Path, ]) – NWM Routelink file containing channel parameters

Returns:

Dataframe with cols nwm_feature_id and usgs_site_code

Return type:

pd.DataFrame

Examples

>>> from hydrotools.nwm_client import utils
>>> df = utils.nwm_routelink_extract_usgs_sites("RouteLink_NHDPLUS.nc")
>>> import csv
>>> df.to_csv("nwm_feature_id_with_usgs_site.csv", index=False, quoting=csv.QUOTE_NONNUMERIC)