Skip to content

Commit

Permalink
get checks passing
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejohnson51 committed Dec 6, 2024
1 parent 3ea2a56 commit 2f80386
Show file tree
Hide file tree
Showing 28 changed files with 360 additions and 387 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ tmp
runners
in-progress
data-raw
README_files
README_files
in-progress-vignettes
11 changes: 5 additions & 6 deletions R/conflicts.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ hydrofabric_conflict_message <- function(x) {
right = "hydrofabric_conflicts()"
)

pkgs <- x %>% purrr::map(~ gsub("^package:", "", .))
others <- pkgs %>% purrr::map(`[`, -1)
pkgs <- purrr::map(x, ~ gsub("^package:", "", .))
others <- purrr::map(pkgs, `[`, -1)
other_calls <- purrr::map2_chr(
others, names(others),
~ paste0(crayon::blue(.x), "::", .y, "()", collapse = ", ")
)

winner <- pkgs %>% purrr::map_chr(1)
winner <- purrr::map_chr(pkgs, 1)
funs <- format(paste0(crayon::blue(winner), "::", crayon::green(paste0(names(x), "()"))))
bullets <- paste0(
crayon::red(cli::symbol$cross), " ", funs,
Expand All @@ -102,9 +102,8 @@ print.hydrofabric_conflicts <- function(x, ..., startup = FALSE) {

confirm_conflict <- function(packages, name) {
# Only look at functions
objs <- packages %>%
purrr::map(~ get(name, pos = .)) %>%
purrr::keep(is.function)
objs <- purrr::keep(purrr::map(packages, ~ get(name, pos = .)),
is.function)

if (length(objs) <= 1)
return()
Expand Down
56 changes: 0 additions & 56 deletions R/mask_hydrofabric.R

This file was deleted.

14 changes: 8 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ knitr::opts_chunk$set(
message = TRUE,
fig.path = 'man/figures/'
)
gpkg = '/Users/mikejohnson/hydrofabric/conus_nextgen.gpkg'
```

# Hydrofabric:<a href="https://github.com/lynker-spatial/hfsubsetR"><img src="man/figures/logo.png" align="right" width="25%"/></a>
# Hydrofabric:<a href="https://github.com/NOAA-OWP/hydrofabric"><img src="man/figures/logo.png" align="right" width="25%"/></a>

<!-- badges: start -->
[![R CMD Check](https://github.com/NOAA-OWP/hydrofabric/actions/workflows/R-CMD-check.yaml/badge.svg?branch=main)](https://github.com/NOAA-OWP/hydrofabric/actions/workflows/R-CMD-check.yaml)
Expand Down Expand Up @@ -75,14 +75,16 @@ gpkg <- './conus_nextgen.gpkg'
get_hydrofabric(outfile = gpkg)
```

```{r}
```{r, eval = FALSE}
subset_fabric <- get_subset(gpkg = gpkg,
comid = 101)
```

```{r, echo = FALSE}
subset_fabric = read_hydrofabric("inst/extdata/comid-101-subset.gpkg")
subset_fabric$nexus = sf::read_sf("inst/extdata/comid-101-subset.gpkg", 'nexus')
{
plot(subset_fabric$divides$geom, col = "gray90")
plot(subset_fabric$catchments$geom, col = "gray90")
plot(subset_fabric$flowpaths$geom, add = TRUE, col = "blue")
plot(subset_fabric$nexus, add = TRUE, col = "red", pch = 16)
}
Expand All @@ -100,7 +102,7 @@ Additionally, open source tools like `climateR` and `zonal` can be used to rapid

```{r}
# Get Daymet Data
(tmax = getDaymet(subset_fabric$divides,
(tmax = getDaymet(subset_fabric$catchments,
varname = "tmax",
startDate = "2020-10-01"))
```
Expand All @@ -111,7 +113,7 @@ plot(tmax$tmax, main = 'Daymet Maximum Temperture')

```{r}
(summary_stats = zonal::execute_zonal(tmax,
subset_fabric$divides,
subset_fabric$catchments,
ID = "divide_id"))
```

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# Hydrofabric:<a href="https://github.com/lynker-spatial/hfsubsetR"><img src="man/figures/logo.png" align="right" width="25%"/></a>
# Hydrofabric:<a href="https://github.com/NOAA-OWP/hydrofabric"><img src="man/figures/logo.png" align="right" width="25%"/></a>

<!-- badges: start -->

Expand Down Expand Up @@ -65,7 +65,7 @@ library(hydrofabric)

## ── Attaching packages ───────────────────────────────────────────────────────── hydrofabric 0.2.1 ──

## ✔ climateR 0.3.6 ✔ hydroloom 1.1.0
## ✔ climateR 0.3.7 ✔ hydroloom 1.1.0
## ✔ dplyr 1.1.4 ✔ sf 1.0.19
## ✔ hfsubsetR 0.3.2 ✔ terra 1.7.78
## ✔ hydrofab 0.6 ✔ zonal 0.1.0
Expand Down Expand Up @@ -133,7 +133,7 @@ to rapidly access and summarize data for a catchment set:

``` r
# Get Daymet Data
(tmax = getDaymet(subset_fabric$divides,
(tmax = getDaymet(subset_fabric$catchments,
varname = "tmax",
startDate = "2020-10-01"))
```
Expand All @@ -155,7 +155,7 @@ to rapidly access and summarize data for a catchment set:

``` r
(summary_stats = zonal::execute_zonal(tmax,
subset_fabric$divides,
subset_fabric$catchments,
ID = "divide_id"))
```

Expand Down
1 change: 0 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ articles:
- 02-design-deep-dive
- 03-processing-deep-dive
- 04-applying-nextgen-model
- 05-subsetting

- title: 2024 CIROH DevCon
contents:
Expand Down
15 changes: 15 additions & 0 deletions data-raw/comid_101.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
gpkg = '/Users/mikejohnson/hydrofabric/conus_nextgen.gpkg'

subset_fabric <- get_subset(gpkg = '/Users/mikejohnson/hydrofabric/conus_nextgen.gpkg',
comid = 101,
outfile = "inst/extdata/comid-101-subset.gpkg")

subset_fabric <- get_subset(gpkg = '/Users/mikejohnson/hydrofabric/CONUS/v2.2/reference/ls_reference.gpkg',
comid = 101,
lyrs = c("divides", "flowpaths"),
outfile = "inst/extdata/reference-comid-101-subset.gpkg")


read_sf('/Users/mikejohnson/hydrofabric/CONUS/v2.2/reference/community_hydrolocations.gpkg') |>
st_as_sf(coords = c("X", "Y"), crs = 5070) |>
st_filter(read_sf("inst/extdata/reference-comid-101-subset.gpkg", "divides"))
Binary file added inst/extdata/aggregate.gpkg
Binary file not shown.
Binary file added inst/extdata/comid-101-subset.gpkg
Binary file not shown.
Binary file added inst/extdata/reference-comid-101-subset.gpkg
Binary file not shown.
15 changes: 10 additions & 5 deletions inst/logo.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ library(hexSticker)
library(showtext)

imgurl <- "man/figures/imgfile.png"
font_add_google("Rammetto One", "rammetto")
showtext_auto()

hexSticker::sticker(imgurl,
package="hydrofabric",
y = 1.5,
p_size=17,
p_color = "brown",
p_family = "rammetto",
#p_fontface = "static",
y = 1.45,
p_size=15,
p_color = "gold",
s_x=1,
s_y=.8,
s_width=.75,
h_color = "dodgerblue",
h_fill = "gray90",
h_color = "brown",
h_size = 2,
h_fill = "dodgerblue",
filename="man/figures/logo.png")
Binary file added man/figures/unnamed-chunk-11-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/unnamed-chunk-7-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/unnamed-chunk-9-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 0 additions & 12 deletions tests/testthat.R

This file was deleted.

Empty file.
4 changes: 4 additions & 0 deletions vignettes/01-intro-deep-dive.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ output:
distill::distill_article:
toc: true
toc_depth: 2
vignette: >
%\VignetteIndexEntry{NOAA's Enterprise Hydrofabric System}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
Expand Down
35 changes: 11 additions & 24 deletions vignettes/02-design-deep-dive.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ author:
- name: "Angus Watters"
affiliation: Lynker
output: distill::distill_article
vignette: >
%\VignetteIndexEntry{The Reference Fabric}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2);library(hydrofabric)
base <- "tutorial"
dir.create(base, showWarnings = FALSE)
base_gpkg = "/Users/mikejohnson/hydrofabric/CONUS/v2.2/nextgen/ls_conus.gpkg"
```

# How do we arrive at the NextGen Hydrofabric?
Expand Down Expand Up @@ -123,7 +128,7 @@ Points of Interest (POIs) for hydrologic modeling are collected from a variety o

```{r, echo = FALSE, eval = FALSE, warning=FALSE}
df = open_dataset('s3://lynker-spatial/hydrofabric/v2.2/conus_hl') |>
df = as_ogr(base_gpkg, "hydrolocations") |>
select("hl_source", 'hl_reference', "hl_link") |>
distinct() |>
collect() |>
Expand All @@ -150,8 +155,10 @@ ggsave(filename = "../man/figures/poi_dist.png")
A VPU is a **V**ector **P**rocessing **Unit**. The USGS determined these regions when designing the NHDPlusV2. Since our work builds off the NHDPlusV2, we adopt these processing units.

```{r, echo = FALSE}
ggplot(data = vpu_boundaries[1:21,]) +
geom_sf(data = vpu_boundaries[1:21,]) +
x = hydrofab::vpu_boundaries[1:21,]
ggplot(data = x) +
geom_sf(data = x) +
geom_sf_label(aes(label = VPUID)) +
theme_void()
```
Expand All @@ -167,26 +174,6 @@ knitr::include_graphics(c('../man/figures/merit-hydro.png', '../man/figures/basi

# Getting the reference fabric

All reference products live on Lynker Spatial s3 account.

They can be accessed with the web interface, downloaded, or interfaced with arrow.

The `hydrofab::get_hydrofabric()` utility will download the most current geofabric for a Vector Processing Unit (VPU).

As an example, lets use the Geonconnex reference features to identify the location of our Fort Collins gage.

This location can be joined to the set of VPU boundaries severed with `nhdplusTools` to find the correct VPU.

```{r}
(gage = open_dataset('s3://lynker-spatial/hydrofabric/v2.2/conus_hl') |>
select("vpuid", 'hl_reference', "hl_link") %>%
filter(hl_link == '06752260') %>%
collect())
reference_gpkg = get_vpu_fabric(vpu = gage$vpuid[1],
outfile = glue("tutorial/vpu_{gage$vpuid[1]}.gpkg"))
```

If the requested file already exists, the file path will be returned.
All reference products live on Lynker Spatial s3 account. They can be accessed with the web interface.

Ok! With that, we have an idea of what the reference fabric is, how it was made, and how we can get it! The next stage is to learn how to manipulate this reference fabric for unique model applications.
Loading

0 comments on commit 2f80386

Please sign in to comment.