This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
remove_gpkg_table <- function(db, table) { | |
con <- RSQLite::dbConnect(RSQLite::SQLite(), db) | |
on.exit(RSQLite::dbDisconnect(con)) | |
o <- RSQLite::dbRemoveTable(con, table) | |
o <- RSQLite::dbSendQuery(con, sprintf("DELETE FROM gpkg_contents where table_name='%s';", table)) | |
RSQLite::dbClearResult(o) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
library(dplyr) | |
library(dataRetrieval) | |
library(RNetCDF) | |
# https://water.usgs.gov/GIS/metadata/usgswrd/XML/gagesII_Sept2011.xml | |
gagesii <- sf::read_sf("R/nexus_locations/gagesII_9322_point_shapefile/gagesII_9322_sept30_2011.shp") | |
# Just look at reference gages with recent active status and more than 80 years of record. | |
ref <- dplyr::filter(gagesii, CLASS == "Ref" & ACTIVE09 == "yes" & FLYRS1900 > 80) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Unnest a data.frame with one list column | |
#' @description Will unnest a data.frame that has one list column such that each element | |
#' of each list has its own row and all other observations are repeated. | |
#' @param x data.frame | |
#' @param col character pointing to the list column | |
unnest <- function(x, col = "set") { | |
times <- lengths(x[[col]]) | |
base_names <- names(x)[!names(x) == col] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start at upstream most head water nexus and trace downstream | |
# find groups bound by outlets and | |
# mark visited catchments in catchment topology vector | |
# keep going until all outlets and headwaters have been consumed | |
demo_aggregation <- function() { | |
library(dplyr) | |
library(sf) | |
load("testing.rda") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
httr::GET("https://ldas.gsfc.nasa.gov/sites/default/files/ldas/nldas/NLDAS_masks-veg-soil.nc4", | |
httr::write_disk("NLDAS_masks-veg-soil.nc")) | |
f <- "NLDAS_masks-veg-soil.nc" | |
meta <- ncmeta::nc_meta(f) | |
meta$variable | |
mask <- stars::read_ncdf(f, var = "NLDAS_mask") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reprex::reprex({ | |
#' @example | |
#' p <- sf::st_point(x = c(-73.82705, 43.29139), dim = "XY") | |
#' make_json_input(p) | |
#' | |
make_json_input <- function(p) { | |
jsonlite::toJSON(list(inputs = list(list(id = "lat", | |
type = "text/plain", | |
value = p[2]), | |
list(id = "lng", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# docker run --mount type=bind,source="$(pwd)",target=/data -w /data dblodgett/hydrogeoenv-custom:latest Rscript ./convert.R | |
temp_source <- tempfile(fileext = ".R") | |
download.file("https://raw.githubusercontent.com/dblodgett-usgs/hyRefactor/master/R/download_fdr_fac.R", | |
temp_source) | |
library("rvest") | |
library("xml2") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subset_hr_mr <- function(lon, lat, out_dir) { | |
dir.create(out_dir, recursive = TRUE, showWarnings = FALSE) | |
point <- sf::st_sfc(sf::st_point(c(lon, lat)), | |
crs = 4326) | |
mr_gpkg <- file.path(out_dir, "mr.gpkg") | |
hr_gpkg <- file.path(out_dir, "hr.gpkg") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/dblodgett-usgs/nhdplusTools | |
library(nhdplusTools) | |
# https://github.com/USGS-R/HUCAgg | |
library(HUCAgg) | |
library(sf) | |
library(dplyr) | |
library(snow) | |
wbd_gdb <- "WBD_National_GDB.gdb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(nhdplusTools) | |
library(sf) | |
library(igraph) | |
library(dplyr) | |
library(tidyr) | |
library(readr) | |
library(jsonlite) | |
nhdplus_path("../../4_data/NHDPlusNationalData/NHDPlusV21_National_Seamless.gdb/") | |
nhd_paths <- stage_national_data() |
NewerOlder