Applying NextGen Structure
Mike Johnson
Lynker, NOAA-AffiliateSource:
vignettes/04-applying-nextgen-model.Rmd
04-applying-nextgen-model.Rmd
NextGen
Once we have a network aggregated to a scale matching the desired hydrologic processes we need to turn it into something NextGen can use (modeling task)
Divergent Topology
NextGen operates on a [flowpath --> nexus]
vs
[flowpath --> flowpath]
topology
This is due to the HY Features conceptual catchment that has 1 inflow draining to 1 outflow.
And example of this can be seen below:
Character based indentification
NextGen requires integer based identification, like described in the data model, prefixed with a character string defining what the feature is
Right now, the following prefixs are used to distinguish between types of model features.
Parameter | Purpose | Elected Value |
---|---|---|
nexus_prefix | the maximum length flowpath desired in the output. | “nex-” |
terminal_nexus_prefix | the minimum length of inter-confluence flowpath desired in the output. | “tnx-” |
coastal_nexus_prefix | the minimum length of between-confluence flowpaths. | “cnx-” |
internal_nexus_prefix | the maximum length flowpath desired in the output. | “inx-” |
catchment_prefix | the minimum length of inter-confluence flowpath desired in the output. | “cat-” |
waterbody_prefix | the minimum length of between-confluence flowpaths. | “wb-” |
The following function (1) identifies nexus locations, (2) moves them when needed and (3) applies the above schema to the features.
ngen = 'tutorial/nextgen.gpkg'
unlink(ngen)
ngen <- apply_nexus_topology("tutorial/aggregated.gpkg", export_gpkg = 'tutorial/nextgen.gpkg')
We can see the results of this by opening the hydrofabric and adding it to a map!
mapview::mapview(read_hydrofabric(ngen)) + read_sf(ngen, "nexus")
Extending NWM attributes
The core utilities provide a series of flowpath, divide, and nexuses.
sf::st_layers(ngen)
#> Driver: GPKG
#> Available layers:
#> layer_name geometry_type features fields crs_name
#> 1 flowpaths Line String 396 10 NAD83 / Conus Albers
#> 2 divides Polygon 396 9 NAD83 / Conus Albers
#> 3 nexus Point 173 4 NAD83 / Conus Albers
#> 4 hydrolocations NA 42 3 <NA>
#> 5 network NA 1308 14 <NA>
However, other information is needed to run some/all NextGen formulations. These include the following:
Flowpath Attributes
- Flowpath attributes are extracted from the a Routelink file
- The values are length averaged by the portion of length each makes up in the refactored/aggregated network
For example, if a 75m flowline has a roughness of 0.05 and a 25m flowline with a roughness of 0.2
(n = (.75 * .05) + (.25 * .2))
#> [1] 0.0875
Flowpaths attributes and lake parameters can be added by pointing to a set of NWM domain files like those found here
add_flowpath_attributes(ngen, source = "/Users/mjohnson/hydrofabric")
#> [1] "tutorial/nextgen.gpkg"
read_sf(ngen, "flowpath_attributes")
#> # A tibble: 396 × 12
#> id rl_Qi_m3s rl_MusX rl_n rl_So rl_ChSlp rl_BtmWdth_m rl_Kchan_mmhr
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 wb-1 0 0.2 0.06 0.0197 0.517 3.91 0
#> 2 wb-10 0 0.2 0.0565 0.0481 0.420 9.14 0
#> 3 wb-100 0 0.2 0.06 0.0971 0.641 2.33 0
#> 4 wb-101 0 0.2 0.06 0.064 0.634 2.39 0
#> 5 wb-102 0 0.2 0.06 0.0726 0.628 2.45 0
#> 6 wb-103 0 0.2 0.06 0.0552 0.679 2.05 0
#> 7 wb-104 0 0.2 0.06 0.0397 0.656 2.33 0
#> 8 wb-105 0 0.2 0.06 0.0596 0.610 2.61 0
#> 9 wb-106 0 0.2 0.06 0.0453 0.584 3.01 0
#> 10 wb-108 0 0.2 0.06 0.114 0.722 1.79 0
#> # ℹ 386 more rows
#> # ℹ 4 more variables: rl_nCC <dbl>, rl_TopWdthCC_m <dbl>, rl_TopWdth_m <dbl>,
#> # length_m <dbl>
Themeing
As an option, QGIS QML theming files can be added to a gpkg. Some
default themeing files come with hydrofabric and can be specified/added
with the append_styles
utility on the desired
layer_names
append_style(ngen,layer_names = c("nexus", "hydrolocations", "flowpaths", "divides", "lakes"))
In QGIS, double clicking the gpkg file will allow you to select which layers to load.