Skip to content

Commit

Permalink
build vignettes (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbjoseph authored Apr 8, 2020
1 parent aae51ce commit 06457e6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 62 deletions.
108 changes: 48 additions & 60 deletions vignettes/cst-intro.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Getting started with the Climate Scenarios Toolbox"
author: "Travis Williams and Max Joseph"
date: "2020-04-06"
date: "2020-04-07"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{cst}
Expand Down Expand Up @@ -61,6 +61,7 @@ the user's operating system.

2) Install `cst` using the package `remotes` as follows:


```r
# install.packages("remotes")
remotes::install_github("earthlab/cst")
Expand All @@ -80,9 +81,10 @@ you can install the python dependencies with:

```r
cst::install_py_deps()
#> Using virtual environment 'cst' ...
#>
#> Installation complete.
```


```r
reticulate::use_condaenv("cst")
```

Expand Down Expand Up @@ -125,42 +127,31 @@ file_refs <- cstdata(park = "Wind Cave National Park",
parameters = c("tasmin", "tasmax", "uas", "vas"),
ncores = parallel::detectCores())
#> [1] "Retrieving area of interest boundaries..."
#> NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
#> NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
#> [1] "Building area of interest grid..."
#> NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
#> NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
#> NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
#> NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
#> NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
#> NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
#> NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
#> NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
#> NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
#> [1] "Retrieving climate data for wind_cave_national_park"
#> [1] "Saving local files to /home/travis/wind_cave_national_park"
#> [1] "Saving local files to /home/mjoseph/wind_cave_national_park"
```

The output of `cstdata` is a data.frame, where each row corresponds to one file:


```r
glimpse(file_refs)
#> Rows: 160
#> Columns: 13
#> $ local_file <chr> "tasmin_wind_cave_national_park_bcc-csm1-1_r1i1p1_rc
#> $ local_path <chr> "/home/travis/wind_cave_national_park/tasmin_wind_ca
#> $ model <chr> "bcc-csm1-1", "bcc-csm1-1", "bcc-csm1-1", "bcc-csm1-…
#> $ parameter <chr> "tasmin", "tasmin", "tasmax", "tasmax", "uas", "uas"…
#> $ rcp <chr> "rcp45", "rcp85", "rcp45", "rcp85", "rcp45", "rcp85"…
#> $ ensemble <chr> "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r
#> $ year1 <dbl> 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980…
#> $ year2 <dbl> 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040…
#> $ area_name <chr> "wind_cave_national_park", "wind_cave_national_park"…
#> $ units <chr> "K", "K", "K", "K", "m s-1", "m s-1", "m s-1", "m s-…
#> $ full_varname <chr> "Minimum Temperature", "Minimum Temperature", "Maxim
#> $ internal_varname <chr> "air_temperature", "air_temperature", "air_temperatu
#> $ parameter_long <chr> "air_temperature", "air_temperature", "air_temperatu
#> Observations: 160
#> Variables: 13
#> $ local_file <chr> "tasmin_wind_cave_national_park_bcc-csm1-1_r1i1p1_rcp45_macav2metdata_1980_2040_daily.nc", "tasmin_wind_ca
#> $ local_path <chr> "/home/mjoseph/wind_cave_national_park/tasmin_wind_cave_national_park_bcc-csm1-1_r1i1p1_rcp45_macav2metdat
#> $ model <chr> "bcc-csm1-1", "bcc-csm1-1", "bcc-csm1-1", "bcc-csm1-1", "bcc-csm1-1", "bcc-csm1-1", "bcc-csm1-1", "bcc-csm
#> $ parameter <chr> "tasmin", "tasmin", "tasmax", "tasmax", "uas", "uas", "vas", "vas", "tasmin", "tasmin", "tasmax", "tasmax"
#> $ rcp <chr> "rcp45", "rcp85", "rcp45", "rcp85", "rcp45", "rcp85", "rcp45", "rcp85", "rcp45", "rcp85", "rcp45", "rcp85"
#> $ ensemble <chr> "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p
#> $ year1 <dbl> 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980
#> $ year2 <dbl> 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040, 2040
#> $ area_name <chr> "wind_cave_national_park", "wind_cave_national_park", "wind_cave_national_park", "wind_cave_national_park"
#> $ units <chr> "K", "K", "K", "K", "m s-1", "m s-1", "m s-1", "m s-1", "K", "K", "K", "K", "m s-1", "m s-1", "m s-1", "m
#> $ full_varname <chr> "Minimum Temperature", "Minimum Temperature", "Maximum Temperature", "Maximum Temperature", "Eastward Wind
#> $ internal_varname <chr> "air_temperature", "air_temperature", "air_temperature", "air_temperature", "eastward_wind", "eastward_win
#> $ parameter_long <chr> "air_temperature", "air_temperature", "air_temperature", "air_temperature", "eastward_wind", "eastward_win
```

