Created
November 6, 2018 19:52
-
-
Save supriya-premkumar/f433a453b5dc2a9b05efadafed6a03db to your computer and use it in GitHub Desktop.
Query NREL weather data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import sys, os | |
# Our SLAC! | |
lat, lon, year = 37.420191, -122.204551, 2015 | |
# NSRDB API KEY | |
api_key = <API KEY> | |
# Set the attributes to extract (e.g., dhi, ghi, etc.), separated by commas. | |
attributes = 'surface_air_temperature_nwp,solar_zenith_angle,ghi,dhi,dni,wind_speed_10m_nwp,wind_direction_10m_nwp,surface_relative_humidity_nwp' | |
# Choose year of data | |
year = '2015' | |
# Set leap year to true or false. True will return leap day data if present, false will not. | |
leap_year = 'false' | |
# Set time interval in minutes, i.e., '30' is half hour intervals. Valid intervals are 30 & 60. | |
interval = '30' | |
# Specify Coordinated Universal Time (UTC), 'true' will use UTC, 'false' will use the local time zone of the data. | |
# NOTE: In order to use the NSRDB data in SAM, you must specify UTC as 'false'. SAM requires the data to be in the | |
# local time zone. | |
utc = 'false' | |
# Your full name, use '+' instead of spaces. | |
your_name = <NAME> | |
# Your reason for using the NSRDB. | |
reason_for_use = 'beta+testing' | |
# Your affiliation | |
your_affiliation = <AFFILIATION> | |
# Your email address | |
your_email = <EMAIL> | |
# Please join our mailing list so we can keep you up-to-date on new developments. | |
mailing_list = 'false' | |
# Declare url string | |
url = 'http://developer.nrel.gov/api/solar/nsrdb_0512_download.csv?wkt=POINT({lon}%20{lat})&names={year}&leap_day={leap}&interval={interval}&utc={utc}&full_name={name}&email={email}&affiliation={affiliation}&mailing_list={mailing_list}&reason={reason}&api_key={api}&attributes={attr}'.format(year=year, lat=lat, lon=lon, leap=leap_year, interval=interval, utc=utc, name=your_name, email=your_email, mailing_list=mailing_list, affiliation=your_affiliation, reason=reason_for_use, api=api_key, attr=attributes) | |
# Return just the first 2 lines to get metadata: | |
info = pd.read_csv(url, nrows=1) | |
# See metadata for specified properties, e.g., timezone and elevation | |
timezone, elevation = info['Local Time Zone'], info['Elevation'] | |
df = pd.read_csv('http://developer.nrel.gov/api/solar/nsrdb_0512_download.csv?wkt=POINT({lon}%20{lat})&names={year}&leap_day={leap}&interval={interval}&utc={utc}&full_name={name}&email={email}&affiliation={affiliation}&mailing_list={mailing_list}&reason={reason}&api_key={api}&attributes={attr}'.format(year=year, lat=lat, lon=lon, leap=leap_year, interval=interval, utc=utc, name=your_name, email=your_email, mailing_list=mailing_list, affiliation=your_affiliation, reason=reason_for_use, api=api_key, attr=attributes), skiprows=2) | |
df = df.set_index(pd.date_range('1/1/{yr}'.format(yr=year), freq=interval+'Min', periods=525600/int(interval))) | |
print df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment