Skip to content

add get_[relative_airmass,sky_diffuse,ground_diffuse,extra_radiation,total_irradiance] and pvlibDeprecationWarning #427

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 41 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2ae47ce
initial refactor
wholmgren Feb 13, 2018
4f3dce5
remove new fields from globalinplane wrapper
wholmgren Feb 13, 2018
360cc32
update test
wholmgren Feb 13, 2018
d50226a
update whatsnew
wholmgren Feb 13, 2018
555a15f
add DeprecationWarning
wholmgren Feb 13, 2018
07ec11c
update api.rst
wholmgren Feb 13, 2018
8b96876
add _deprecation.py module
wholmgren Feb 19, 2018
c715cf9
extraradiation to get_extra_radiation
wholmgren Feb 19, 2018
6abe7ad
grounddiffuse to get_ground_diffuse
wholmgren Feb 19, 2018
aaf4385
remove deprecated klutcher (misspelling) from get_sky_diffuse
wholmgren Feb 19, 2018
08f4c1f
total_irrad to get_total_poa_irradiance
wholmgren Feb 19, 2018
184e063
update api.rst
wholmgren Feb 19, 2018
ef1ce2f
change airmass function names
wholmgren Feb 23, 2018
e63938e
forgot to change get_extra_radiation in api.rst
wholmgren Feb 23, 2018
0406cf2
remove poa from new function names
wholmgren Apr 6, 2018
9da59db
no PVLIBDeprecationWarnings in tests
wholmgren Apr 7, 2018
09dc3e0
merge 0.5.2, move whatsnew updates
wholmgren May 13, 2018
4aab55f
update deprecation versions
wholmgren May 13, 2018
ba9090d
Merge branch 'master' into totalirrad
wholmgren May 25, 2018
cc99958
Merge branch 'master' into totalirrad
wholmgren Jun 13, 2018
db03032
fix bad merge of whatsnew
wholmgren Jun 13, 2018
85c4ad8
add fail_on_pvlib_version decorator
wholmgren Jun 14, 2018
5900c25
pep8
wholmgren Jun 14, 2018
bd73f29
rename warning, add test_conftest
wholmgren Jun 16, 2018
bd3d734
remove extra comments
wholmgren Jun 16, 2018
55e38e0
Merge branch 'master' into totalirrad
wholmgren Aug 6, 2018
866c9d0
fix broken test
wholmgren Aug 6, 2018
0326a6a
update get_total_irradiance arg names
wholmgren Aug 6, 2018
1353611
add test values, fix botched merges
wholmgren Aug 6, 2018
f5e2aec
Merge branch 'master' into totalirrad
wholmgren Aug 7, 2018
556badf
update to latest mpl code with minor mods
wholmgren Aug 8, 2018
185a8b8
remove missed kwarg only syntax
wholmgren Aug 8, 2018
fe079ea
absolute_airmass becomes get_absolute_airmass for consistency and fut…
wholmgren Aug 8, 2018
4c595ac
update extraradiation call in forecast.py
wholmgren Aug 9, 2018
9fef243
update docs to use new api
wholmgren Aug 9, 2018
2919176
update tutorials
wholmgren Aug 10, 2018
136e24b
appveyor config
wholmgren Aug 10, 2018
d18bfce
sprinkle plt.close to reduce memory on rtd
wholmgren Aug 10, 2018
94fbe69
Merge remote-tracking branch 'pvlib/master' into totalirrad
wholmgren Aug 10, 2018
258e32a
fix fail_on_pvlib_version
wholmgren Aug 10, 2018
73c4fc5
allow xpass on python2 and windows
wholmgren Aug 10, 2018
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
13 changes: 7 additions & 6 deletions docs/sphinx/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ Airmass and atmospheric models
:toctree: generated/

location.Location.get_airmass
atmosphere.absoluteairmass
atmosphere.relativeairmass
atmosphere.absolute_airmass
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

atmosphere.get_relative_airmass
atmosphere.pres2alt
atmosphere.alt2pres
atmosphere.gueymard94_pw
Expand Down Expand Up @@ -133,21 +133,22 @@ Decomposing and combining irradiance
.. autosummary::
:toctree: generated/

