solutions 

Overview

This Notebook will demonstrate how you can use caladaptR to:


Setup

The first thing we do is to load caladaptR and the other package we’re going to need. (If you haven’t installed these yet, see this setup script).

library(caladaptr)
library(units)
library(ggplot2)
library(dplyr)
library(sf)
library(tidyr)

We use the conflicted package to tell R which package we want it to use for some common function names:

library(conflicted)
conflict_prefer("filter", "dplyr", quiet = TRUE)
conflict_prefer("count", "dplyr", quiet = TRUE)
conflict_prefer("select", "dplyr", quiet = TRUE)


Part I. Get temperature data for a point location

In Part I, you generate a time series plot of projected maximum annual temperature like the one below for a point location using the four recommended GCMs for California and emissions scenario RCP 4.5.

1. Create the API Request

The first step in getting climate variables back is to create a Cal-Adapt API request object. This involves stringing together a series of functions that specify the pieces of the request.

The following will create an API request for projected temperature data from Scripps:

pt1_cap <- ca_loc_pt(coords = c(-119.168765, 35.487802)) %>%
  ca_gcm(gcms[1:4]) %>%                                 
  ca_scenario(c("rcp45", "rcp85")) %>%
  ca_period("year") %>%
  ca_years(start = 2030, end = 2080) %>%
  ca_cvar(c("tasmin", "tasmax"))


Pro Tip:

  • the order of the constructor functions doesn’t matter

  • when entering coordinates, they must be i) in decimal degrees, and ii) formatted as longitude, latitude (in that order!)

  • this example creates an API request for modeled climate data; for other datasets you might use different constructor functions

  • you don’t have to memorize a bunch of keywords. caladaptr has several built-in constants that contain the values you can pass to API construction functions, including gcms, scenarios, cvars, and periods.


Challenge 1

Enter the following constants to see what they contain gcms, scenarios, cvars, and periods [Answer].

gcms
 [1] "HadGEM2-ES" "CNRM-CM5"   "CanESM2"    "MIROC5"     "ACCESS1-0"  "CCSM4"      "CESM1-BGC" 
 [8] "CMCC-CMS"   "GFDL-CM3"   "HadGEM2-CC" "ens32avg"   "ens32max"   "ens32min"  
scenarios
[1] "rcp45"      "rcp85"      "historical"
cvars
 [1] "tasmax"     "tasmin"     "pr"         "swe"        "baseflow"   "et"         "rainfall"  
 [8] "runoff"     "snowfall"   "soilMoist1" "Tair"      
periods
[1] "day"    "month"  "year"   "30yavg"

Pro Tip:

  • not every combination of GCM, scenario, climate variable, and period has a data set

  • these constants are useful for constructing API requests for modeled climate data; they may not be needed for other datasets


2. Examine an API Request

To see what’s in an API request object, type its name at the console:

pt1_cap
Cal-Adapt API Request
Location(s): 
  x: -119.169
  y: 35.488
Variable(s): tasmin, tasmax
Temporal aggregration period(s): year
GCM(s): HadGEM2-ES, CNRM-CM5, CanESM2, MIROC5
Scenario(s): rcp45, rcp85
Dates: 2030-01-01 to 2080-12-31
 

Pro Tip:

  • you can customize the colors with ca_settings(). Let console_colors = "dark" or light depending on your RStudio color background.
ca_settings(console_colors = "dark")
Console colors updated:
  Accent 1
  Accent 2
  Accent 3
  Accent 4
  Message
  Success
pt1_cap
Cal-Adapt API Request
Location(s): 
  x: -119.169
  y: 35.488
Variable(s): tasmin, tasmax
Temporal aggregration period(s): year
GCM(s): HadGEM2-ES, CNRM-CM5, CanESM2, MIROC5
Scenario(s): rcp45, rcp85
Dates: 2030-01-01 to 2080-12-31
 


