-
Notifications
You must be signed in to change notification settings - Fork 19
/
graphite-OSDs.R
51 lines (35 loc) · 1.08 KB
/
graphite-OSDs.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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')