irradiance.extraradiation
irradiance.get_extra_radiation
irradiance.aoi
irradiance.aoi_projection
irradiance.poa_horizontal_ratio
irradiance.beam_component
irradiance.globalinplane
irradiance.grounddiffuse
irradiance.poa_components
irradiance.get_ground_diffuse

Transposition models
--------------------

.. autosummary::
:toctree: generated/

irradiance.total_irrad
irradiance.get_total_irradiance
irradiance.get_sky_diffuse
irradiance.isotropic
irradiance.perez
irradiance.haydavies
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member

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.

Expand Down
28 changes: 28 additions & 0 deletions docs/sphinx/source/whatsnew/v0.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ v0.6.0 (___, 2018)

API Changes
~~~~~~~~~~~
* pvlib python is changing a handful of function names. In general, functions
that can calculate a quantity using multiple algorithms now start
with the prefix ``get_``. For example, ``relativeairmass`` can calculate
airmass using one of many ``model`` arguments. Its name has been changed
to ``get_relative_airmass``. The old function names remain in this
release, but will emit a ``PVLibDeprecationWarning`` when called. The
old functions will be removed in the 0.7 release. Functions composed
of multiple words jammed together have been renamed with underscores
separating the words (see above).
Each change is detailed below. (:issue:`427`)
* Deprecated relativeairmass. relativeairmass will be removed in 0.7.
Use the new get_relative_airmass instead. (:issue:`427`)
* Deprecated absoluteairmass. absoluteairmass will be removed in 0.7.
Use the new absolute_airmass instead. (:issue:`427`)
* Deprecated irradiance.globalinplane. globalinplane will be removed in 0.7.
Use the new irradiance.poa_components instead. (:issue:`427`)
* Added irradiance.poa_components. Function is the same as the now-deprecated
irradiance.globalinplane, but adds 'poa_sky_diffuse' and
'poa_ground_diffuse' to the output. (:issue:`427`)
* Deprecated irradiance.extraradiation. Use irradiance.get_extra_radiation
instead. irradiance.extraradiation will be removed in 0.7. (:issue:`427`)
* Deprecated irradiance.grounddiffuse. Use irradiance.get_ground_diffuse
instead. irradiance.grounddiffuse will be removed in 0.7. (:issue:`427`)
* Added irradiance.get_poa_sky_diffuse. (:issue:`427`)
* Deprecated irradiance.total_irrad. Use irradiance.get_total_poa_irradiance
instead. irradiance.total_irrad will be removed in 0.7. (:issue:`427`)
* Removed 'klutcher' from get_sky_diffuse/total_irrad. This misspelling was
deprecated long ago but never removed. (:issue:`97`)
* pvsystem.calcparams_desoto now requires arguments for each module model
parameter. (:issue:`462`)
* Add losses_parameters attribute to PVSystem objects and remove the kwargs
Expand Down
318 changes: 318 additions & 0 deletions pvlib/_deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,318 @@
"""Matplotlib license for the deprecation module.

License agreement for matplotlib versions 1.3.0 and later
=========================================================

1. This LICENSE AGREEMENT is between the Matplotlib Development Team
("MDT"), and the Individual or Organization ("Licensee") accessing and
otherwise using matplotlib software in source or binary form and its
associated documentation.

2. Subject to the terms and conditions of this License Agreement, MDT
hereby grants Licensee a nonexclusive, royalty-free, world-wide license
to reproduce, analyze, test, perform and/or display publicly, prepare
derivative works, distribute, and otherwise use matplotlib
alone or in any derivative version, provided, however, that MDT's
License Agreement and MDT's notice of copyright, i.e., "Copyright (c)
2012- Matplotlib Development Team; All Rights Reserved" are retained in
matplotlib alone or in any derivative version prepared by
Licensee.

3. In the event Licensee prepares a derivative work that is based on or
incorporates matplotlib or any part thereof, and wants to
make the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to matplotlib .

4. MDT is making matplotlib available to Licensee on an "AS
IS" basis. MDT MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, MDT MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB
WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.

5. MDT SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING
MATPLOTLIB , OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
THE POSSIBILITY THEREOF.

6. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.

7. Nothing in this License Agreement shall be deemed to create any
relationship of agency, partnership, or joint venture between MDT and
Licensee. This License Agreement does not grant permission to use MDT
trademarks or trade name in a trademark sense to endorse or promote
products or services of Licensee, or any third party.

8. By copying, installing or otherwise using matplotlib ,
Licensee agrees to be bound by the terms and conditions of this License
Agreement.

License agreement for matplotlib versions prior to 1.3.0
========================================================

1. This LICENSE AGREEMENT is between John D. Hunter ("JDH"), and the
Individual or Organization ("Licensee") accessing and otherwise using
matplotlib software in source or binary form and its associated
documentation.

2. Subject to the terms and conditions of this License Agreement, JDH
hereby grants Licensee a nonexclusive, royalty-free, world-wide license
to reproduce, analyze, test, perform and/or display publicly, prepare
derivative works, distribute, and otherwise use matplotlib
alone or in any derivative version, provided, however, that JDH's
License Agreement and JDH's notice of copyright, i.e., "Copyright (c)
2002-2011 John D. Hunter; All Rights Reserved" are retained in
matplotlib alone or in any derivative version prepared by
Licensee.

3. In the event Licensee prepares a derivative work that is based on or
incorporates matplotlib or any part thereof, and wants to
make the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to matplotlib.

4. JDH is making matplotlib available to Licensee on an "AS
IS" basis. JDH MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, JDH MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB
WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.

5. JDH SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING
MATPLOTLIB , OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
THE POSSIBILITY THEREOF.

6. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.

7. Nothing in this License Agreement shall be deemed to create any
relationship of agency, partnership, or joint venture between JDH and
Licensee. This License Agreement does not grant permission to use JDH
trademarks or trade name in a trademark sense to endorse or promote
products or services of Licensee, or any third party.

8. By copying, installing or otherwise using matplotlib,
Licensee agrees to be bound by the terms and conditions of this License
Agreement.
"""

# modified from Matplotlib b97cd2d (post 2.2.2) in the following ways:
# 1. use module-level _projectName = 'pvlib' and
# _projectWarning = 'pvlibDeprecationWarning' in place of MPL specific
# string/Class.
# 2. remove keyword only argument requirement for removal
# 3. remove deprecated obj_type from deprecated function
# 4. if removal is empty, say 'soon' instead of assuming two minor releases
# later.

import functools
import textwrap
import warnings


class pvlibDeprecationWarning(UserWarning):
"""A class for issuing deprecation warnings for pvlib users.

In light of the fact that Python builtin DeprecationWarnings are ignored
by default as of Python 2.7 (see link below), this class was put in to
allow for the signaling of deprecation, but via UserWarnings which are not
ignored by default.

https://docs.python.org/dev/whatsnew/2.7.html#the-future-for-python-2-x
"""

pass


# make it easier for others to copy paste this code into their projects
_projectName = 'pvlib'
_projectWarning = pvlibDeprecationWarning


def _generate_deprecation_message(
since, message='', name='', alternative='', pending=False,
obj_type='attribute', addendum='', removal=''):

if removal == "":
removal = "soon"
elif removal:
if pending:
raise ValueError(
"A pending deprecation cannot have a scheduled removal")
removal = "in {}".format(removal)

if not message:
message = (
"The %(name)s %(obj_type)s"
+ (" will be deprecated in a future version"
if pending else
(" was deprecated in %(projectName)s %(since)s"
+ (" and will be removed %(removal)s"
if removal else
"")))
+ "."
+ (" Use %(alternative)s instead." if alternative else "")
+ (" %(addendum)s" if addendum else ""))

return message % dict(
func=name, name=name, obj_type=obj_type, since=since, removal=removal,
alternative=alternative, addendum=addendum, projectName=_projectName)


