From fc0786b37cfa2489378e6dcc91fb9d19911dc625 Mon Sep 17 00:00:00 2001 From: Silvia Vangelova Date: Fri, 16 Feb 2024 09:34:10 -0500 Subject: [PATCH 1/2] update to next version of NREL --- .vscode/launch.json | 17 +++++++++++++ nrel_psm3_2_epw/assets.py | 37 ++++++++++++++++++++------- requirements.txt | 53 +++++++++++++++++++++++++++++++++++---- run_streamlit.bat | 2 +- streamlit_app.py | 17 +++++-------- 5 files changed, 100 insertions(+), 26 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b9af34e --- /dev/null +++ b/.vscode/launch.json @@ -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" + ] + } + ] +} \ No newline at end of file diff --git a/nrel_psm3_2_epw/assets.py b/nrel_psm3_2_epw/assets.py index 83c7aa8..6383d8c 100644 --- a/nrel_psm3_2_epw/assets.py +++ b/nrel_psm3_2_epw/assets.py @@ -1,3 +1,4 @@ +import json import sys import numpy as np @@ -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) diff --git a/requirements.txt b/requirements.txt index 976fc4f..3d6fbfe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,48 @@ -click==8 -numpy -pandas -requests -datetime \ No newline at end of file +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 diff --git a/run_streamlit.bat b/run_streamlit.bat index c100f69..d03149f 100644 --- a/run_streamlit.bat +++ b/run_streamlit.bat @@ -1,2 +1,2 @@ -call "C:\Users\pkastner\Anaconda3\Scripts\activate.bat" datascience +call ".\env\Scripts\activate.bat" env streamlit run %~dp0streamlit_app.py \ No newline at end of file diff --git a/streamlit_app.py b/streamlit_app.py index 461bad5..f5c6d91 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -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). @@ -24,14 +24,11 @@ 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' @@ -39,8 +36,6 @@ 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" @@ -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): From b9fe90d030f3bbed30e1f13e03c1a0b24e054b54 Mon Sep 17 00:00:00 2001 From: Silvia Vangelova Date: Fri, 16 Feb 2024 09:37:48 -0500 Subject: [PATCH 2/2] update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4963a58..1e4b270 100644 --- a/README.md +++ b/README.md @@ -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