You can double-check if your API request is complete by passing it to ca_preflight():

pt1_cap %>% ca_preflight()
General issues
 - none found
Issues for querying values
 - none found
Issues for downloading rasters
 - none found


To verify the location in an API request, you can plot it:

plot(pt1_cap)

Pro Tip:

  • To view the LOCA grid cells, add locagrid = TRUE to the plot command.
plot(pt1_cap, locagrid = TRUE)

Your Turn:

Where is this point located? [Answer].

Answer: in Shafter (outside Bakersfield), Kern County, CA


3. Fetch Data

Now it’s time to fetch data by feeding our API request into ca_getvals_tbl(). The object returned will be a tibble (data frame):

pt1_tbl <- pt1_cap %>% ca_getvals_tbl(quiet = TRUE)

head(pt1_tbl)


4. Wrangle the Results for Plotting

To produce the desired time series plot, we need to i) pull out just values for RCP 4.5, and ii) convert degrees to °F. For the unit conversion, we can use the handy set_units function from the units package.

pt1_rcp45_tbl <- pt1_tbl %>%
  filter(scenario == "rcp45", cvar == "tasmax") %>%
  mutate(temp_f = set_units(val, degF))

pt1_rcp45_tbl %>% head()


5. Plot the Time Series

Plot these with ggplot:

ggplot(data = pt1_rcp45_tbl, aes(x = as.Date(dt), y = as.numeric(temp_f))) +
  geom_line(aes(color=gcm)) +
  labs(title = "Average Maximum Daily Temperature Per Year for RCP4.5", x = "year", y = "temp (F)")

Challenge 2

Modify the above to create a similar plot for RCP 8.5. [Answer].

pt1_rcp85_tbl <- pt1_tbl %>%
  filter(scenario == "rcp85", cvar == "tasmax") %>%
  mutate(temp_f = set_units(val, degF))

ggplot(data = pt1_rcp85_tbl, aes(x = as.Date(dt), y = as.numeric(temp_f))) +
  geom_line(aes(color=gcm)) +
  labs(title = "Average Maximum Daily Temperature Per Year for RCP8.5", x = "year", y = "temp (F)")

Challenge 3

For the same point, make a plot of average maximum temperature year for the same 4 GCMs for the period 1950-2005. [Hint]. [Answer].

pt1_hist_cap <- ca_loc_pt(coords = c(-119.168765, 35.487802)) %>%
  ca_gcm(gcms[1:4]) %>%                                 
  ca_scenario("historical") %>%
  ca_period("year") %>%
  ca_years(start = 1950, end = 2005) %>%
  ca_cvar("tasmax")

pt1_hist_cap %>% ca_preflight()
General issues
 - none found
Issues for querying values
 - none found
Issues for downloading rasters
 - none found
pt1_hist_tbl <- pt1_hist_cap %>% 
  ca_getvals_tbl(quiet = TRUE)

pt1_hist_degf_tbl <- pt1_hist_tbl %>%
  mutate(temp_f = set_units(val, degF))

ggplot(data = pt1_hist_degf_tbl, aes(x = as.Date(dt), y = as.numeric(temp_f))) +
  geom_line(aes(color=gcm)) +
  labs(title = "Average Maximum Daily Temperature Per Year for Historical Emission Scenario", x = "year", y = "temp (F)")

LS0tDQp0aXRsZTogIkdldHRpbmcgU3RhcnRlZCB3aXRoIGNhbGFkYXB0UiINCm91dHB1dDoNCiAgaHRtbF9ub3RlYm9vazogDQogICAgY3NzOiBodHRwczovL3VjYW5yLWlnaXMuZ2l0aHViLmlvL2NhbGFkYXB0ci1yZXMvYXNzZXRzL25iX2NzczAxLmNzcw0KICAgIGluY2x1ZGVzOg0KICAgICAgYmVmb3JlX2JvZHk6IGh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