This is an API access example using token-based authentication with R.
require(curl)
token = 'your_token_here'
s = new_handle()
# Send token header with each request
handle_setheaders(s, 'Authorization'=paste('Token', token))
##
# PV example
##
api_base = 'https://www.renewables.ninja/api/data/pv'
# Set your input parameters
args = list(
'lat' = 34.125,
'lon' = 39.814,
'date_from' = '2014-01-01',
'date_to' = '2014-12-31',
'dataset' = 'merra2',
'capacity' = 1.0,
'system_loss' = 0.10,
'tracking' = 0,
'tilt' = 35,
'azim' = 180,
'format' = 'csv',
'metadata' = 'false'
)
# Build the URL
args = paste(names(args), args, sep='=', collapse='&')
url = paste0(api_base, '?', args)
# Read the data as CSV
req = curl(url, handle=s)
csv = read.csv(req, skip=3, stringsAsFactors=FALSE)
# Format the time column
csv$time = as.POSIXct(csv$time, format="%Y-%m-%d %H:%M")
# Visualise
plot(csv, type='l')
Getting wind data works analogously:
##
# Wind example
##
api_base = 'https://www.renewables.ninja/api/data/wind'
# Set your input parameters
args = list(
'lat' = 34.125,
'lon' = 39.814,
'date_from' = '2014-01-01',
'date_to' = '2014-12-31',
'capacity' = 1.0,
'height' = 100,
'turbine' = 'Vestas V80 2000',
'format' = 'csv',
'metadata' = 'false'
)
# Build the URL
args = paste(names(args), args, sep='=', collapse='&')
url = paste0(api_base, '?', args)
# Read the data as CSV
req = curl(url, handle=s)
csv = read.csv(req, skip=3, stringsAsFactors=FALSE)
# Format the time column
csv$time = as.POSIXct(csv$time, format="%Y-%m-%d %H:%M")
# Visualise
plot(csv, type='l')