-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: generate solar profiles during HIFLD grid-building #256
Merged
+280
−119
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8a0eb0d
chore: add URL paths to Form 860 solar/wind-specific data
danielolsen cd58456
chore: update nrel-pysam requirement to version 3.0
danielolsen 6f160eb
chore: update PVWatts module to version 8
danielolsen 0b9d25c
chore: add name to generator index
danielolsen a4ecc59
ci: add python 3.10 test
danielolsen 66f8766
doc: fix docstrings for solar profile functions
danielolsen 41f07db
feat: add method to translate PSM3Data back to original CSV file format
danielolsen 29fae1c
refactor: make NREL API downloads resilient to 5xx errors
danielolsen 8dbaf06
feat: add concentrating solar power profile generation function
danielolsen 5ed0aa6
refactor: fetch full weather year, but still manage non-leap output
danielolsen fa33f4c
feat: add function to pass solar-specific 860 data to profile generation
danielolsen 7cb4d14
feat: add solar profile generation step to orchestration
danielolsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from prereise.gather.griddata.hifld import const | ||
from prereise.gather.griddata.hifld.data_access.load import get_eia_form_860 | ||
from prereise.gather.solardata.nsrdb.sam import retrieve_data_individual | ||
|
||
|
||
def floatify(x): | ||
"""Coerce an object to a float, returning a float NaN for any objects which raise an | ||
exception when passed to :func:`float`. | ||
:param object x: object to coerce. | ||
:return: (*float*) -- coerced value. | ||
""" | ||
try: | ||
return float(x) | ||
except ValueError: | ||
return float("nan") | ||
|
||
|
||
def build_solar(nrel_email, nrel_api_key, solar_plants, **solar_kwargs): | ||
"""Use plant-level data to build solar profiles. | ||
:param str nrel_email: email used to`sign up <https://developer.nrel.gov/signup/>`_. | ||
:param str nrel_api_key: API key. | ||
:param pandas.DataFrame solar_plants: data frame of solar farms. | ||
:param dict solar_kwargs: keyword arguments to pass to | ||
:func:`prereise.gather.solardata.nsrdb.sam.retrieve_data_individual`. | ||
:return: (*pandas.DataFrame*) -- data frame of normalized power profiles. The index | ||
is hourly timestamps for the profile year, the columns are plant IDs, the values | ||
are floats. | ||
""" | ||
boolean_columns = ["Single-Axis Tracking?", "Dual-Axis Tracking?", "Fixed Tilt?"] | ||
float_columns = ["DC Net Capacity (MW)", "Nameplate Capacity (MW)", "Tilt Angle"] | ||
# Load raw 'extra' table data, join on plant & generating unit, re-establish index | ||
extra_solar_data = get_eia_form_860(const.blob_paths["eia_form860_2019_solar"]) | ||
full_data = solar_plants.merge( | ||
extra_solar_data, on=["Plant Code", "Generator ID"], suffixes=(None, "_extra") | ||
) | ||
full_data.index = solar_plants.index | ||
# Process data to expected types for profile generation | ||
for col in float_columns: | ||
full_data[col] = full_data[col].map(floatify) | ||
for col in boolean_columns: | ||
# 'Y' becomes True, anything else ('N', blank, etc) becomes False | ||
full_data[col] = full_data[col] == "Y" | ||
|
||
# If panel type isn't known definitively, assume 100% Fixed Tilt | ||
# Solar thermal also ends up labeled as fixed tilt, but this will be ignored | ||
bad_booleans = full_data.index[full_data[boolean_columns].sum(axis=1) != 1] | ||
full_data.loc[bad_booleans, boolean_columns] = False | ||
full_data.loc[bad_booleans, "Fixed Tilt?"] = True | ||
|
||
full_data.index.name = "plant_id" # needed for next step but gets lost in the merge | ||
profiles = retrieve_data_individual( | ||
nrel_email, | ||
nrel_api_key, | ||
solar_plant=full_data, | ||
**solar_kwargs, | ||
) | ||
return profiles |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,19 @@ def to_dict(self): | |
) | ||
return result | ||
|
||
def to_sam_weather_file_format(self): | ||
"""Convert the data to the format expected by nrel-pysam for local files. See | ||
https://developer.nrel.gov/docs/solar/nsrdb/psm3-download/. | ||
:return: (*list*) -- a list of lists which can be passed to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically I think |
||
:meth:`csv.writer.writerows` and then loaded from disk. | ||
""" | ||
metadata_names = ["lat", "lon", "tz", "elevation"] | ||
metadata_values = self.lat, self.lon, self.tz, self.elevation | ||
data_headers = self.data_resource.columns.tolist() | ||
data_rows = self.data_resource.to_numpy().tolist() | ||
return [metadata_names, metadata_values, data_headers] + data_rows | ||
|
||
|
||
class NrelApi: | ||
"""Provides an interface to the NREL API for PSM3 data. It supports | ||
|
@@ -151,6 +164,10 @@ def get_psm3_at( | |
) | ||
def download(url): | ||
resp = requests.get(url) | ||
if resp.status_code // 100 == 5: # all 5xx errors, server side | ||
raise TransientError( | ||
f"Server side error, retry_count={download.retry_count}" | ||
) | ||
if resp.status_code == 429: | ||
raise TransientError( | ||
f"Too many requests, retry_count={download.retry_count}" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the user perspective, do we want to enable the user to generate the grid without generating the profiles? If so, we could add a flag input, and add default
None
values for the profile-specific input parameters.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, we may want the user to be able to create the full Grid CSVs, and then use these for multiple years. We could break
create_csvs
into a grid-step and a profiles step, or allow the user to pass a list of years to have everything handled automatically.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree it makes sense to be able to create the grid and profiles separately. Assuming this isn't something that would be used often, I might leave it at something like
create_grid
andcreate_profiles
, or makecreate_csvs
a wrapper around those if it's convenient.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. EDIT: The refactor has also been tested and behaves as expected when calling the
create_csvs
wrapper function.