Working with Climate Data in R with caladaptR

Andy Lyons
May 2021

Cal-Adapt

Cal-Adapt is California’s official portal for peer-reviewed climate data.

Datasets are selected with guidance and priorities from California State agencies.

Projected Climate Data:

Extent of LOCA downscaled climate data layers:


Cal-Adapt Data

Options for Accessing Cal-Adapt Data

Feature Cal-Adapt website Cal-Adapt FTP caladaptPy caladaptR
Download rasters
Statewide
User area-of-interest planned
10 recommended GCMs
All 32 GCMs
Query features
Points (user-provided)
Lines (user-provided)
Polygons (user-provided)
Polygons (presets, boundary layers)
Other
Extract underlying tables from preset charts


More info:

caladaptR

Key Features

  • pipe friendly functions
  • accepts and returns standard data classes (e.g., tibble, sf, raster)
  • units encoded in the results
  • follows development guidelines from rOpenSci


Main Uses


Prerequisites

The user is expected to know:

caladaptR workflow

In general, there are five steps to using caladaptR:

Quick Example

  1. Load the package:
library(caladaptr)
  1. Create an API request object:
cap1 <- ca_loc_pt(coords = c(-121.4687, 38.5938)) %>%  ## specify a location
  ca_cvar(c("tasmax", "tasmin")) %>%                   ## climate variables
  ca_gcm(gcms[1:4]) %>%                                ## GCM(s)
  ca_scenario(scenarios[1:2]) %>%                      ## emission scenarios(s)
  ca_period("year") %>%                                ## temporal aggregation period
  ca_years(start = 2040, end = 2060)                   ## start and end dates
  1. Check API request
cap1
## Cal-Adapt API Request
## Location(s): 
##   x: -121.469
##   y: 38.594
## Variable(s): tasmax, tasmin
## Temporal aggregration period(s): year
## GCM(s): HadGEM2-ES, CNRM-CM5, CanESM2, MIROC5
## Scenario(s): rcp45, rcp85
## Dates: 2040-01-01 to 2060-12-31
## 
cap1 %>% ca_preflight()
## General issues
##  - none found
## Issues for querying values
##  - none found
## Issues for downloading rasters
##  - none found
plot(cap1, locagrid = TRUE)
  1. Fetch data:
cap1_tbl <- ca_getvals_tbl(cap1, quiet = TRUE)
  1. View the results
cap1_tbl %>% slice(1:10)

Need Big Data?

No problem!

cap1_db <- cap1 %>% 
  ca_getvals_db(db_fn = "c:/data/mydata.sqlite", db_tbl = "temp_min_max")


https://dbplyr.tidyverse.org/

Need Rasters?

No problem!

cap1_tifs <- cap1 %>% 
  ca_getrst_stars(out_dir = "c:/data/tifs")



https://r-spatial.github.io/stars/

Shiny Apps

→ browser based GUIs

See samples:

## Install caladaptr.apps and all dependent packages
remotes::install_github("ucanr-igis/caladaptr.apps")
library(caladaptr.apps)

## Launch the time series app
ca_launch("timeseries")

## Launch the projected chill portions app
ca_launch("chill")

Learning More

Website: https://ucanr-igis.github.io/caladaptr/

Resources

  • documentation
  • getting started guide
  • R notebooks
  • presentations

Get Involved

  • join email list
  • submit feature requests and bug reports via GitHub Issues
  • share ideas for code recipes and Shiny apps


Andy Lyons