We can generate a data.frame of daily climate values averaged over the study
Expand All @@ -181,17 +172,17 @@ columns. Note that, in the output of `cst_df()`, average values represent all 2k

```r
glimpse(df)
#> Rows: 891,240
#> Columns: 9
#> $ rcp <chr> "rcp45", "rcp85", "rcp45", "rcp85", "rcp45", "rcp85", "rcp4…
#> $ date <date> 1980-01-01, 1980-01-01, 1980-01-01, 1980-01-01, 1980-01-01…
#> $ model <chr> "bcc-csm1-1", "bcc-csm1-1", "bcc-csm1-1-m", "bcc-csm1-1-m",…
#> $ ensemble <chr> "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1",…
#> $ area_name <chr> "wind_cave_national_park", "wind_cave_national_park", "wind…
#> $ tasmin <dbl> 268.6556, 268.6556, 249.5089, 249.5089, 267.4565, 267.4565,…
#> $ tasmax <dbl> 280.0941, 280.0941, 258.7186, 258.7186, 279.6128, 279.6128,…
#> $ uas <dbl> 3.0490896, 3.0490896, -1.6518571, -1.6518571, 2.6976433, 2.…
#> $ vas <dbl> 1.4561018, 1.4561018, -1.7092865, -1.7092865, -2.1272987, -…
#> Observations: 891,240
#> Variables: 9
#> $ rcp <chr> "rcp45", "rcp85", "rcp45", "rcp85", "rcp45", "rcp85", "rcp45", "rcp85", "rcp45", "rcp85", "rcp45", "rcp85", "rcp4…
#> $ date <date> 1980-01-01, 1980-01-01, 1980-01-01, 1980-01-01, 1980-01-01, 1980-01-01, 1980-01-01, 1980-01-01, 1980-01-01, 1980
#> $ model <chr> "bcc-csm1-1", "bcc-csm1-1", "bcc-csm1-1-m", "bcc-csm1-1-m", "BNU-ESM", "BNU-ESM", "CanESM2", "CanESM2", "CCSM4",
#> $ ensemble <chr> "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r1i1p1", "r6i1p1", "r6i1p1", "r1i1p1", "r1
#> $ area_name <chr> "wind_cave_national_park", "wind_cave_national_park", "wind_cave_national_park", "wind_cave_national_park", "wind…
#> $ tasmin <dbl> 268.6556, 268.6556, 249.5089, 249.5089, 267.4565, 267.4565, 264.1158, 264.1158, 267.7256, 267.7256, 266.8319, 266
#> $ tasmax <dbl> 280.0941, 280.0941, 258.7186, 258.7186, 279.6128, 279.6128, 273.8713, 273.8713, 282.7361, 282.7361, 280.0200, 280
#> $ uas <dbl> 3.04908961, 3.04908961, -1.65185707, -1.65185707, 2.69764333, 2.69764333, 2.99376419, 2.99376419, 3.05113290, 3.0
#> $ vas <dbl> 1.4561018, 1.4561018, -1.7092865, -1.7092865, -2.1272987, -2.1272987, -0.6530413, -0.6530413, 2.7725530, 2.772553
```

We can work with this data frame to do some basic visualizations, like time
Expand Down Expand Up @@ -339,18 +330,18 @@ and reference period.

