Skip to content

Commit 3c5a154

Browse files
kimberlyh66dlebauer
authored andcommitted
fixed link to agronomic metadata tutorial (#35)
* fixed link to agronomic metadata tutorial * Updated tutorial. Added a summary showing the 3 ways to access API data. * Further updated the tutorial on how to access API using URL query and bash shell. * Further updated tutorial. Added short comment on the use of the fromJSON function. * Further updated R jsonlite portion of tutorial * Update traits/01-web-access.Rmd Co-Authored-By: kimberlyh66 <44081116+kimberlyh66@users.noreply.github.com> * added comment. link to traitvis webapp not working. * fixed links to terraref and pecan sites, betydb schemas, and doi reference. also updated comment on embedded shiny app (link to traitvis app does work). * updated beta user program link, and fixed links to agronomic metadata tutorial and terraref bety home page * made changes according to previous comments * Update traits/04-danforth-indoor-phenotyping-facility.Rmd Co-Authored-By: kimberlyh66 <44081116+kimberlyh66@users.noreply.github.com> * made minor edits - assuming betykey in traits directory since ~ does not work on Windows
1 parent 65f79d5 commit 3c5a154

6 files changed

Lines changed: 130 additions & 122 deletions

index.Rmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ output:
1313

1414
```{r}
1515
knitr::opts_chunk$set(echo = FALSE, cache = TRUE)
16-
```
16+
options(warn = -1)
17+
```
18+

traits/00-BETYdb-getting-started.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ It contains trait (phenotype) data at the plot or plant level as well as meta da
1414
### Introduction to BETYdb
1515

1616
The TERRA REF trait database (terraref.ncsa.illinois.edu/bety) uses the BETYdb data schema (structure) and web application.
17-
The BETYdb software is actively used and developed by the [TERRA Reference](terraref.org) program as well as by the [PEcAn project](pecanproject.org).
17+
The BETYdb software is actively used and developed by the [TERRA Reference](http://terraref.org) program as well as by the [PEcAn project](http://pecanproject.org).
1818

1919
For more information about BETYdb, see the following:
2020

2121
* BETYdb documentation (available via the web application under 'Docs')
2222
* _Data Access_: how to access data
2323
* _Data Entry Workflow:_ how to add data to the database
24-
* _BETYdb Technical Documentation_ is written for advanced users and website and database administrators who may also be interested in the [full database schema](betydb.org/schemas)
25-
* BETYdb: A Yield, Trait and Ecosystem Service Database Applied to Second Generation Bioenergy Feedstocks. ([LeBauer et al, 2017](dx.doi.org/10.1111/gcbb.12420))
24+
* _BETYdb Technical Documentation_ is written for advanced users and website and database administrators who may also be interested in the [full database schema](https://www.betydb.org/schemas)
25+
* BETYdb: A Yield, Trait and Ecosystem Service Database Applied to Second Generation Bioenergy Feedstocks. ([LeBauer et al, 2017](https://onlinelibrary.wiley.com/doi/abs/10.1111/gcbb.12420))
2626

2727
Other than the TERRA REF trait database, there are a handful of other projects that use the BETYdb software, mostly with the PEcAn and TERRA programs. The content presented here is focused on the TERRA REF instance of BETYdb. Most of the information presented here is relevant to other databases, but the TERRA program has more emphasis on trait diversity among cultivars or genotypes within a crop whereas PEcAn focuses on the diversity of traits within ecosystems and plant functional types. In addition, the TERRA program is more focused on high throughput phenotyping - intensive monitoring of agricultural breeding trials whereas PEcAn focuses on assimilating heterogeneous data to forecast ecosystem functioning. Fortunately, both uses can use the shared ecosystem of software used for these tasks. For example, the PEcAn crop modeling infrastructure can be directly used to infer additional targets of breeding, and the diversity of traits observed in breeding trials can be a first step toward predicting the impacts of crop traits on productivity and ecosystem functioning.
2828

@@ -40,5 +40,5 @@ The traitvis webapp provides an interface for exploring available data that is u
4040
* website: https://traitvis.workbench.terraref.org
4141

4242
```{r}
43-
knitr::include_app("https://traitvis.workbench.terraref.org/", height = "1400px")
43+
knitr::include_app("https://traitvis.workbench.terraref.org", height = "1400px") #not working; shiny app is not being displayed in html output
4444
```

traits/01-web-access.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ output: html_document
1212
### Web interface
1313

1414
* Sign up for an account at https://terraref.ncsa.illinois.edu/bety
15-
* Sign up for the TERRA REF [beta user program](https://docs.google.com/forms/d/e/1FAIpQLScBsD042RrRok70BCGCRwARTcm9etvVHqvQaz1c5X7c5y0H3w/viewform?c=0&w=1)
15+
* Sign up for the TERRA REF [beta user program](https://docs.google.com/forms/d/e/1FAIpQLScIUJL_OSL9BvBOdlczErds3aOg5Lwz4NIdNQnUiXdsLsYdhw/viewform)
1616
* Wait for database access to be granted
1717
* Your API key will be sent in the email. It can also be found - and regenerated - by navigating to the Users page (data --> [users](https://terraref.ncsa.illinois.edu/bety/users)) in the web interface.
1818

@@ -25,11 +25,11 @@ On the Welcome page there is a search option for trait and yield data. This tool
2525

2626
### Download search results as as csv file from the web interface
2727

28-
* Point your browser to terraref.ncsa.illinois.edu/bety
28+
* Point your browser to https://terraref.ncsa.illinois.edu/bety/
2929
* login
3030
* enter "NDVI" in the search box
3131
* on the next page you will see the results of this search
3232
* if you want all of the data, including data that has not gone through QA/QC, make sure to check the 'include unchecked records' option
3333
* in the upper right, you will see a button that will allow you to download the search results as a CSV file. Click it. Open the file in a text editor or spreadsheet program and review its contents.
3434

35-
Note that the web interface only provides a core set of data and limited meta-data. To access all of the data within BETYdb, it is necessary to search and merge multiple tables. More complex queries, such as those in the [Agronomic metadata](../traits/04-agronomic-metadata.Rmd).
35+
Note that the web interface only provides a core set of data and limited meta-data. To access all of the data within BETYdb, it is necessary to search and merge multiple tables. More complex queries, such as those in the [Agronomic metadata](06-agronomic-metadata.Rmd).

traits/02-betydb-api-access.Rmd

Lines changed: 112 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,112 @@
1-
---
2-
title: "Accessing Trait Data Via the BETYdb API"
3-
author: "David LeBauer"
4-
date: "11/7/2017"
5-
output: html_document
6-
---
7-
8-
9-
## Using URLs to construct Queries
10-
11-
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.
12-
13-
### What is an API?
14-
15-
An API is an 'Application Programming Interface'. An API is a way that you and your software can connect to and access data.
16-
17-
All of our databases have web interfaces for humans to browse as well as APIs that are constructed as URLs.
18-
19-
20-
### Using Your API key to Connect
21-
22-
An API key is like a password. It allows you to access data, and should be kept private.
23-
Therefore, we are not going to put it in code that we share. The one exception is the key 9999999999999999999999999999999999999999 that will allow you to access metadata tables (all tables except _traits_ and _yields_). It will also allow you to access all of the simulated data in the terraref.ncsa.illinois.edu/bety-test database.
24-
25-
A common way of handling private API keys is to place it in a text file in your home directory.
26-
Don't put it in a project directory where it might be inadvertently shared.
27-
28-
Here is how to find and save your API key:
29-
30-
* click file --> new --> text file
31-
* copy the api key that was sent when you registered into the file
32-
* file --> save as '~/.betykey'
33-
34-
For the public key, you can call this file `~/.betykey_public`.
35-
36-
### Components of a URL query
37-
38-
39-
* base url: `terraref.ncsa.illinois.edu/bety`
40-
* path to the api: `/api/beta`
41-
* api endpoint: `/search` or `traits` or `sites`. For BETYdb, these are the names of database tables.
42-
* Query parameters: `genus=Sorghum`
43-
* Authentication: `key=9999999999999999999999999999999999999999` is the public key for the TERRA REF traits database.
44-
45-
46-
### Constructing a URL query
47-
48-
First, lets construct a query by putting together a URL.
49-
50-
1. start with the database url: `terraref.ncsa.illinois.edu/bety`
51-
* this url brings you to the home page
52-
2. Add the path to the API, `/api/beta`
53-
* now we have terraref.ncsa.illinois.edu/bety/api/beta, which points to the API documentation
54-
3. Add the name of the table you want to query. Lets start with `variables`
55-
* terraref.ncsa.illinois.edu/bety/api/beta/variables
56-
4. add query terms by appending a `?` and combining with `&`, for example:
57-
* `key=9999999999999999999999999999999999999999`
58-
* `type=trait` where the variable type is 'trait'
59-
* `name=~height` where the variable name contains 'height'
60-
5. This is your complete query:
61-
* `terraref.ncsa.illinois.edu/bety/api/beta/variables?type=trait&name=~height&key=9999999999999999999999999999999999999999`
62-
* it will query all variables that are type trait and have 'height' in the name
63-
* Does it return the expected values?
64-
65-
66-
#### Your Turn
67-
68-
> What will the URL https://terraref.ncsa.illinois.edu/bety/api/beta/species?genus=Sorghum&key=9999999999999999999999999999999999999999 return?
69-
70-
> write a URL that will query the database for sites with "Field Scanner" in the name field. Hint: combine two terms with a `+` as in `Field+Scanner`
71-
72-
What do you see? Do you think that this is all of the records? What happens if you add `&limit=none`?
73-
74-
### Our first Query
75-
76-
#### Shell
77-
78-
```sh
79-
wget -O sorghum.json \\ # -O names the output file
80-
"https://terraref.ncsa.illinois.edu/bety/api/beta/species?genus=Sorghum&key=999999999999999999999999999999999999
81-
9999"
82-
```
83-
84-
If you want to write the query without exposing the key in plain text, you can construct it thus:
85-
86-
```sh
87-
wget -O sorghum.json \\
88-
"https://terraref.ncsa.illinois.edu/bety/api/beta/species?genus=Sorghum&key=`cat ~/.betykey_public`"
89-
```
90-
91-
> What does `cat ~/.betykey_public` do?
92-
93-
> How can you look at the files?
94-
95-
96-
#### R - using the jsonlite package
97-
98-
```{r text-api}
99-
sorghum.json <- readLines(
100-
paste0("https://terraref.ncsa.illinois.edu/bety/api/beta/species?genus=Sorghum&key=",
101-
readLines('~/.betykey')))
102-
103-
## print(sorghum.json)
104-
## not a particularly useful format
105-
## lets convert to a data frame
106-
sorghum <- jsonlite::fromJSON(sorghum.json)
107-
```
1+
---
2+
title: "Accessing Trait Data Via the BETYdb API"
3+
author: "David LeBauer"
4+
date: "11/7/2017"
5+
output: html_document
6+
---
7+
8+
9+
## Using URLs to construct Queries
10+
11+
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.
12+
13+
### What is an API?
14+
15+
An API is an 'Application Programming Interface'. An API is a way that you and your software can connect to and access data.
16+
17+
All of our databases have web interfaces for humans to browse as well as APIs that are constructed as URLs.
18+
19+
20+
### Using Your API key to Connect
21+
22+
An API key is like a password. It allows you to access data, and should be kept private.
23+
Therefore, we are not going to put it in code that we share. The one exception is the key 9999999999999999999999999999999999999999 that will allow you to access metadata tables (all tables except _traits_ and _yields_). It will also allow you to access all of the simulated data in the https://terraref.ncsa.illinois.edu/bety-test database.
24+
25+
A common way of handling private API keys is to place it in a text file in your current directory.
26+
Don't put it in a project directory where it might be inadvertently shared.
27+
28+
Here is how to find and save your API key:
29+
30+
* click file --> new --> text file
31+
* copy the api key that was sent when you registered into the file
32+
* file --> save as '.betykey'
33+
34+
For the public key, you can call this file `.betykey_public`.
35+
36+
### Ways to access API data
37+
38+
1. Through a URL query
39+
2. Using the bash shell
40+
3. Using the R jsonlite package
41+
42+
43+
### Accessing data using a URL query
44+
45+
46+
## Components of a URL query
47+
48+
* base url: `terraref.ncsa.illinois.edu/bety`
49+
* path to the api: `/api/v1`
50+
* api endpoint: `/search` or `traits` or `sites`. For BETYdb, these are the names of database tables.
51+
* Query parameters: `genus=Sorghum`
52+
* Authentication: `key=9999999999999999999999999999999999999999` is the public key for the TERRA REF traits database.
53+
54+
## Constructing a URL query
55+
56+
First, lets construct a query by putting together a URL.
57+
58+
1. start with the database url: `terraref.ncsa.illinois.edu/bety`
59+
* this url brings you to the home page
60+
2. Add the path to the API, `/api/v1`
61+
* now we have terraref.ncsa.illinois.edu/bety/api/v1, which points to the API documentation
62+
3. Add the name of the table you want to query. Lets start with `variables`
63+
* terraref.ncsa.illinois.edu/bety/api/v1/variables
64+
4. add query terms by appending a `?` and combining with `&`, for example:
65+
* `key=9999999999999999999999999999999999999999`
66+
* `type=trait` where the variable type is 'trait'
67+
* `name=~height` where the variable name contains 'height'
68+
5. This is your complete query:
69+
* `terraref.ncsa.illinois.edu/bety/api/v1/variables?type=trait&name=~height&key=9999999999999999999999999999999999999999`
70+
* it will query all variables that are type trait and have 'height' in the name
71+
* Does it return the expected values?
72+
73+
## Your Turn
74+
75+
> What will the URL https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=9999999999999999999999999999999999999999 return?
76+
77+
> Write a URL that will query the database for sites with "Field Scanner" in the name field. Hint: combine two terms with a `+` as in `Field+Scanner`
78+
79+
What do you see? Do you think that this is all of the records? What happens if you add `&limit=none`?
80+
81+
82+
83+
#### Accessing data using the Shell
84+
85+
Type the following command into a bash shell (the `-o` option names the output file):
86+
87+
```sh
88+
curl -o sorghum.json \
89+
"https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=9999999999999999999999999999999999999999"
90+
```
91+
92+
If you want to write the query without exposing the key in plain text, you can construct it like this:
93+
94+
```sh
95+
curl -o sorghum.json \
96+
"https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=`cat .betykey_public`"
97+
```
98+
99+
### Accessing API data using the R jsonlite package
100+
101+
```{r text-api}
102+
sorghum.json <- readLines(
103+
paste0("https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=",
104+
readLines('.betykey')))
105+
106+
## print(sorghum.json)
107+
## not a particularly useful format
108+
## lets convert to a data frame
109+
sorghum <- jsonlite::fromJSON(sorghum.json)
110+
```
111+
112+
More on how to use the rOpenSci traits package coming up in the [next tutorial](03-access-r-traits.Rmd)

traits/03-access-r-traits.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ library(dplyr)
3333
```{r writing-key}
3434
# This should be done once with the key sent to you in your email
3535
# writeLines('abcdefg_rest_of_key_sent_in_email',
36-
# con = '~/.betykey')
36+
# con = '.betykey')
3737
3838
# Example with the public key:
3939
writeLines('9999999999999999999999999999999999999999',
40-
con = '~/.betykey_public')
40+
con = '.betykey_public')
4141
```
4242

4343
#### R - using the traits package
@@ -55,7 +55,7 @@ sorghum_info <- betydb_query(table = 'species',
5555
api_version = 'beta',
5656
limit = 'none',
5757
betyurl = "https://terraref.ncsa.illinois.edu/bety/",
58-
key = readLines('~/.betykey', warn = FALSE))
58+
key = readLines('.betykey', warn = FALSE))
5959
6060
```
6161

