mesowest
provides utilities for interfacing with the mesowest API using R
library(devtools)
install_github('fickse/mesowest')
After you have obtained an API key, request a token...
library(mesowest)
requestToken(apikey = "YoUrApIkEY918202s")
# or interactively choose a text file with the key...
requestToken()
The token is saved to a text file in your root directory (~/
)
Services are accessed through the function mesowest::mw
Parameters can be input as named arguments
mw(service = 'metadata', complete=1, state='UT', county='Garfield')
If this results in awkward nested dataframes, include jsonsimplify = FALSE
as an argument.
Data can be queried using named parameters in the api
# request hourly timeseries data
d <- mw(service = 'timeseries', stid ='SFLU1', vars = c('air_temp', 'relative_humidity'), start = '201610250001', end = '201610260001', jsonsimplify= TRUE)
# parsing the nested lists
clim <- data.frame( lapply( d$STATION$OBSERVATIONS, unlist) )
d <- mw(service = 'latest', county = 'Garfield', state = 'UT', vars = 'air_temp')
cbind(d$STATION$STID, d$STATION$OBSERVATIONS)
# requesting hourly totals
mw(service = 'precipitation', stid='SFLU1', start = '201610250010', end ='201611250001', pmode='intervals', interval = 'hour', jsonsimplify = TRUE, returnURL =FALSE)
A quick reference for parameters can be accessed with getparams()
# all parameters for all services
getparams()
# parameters for a specific service
getparams('networks')
There is also a shortcut api call to list variables
mwvariables()
The mw() function generates an API request which may be inspected by setting returnURL = TRUE
.
E.g. this query
mw(service = 'latest', county = 'Garfield', state = 'UT', vars = 'air_temp', returnURL = TRUE)`
returns this:
http://api.mesowest.net/v2/stations/latest?&token=XX_YOURTOKEN_XX&county=Garfield&state=UT&vars=air_temp
Note: This package was created independently from SynopticLabs, MesoWest, or any associates. It is intended to be used for research purposes only.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.