diff --git a/README.md b/README.md index 9d3634380..5c32aeba8 100644 --- a/README.md +++ b/README.md @@ -59,12 +59,12 @@ solar and storage. [https://developer.nrel.gov/signup/](https://developer.nrel.gov/signup/) -7. To set up the `NREL_API_KEY` required for resource downloads, you can create an Environment Variable called - `NREL_API_KEY`. Otherwise, you can keep the key in a new file called ".env" in the root directory of this project. +7. To set up the `NREL_API_KEY` and `NREL_API_EMAIL` required for resource downloads, you can create Environment Variables called `NREL_API_KEY` and `NREL_API_EMAIL`. Otherwise, you can keep the key in a new file called ".env" in the root directory of this project. Create a file ".env" that contains the single line: - ``` + ``` NREL_API_KEY=key + NREL_API_EMAIL=your.name@email.com ``` 8. Verify setup by running tests: diff --git a/hopp/simulation/technologies/resource/resource.py b/hopp/simulation/technologies/resource/resource.py index 4df12be76..607ffa842 100644 --- a/hopp/simulation/technologies/resource/resource.py +++ b/hopp/simulation/technologies/resource/resource.py @@ -36,7 +36,6 @@ def __init__(self, lat, lon, year, **kwargs): self.name = 'hybrid-systems' self.affiliation = 'NREL' self.reason = 'hybrid-analysis' - self.email = 'nicholas.diorio@nrel.gov' self.mailing_list = 'true' # paths diff --git a/hopp/simulation/technologies/resource/solar_resource.py b/hopp/simulation/technologies/resource/solar_resource.py index a69d10be7..781fa9aae 100644 --- a/hopp/simulation/technologies/resource/solar_resource.py +++ b/hopp/simulation/technologies/resource/solar_resource.py @@ -6,7 +6,7 @@ import csv from PySAM.ResourceTools import SAM_CSV_to_solar_data -from hopp.utilities.keys import get_developer_nrel_gov_key +from hopp.utilities.keys import get_developer_nrel_gov_key, get_developer_nrel_gov_email from hopp.utilities.log import hybrid_logger as logger from hopp.simulation.technologies.resource.resource import Resource from hopp import ROOT_DIR @@ -71,7 +71,7 @@ def __init__( def download_resource(self): url = '{base}?wkt=POINT({lon}+{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( base=BASE_URL, year=self.year, lat=self.latitude, lon=self.longitude, leap=self.leap_year, interval=self.interval, - utc=self.utc, name=self.name, email=self.email, + utc=self.utc, name=self.name, email=get_developer_nrel_gov_email(), mailing_list=self.mailing_list, affiliation=self.affiliation, reason=self.reason, api=get_developer_nrel_gov_key(), attr=self.solar_attributes) diff --git a/hopp/simulation/technologies/resource/wind_resource.py b/hopp/simulation/technologies/resource/wind_resource.py index 0d781351c..a090849d6 100644 --- a/hopp/simulation/technologies/resource/wind_resource.py +++ b/hopp/simulation/technologies/resource/wind_resource.py @@ -3,7 +3,7 @@ from typing import Union from PySAM.ResourceTools import SRW_to_wind_data -from hopp.utilities.keys import get_developer_nrel_gov_key +from hopp.utilities.keys import get_developer_nrel_gov_key, get_developer_nrel_gov_email from hopp.simulation.technologies.resource.resource import Resource from hopp import ROOT_DIR @@ -121,7 +121,7 @@ def download_resource(self): if self.source == "WTK": url = '{base}?year={year}&lat={lat}&lon={lon}&hubheight={hubheight}&api_key={api_key}&email={email}'.format( - base=WTK_BASE_URL, year=self.year, lat=self.latitude, lon=self.longitude, hubheight=height, api_key=get_developer_nrel_gov_key(), email=self.email + base=WTK_BASE_URL, year=self.year, lat=self.latitude, lon=self.longitude, hubheight=height, api_key=get_developer_nrel_gov_key(), email=get_developer_nrel_gov_email() ) elif self.source == "TAP": url = '{base}?height={hubheight}m&lat={lat}&lon={lon}&year={year}'.format( diff --git a/hopp/utilities/keys.py b/hopp/utilities/keys.py index 2895d91f0..bb460af1d 100644 --- a/hopp/utilities/keys.py +++ b/hopp/utilities/keys.py @@ -2,12 +2,15 @@ import os developer_nrel_gov_key = "" +developer_nrel_gov_email = "" def set_developer_nrel_gov_key(key: str): global developer_nrel_gov_key developer_nrel_gov_key = key - +def set_developer_nrel_gov_email(email: str): + global developer_nrel_gov_email + developer_nrel_gov_email = email def get_developer_nrel_gov_key(): global developer_nrel_gov_key @@ -20,6 +23,16 @@ def get_developer_nrel_gov_key(): "Section 2 of 'Installing from Package Repositories' in the README.md") return developer_nrel_gov_key +def get_developer_nrel_gov_email(): + global developer_nrel_gov_email + if developer_nrel_gov_email is None: + raise ValueError("Please provide NREL Developer email using `set_developer_nrel_gov_email`" + "(`from hopp.utilities.keys import set_developer_nrel_gov_email`) \n" + " Ensure your Developer email is set either as a `EMAIL` Environment Variable or" + " using the .env file method. For details on setting up .env, " + "please see Section 7 of 'Installing from Source' or " + "Section 2 of 'Installing from Package Repositories' in the README.md") + return developer_nrel_gov_email def set_nrel_key_dot_env(path=None): if path and os.path.exists(path): @@ -28,5 +41,8 @@ def set_nrel_key_dot_env(path=None): r = find_dotenv(usecwd=True) load_dotenv(r) NREL_API_KEY = os.getenv("NREL_API_KEY") + NREL_API_EMAIL = os.getenv("NREL_API_EMAIL") if NREL_API_KEY is not None: set_developer_nrel_gov_key(NREL_API_KEY) + if NREL_API_EMAIL is not None: + set_developer_nrel_gov_email(NREL_API_EMAIL)