def warn_deprecated(
since, message='', name='', alternative='', pending=False,
obj_type='attribute', addendum='', removal=''):
"""
Used to display deprecation in a standard way.
Parameters
----------
since : str
The release at which this API became deprecated.
message : str, optional
Override the default deprecation message. The format
specifier `%(name)s` may be used for the name of the function,
and `%(alternative)s` may be used in the deprecation message
to insert the name of an alternative to the deprecated
function. `%(obj_type)s` may be used to insert a friendly name
for the type of object being deprecated.
name : str, optional
The name of the deprecated object.
alternative : str, optional
An alternative API that the user may use in place of the deprecated
API. The deprecation warning will tell the user about this alternative
if provided.
pending : bool, optional
If True, uses a PendingDeprecationWarning instead of a
DeprecationWarning. Cannot be used together with *removal*.
removal : str, optional
The expected removal version. With the default (an empty string), a
removal version is automatically computed from *since*. Set to other
Falsy values to not schedule a removal date. Cannot be used together
with *pending*.
obj_type : str, optional
The object type being deprecated.
addendum : str, optional
Additional text appended directly to the final message.
Examples
--------
Basic example::
# To warn of the deprecation of "matplotlib.name_of_module"
warn_deprecated('1.4.0', name='matplotlib.name_of_module',
obj_type='module')
"""
message = '\n' + _generate_deprecation_message(
since, message, name, alternative, pending, obj_type, addendum,
removal=removal)
category = (PendingDeprecationWarning if pending
else _projectWarning)
warnings.warn(message, category, stacklevel=2)


def deprecated(since, message='', name='', alternative='', pending=False,
addendum='', removal=''):
"""
Decorator to mark a function or a class as deprecated.
Parameters
----------
since : str
The release at which this API became deprecated. This is
required.
message : str, optional
Override the default deprecation message. The format
specifier `%(name)s` may be used for the name of the object,
and `%(alternative)s` may be used in the deprecation message
to insert the name of an alternative to the deprecated
object.
name : str, optional
The name of the deprecated object; if not provided the name
is automatically determined from the passed in object,
though this is useful in the case of renamed functions, where
the new function is just assigned to the name of the
deprecated function. For example::
def new_function():
...
oldFunction = new_function
alternative : str, optional
An alternative API that the user may use in place of the deprecated
API. The deprecation warning will tell the user about this alternative
if provided.
pending : bool, optional
If True, uses a PendingDeprecationWarning instead of a
DeprecationWarning. Cannot be used together with *removal*.
removal : str, optional
The expected removal version. With the default (an empty string), a
removal version is automatically computed from *since*. Set to other
Falsy values to not schedule a removal date. Cannot be used together
with *pending*.
addendum : str, optional
Additional text appended directly to the final message.
Examples
--------
Basic example::
@deprecated('1.4.0')
def the_function_to_deprecate():
pass
"""

def deprecate(obj, message=message, name=name, alternative=alternative,
pending=pending, addendum=addendum):

if not name:
name = obj.__name__

if isinstance(obj, type):
obj_type = "class"
old_doc = obj.__doc__
func = obj.__init__

def finalize(wrapper, new_doc):
obj.__doc__ = new_doc
obj.__init__ = wrapper
return obj
else:
obj_type = "function"
if isinstance(obj, classmethod):
func = obj.__func__
old_doc = func.__doc__

def finalize(wrapper, new_doc):
wrapper = functools.wraps(func)(wrapper)
wrapper.__doc__ = new_doc
return classmethod(wrapper)
else:
func = obj
old_doc = func.__doc__

def finalize(wrapper, new_doc):
wrapper = functools.wraps(func)(wrapper)
wrapper.__doc__ = new_doc
return wrapper

message = _generate_deprecation_message(
since, message, name, alternative, pending, obj_type, addendum,
removal=removal)
category = (PendingDeprecationWarning if pending
else _projectWarning)

def wrapper(*args, **kwargs):
warnings.warn(message, category, stacklevel=2)
return func(*args, **kwargs)

old_doc = textwrap.dedent(old_doc or '').strip('\n')
message = message.strip()
new_doc = (('\n.. deprecated:: %(since)s'
'\n %(message)s\n\n' %
{'since': since, 'message': message}) + old_doc)
if not old_doc:
# This is to prevent a spurious 'unexected unindent' warning from
# docutils when the original docstring was blank.
new_doc += r'\ '

return finalize(wrapper, new_doc)

return deprecate
Loading