-
Notifications
You must be signed in to change notification settings - Fork 999
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
add get_[relative_airmass,sky_diffuse,ground_diffuse,extra_radiation,total_irradiance] and pvlibDeprecationWarning #427
Conversation
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.
I'm not very familiar with this code, but I had a few comments/suggestions.
docs/sphinx/source/api.rst
Outdated
@@ -138,7 +138,7 @@ Decomposing and combining irradiance | |||
irradiance.aoi_projection | |||
irradiance.poa_horizontal_ratio | |||
irradiance.beam_component | |||
irradiance.globalinplane | |||
irradiance.poa_components | |||
irradiance.grounddiffuse |
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.
Is this a good opportunity to make naming more consistent, such as irradiance.extra_radiation
and irradiance.ground_diffuse
?
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.
Sure. Probably a good idea to make all API changes to a module at once.
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.
How about the pattern of get_extraterrestrial and get_ground_diffuse as the wrapper, and ground_diffuse_isotropic as our one and only wrapped function? That's what I'm suggesting for sky_diffuse models. I can see the same pattern working for get_clearsky (kwarg to specify the clearsky model), get_airmass, get_iam, etc.
Many function names were simply carried over from Matlab where we wrote a library, not an object-organized package.
docs/sphinx/source/api.rst
Outdated
@@ -148,6 +148,7 @@ Transposition models | |||
:toctree: generated/ | |||
|
|||
irradiance.total_irrad | |||
irradiance.get_sky_diffuse | |||
irradiance.isotropic | |||
irradiance.perez | |||
irradiance.haydavies |
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.
Perhaps naming consistency is better here. Only one function has get_
prefix.
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.
In this module, yes, but we use get_
for a few other "wrapper" functions/methods in solarposition.py
, location.py
, and pvsystem.py
. I am torn on this.
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.
I'm not in favor of 'get_isotropic', an exception to my preference for verb prefixes. isotropic, perez, haydavies are named models. If we want to extend the function name, I'd use a category prefix, i.e., sky_diffuse_isotropic, sky_diffuse_perez, etc., and have get_sky_diffuse wrap all of them with a kwarg.
pvlib/test/test_irradiance.py
Outdated
@@ -260,8 +260,7 @@ def test_globalinplane(): | |||
40, 180, irrad_data['dhi'], irrad_data['dni'], dni_et, | |||
ephem_data['apparent_zenith'], ephem_data['azimuth'], airmass) | |||
irradiance.globalinplane( | |||
aoi=aoi, dni=irrad_data['dni'], poa_sky_diffuse=diff_perez, | |||
poa_ground_diffuse=gr_sand) | |||
aoi, irrad_data['dni'], diff_perez, gr_sand) |
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.
Does this test essentially check that poa_components()
executes without exception?
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.
Correct. I only changed this test because I changed the globalinplane
function signature to *args
so that it could be a direct pass through to poa_components
. No one ever bothered to add numeric assertions to this test.
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.
Is there an issue for test improvement that we could put in a comment here?
Here are some variations of @cwhanse and @thunderfish24 API suggestions. I implemented
Summary in code form: In [1]: from pvlib import irradiance
In [2]: irradiance.extraradiation(1)
/Users/holmgren/miniconda3/envs/pvlib36/bin/ipython:1: PVLibDeprecationWarning: The extraradiation function was deprecated in version 0.5.2. Use get_extra_radiation instead.
#!/Users/holmgren/miniconda3/envs/pvlib36/bin/python
Out[2]: 1413.981805
In [3]: irradiance.get_extra_radiation(1)
Out[3]: 1413.981805
In [4]: irradiance.grounddiffuse(30, 100)
/Users/holmgren/miniconda3/envs/pvlib36/bin/ipython:1: PVLibDeprecationWarning: The grounddiffuse function was deprecated in version 0.5.2. Use get_poa_ground_diffuse instead.
#!/Users/holmgren/miniconda3/envs/pvlib36/bin/python
Out[4]: 1.674682452694516
In [5]: irradiance.get_poa_ground_diffuse(30, 100)
Out[5]: 1.674682452694516
In [6]: irradiance.globalinplane(0, 0, 0, 0)
/Users/holmgren/miniconda3/envs/pvlib36/bin/ipython:1: PVLibDeprecationWarning: The globalinplane function was deprecated in version 0.5.2. Use poa_components instead. This function will be removed in 0.6
#!/Users/holmgren/miniconda3/envs/pvlib36/bin/python
Out[6]: OrderedDict([('poa_global', 0.0), ('poa_direct', 0.0), ('poa_diffuse', 0)])
In [7]: irradiance.poa_components(0, 0, 0, 0)
Out[7]:
OrderedDict([('poa_global', 0.0),
('poa_direct', 0.0),
('poa_diffuse', 0),
('poa_sky_diffuse', 0),
('poa_ground_diffuse', 0)])
In [8]: irradiance.total_irrad(30, 180, 60, 180, 1000, 800, 200)
/Users/holmgren/miniconda3/envs/pvlib36/bin/ipython:1: PVLibDeprecationWarning: The total_irrad function was deprecated in version 0.5.2. Use get_total_poa_irradiance instead.
#!/Users/holmgren/miniconda3/envs/pvlib36/bin/python
Out[8]:
OrderedDict([('poa_global', 1066.0254037844388),
('poa_direct', 866.0254037844387),
('poa_diffuse', 200.0),
('poa_sky_diffuse', 186.60254037844388),
('poa_ground_diffuse', 13.397459621556129)])
In [9]: irradiance.get_total_poa_irradiance(30, 180, 60, 180, 1000, 800, 200)
Out[9]:
OrderedDict([('poa_global', 1066.0254037844388),
('poa_direct', 866.0254037844387),
('poa_diffuse', 200.0),
('poa_sky_diffuse', 186.60254037844388),
('poa_ground_diffuse', 13.397459621556129)]) Note that I added matplotlib's deprecation machinery to avoid copy/paste and lots of manual warnings. Credit to Unidata/MetPy#519 for the idea. It looks like AstroPy also uses a version of the matplotlib deprecation machinery. scikit-learn does something similar, but with different code. I don't know if there's a preferred way, but this works reasonably well. Thoughts? edited because I botched the MetPy issue number. |
It might also make sense to change |
I think the 'poa' is not necessary in these function names, since one can pass tilt=0.
Both make sense to me. |
Good point. I removed poa from the function names. I also changed the airmass function names as proposed. I'm building the new API docs here To do:
|
I've decided that we should wait on this for an 0.6 release. It seems a little rude to make pvlib spit out a bunch of new warnings when people make a minor update to the package. The old functions would then be removed in the 0.7 release. We can adjust other issues to 0.7 or 0.8 get the changes out faster. |
Need to look into this more detail, but maybe the |
@mikofski do you have suggestions/thoughts on deriving a pvlib warning from |
@wholmgren I hadn't realized the distinction between future and deprecation or pending deprecation warnings until now. TL;DR:According to my read of the PEP and Python Warnings docs, I think we should use more detailSince PVLib is more like a developer toolbox, and less likely to be consumed by another application, it seems appropriate to issue verbose warnings. I think until Python-3.7 becomes more widespread, most users with Python-3.6 won't see deprecation or pending deprecation warnings unless they have turned warning filters off. If PEP-565 is backported to Python-3.6 then we can reconsider. I also think we need guidelines in the contributor documentation that establish our procedures and some terms such as:
Pandas seems like a similar toolbox to PVLib, so I looked at it to see their MO. AFAICT: they seem to take the view that when new features will deprecate old ones, there are 3 stages:
PandasI searched through the Pandas codebase and documents and here's my guess:
Pandas provides decorators to deprecated functions and kwargs which defaults to |
Thank you for the detailed review @mikofski! This is very helpful. Let's go with a warning inherited from Let's discuss the other questions in a separate issue and documentation PR. |
This PR has gone on for so long that I've forgotten where I started... It turns out that the deprecation code I copied from Matplotlib/Metpy uses |
docs/sphinx/source/api.rst
Outdated
@@ -102,8 +102,8 @@ Airmass and atmospheric models | |||
:toctree: generated/ | |||
|
|||
location.Location.get_airmass | |||
atmosphere.absoluteairmass | |||
atmosphere.relativeairmass | |||
atmosphere.absolute_airmass |
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.
At the risk of prolonging the PR unnecessarily, why not get_absolute_airmass
here?
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.
pvlib only includes one absolute airmass model so it didn't occur to me to add get_
here. I'm fine with either approach at this point.
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.
I see your point. It may help when someone is trying to find the relevant function, to keep names parallel. There are other models for absolute air mass which we haven't implement.
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.
Changed.
This PR probably makes a mess of the notebook tutorials and documentation. Probably best to fix them before merging. |
I think this is finally ready to merge. I updated the code in the sphinx documentation and the tutorials to use the new functions. Rendered documentation here and tutorials here. Minor related documentation changes... added The appveyor/windows python 2.7 test configurations were failing on a test of a new deprecation test decorator. The same test passed on travis python 2.7 and earlier in this PR it also passed on appveyor (with nothing relevant to it changed since then). I modified the test to allow it to fail on windows on python 2.7. |
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.
This is a massive overhaul, it LGTM, altho I had to get out my glasses bc I reviewed it on my phone
git diff upstream/master -u -- "*.py" | flake8 --diff
and/or landscape.io linting service.docs/sphinx/source/api.rst
for API changes.docs/sphinx/source/whatsnew
file for all changes.This PR implements the refactoring discussed in #422.
I added a deprecation warning to globalinplane.
We could go ahead and change the name of total_irrad in this PR, but that would require changes to a few other parts of the library that I wasn't yet ready to commit to. If we do change it, we'd keep the old name until 0.6 and add a deprecation warning in the mean time (like I did for globalinplane).
Everything here is open for discussion.