@@ -65,7 +65,7 @@ Notice all of the arguments that the `betydb_query` function requires? We can ch
6565

6666

6767
```{r}
68-
options(betydb_key = readLines('~/.betykey', warn = FALSE),
68+
options(betydb_key = readLines('.betykey', warn = FALSE),
6969
betydb_url = "https://terraref.ncsa.illinois.edu/bety/",
7070
betydb_api_version = 'beta')
7171
```

traits/04-danforth-indoor-phenotyping-facility.Rmd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
title: "Phenotype Analysis"
33
author: "David LeBauer, Craig Willis"
44
date: "`r Sys.Date()`"
5-
output: md_document
5+
output:
6+
html_document: default
67
---
78

89
```{r 02-setup, include=FALSE}
@@ -26,7 +27,7 @@ library(traits)
2627
Unlike the first two tutorials, now we will be querying real data from the public TERRA REF database. So we will use a new URL, https://terraref.ncsa.illinois.edu/bety/, and we will need to use our own private key.
2728

2829
```{r terraref-connect-options}
29-
options(betydb_key = readLines('~/.betykey', warn = FALSE),
30+
options(betydb_key = readLines('.betykey'),
3031
betydb_url = "https://terraref.ncsa.illinois.edu/bety/",
3132
betydb_api_version = 'beta')
3233
```
@@ -114,4 +115,4 @@ ggplot(data = danforth_sorghum, aes(x = date, y = mean, color = cultivar)) +
114115
2. An 'entity' is a replicate.
115116
* How many entities are there?
116117
* How many entities per cultivar?
117-
* Did they all make it through the entire growing season?
118+
* Did they all make it through the entire growing season?

0 commit comments

Comments
 (0)