Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/sphinx/source/whatsnew/v0.9.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Bug fixes
where passing localized timezones with large UTC offsets could return
rise/set/transit times for the wrong day in recent versions of ``ephem``
(:issue:`1449`, :pull:`1448`)
* :py:func:`pvlib.iotools.get_psm3` now raises a deprecation warning for
single-year requests where the `leap_day` parameter is not specified.
Starting in pvlib 0.11.0 `leap_day` will default to True instead of False.
(:issue:`1481`, :pull:`1511`)


Testing
Expand Down
10 changes: 9 additions & 1 deletion pvlib/iotools/psm3.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@


def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60,
attributes=ATTRIBUTES, leap_day=False, full_name=PVLIB_PYTHON,
attributes=ATTRIBUTES, leap_day=None, full_name=PVLIB_PYTHON,
affiliation=PVLIB_PYTHON, map_variables=None, timeout=30):
"""
Retrieve NSRDB PSM3 timeseries weather data from the PSM3 API. The NSRDB
Expand Down Expand Up @@ -165,6 +165,14 @@ def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60,
attributes = [amap.get(a, a) for a in attributes]
attributes = list(set(attributes)) # remove duplicate values

if (leap_day is None) and (not names.startswith('t')):
warnings.warn(
'The ``get_psm3`` function will default to leap_day=True '
'starting in pvlib 0.11.0. Specify leap_day=True '
'to enable this behavior now, or specify leap_day=False '
'to hide this warning.', pvlibDeprecationWarning)
leap_day = False

# required query-string parameters for request to PSM3 API
params = {
'api_key': api_key,
Expand Down
23 changes: 18 additions & 5 deletions pvlib/tests/iotools/test_psm3.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_get_psm3_tmy(nrel_api_key):
"""test get_psm3 with a TMY"""
data, metadata = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key,
PVLIB_EMAIL, names='tmy-2017',
map_variables=False)
leap_day=False, map_variables=False)
expected = pd.read_csv(TMY_TEST_DATA)
assert_psm3_equal(data, metadata, expected)

Expand All @@ -89,7 +89,8 @@ def test_get_psm3_singleyear(nrel_api_key):
"""test get_psm3 with a single year"""
data, metadata = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key,
PVLIB_EMAIL, names='2017',
map_variables=False, interval=30)
leap_day=False, map_variables=False,
interval=30)
expected = pd.read_csv(YEAR_TEST_DATA)
assert_psm3_equal(data, metadata, expected)

Expand All @@ -100,7 +101,7 @@ def test_get_psm3_5min(nrel_api_key):
"""test get_psm3 for 5-minute data"""
data, metadata = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key,
PVLIB_EMAIL, names='2019', interval=5,
map_variables=False)
leap_day=False, map_variables=False)
assert len(data) == 525600/5
first_day = data.loc['2019-01-01']
expected = pd.read_csv(YEAR_TEST_DATA_5MIN)
Expand Down Expand Up @@ -137,7 +138,8 @@ def test_get_psm3_tmy_errors(
"""
with pytest.raises(HTTPError) as excinfo:
psm3.get_psm3(latitude, longitude, api_key, PVLIB_EMAIL,
names=names, interval=interval, map_variables=False)
names=names, interval=interval, leap_day=False,
map_variables=False)
# ensure the HTTPError caught isn't due to overuse of the API key
assert "OVER_RATE_LIMIT" not in str(excinfo.value)

Expand Down Expand Up @@ -186,7 +188,7 @@ def test_get_psm3_attribute_mapping(nrel_api_key):
data, meta = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL,
names=2019, interval=60,
attributes=['ghi', 'wind_speed'],
map_variables=True)
leap_day=False, map_variables=True)
assert 'ghi' in data.columns
assert 'wind_speed' in data.columns
assert 'latitude' in meta.keys()
Expand All @@ -199,3 +201,14 @@ def test_get_psm3_attribute_mapping(nrel_api_key):
def test_psm3_variable_map_deprecation_warning(nrel_api_key):
with pytest.warns(pvlibDeprecationWarning, match='names will be renamed'):
_ = psm3.read_psm3(MANUAL_TEST_DATA)


@pytest.mark.remote_data
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
def test_psm3_leap_day_deprecation_warning(nrel_api_key):
with pytest.warns(pvlibDeprecationWarning,
match='default to leap_day=True'):
_, _ = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL,
names=2019, interval=60,
attributes=['ghi', 'wind_speed'],
map_variables=True)