Skip to content

Commit 364499d

Browse files
authored
Merge pull request #1 from xtearas/main
update to new version of NREL Physical Solar Model (PSM)
2 parents 5c57a90 + b9fe90d commit 364499d

File tree

6 files changed

+102
-28
lines changed

6 files changed

+102
-28
lines changed

.vscode/launch.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Python:Streamlit",
6+
"type": "debugpy",
7+
"request": "launch",
8+
"module": "streamlit",
9+
"args": [
10+
"run",
11+
"streamlit_app.py",
12+
"--server.port",
13+
"http://localhost:8501"
14+
]
15+
}
16+
]
17+
}

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# NREL-PSM3-2-EPW
2-
A script that writes out epw files from NREL PSM3 data
2+
A script that writes out epw files from NREL Physical Solar Model (PSM) v3.2.2
33

44
# Demo
55

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

88
# How to use
99

nrel_psm3_2_epw/assets.py

+28-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import sys
23

34
import numpy as np
@@ -8,31 +9,49 @@
89
import calendar
910

1011

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

18-
# Declare url string
19-
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(
20-
year=year, lat=lat, lon=lon, leap=leap_year, interval=interval, utc=utc, name=your_name, email=your_email,
21-
mailing_list=mailing_list, affiliation=your_affiliation,
22-
reason=reason_for_use, api=api_key, attr=attributes)
19+
url = f"https://developer.nrel.gov/api/nsrdb/v2/solar/psm3-2-2-download.csv?api_key={api_key}"
20+
21+
payload = {
22+
"names": year,
23+
"leap_day": leap_year,
24+
"interval": interval,
25+
"utc": utc,
26+
"full_name": your_name,
27+
"email": your_email,
28+
"affiliation": your_affiliation,
29+
"mailing_list": mailing_list,
30+
"reason": reason_for_use,
31+
"attributes": attributes,
32+
"wkt": f"POINT({lon} {lat})"
33+
}
34+
35+
headers = {
36+
'content-type': "application/x-www-form-urlencoded",
37+
'cache-control': "no-cache"
38+
}
2339

2440
r = None
2541
all_data = None
2642

2743
try:
28-
r = requests.get(url, timeout=20)
44+
r = requests.request("GET", url, params=
45+
payload, headers=headers, timeout=20)
46+
47+
print(r.text)
2948
r.raise_for_status()
3049

3150
# Return just the first 2 lines to get metadata:
32-
all_data = pd.read_csv(url)
51+
all_data = pd.read_csv(r.url)
3352

3453
if all_data is None:
35-
raise("Could not retrieve any data")
54+
raise ("Could not retrieve any data")
3655

3756
except requests.exceptions.HTTPError as errh:
3857
print("Http Error:", errh)

requirements.txt

+48-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
1-
click==8
2-
numpy
3-
pandas
4-
requests
5-
datetime
1+
altair==5.2.0
2+
attrs==23.2.0
3+
blinker==1.7.0
4+
cachetools==5.3.2
5+
certifi==2024.2.2
6+
charset-normalizer==3.3.2
7+
click==8.0.0
8+
colorama==0.4.6
9+
DateTime==5.4
10+
gitdb==4.0.11
11+
GitPython==3.1.42
12+
idna==3.6
13+
importlib-metadata==7.0.1
14+
Jinja2==3.1.3
15+
jsonschema==4.21.1
16+
jsonschema-specifications==2023.12.1
17+
markdown-it-py==3.0.0
18+
MarkupSafe==2.1.5
19+
mdurl==0.1.2
20+
numpy==1.26.4
21+
packaging==23.2
22+
pandas==2.2.0
23+
pillow==10.2.0
24+
protobuf==4.25.3
25+
pyarrow==15.0.0
26+
pydeck==0.8.1b0
27+
Pygments==2.17.2
28+
python-dateutil==2.8.2
29+
pytz==2024.1
30+
referencing==0.33.0
31+
requests==2.31.0
32+
rich==13.7.0
33+
rpds-py==0.18.0
34+
six==1.16.0
35+
smmap==5.0.1
36+
streamlit==1.31.1
37+
tenacity==8.2.3
38+
toml==0.10.2
39+
toolz==0.12.1
40+
tornado==6.4
41+
typing_extensions==4.9.0
42+
tzdata==2024.1
43+
tzlocal==5.2
44+
urllib3==2.2.0
45+
validators==0.22.0
46+
watchdog==4.0.0
47+
zipp==3.17.0
48+
zope.interface==6.2

run_streamlit.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
call "C:\Users\pkastner\Anaconda3\Scripts\activate.bat" datascience
1+
call ".\env\Scripts\activate.bat" env
22
streamlit run %~dp0streamlit_app.py

streamlit_app.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

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

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

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

3936
interval = '60'
4037
utc = 'false'
4138
your_name = "John+Doe"
42-
# api_key_file = open("api_key", 'r')
43-
# api_key = api_key_file.readline()
4439
reason_for_use = 'beta+testing'
4540
your_affiliation = 'aaa'
4641
your_email = "[email protected]"
@@ -145,7 +140,7 @@ def download_button(object_to_download, download_filename, button_text, pickle_i
145140

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

148-
file_name = download_epw(float(lat), float(lon), int(year), location, attributes, interval, utc, your_name,
143+
file_name = download_epw(lon, lat, int(year), location, attributes, interval, utc, your_name,
149144
api_key, reason_for_use, your_affiliation, your_email, mailing_list, leap_year)
150145

151146
if os.path.exists(file_name):

0 commit comments

Comments
 (0)