Skip to content

Commit 1b01e46

Browse files
committed
Merge branch 'traits_tutorials' of github.com:terraref/tutorials into traits_tutorials
2 parents 026acff + 11439e4 commit 1b01e46

3 files changed

Lines changed: 83 additions & 27 deletions

File tree

index.Rmd

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,62 @@ date: "`r Sys.Date()`"
66
documentclass: book
77
output:
88
bookdown::gitbook: default
9-
bookdown::pdf_book: default
109
---
1110

12-
# Preamble
11+
# Overview
12+
13+
This book is intended to introduce users to TERRA REF data as quickly as possible.
14+
15+
It introduces to the wide range of phenomics datasets generated by the TERRA Reference program. Not only does TERRA REF have a large number of data sets, but many of the databases can be accessed in a number of different ways. While this makes it more complicated to learn, the goal is to provide users with the flexibility to access data in the most useful way.
16+
17+
## User Accounts and permission to access TERRA REF data
18+
19+
TODO: link to relevant parts of docs.terraref.org
20+
21+
## Ways of Acessing Data
22+
23+
* Web Interfaces
24+
* Files
25+
* Programming APIs
26+
* API Clients
27+
28+
## Other Resources
29+
30+
The TERRA REF website: terraref.org
31+
The TERRA REF Technical Documentation: docs.terraref.org
32+
33+
## Contents
34+
35+
Scope ...
36+
37+
Audience ...
38+
39+
40+
## Pre-requisites
41+
42+
While we assume that readers will have some familiarity with the nature of the problem - remote sensing of crop plants - for the most part, these tutorials assume that the user will bring their own scientific questions and a sense of curiosity and are eager to learn.
43+
44+
Some of the lessons only require a web browser; others will assume familarity with programming at the command line in (typically only one of) Python, R, and / or SQL. You should be willing to find help (see finding help, below).
45+
46+
## Technical Requirements
47+
48+
At a minimum, you should have:
49+
50+
* An internet connection
51+
* Web Browser
52+
* A TERRA REF Beta User account
53+
* If you have not done so, please sign up at terraref.org/beta
54+
* Access to the data that you are using
55+
* The tutorials will state which databases you will need access to
56+
* Software:
57+
* Software requirements vary with the tutorials, and may be complex
58+
*
59+
60+
## Finding help
61+
62+
* Slack
63+
* GitHub
64+
* Google
1365

1466
```{r}
1567
knitr::opts_chunk$set(echo = FALSE, cache = TRUE)

traits/02-betydb-api-access.Rmd

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
# Accessing Trait Data Via the BETYdb API
22

3-
## Using URLs to construct Queries
4-
5-
The first step toward reproducible pipelines is to automate the process of searching the database and returning results. This is one of the key roles of an Application programming interface, or 'API'. You can learn to use the API in less than 20 minutes, starting now.
3+
This will teach you how to query trait data using a browser as well as using the command line tool `curl`. This interface is the primary way in which you can access data from the command line.
64

7-
### What is an API?
5+
## What is an API?
86

97
An API is an 'Application Programming Interface'. An API is a way that you and your software can connect to and access data.
108

119
All of our databases have web interfaces for humans to browse as well as APIs that are constructed as URLs.
1210

11+
## Tutorial Contents
12+
13+
In this tutorial, we will describe three ways to access data using:
14+
15+
1. A URL typed into your browser
16+
2. The command line, or terminal
17+
3. The R jsonlite package
18+
19+
We also have interfaces using R 'traits' package or the Python 'terrautils' package that return data in a more familiar and ready to analyze tabular format; these will be described later. You can skip ahead to those chapters, but this chapter will provide some insight into the methods that underlie those libraries.
20+
21+
## Using URLs to construct Queries
22+
23+
The first step toward reproducible pipelines is to automate the process of searching the database and returning results. This is one of the key roles of an Application programming interface, or 'API'. You can learn to use the API in less than 20 minutes, starting now.
24+
1325

1426
### Using Your API key to Connect
1527

@@ -27,25 +39,19 @@ Here is how to find and save your API key:
2739

2840
For the public key, you can call this file `.betykey_public`.
2941

30-
### Ways to access API data
31-
32-
1. Through a URL query
33-
2. Using the bash shell
34-
3. Using the R jsonlite package
3542

43+
## Accessing data using a URL query
3644

37-
### Accessing data using a URL query
3845

39-
40-
## Components of a URL query
46+
### Components of a URL query
4147

4248
* base url: `terraref.ncsa.illinois.edu/bety`
4349
* path to the api: `/api/v1`
4450
* api endpoint: `/search` or `traits` or `sites`. For BETYdb, these are the names of database tables.
4551
* Query parameters: `genus=Sorghum`
4652
* Authentication: `key=9999999999999999999999999999999999999999` is the public key for the TERRA REF traits database.
4753

48-
## Constructing a URL query
54+
### Constructing a URL query
4955

5056
First, lets construct a query by putting together a URL.
5157

@@ -72,9 +78,7 @@ First, lets construct a query by putting together a URL.
7278
7379
What do you see? Do you think that this is all of the records? What happens if you add `&limit=none`?
7480

75-
76-
77-
#### Accessing data using the Shell
81+
## Accessing data using the Command Line Terminal
7882

7983
Type the following command into a bash shell (the `-o` option names the output file):
8084

@@ -90,7 +94,7 @@ curl -o sorghum.json \
9094
"https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=`cat .betykey_public`"
9195
```
9296

93-
### Accessing API data using the R jsonlite package
97+
## Using the R jsonlite package to access the API with a URL query
9498

9599
```{r text-api, warning = FALSE}
96100
sorghum.json <- readLines(

traits/03-access-r-traits.Rmd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# Accessing Trait Data in R
22

3-
## Using the R traits package to query the database
3+
The rOpenSci traits package makes it easier to query the TERRA REF trait database because 1) you can pass the query parameters in an R function, and the package takes care of putting the parameters into a valid URL and 2) because the package returns data in a tabular format that is ready to analyze.
44

5-
The rOpenSci traits package makes it easier to query the TERRA REF trait database, or any database that uses BETYdb software.
5+
## Using the R traits package to query the database
66

7-
First, make sure we have the latest version from the terraref fork of the repository on github. (you can install using the standard `install.packages('traits')` but as of Jan 2018 this version times out on very large datasets).
7+
## Setup
88

9-
### Install the traits package
9+
Install the traits package
1010

11-
This is for users working on their own computer - if you are using the TERRA REF Rstudio Docker container (including on workbench) you can skip this step.
11+
The traits package is on CRAN, and can therefore be installed using the following command:
1212

1313
```{r install_traits, echo = FALSE, include = FALSE}
14-
devtools::install_github('terraref/traits')
14+
install.packages('traits')
1515
```
1616

17-
Now, we can load the packages that we will need to get started.
17+
Load other packages that we will need to get started.
1818

1919
```{r 00-setup, message = FALSE}
2020
library(traits)
@@ -24,7 +24,7 @@ theme_set(theme_bw())
2424
library(dplyr)
2525
```
2626

27-
27+
Create a file that contains your API key. If you have signed up for access to the TERRA REF database, your API key will have been sent to you in an email. The public key will provide access to all metadata; you will need a personal key _and_ permissions to access the trait data. If you receive empty (NULL) datasets, it is likely that you do not have permissions.
2828

2929
```{r writing-key}
3030
# This should be done once with the key sent to you in your email

0 commit comments

Comments
 (0)