Skip to content

Commit

Permalink
Merge pull request #1 from xtearas/main
Browse files Browse the repository at this point in the history
update to new version of NREL Physical Solar Model (PSM)
  • Loading branch information
kastnerp authored Feb 16, 2024
2 parents 5c57a90 + b9fe90d commit 364499d
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 28 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python:Streamlit",
"type": "debugpy",
"request": "launch",
"module": "streamlit",
"args": [
"run",
"streamlit_app.py",
"--server.port",
"http://localhost:8501"
]
}
]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# NREL-PSM3-2-EPW
A script that writes out epw files from NREL PSM3 data
A script that writes out epw files from NREL Physical Solar Model (PSM) v3.2.2

# Demo

- [Link to demo](http://bit.ly/NREL--PSM3-2-EPW)
- [Link to demo](https://nrel-psm3-2-epw-2djuwytnlpmk4fmsfai74g.streamlit.app/)

# How to use

Expand Down
37 changes: 28 additions & 9 deletions nrel_psm3_2_epw/assets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import sys

import numpy as np
Expand All @@ -8,31 +9,49 @@
import calendar


def download_epw(lat, lon, year, location, attributes, interval, utc, your_name, api_key, reason_for_use,
def download_epw(lon, lat, year, location, attributes, interval, utc, your_name, api_key, reason_for_use,
your_affiliation, your_email, mailing_list, leap_year):
currentYear = datetime.now().year
if int(year) == currentYear or int(year) == currentYear-1:
raise Exception("NREL does not provide data for the current year " + str(
year) + ". It is also unlikely that there is data availability for " + str(int(year) - 1) + ".")

# Declare url string
url = 'https://developer.nrel.gov/api/solar/nsrdb_psm3_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)
url = f"https://developer.nrel.gov/api/nsrdb/v2/solar/psm3-2-2-download.csv?api_key={api_key}"

payload = {
"names": year,
"leap_day": leap_year,
"interval": interval,
"utc": utc,
"full_name": your_name,
"email": your_email,
"affiliation": your_affiliation,
"mailing_list": mailing_list,
"reason": reason_for_use,
"attributes": attributes,
"wkt": f"POINT({lon} {lat})"
}

headers = {
'content-type': "application/x-www-form-urlencoded",
'cache-control': "no-cache"
}

r = None
all_data = None

try:
r = requests.get(url, timeout=20)
r = requests.request("GET", url, params=
payload, headers=headers, timeout=20)

print(r.text)
r.raise_for_status()

# Return just the first 2 lines to get metadata:
all_data = pd.read_csv(url)
all_data = pd.read_csv(r.url)

if all_data is None:
raise("Could not retrieve any data")
raise ("Could not retrieve any data")

except requests.exceptions.HTTPError as errh:
print("Http Error:", errh)
Expand Down
53 changes: 48 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
click==8
numpy
pandas
requests
datetime
altair==5.2.0
attrs==23.2.0
blinker==1.7.0
cachetools==5.3.2
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.0.0
colorama==0.4.6
DateTime==5.4
gitdb==4.0.11
GitPython==3.1.42
idna==3.6
importlib-metadata==7.0.1
Jinja2==3.1.3
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdurl==0.1.2
numpy==1.26.4
packaging==23.2
pandas==2.2.0
pillow==10.2.0
protobuf==4.25.3
pyarrow==15.0.0
pydeck==0.8.1b0
Pygments==2.17.2
python-dateutil==2.8.2
pytz==2024.1
referencing==0.33.0
requests==2.31.0
rich==13.7.0
rpds-py==0.18.0
six==1.16.0
smmap==5.0.1
streamlit==1.31.1
tenacity==8.2.3
toml==0.10.2
toolz==0.12.1
tornado==6.4
typing_extensions==4.9.0
tzdata==2024.1
tzlocal==5.2
urllib3==2.2.0
validators==0.22.0
watchdog==4.0.0
zipp==3.17.0
zope.interface==6.2
2 changes: 1 addition & 1 deletion run_streamlit.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
call "C:\Users\pkastner\Anaconda3\Scripts\activate.bat" datascience
call ".\env\Scripts\activate.bat" env
streamlit run %~dp0streamlit_app.py
17 changes: 6 additions & 11 deletions streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Draw a title and some text to the app:
'''
# NREL-PSM3-2-EPW
# NREL-PSM3-2-EPW v3.2.2
This script converts climate data from NREL to the EnergyPlus EPW format.
If you do not have an API key, feel free to request one [here](https://developer.nrel.gov/signup).
Expand All @@ -24,23 +24,18 @@
Please provide _Lat_, _Lon_, _Location_, and _Year_.
'''

lat = st.text_input('Lat:', value=42.434269, max_chars=None, type='default')
lon = st.text_input('Lon:', value=-76.500354, max_chars=None, type='default')
location = st.text_input('Location (just used to name the file):', value="Ithaca", max_chars=None, type='default')
year = st.text_input('Year:', value=2019, max_chars=None, type='default')
lat = st.text_input('Lat:', value=33.770, max_chars=None, type='default')
lon = st.text_input('Lon:', value=-84.3824, max_chars=None, type='default')
location = st.text_input('Location (just used to name the file):', value="Atlanta", max_chars=None, type='default')
year = st.text_input('Year:', value=2020, max_chars=None, type='default')

# lat, lon = 42.434269, -76.500354
# location = "Ithaca"
# year = '2019'
attributes = 'air_temperature,clearsky_dhi,clearsky_dni,clearsky_ghi,cloud_type,dew_point,dhi,dni,fill_flag,ghi,' \
'relative_humidity,solar_zenith_angle,surface_albedo,surface_pressure,total_precipitable_water,' \
'wind_direction,wind_speed,ghuv-280-400,ghuv-295-385'

interval = '60'
utc = 'false'
your_name = "John+Doe"
# api_key_file = open("api_key", 'r')
# api_key = api_key_file.readline()
reason_for_use = 'beta+testing'
your_affiliation = 'aaa'
your_email = "Joe@Doe.edu"
Expand Down Expand Up @@ -145,7 +140,7 @@ def download_button(object_to_download, download_filename, button_text, pickle_i

st.write("Requesting data from NREL...")

file_name = download_epw(float(lat), float(lon), int(year), location, attributes, interval, utc, your_name,
file_name = download_epw(lon, lat, int(year), location, attributes, interval, utc, your_name,
api_key, reason_for_use, your_affiliation, your_email, mailing_list, leap_year)

if os.path.exists(file_name):
Expand Down

0 comments on commit 364499d

Please sign in to comment.