NOAA-OWP / hyAggregate

Develop aggregated hydrologic and hydraulic networks
Other
2 stars 1 forks source link

Add capacity for enforced nexus locations #3

Closed mikejohnson51 closed 2 years ago

mikejohnson51 commented 2 years ago

Currently, aggregation looks like this:

aggregate_along_mainstems(network_list,
                                            ideal_size_sqkm,
                                            min_area_sqkm,
                                            min_length_km)

And is control with cs_group based solely on an idealized area. It is then constricted further with agg_length_area which enforces minimum area/length thresholds.

The ideal behavior is to have something that looks like this:

aggregate_along_mainstems(network_list,
                                            ideal_size_sqkm,
                                            min_area_sqkm,
                                            min_length_km,
                                            nexus_locations = ...)

The purpose is to ensure that cs_group will not aggregate over enforced nexus locations, and that agg_length_area will always push upstream/dowstream (respectively) of the enforced nexus.

nexus_locations can be given base on refactored fabric IDs.

Process

Part 1: Fixing cs_group - DONE

As part of the reference fabric, know POIs are provided. The primary one of interest now is the Type_WBOut.

POIs are POINT objects at the outlet of the ID they are associated with...

library(dplyr); library(ggplot2); library(sf)

gpkg  = "/Volumes/Transcend/ngen/CONUS-hydrofabric/refactor/refactor_01.gpkg"
POI = read_sf(gpkg, 'mapped_POIs') |> 
  filter(!is.na(Type_WBOut))

cat = read_sf(gpkg, 'refactored_divides') |> 
  filter(ID == POI$ID[1])

fl = read_sf(gpkg, 'refactored_flowpaths') |> 
  filter(ID == POI$ID[1])

fl_out = read_sf(gpkg, 'refactored_flowpaths') |> 
  filter(ID == POI$toID[1])

ggplot() + 
  geom_sf(data = cat) + 
  geom_sf(data = fl) + 
  geom_sf(data = fl_out, col = "red") + 
  geom_sf(data = POI[1,])

Created on 2022-07-20 by the reprex package (v2.0.1)

Therefore these IDs can be used to fracture a mainstem (currently implementation of cs_group), into sub mainstems, over which the current cs_group can run. The trick will be bringing these back into a single group set to aggregate over with aggregate_sets.

Part 2: fixing agg_length_area DONE

This was accomplished by modifying and adding cs_group;assign_id;middle_massage; pinch_sides to remove agg_length_area

Part 3: fixing headwater collapse DONE

This was done by adding build_collapse_table and collapse_hw to replace collapse_network_inward. These functions are (1) iterative, (2) more "graph" based (still requires computing outlets) and (3) can enforce predefined nexus locations

Part 4: Making sure predefined nexus locations end up in nexus output

This requires the creation of a type attribute for each features and a validation check that all enforce nexus locations appear as a computed nexus.

...

mikejohnson51 commented 2 years ago

Things are looking really good until VPU-03S is hit - In one case Gages are aggregated over by catchments but not by flowpath. This results in 2 NULL geometry catchments which in turn break the creation of weight grids.

Screen Shot 2022-07-28 at 10 43 46 AM

mikejohnson51 commented 2 years ago

See https://code.usgs.gov/wma/nhgf/gfv2.0/-/issues/80

mikejohnson51 commented 2 years ago

The above was a error, this issue is complete!