-
Notifications
You must be signed in to change notification settings - Fork 0
/
Usage.Rmd
116 lines (83 loc) · 2.67 KB
/
Usage.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
title: "Usage of Microclim R Api"
author: "Aji John"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Usage of Microclim R Api}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
This API toolkit gives you an easy wasy to interact with microclim.org which is a microclimatic data repository.
One of the important purpose is to do ecological forecasting. This vignette helps implements a typical usecase to;
- Load the microclimR api
- Download the microclim data
- Run a basic analysis
## Load the required
First things first, install and load the microclim R library
```{r,eval=FALSE}
library(devtools)
devtools::install_github("trenchproject/microclimRapi")
library(microclimRapi)
library(httr)
library(jsonlite)
```
## Get Token
Microclim.org gives a token to a registered user to use its services via APIs. In the account page, you can find your API key and secret.
```{r,eval=FALSE}
api_token = getToken('07d4d584c04941a25e291feb8881c685','9ef6bbb24a855fbb765f3890e05592f4','localhost:3000/')
```
## Get Token
This API pkg uses extensively Reference Class(RC) feature of R, a setp-up from S4 classes. Behaviour is like other OO languages.
```{r,eval=FALSE}
ma <- microclimRapi:::MicroclimAPI$new(token = api_token,url_mc='http://localhost:3000/')
```
## Prepare Request and Place a request for extraction
```{r,eval=FALSE}
mr <- microclimRapi:::MicroclimRequest$new(
latS = 39.40012200014591,
latN=39.92132255884663,
lonW=-106.47674560546875,
lonE=-105.92193603515625,
variable="ALBEDO",
shadelevel=0,
hod=0,
interval=0,
aggregation=0,
stdate="19810101",
eddate="19810128",
file="csv")
# place a request
ext_req= ma$request(mr)
print(toJSON(ext_req))
```
## Check on your request
If Request status is 'EMAILED', you can proceed with downloading the data.
```{r,eval=FALSE}
#check the status of your request
ma$status(requestId)
#status 'EMAILED' means job is complete.
```
## Get CSV/netCDF
```{r,eval=FALSE}
#Pull your netCDF
if(ma$status(requestId) == "EMAILED")
{
# place a request to fetch the files
ftch_req= ma$fetch(requestId)
# pass the filename
ncD <- ma$download(requestId,ftch_req$files[[1]]$Key)
#File name has request id as part of it
writeBin(ncD, strsplit(ftch_req$files[[1]]$Key, "/")[[1]][2])
}
```
##Research question - BioPhy Model for a Lizard projecting into future.
```{r,eval=FALSE}
# Describe the model
# For the given date range
# Tair
# Tsurface
# UV
# SWDOWN
#
```