In [87]:
library(devtools)
In [88]:
devtools::install_github("trenchproject/microclimRapi")
In [95]:
library(microclimRapi)
In [96]:
api_token = getToken('0eda0dd88d1e6b417e8e9bebfc02cd95','a0fc61db2d657c5359c775b62bffb669','http://microclim.org/')
In [97]:
print(api_token)
API token received, now place the request for extraction
In [98]:
ma <- microclimRapi:::MicroclimAPI$new(token = api_token,url_mc='http://microclim.org/')
In [99]:
# Eagle Nest Wilderness Area - Colorado
mr <- microclimRapi:::MicroclimRequest$new(
latS = "39.48178546986059",
latN="39.890772566959534",
lonW="-106.51519775390625",
lonE="-106.03317260742188",
variable="ALBEDO",
shadelevel=0,
hod=0,
interval=0,
aggregation=0,
stdate="19810101",
eddate="19810131",
file="csv")
In [100]:
# Place a request to extract
ext_req= ma$request(mr)
In [101]:
print(ext_req)
In [102]:
print(ext_req$request_id)
In [103]:
ma$status(ext_req$request_id)
If status is EMAILED, then files can be downloaded
In [114]:
ftch_req=''
#Pull the files
if(ma$status(ext_req$request_id) == "EMAILED")
{
# place a request to fetch the files
ftch_req= ma$fetch(ext_req$request_id)
}
In [115]:
ftch_req
In [106]:
ftch_req$files[[1]]$Key
In [109]:
ncD <- ma$download(ext_req$request_id,ftch_req$files[[1]]$Key)
In [110]:
#download the csv file
writeBin(ncD, strsplit(ftch_req$files[[1]]$Key, "/")[[1]][2])
In [111]:
file.exists(strsplit(ftch_req$files[[1]]$Key, "/")[[1]][2])
In [112]:
lv <- read.csv(strsplit(ftch_req$files[[1]]$Key, "/")[[1]][2],comment.char = "#")
In [113]:
str(lv)
In [ ]: