knitr::opts_chunk$set(echo = TRUE)
library(dm)

Hydrofabric

gpkg = '/Users/mikejohnson/hydrofabric/CONUS/v2.2/nextgen/ls_conus.gpkg'

con = DBI::dbConnect(RSQLite::SQLite(), gpkg)

lyrs = sf::st_layers(gpkg)$name
lyrs = lyrs[!grepl("attributes", lyrs)]

dm::dm_from_con(con, table_names = lyrs, learn_keys = FALSE) |> 
  dm_set_colors("dodgerblue" = "flowpaths",
                "red"        = "divides",
                "gray10"     = "nexus",
                # "darkgreen"  = "flowpath-attributes",
                # "darkgreen"  = "flowpath-attributes-ml",
                "navy"       = "lakes",
                "#F0A0FF"    = "hydrolocations",
                "pink"       = "pois",
                "orange"     = "network") |> 
  dm_draw(view_type = 'all')
dm = tibble::tribble(
  ~attribute, ~description,
  "id",  "Unique flowpath identifier",                       
  "toid", "Flowpath id where water flows",                         
  "mainstem", "Persistent Mainstem Identifier", 
  "nex_id",    "Unique nexus ID",   
  "divide_id",  "Unique divide identifier",             
  "poi_id", "Unique Point of Interest identifier",                       
  "vpuid", "Vector Processing Unit ID",  
  "domain",     'Domain of Hydrofabric (conus, hi, gl, ak, prvi)',  

  "order", "Stream order (Strahler)",                    
  "hydroseq", "Hydrologic Sequence",                    
  "lengthkm", "Length in kilometers of Flowpath",                  
  "areasqkm", "Incremental Areas of Divide",                    
  "tot_drainage_areasqkm", "Total Upstream Drainage Area",        
  "has_divide", "Does Flowpath ID have an associated divide",  
  "has_flowline", "Does divide have an associated flowpath", 
  "type", "Divide Type, one of coastal, internal, network",                         
  "ds_id", "Most Downstream flowpath element adjacent to internal divides.", 

  "lake_id", "Unique NWS Lake ID (taken from NHDPlus)",  
  "res_id",  "Unique Reservoir Identifier",  
  "LkArea", "Area associate with lake_id, Square Kilometers",                       
  "LkMxE",  "Maximum lake elevation (meters above sea level)",                      
  "WeirC",  "Weir coefficient",                   
  "WeirL",  "Weir length (meters)",                  
  "OrificeC", "Orifice coefficient",                  
  "OrificeA", "Orifice cross-sectional area, Square meters",                   
  "OrificeE", "Orifice elevation (meters above sea level)",                   
  "lake_y",  'Y coordinate of the lake centroid',
  "lake_x", 'X coordinate of the lake centroid',
  "time",  'Time of measurement. Associated with lakes',                       
  "WeirE",  'Weir elevation (meters above sea level)',                    
  "ifd",        'Initial fraction water depth',                   
  "Dam_Length", 'Length of the dam in meters',                  
  "reservoir_index_AnA",          "Reservoir release data type for AnA configuration; Level pool = 1, USGS-persistence = 2, USACE-persistence = 3, RFC-forecasts = 4",        
  "reservoir_index_Extended_AnA", "Reservoir release data type for extended AnA configuration; Level pool = 1, USGS-persistence = 2, USACE-persistence = 3, RFC-forecasts = 4",
  "reservoir_index_GDL_AK",       "Reservoir release data type for Alaska domain; Level pool = 1, USGS-persistence = 2, USACE-persistence = 3, RFC-forecasts = 4, APRFC-GDL = 5",    
  "reservoir_index_Medium_Range", "Reservoir release data type for extended medium range configuration; Level pool = 1, USGS-persistence = 2, USACE-persistence = 3, RFC-forecasts = 4",
  "reservoir_index_Short_Range",  "Reservoir release data type for extended shirt range configuration; Level pool = 1, USGS-persistence = 2, USACE-persistence = 3, RFC-forecasts = 4",

  "hf_source",                    "Source of the reference hydrofabric",                    
  "hf_id",     "Unique ID of the source (hf_sourcre) reference hydrofabric",  
  "hf_hydroseq",  "Source hydrofabric hydrosequence",
  "hf_lengthkm",  "Source hydrofabric length in kilometers",
  "hf_mainstem", "Source hydrofabric mainstem",

  "hl_link",   "Unique ID of the hydrolocations in the reference dataset",        
  "hl_reference", "Native dataset that hydrolocation was extracted from",         
  "hl_uri", "Concatenation of hl_reference and hl_link",                    
  "hl_source", "Where is the data source from? USGS-NOAA Reference Fabric, or, NOAA-OWP",        
  "hl_x", "X coordinate of the hydrolocation",                        
  "hl_y", "Y coordinate of the hydrolocation",  

  "n", "Manning's in channel roughness",                         
  "link",      "Idential to id,   but naming needed for t-route",                      
  "to",        "Idential to toid, but naming needed for t-route",                    
  "Length_m",  "Length of flowpath id (meters)",                     
  "nCC",       "Compound Channel Top Width (meters)" ,                        
  "BtmWdth",   "Bottom width of channel (meters)" ,                     
  "TopWdth",   "Top Width (meters)",                      
  "TopWdthCC", "Compound Channel Top Width (meters)",          
  "ChSlp",     "Channel side slope",                      
  "alt",       "Elevation in meters, at the headwater node, taken from the 3DEP 10m DEM",                          
  "So",        'Slope (meters/meters), computed from the 3DEP 10m DEM',            
  "MusX", 'Channel side slope',                         
  "MusK", 'Muskingum routing time (seconds)',                        
  "gage", "If there is a gage, the hl_link is stored" ,                        
  "gage_nex_id", "The downstream nexus associated with the gage",                  
  "WaterbodyID",      "If there is a waterbody, the hl_link is stored",                  
  "waterbody_nex_id", "The downstream nexus associated with the gage",
  "Y", "Estimated depth (m) associated with TopWdth",
  "YCC", "Estimated depth (m) associated with TopWdthCC",
  "dingman_r", "Estimated channel shape",

  "geom", 'Spatial Geometry("POINT", "LINESTRING", "POLYGON")'
  )  


