From 4207c8dab0fadd49ef93f1884718148ed80c4ac8 Mon Sep 17 00:00:00 2001 From: Beaudette Date: Tue, 4 Jun 2024 12:38:56 -0700 Subject: [PATCH] Create graphite-OSDs.R --- misc/graphite-OSDs.R | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 misc/graphite-OSDs.R diff --git a/misc/graphite-OSDs.R b/misc/graphite-OSDs.R new file mode 100644 index 00000000..c0a072d0 --- /dev/null +++ b/misc/graphite-OSDs.R @@ -0,0 +1,51 @@ +library(aqp) +library(soilDB) +library(terra) +library(spData) +library(sf) + +data("us_states") +us_states <- st_transform(us_states, 5070) + +# convert to SpatVect +us_states <- vect(us_states) + +# tight bounding box around CONUS +b <- ext(us_states) + +s <- OSDquery(everything = 'graphit:*') +x <- fetchOSD(s$series) + +par(mar = c(0, 0, 2, 3)) +plotSPC(x, name.style = 'center-center', width = 0.35) +title('OSDs with "graphit" in the narrative') + +e <- lapply(s$series, seriesExtent, type = 'raster') + + +plot(e[[1]]) + +# remove NULL +e <- e[which(!sapply(e, is.null))] + +# combine into SpatRasterCollection +ee <- sprc(e) + +# combine into single SpatRaster +ee <- mosaic(ee, fun = 'sum') + +# values > 100 are rounding errors +ee[ee > 100] <- 100 + +# give merged raster a name +names(ee) <- 'Graphite Mentioned in OSD' + +# aggregate to 5x larger grid, sum of cell percent cover +a <- aggregate(ee, fact = 5, fun = sum, na.rm = TRUE) + +# rescale percent cover to larger grid size +a <- a / 5^2 + +# CONUS map +plot(a, axes = FALSE, col = 'royalblue', ext = b, mar = c(1, 1, 3, 4), main = names(a), legend = FALSE) +lines(us_states, col = 'grey')