```r
glimpse(comps)
#> Rows: 80
#> Columns: 9
#> Observations: 80
#> Variables: 9
#> Groups: rcp [2]
#> $ model <chr> "bcc-csm1-1", "bcc-csm1-1-m", "BNU-ESM", "CanESM2", …
#> $ rcp <chr> "rcp45", "rcp45", "rcp45", "rcp45", "rcp45", "rcp45"…
#> $ parameter <chr> "tasmin", "tasmin", "tasmin", "tasmin", "tasmin", "t
#> $ units <chr> "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K…
#> $ reference_period <chr> "1980 - 2000", "1980 - 2000", "1980 - 2000", "1980 -…
#> $ target_period <chr> "2020 - 2040", "2020 - 2040", "2020 - 2040", "2020 -…
#> $ reference_value <dbl> 284.0221, 283.8716, 284.1512, 283.6515, 283.9051, 28
#> $ target_value <dbl> 284.9774, 285.0160, 285.6242, 286.2288, 285.4229, 28
#> $ difference <dbl> 0.9553126, 1.1443937, 1.4730053, 2.5772584, 1.517751
#> $ model <chr> "bcc-csm1-1", "bcc-csm1-1-m", "BNU-ESM", "CanESM2", "CCSM4", "CNRM-CM5", "CSIRO-Mk3-6-0", "GFDL-ESM2G", "G
#> $ rcp <chr> "rcp45", "rcp45", "rcp45", "rcp45", "rcp45", "rcp45", "rcp45", "rcp45", "rcp45", "rcp45", "rcp45", "rcp45"
#> $ parameter <chr> "tasmin", "tasmin", "tasmin", "tasmin", "tasmin", "tasmin", "tasmin", "tasmin", "tasmin", "tasmin", "tasmi
#> $ units <chr> "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "
#> $ reference_period <chr> "1980 - 2000", "1980 - 2000", "1980 - 2000", "1980 - 2000", "1980 - 2000", "1980 - 2000", "1980 - 2000", "
#> $ target_period <chr> "2020 - 2040", "2020 - 2040", "2020 - 2040", "2020 - 2040", "2020 - 2040", "2020 - 2040", "2020 - 2040", "
#> $ reference_value <dbl> 284.0221, 283.8716, 284.1512, 283.6515, 283.9051, 283.6558, 283.7654, 283.5367, 284.0057, 283.9708, 283.40
#> $ target_value <dbl> 284.9774, 285.0160, 285.6242, 286.2288, 285.4229, 285.4266, 285.5118, 284.3646, 284.4843, 284.3611, 285.40
#> $ difference <dbl> 0.9553126, 1.1443937, 1.4730053, 2.5772584, 1.5177512, 1.7707875, 1.7463857, 0.8279304, 0.4785571, 0.39036
```

One useful plot shows the difference in the two variables between reference and
Expand Down Expand Up @@ -401,11 +392,9 @@ Here are the GCMs (the models):

```r
references$models
#> [1] "bcc-csm1-1" "bcc-csm1-1-m" "BNU-ESM" "CanESM2"
#> [5] "CCSM4" "CNRM-CM5" "CSIRO-Mk3-6-0" "GFDL-ESM2M"
#> [9] "GFDL-ESM2G" "HadGEM2-ES365" "HadGEM2-CC365" "inmcm4"
#> [13] "IPSL-CM5A-LR" "IPSL-CM5A-MR" "IPSL-CM5B-LR" "MIROC5"
#> [17] "MIROC-ESM" "MIROC-ESM-CHEM" "MRI-CGCM3" "NorESM1-M"
#> [1] "bcc-csm1-1" "bcc-csm1-1-m" "BNU-ESM" "CanESM2" "CCSM4" "CNRM-CM5" "CSIRO-Mk3-6-0"
#> [8] "GFDL-ESM2M" "GFDL-ESM2G" "HadGEM2-ES365" "HadGEM2-CC365" "inmcm4" "IPSL-CM5A-LR" "IPSL-CM5A-MR"
#> [15] "IPSL-CM5B-LR" "MIROC5" "MIROC-ESM" "MIROC-ESM-CHEM" "MRI-CGCM3" "NorESM1-M"
```

Here are the emissions scenarios:
Expand All @@ -421,8 +410,7 @@ And here are the climate parameters:

```r
references$parameters
#> [1] "tasmin" "tasmax" "rhsmin" "rhsmax" "pr" "rsds" "uas" "vas"
#> [9] "huss" "vpd"
#> [1] "tasmin" "tasmax" "rhsmin" "rhsmax" "pr" "rsds" "uas" "vas" "huss" "vpd"
```

Labels for each acronym are also available, for example:
Expand Down
7 changes: 5 additions & 2 deletions vignettes/cst-intro.Rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ the user's operating system.

2) Install `cst` using the package `remotes` as follows:

```r
```{r, eval = FALSE}
# install.packages("remotes")
remotes::install_github("earthlab/cst")
```
Expand All @@ -81,8 +81,11 @@ sure you have conda installed
you can install the python dependencies with:


```{r}
```{r installpydeps, eval = FALSE}
cst::install_py_deps()
```

```{r useenv}
reticulate::use_condaenv("cst")
```

Expand Down
Binary file modified vignettes/plot-comps-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/plot-grow-season-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/vpd-timeseries-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 06457e6

Please sign in to comment.