dt = lapply(1:length(lyrs), function(x){ 
  tmp = colnames(hfsubsetR::as_ogr(gpkg, lyrs[x]))
  data.frame(
    attribute = tmp,
    layer = rep(lyrs[x], length(tmp))
  )
  }) |> 
  dplyr::bind_rows() |> 
  filter(attribute != "fid") |> 
  group_by(attribute) |> 
  mutate(layers = paste(layer, collapse = ", "),
         layer = NULL) |>
  dplyr::slice(1) |> 
  ungroup() |> 
  left_join(dm, by = 'attribute') 

dt[ order(dt$attribute),] |> 
  select(attribute,description,layers) |> 
  DT::datatable(
     filter = list(position = 'top', clear = FALSE),
      options = list(
        search = list(regex = TRUE, caseInsensitive = FALSE),
        pageLength = 100
  ),
  rownames = FALSE) 

Flowpath Attributes

lyrs = sf::st_layers(gpkg)$name
lyrs = lyrs[grepl("flowpath", lyrs)]

dm::dm_from_con(con, table_names = lyrs, learn_keys = FALSE) |> 
  dm_set_colors("dodgerblue" = "flowpaths",
                # "red"        = "divides",
                # "gray10"     = "nexus",
                "lightgreen"  = "flowpath-attributes",
                "darkgreen"  = "flowpath-attributes-ml",
                # "navy"       = "lakes",
                # "#F0A0FF"    = "hydrolocations",
                # "pink"       = "pois",
                # "orange"     = "network"
                ) |> 
  dm_draw(view_type = 'all')

lyrs = lyrs[2:3]
dt = lapply(1:length(lyrs), function(x){ 
  tmp = colnames(hfsubsetR::as_ogr(gpkg, lyrs[x]))
  data.frame(
    attribute = tmp,
    layer = rep(lyrs[x], length(tmp))
  )
  }) |> 
  dplyr::bind_rows() |> 
  filter(attribute != "fid") |> 
  group_by(attribute) |> 
  mutate(layers = paste(layer, collapse = ", "),
         layer = NULL) |>
  dplyr::slice(1) |> 
  ungroup() |> 
  left_join(dm, by = 'attribute') 

dt[ order(dt$attribute),] |> 
  select(attribute,description,layers) |> 
  DT::datatable(
     filter = list(position = 'top', clear = FALSE),
      options = list(
        search = list(regex = TRUE, caseInsensitive = FALSE),
        pageLength = 100
  ),
  rownames = FALSE) 

Divide Attributes

lyrs = sf::st_layers(gpkg)$name
lyrs = lyrs[grepl("divide", lyrs)]

dm::dm_from_con(con, table_names = lyrs, learn_keys = FALSE) |> 
  dm_set_colors(
                "red"        = "divides",
                # "gray10"     = "nexus",
                "pink"  = "divide-attributes"
                ) |> 
  dm_draw(view_type = 'all')


