-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Deprecate parse_psm3
and parse_cams
#2458
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7b49520
deprecate parse_psm3
kandersolar 35ca540
deprecate parse_cams
kandersolar 62ca90e
whatsnew
kandersolar 02b1137
lint
kandersolar 1e88527
Update docs/sphinx/source/whatsnew/v0.12.1.rst
kandersolar 53da1a6
Merge branch 'main' into deprecate-parse
kandersolar ac14607
lint
kandersolar 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 hidden or 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 hidden or 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 | ||
---|---|---|---|---|
|
@@ -7,8 +7,8 @@ | |||
import requests | ||||
import pandas as pd | ||||
from json import JSONDecodeError | ||||
import warnings | ||||
from pvlib._deprecation import pvlibDeprecationWarning | ||||
from pvlib._deprecation import deprecated | ||||
from pvlib import tools | ||||
|
||||
NSRDB_API_BASE = "https://developer.nrel.gov" | ||||
PSM_URL = NSRDB_API_BASE + "/api/nsrdb/v2/solar/psm3-2-2-download.csv" | ||||
|
@@ -127,7 +127,7 @@ def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60, | |||
timeseries data from NREL PSM3 | ||||
metadata : dict | ||||
metadata from NREL PSM3 about the record, see | ||||
:func:`pvlib.iotools.parse_psm3` for fields | ||||
:func:`pvlib.iotools.read_psm3` for fields | ||||
|
||||
Raises | ||||
------ | ||||
|
@@ -152,7 +152,7 @@ def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60, | |||
|
||||
See Also | ||||
-------- | ||||
pvlib.iotools.read_psm3, pvlib.iotools.parse_psm3 | ||||
pvlib.iotools.read_psm3 | ||||
|
||||
References | ||||
---------- | ||||
|
@@ -216,12 +216,12 @@ def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60, | |||
# the CSV is in the response content as a UTF-8 bytestring | ||||
# to use pandas we need to create a file buffer from the response | ||||
fbuf = io.StringIO(response.content.decode('utf-8')) | ||||
return parse_psm3(fbuf, map_variables) | ||||
return read_psm3(fbuf, map_variables) | ||||
|
||||
|
||||
def parse_psm3(fbuf, map_variables=True): | ||||
def read_psm3(filename, map_variables=True): | ||||
""" | ||||
Parse an NSRDB PSM3 weather file (formatted as SAM CSV). The NSRDB | ||||
Read an NSRDB PSM3 weather file (formatted as SAM CSV). The NSRDB | ||||
is described in [1]_ and the SAM CSV format is described in [2]_. | ||||
|
||||
.. versionchanged:: 0.9.0 | ||||
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.
Suggested change
May be time to clean-up this admonition 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. +1, but I suggest we do it as part of a wider survey of old |
||||
|
@@ -231,8 +231,8 @@ def parse_psm3(fbuf, map_variables=True): | |||
|
||||
Parameters | ||||
---------- | ||||
fbuf: file-like object | ||||
File-like object containing data to read. | ||||
filename: str, path-like, or buffer | ||||
Filename or in-memory buffer of a file containing data to read. | ||||
map_variables: bool, default True | ||||
When true, renames columns of the Dataframe to pvlib variable names | ||||
where applicable. See variable :const:`VARIABLE_MAP`. | ||||
|
@@ -302,12 +302,15 @@ def parse_psm3(fbuf, map_variables=True): | |||
Examples | ||||
-------- | ||||
>>> # Read a local PSM3 file: | ||||
>>> df, metadata = iotools.read_psm3("data.csv") # doctest: +SKIP | ||||
|
||||
>>> # Read a file object or an in-memory buffer: | ||||
>>> with open(filename, 'r') as f: # doctest: +SKIP | ||||
... df, metadata = iotools.parse_psm3(f) # doctest: +SKIP | ||||
... df, metadata = iotools.read_psm3(f) # doctest: +SKIP | ||||
|
||||
See Also | ||||
-------- | ||||
pvlib.iotools.read_psm3, pvlib.iotools.get_psm3 | ||||
pvlib.iotools.get_psm3 | ||||
|
||||
References | ||||
---------- | ||||
|
@@ -316,34 +319,35 @@ def parse_psm3(fbuf, map_variables=True): | |||
.. [2] `Standard Time Series Data File Format | ||||
<https://web.archive.org/web/20170207203107/https://sam.nrel.gov/sites/default/files/content/documents/pdf/wfcsv.pdf>`_ | ||||
""" | ||||
# The first 2 lines of the response are headers with metadata | ||||
metadata_fields = fbuf.readline().split(',') | ||||
metadata_fields[-1] = metadata_fields[-1].strip() # strip trailing newline | ||||
metadata_values = fbuf.readline().split(',') | ||||
metadata_values[-1] = metadata_values[-1].strip() # strip trailing newline | ||||
with tools._file_context_manager(filename) as fbuf: | ||||
# The first 2 lines of the response are headers with metadata | ||||
metadata_fields = fbuf.readline().split(',') | ||||
metadata_values = fbuf.readline().split(',') | ||||
# get the column names so we can set the dtypes | ||||
columns = fbuf.readline().split(',') | ||||
columns[-1] = columns[-1].strip() # strip trailing newline | ||||
# Since the header has so many columns, excel saves blank cols in the | ||||
# data below the header lines. | ||||
columns = [col for col in columns if col != ''] | ||||
dtypes = dict.fromkeys(columns, float) # all floats except datevec | ||||
dtypes.update({'Year': int, 'Month': int, 'Day': int, 'Hour': int, | ||||
'Minute': int, 'Cloud Type': int, 'Fill Flag': int}) | ||||
data = pd.read_csv( | ||||
fbuf, header=None, names=columns, usecols=columns, dtype=dtypes, | ||||
delimiter=',', lineterminator='\n') # skip carriage returns \r | ||||
|
||||
metadata_fields[-1] = metadata_fields[-1].strip() # trailing newline | ||||
metadata_values[-1] = metadata_values[-1].strip() # trailing newline | ||||
metadata = dict(zip(metadata_fields, metadata_values)) | ||||
# the response is all strings, so set some metadata types to numbers | ||||
metadata['Local Time Zone'] = int(metadata['Local Time Zone']) | ||||
metadata['Time Zone'] = int(metadata['Time Zone']) | ||||
metadata['Latitude'] = float(metadata['Latitude']) | ||||
metadata['Longitude'] = float(metadata['Longitude']) | ||||
metadata['Elevation'] = int(metadata['Elevation']) | ||||
# get the column names so we can set the dtypes | ||||
columns = fbuf.readline().split(',') | ||||
columns[-1] = columns[-1].strip() # strip trailing newline | ||||
# Since the header has so many columns, excel saves blank cols in the | ||||
# data below the header lines. | ||||
columns = [col for col in columns if col != ''] | ||||
dtypes = dict.fromkeys(columns, float) # all floats except datevec | ||||
dtypes.update(Year=int, Month=int, Day=int, Hour=int, Minute=int) | ||||
dtypes['Cloud Type'] = int | ||||
dtypes['Fill Flag'] = int | ||||
data = pd.read_csv( | ||||
fbuf, header=None, names=columns, usecols=columns, dtype=dtypes, | ||||
delimiter=',', lineterminator='\n') # skip carriage returns \r | ||||
|
||||
# the response 1st 5 columns are a date vector, convert to datetime | ||||
dtidx = pd.to_datetime( | ||||
data[['Year', 'Month', 'Day', 'Hour', 'Minute']]) | ||||
dtidx = pd.to_datetime(data[['Year', 'Month', 'Day', 'Hour', 'Minute']]) | ||||
# in USA all timezones are integers | ||||
tz = 'Etc/GMT%+d' % -metadata['Time Zone'] | ||||
data.index = pd.DatetimeIndex(dtidx).tz_localize(tz) | ||||
|
@@ -357,43 +361,5 @@ def parse_psm3(fbuf, map_variables=True): | |||
return data, metadata | ||||
|
||||
|
||||
def read_psm3(filename, map_variables=True): | ||||
""" | ||||
Read an NSRDB PSM3 weather file (formatted as SAM CSV). The NSRDB | ||||
is described in [1]_ and the SAM CSV format is described in [2]_. | ||||
|
||||
.. versionchanged:: 0.9.0 | ||||
The function now returns a tuple where the first element is a dataframe | ||||
and the second element is a dictionary containing metadata. Previous | ||||
versions of this function had the return values switched. | ||||
|
||||
Parameters | ||||
---------- | ||||
filename: str | ||||
Filename of a file containing data to read. | ||||
map_variables: bool, default True | ||||
When true, renames columns of the Dataframe to pvlib variable names | ||||
where applicable. See variable :const:`VARIABLE_MAP`. | ||||
|
||||
Returns | ||||
------- | ||||
data : pandas.DataFrame | ||||
timeseries data from NREL PSM3 | ||||
metadata : dict | ||||
metadata from NREL PSM3 about the record, see | ||||
:func:`pvlib.iotools.parse_psm3` for fields | ||||
|
||||
See Also | ||||
-------- | ||||
pvlib.iotools.parse_psm3, pvlib.iotools.get_psm3 | ||||
|
||||
References | ||||
---------- | ||||
.. [1] `NREL National Solar Radiation Database (NSRDB) | ||||
<https://nsrdb.nrel.gov/>`_ | ||||
.. [2] `Standard Time Series Data File Format | ||||
<https://web.archive.org/web/20170207203107/https://sam.nrel.gov/sites/default/files/content/documents/pdf/wfcsv.pdf>`_ | ||||
""" | ||||
with open(str(filename), 'r') as fbuf: | ||||
content = parse_psm3(fbuf, map_variables) | ||||
return content | ||||
parse_psm3 = deprecated(since="0.12.1", name="parse_psm3", | ||||
alternative="read_psm3")(read_psm3) |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.