-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ENH: Create psm3.py #694
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
ENH: Create psm3.py #694
Changes from 1 commit
e0859f7
6535a04
f7003ac
15f93d3
4c8c073
2b9cff5
c52d5b7
2809897
6cf57a4
05cf879
13c196a
02c143f
64d7cb9
f9df42d
b6f79cf
8884c7f
1935215
24c1f3b
4059db5
f12c36b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
* in raise docstring, change "returns" to "raises", and clarify that either r.json()['errors'] or r.content is the exception arg depending on the type of HTTP error, and give examples * add warning in docstring that data are limited to NSRDB locations * comment on WKT formatting and add TODO to consider making a format_WKT() function in tools.py one day * add response kwarg to HTTPError for better user exception handling * in test_psm3 add comments to clarify the tests for errors and add two more test for bad "names" and interval args
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,13 @@ | |
'Temperature Units', 'Pressure Units', 'Wind Direction Units', | ||
'Wind Speed', 'Surface Albedo Units', 'Version'] | ||
PVLIB_EMAIL = 'pvlib-admin@googlegroups.com' | ||
DEMO_KEY = 'DEMO_KEY' | ||
|
||
|
||
@needs_pandas_0_22 | ||
def test_get_psm3(): | ||
"""test get_psm3""" | ||
header, data = psm3.get_psm3(LATITUDE, LONGITUDE, 'DEMO_KEY', PVLIB_EMAIL) | ||
header, data = psm3.get_psm3(LATITUDE, LONGITUDE, DEMO_KEY, PVLIB_EMAIL) | ||
expected = pd.read_csv(TEST_DATA) | ||
# check datevec columns | ||
assert np.allclose(data.Year, expected.Year) | ||
|
@@ -52,6 +53,14 @@ def test_get_psm3(): | |
assert (data.index.tzinfo.zone == 'Etc/GMT%+d' % -header['Time Zone']) | ||
# check errors | ||
with pytest.raises(HTTPError): | ||
# HTTP 403 forbidden because api_key is rejected | ||
psm3.get_psm3(LATITUDE, LONGITUDE, api_key='BAD', email=PVLIB_EMAIL) | ||
with pytest.raises(HTTPError): | ||
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. why does this one fail? 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.
perhaps I should add some more comments here to explain these tests - like I did here - for future devs? 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. BAD was self explanatory. I don't think we need to test that it fails outside the US. Not our problem. 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. PSM3 has data in a lat/long rectangle around the lower 48 states, so there's coverage in northern Mexico for example. But it has a coastline filter and excludes data in the Gulf of Mexico. I think we should test for failure at lat/long where PSM3 does not have data. 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. Does PSM3 return a sensible error if lat/lon outside of its area? 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.
Returns
The first line is what I expect, the next 2 are json decoding errors that puzzle me. 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. Aha, I suspect the 2nd and 3rd messages are empty responses because of the once-per-2second throttle, so Confirmed. 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.
This could be confusing to pvlib users because we're asking the to specify lat/lon instead of API. So I'm ok with catching this in the function and raising a more descriptive error about lat/lon. |
||
psm3.get_psm3(51, -5, 'DEMO_KEY', PVLIB_EMAIL) | ||
# coordinates were not found in the NSRDB | ||
psm3.get_psm3(51, -5, DEMO_KEY, PVLIB_EMAIL) | ||
with pytest.raises(HTTPError): | ||
# names is not one of the available options | ||
psm3.get_psm3(LATITUDE, LONGITUDE, DEMO_KEY, PVLIB_EMAIL, names='bad') | ||
with pytest.raises(HTTPError): | ||
# intervals can only be 30 or 60 minutes | ||
psm3.get_psm3(LATITUDE, LONGITUDE, DEMO_KEY, PVLIB_EMAIL, interval=15) |
Uh oh!
There was an error while loading. Please reload this page.