tibble::tribble(
~attribute,   ~Description,                                             ~`Layer(s)`,  ~`Summary Function`,     ~Units,             ~`Native Resolution`, ~Source,
"divide_id",  'Unique divide identifier',                               NA,           NA ,                     NA ,               "30m simplified" ,       'hfv2.2',
"centroid_x", 'X coordinates of divide centroid',                       1 ,           'st_point_on_surface',   "Units of CRS",    "m (EPSG:5070)",         'hfv2.2',
"centroid_y", 'Y coordinates of divide centroid',                       1 ,           'st_point_on_surface',   "Units of CRS",    "m (EPSG:5070)",         'hfv2.2',
"vpuid",      'Vector Processing Unit ID',                              NA,           NA ,                     NA ,                NA ,                    'hfv2.2',
"ISLTYP" ,    'Dominant soil type category',                            1 ,           'mode',                  'cataglorical',    '1km',                   'NWM 3.0.11 wrfinput',
"IVGTYP" ,    'Dominant vegetation type category',                      1 ,           'mode',                  'cataglorical',    '1km',                   'NWM 3.0.11 wrfinput',
"bexp" ,      'Beta Parameter: soil C-H B exponent',                    4 ,           'mode',                  'Unitless',        '1km',                   'NWM 3.0.11 soilproperties',
"dksat" ,     'Saturated Soil Connectivity',                            4 ,           'geometric mean',        'mm/h',            '1km',                   'NWM 3.0.11 soilproperties',
"psisat" ,    'Saturated soil matric potential',                        4 ,           'geometric mean',        'kpa',             '1km',                   'NWM 3.0.11 soilproperties',
"cwpvt" ,     'Empirical canopy wind parameter',                        1 ,           'mean',                  '1/m',             '1km',                   'NWM 3.0.11 soilproperties',
"mfsno" ,     'Snowmelt m parameter',                                   1 ,           'mean',                  'Unitless' ,       '1km',                   'NWM 3.0.11 soilproperties',
"mp" ,        'Slope of Conductance to photosynthesis relationship',    1 ,           'mean',                  "Unitless",        '1km',                   'NWM 3.0.11 soilproperties',
"refkdt" ,    'Parameter in the surface runoff parameterization',       1 ,           'mean',                  "Unitless",        '1km',                   'NWM 3.0.11 soilproperties',
"slope_1km",  'Slope [0-1]',                                            1 ,           'mean',                  'Degrees',         '1km',                   'NWM 3.0.11 soilproperties',
"smcmax" ,    'Saturated value of soil moisture [volumetric]',          4 ,           'mean',                  "m/m" ,            '1km',                   'NWM 3.0.11 soilproperties',
"smcwlt" ,    'Wilting point soil moisture [volumetric]',               4 ,           'mean',                  "m/m" ,            '1km',                   'NWM 3.0.11 soilproperties',
"vcmx25" ,    'Maximum rate of carboxylation at 25 C',                  1 ,           'mean',                  'umol/m2/s',       '1km',                   'NWM 3.0.11 soilproperties',
"Coeff" ,     'Groundwater Coefficient' ,                               1 ,           'mean',                  "m3/s",            'NHDPlus2.1',            'NWM 3.0.11 GWBUCKPARM',
"Zmax" ,      'The total height of the baseflow "bucket"',              1 ,           'mean',                  "mm",              'NHDPlus2.1',            'NWM 3.0.11 GWBUCKPARM',
"Expon" ,     'Groundwater Exponent',                                   1 ,           'mode',                  "Unitless",        'NHDPlus2.1',            'NWM 3.0.11 GWBUCKPARM',
"impervious", "Percent Impervious Surface",                             1 ,           'mean' ,                 "Percent",         "30m",                   '2021 NLCD Impervious Surface',
"elevation" , 'Elevation from DEM',                                     1 ,           'mean' ,                 "Meters",          "30m",                   '30m 3DEP resampled 240m',
"slope_mean", 'Slope computed from DEM [0-100]' ,                       1 ,           'mean' ,                 "Degrees",         "30m",                   'Derived from 30m 3DEP resampled 240m',
"aspect",     'Aspect computed from DEM',                               1 ,           'circular mean',         "Degrees",         "30m",                   'Derived from 30m 3DEP resampled 240m',
"twi",        "Topographic Wetness Index",                              1 ,           'Quartile Distribution', "Unitless",        "30m",                   'Hoylman, 2021') |> 
  DT::datatable(
     filter = list(position = 'top', clear = FALSE),
      options = list(
        search = list(regex = TRUE, caseInsensitive = FALSE),
        pageLength = 100
  ),
  rownames = FALSE) 


NOAA-OWP/hydrofabric documentation built on Dec. 7, 2024, 11:24 a.m.