The climateR package is supplemented by the AOI framework
established in the AOI
R package.
To get a climate product, an area of interest must be defined:
Here we are loading a polygon for the state of North Carolina More examples of constructing AOI calls can be found here.
With an AOI, we can construct a call to a dataset for a parameter(s) and date(s) of choice. Here we are querying the PRISM dataset for maximum and minimum temperature on October 29, 2018:
climateR
offers support for sf
,
sfc
, and bbox
objects. Here we are requesting
wind velocity data for the four corners region of the USA by bounding
coordinates.
In addition to multiple variables we can request variables through time, here let’s look at the gridMET rainfall for the Gulf Coast during Hurricane Harvey:
Some sources are downscaled Global Climate Models (GCMs). These allow you to query forecasted ensemble members from different models and/or climate scenarios. One example is from the MACA dataset:
system.time({
m = getMACA(AOI = aoi_get(state = "FL"),
model = "CCSM4",
varname = 'pr',
scenario = c('rcp45', 'rcp85'),
startDate = "2080-06-29", endDate = "2080-06-30")
})
#> user system elapsed
#> 0.599 0.000 4.658
Getting multiple models results is also quite simple:
models = c("BNU-ESM","CanESM2", "CCSM4")
temp = getMACA(AOI = aoi_get(state = "CO"),
varname = 'tasmin',
model = models,
startDate = "2080-11-29")
temp = c(temp[[1]], mean(temp[[1]]))
names(temp) = c(models, "Ensemble Mean")
If you don’t know your models, you can always grab a random set by specifying a number:
Not all datasets are USA focused either. TerraClimate offers global, monthly data up to the current year for many variables, and CHIRPS provides daily rainfall data:
Finally, data gathering is not limited to areal extents and can be retrieved as a time series at locations.
future = getMACA(geocode("Fort Collins", pt = TRUE),
model = 5,
varname = "tasmax",
startDate = "2050-01-01",
endDate = "2050-01-31")
future_long = pivot_longer(future, -date)
ggplot(data = future_long, aes(x = date, y = value, col = name)) +
geom_line() +
theme_linedraw() +
scale_color_brewer(palette = "Dark2") +
labs(title = "Fort Collins Temperture: January, 2050",
x = "Date",
y = "Degree K",
color = "Model")
Extracting data for a set of points is an interesting challenge. It turns it is much more efficient to grab the underlying raster stack and then extract time series as opposed to iterating over the locations:
climateR
will grab the SpatRaster underlying the
bounding area of the pointssites_stack = getTerraClim(AOI = cities,
varname = "tmax",
startDate = "2018-01-01",
endDate = "2018-12-31")
extract_sites
to extract the times series from
these locations. The id
parameter is the unique identifier
from the site data with which to names the resulting columns.sites_wide = extract_sites(r = sites_stack, pts = cities, ID = "NAME")
sites_wide[1:5, 1:5]
#> date ADAMSCITY AGATE AGUILAR AKRON
#> 1 2018-01-01 9.5 8.2 11.4 7.1
#> 2 2018-02-01 8.1 7.1 9.9 5.8
#> 3 2018-03-01 14.6 14.1 15.0 13.5
#> 4 2018-04-01 17.5 16.6 17.6 16.2
#> 5 2018-05-01 25.1 25.0 25.5 24.8
To make the data ‘tidy’ simply pivot on the date
column:
tmax = tidyr::pivot_longer(sites_wide, -date)
head(tmax)
#> # A tibble: 6 × 3
#> date name value
#> <dttm> <chr> <dbl>
#> 1 2018-01-01 00:00:00 ADAMSCITY 9.5
#> 2 2018-01-01 00:00:00 AGATE 8.2
#> 3 2018-01-01 00:00:00 AGUILAR 11.4
#> 4 2018-01-01 00:00:00 AKRON 7.10
#> 5 2018-01-01 00:00:00 ALAMOSA 5.2
#> 6 2018-01-01 00:00:00 ALLENSPARK 6.10