Skip to content

ENH: add methods and tests for a explicit IV curve calculation of single-diode model #409

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 76 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
22d2e5c
add methods and tests for a faster way to calculate single-diode model
mikofski Jan 27, 2018
bb7c49a
log estimate of speedup in test
mikofski Jan 27, 2018
36d4f78
use ordered dict for output, match inputs and outputs, add iv-curve
mikofski Jan 27, 2018
817a303
add "slow" but reliable ways to calculate i_from_v and vv
mikofski Jan 28, 2018
b17a8cd
add check for numerical errors
mikofski Jan 30, 2018
0666d29
use float64, output symbols for fun, make executable
mikofski Jan 30, 2018
595e254
add tests for slower_way using fminbound
mikofski Jan 30, 2018
5ade588
change voc to v_oc
mikofski Jan 30, 2018
7179096
add numeric type to args in docstrings
mikofski Jan 30, 2018
4b66f87
replace custom newton method with scipy.optimize.newton
mikofski Jan 31, 2018
664d7d8
get lambdas working in fast_i_from_v
mikofski Jan 31, 2018
09a9e14
add fast_v_from_i using newton
mikofski Jan 31, 2018
06be522
add fast_mppt
mikofski Jan 31, 2018
1aba56a
calculate i_x and i_xx too for both fast and slow
mikofski Jan 31, 2018
f09be91
test i_x and i_xx too
mikofski Jan 31, 2018
4905363
use brentq instead of fminbound
mikofski Jan 31, 2018
a3d2bb4
change test for numerical errors to use data file
mikofski Jan 31, 2018
8ee1b94
working on #410
mikofski Jan 31, 2018
c9a893a
helping test_singlediode pass tests
mikofski Jan 31, 2018
c5248bb
add the requires scipy decorator
mikofski Jan 31, 2018
68c65c3
fixes #410
mikofski Jan 31, 2018
41e0c83
add i, v, and p to out
mikofski Jan 31, 2018
d7b6e62
need to calculate i-v curve points to compare
mikofski Jan 31, 2018
aa3d29a
add mppt method, update docs
mikofski Jan 31, 2018
9fc350d
fix latex and other sphinx formatting issue sand typos
mikofski Jan 31, 2018
54e8d18
fix circular import issues?
mikofski Feb 1, 2018
16ad9b4
try something remove redundant package imports
mikofski Feb 1, 2018
7aca302
don't raise import error at module level if no scipy
mikofski Feb 1, 2018
086e73f
okay I think I fixed it, now return pvlib module objects
mikofski Feb 1, 2018
9f2b157
try to modify i_from_v
mikofski Feb 1, 2018
555e946
implement v_from_i wrapper
mikofski Feb 1, 2018
52a8e88
respond to @thunderfish24 review items:
mikofski Feb 1, 2018
c0e18a5
change default argument for method to "gold"
mikofski Feb 1, 2018
09c6a75
update test_singlediode_methods to use lambertw in comparison
mikofski Feb 1, 2018
ff8cc0b
change name from mppt -> mpp
mikofski Feb 1, 2018
446fa9e
add test to check for verbose yet graceful failure of v_from_i
mikofski Feb 1, 2018
f976f61
fix pytest.raise context, add test_v_from_i
mikofski Feb 1, 2018
db88022
change mppt->mpp in api.rst docs
mikofski Feb 1, 2018
a509dd3
fix what's new to point to mpp in docs, also add links to bishop88 an…
mikofski Feb 1, 2018
62010c2
Merge branch 'master' into faster_way
mikofski Jun 20, 2018
5c939b8
TST: fix precision test to use new calcparams* API
mikofski Jun 20, 2018
66a801d
TST: update singlediode test for updated atol in #415
mikofski Jun 20, 2018
df1423b
DOC: update what's new for 0.6 with proposed explicit SDM solution
mikofski Jun 20, 2018
eb20cf4
DOC: update docstring to conform to numpydoc style in sdm methods
mikofski Jun 20, 2018
e3805ef
Merge branch 'master' into faster_way
mikofski Jun 26, 2018
5f89578
ENH: refactor est_voc -> estimate_voc
mikofski Jun 26, 2018
ba84fcf
ENH refactor pvsystem.estimate_voc too, also update docs to numpy style
mikofski Jun 26, 2018
0f3893c
ENH refactor vd->diode_voltage in bishop88
mikofski Jun 26, 2018
d6023b1
ENH: TST: refactor reshaping conditions for _array_newton
mikofski Jun 27, 2018
80b3352
ENH: TST: make brentq vectorized always
mikofski Jun 27, 2018
ef20676
ENH: TST: can't vectorize brentq because it treats args as array
mikofski Jun 27, 2018
98d1c01
BUG: TST: use "brentq" instead of "gold"
mikofski Jun 27, 2018
4ecd913
TST: change test fixtures with nonsensical values in quadrant four
mikofski Jun 27, 2018
bf05d2d
TST: fix mpp tests
mikofski Jun 28, 2018
edc445d
ENH: clean up last little bit
mikofski Jun 28, 2018
f542d15
ENH: BUG: TST: DOC: remove all traces for "fast" or "slow"
mikofski Jun 28, 2018
cc6c976
TST: BUG: fix the boolean mask numpy<1.14 bug in tests
mikofski Jun 28, 2018
22c53fc
ENH: TST: ignore .pytest_cache/ folder
mikofski Jun 29, 2018
442a3d4
DOC: MAINT: respond to review by @cwhanse , clean up docstrings
mikofski Jun 29, 2018
6bcffe8
MAINT: update comment about mpp search algorithm
mikofski Jun 29, 2018
e6b60c6
MAINT: update what's new for v0.6
mikofski Jun 29, 2018
0fc9c83
DOC: make sure docs render well
mikofski Jun 29, 2018
fc6cee1
DOC: MAINT: rewording what's new with @cwhanse comments to make it clear
mikofski Jun 29, 2018
28c8ffb
API: change bishop88 and estimate_voc to be used from singlediode_met…
mikofski Jun 29, 2018
58361c1
DOC: link to new singlediode_methods subfunctions in what's new
mikofski Jun 29, 2018
5f9ed41
API: DOC: ENH: change pvsystem.mpp() -> max_power_point()
mikofski Jun 29, 2018
43475cc
MAINT: address comments by @wholmgren
mikofski Jun 30, 2018
c79ab97
Merge branch 'master' into faster_way
mikofski Jul 10, 2018
1ad6031
MAINT: add comment to explain why we import brentq in try-except
mikofski Jul 10, 2018
f14ba04
MAINT: move lambertw methods to singlediode_methods.py
mikofski Jul 10, 2018
8d86560
MAINT: add docstring elaborating the numerical precision test
mikofski Jul 10, 2018
337d7b4
MAINT: use np.expm1(x) for exp(x) - 1 in bishop88 single diode method
mikofski Jul 10, 2018
ce5b0f5
MAINT: replace boilerplate code for broadcasting newton array args
mikofski Jul 10, 2018
3e009f8
MAINT: TEST: parametrize i_from_v and v_from_i for methods, atol
mikofski Jul 10, 2018
082dfd5
MAINT: remove import of functools.partial in pvsystem.py
mikofski Jul 10, 2018
ceb69cd
MAINT: wrap lines longer than 79 characters
mikofski Jul 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Byte-compiled / optimized / DLL files
.pytest_cache/
__pycache__/
*.py[cod]

Expand Down
20 changes: 18 additions & 2 deletions docs/sphinx/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ algorithm.

spa


Correlations and analytical expressions for low precision solar position
calculations.

Expand All @@ -80,6 +79,7 @@ calculations.
solarposition.equation_of_time_pvcdrom
solarposition.hour_angle


Clear sky
=========

Expand Down Expand Up @@ -205,6 +205,23 @@ Functions relevant for the single diode model.
pvsystem.i_from_v
pvsystem.singlediode
pvsystem.v_from_i
pvsystem.mpp
pvsystem.estimate_voc
pvsystem.bishop88

Low-level functions to support :func:`pvlib.pvsystem.bishop88`. *Note*:
:func:`pvlib.singlediode_methods.bishop88` and
:func:`pvlib.singlediode_methods.estimate_voc` are also imported into the
``pvlib.pvsystem`` module.
Copy link
Member

Choose a reason for hiding this comment

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

I recommend against importing these functions into pvlib.pvsystem, especially if we're thinking of moving the lambertw function out of it. It's much easier to go one way than the other.

Copy link
Member Author

@mikofski mikofski Jun 29, 2018

Choose a reason for hiding this comment

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

✔️ thanks for the decisiveness.


.. autosummary::
:toctree: generated/

singlediode_methods.estimate_voc
singlediode_methods.bishop88
Copy link
Member

Choose a reason for hiding this comment

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

@cwhanse you once asked for a more specific function name. Does encapsulating the function within a singlediode module address that concern?

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 OK with bishop88 here as a member of singlediode_methods. It's siblings will be lambertw and perhaps others.

singlediode_methods.bishop88_i_from_v
singlediode_methods.bishop88_v_from_i
singlediode_methods.bishop88_mpp
Copy link
Member

Choose a reason for hiding this comment

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

"methods" makes me think of methods vs. functions but maybe that's just me. probably best to go with it.

Copy link
Member

Choose a reason for hiding this comment

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

That was my thought, also, but in this case I think it's OK.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can change this to "how" I think that's what Pandas often uses. Is there any precedent for PVLIB?

Copy link
Member

Choose a reason for hiding this comment

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

You mean singlediode_how.py? A little odd to me but not opposed. singlediode_algorithms? I'd stay away from singlediode_models here. I am ok with singlediode_methods if others are. I think the context is clear enough.

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 ok with singlediode_methods

Copy link
Member Author

Choose a reason for hiding this comment

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

LOL! I meant the keyword, but I'm fine with everything as it is if you are.


SAPM model
----------
Expand All @@ -231,7 +248,6 @@ PVWatts model
pvsystem.pvwatts_ac
pvsystem.pvwatts_losses


Other
-----

Expand Down
35 changes: 32 additions & 3 deletions docs/sphinx/source/whatsnew/v0.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,37 @@ API Changes

Enhancements
~~~~~~~~~~~~
* Add sea surface albedo in irradiance.py (:issue:`458`)
* Implement first_solar_spectral_loss in modelchain.py (:issue:`359`)
* Clarify arguments Egref and dEgdT for calcparams_desoto (:issue:`462`)
* Add sea surface albedo in ``irradiance.py`` (:issue:`458`)
* Implement :meth:`~pvlib.modelchain.ModelChain.first_solar_spectral_loss`
in ``modelchain.py`` (:issue:`359`)
* Clarify arguments ``Egref`` and ``dEgdT`` for
:func:`~pvlib.pvsystem.calcparams_desoto` (:issue:`462`)
* Implement a reliable "gold" implementation of the single diode model (SDM)
Copy link
Member

Choose a reason for hiding this comment

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

These additions to whatsnew seem out of date.

  • need to mention singlediode_methods and what new functions are attached, and what functions (if any) have moved from pvsystem
  • would help to list the values for the new kwarg method on singlediode and what they do
  • I think bishop88 is in singlediode_methods not pvsystem , the reference needs to be corrected elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

I exposed the two new main functions, bishop88 and estimate_voc in pvsystem, at the top of the module just after the imports - my thought process being that the methods in singlediode_methods would be too low level for most folks, but not necessarily private.

I'll go with the flow, but perhaps that additional documentation and API change can be added in another PR, perhaps the one where we move the Lambert-W methods to that module?

I'll just add some notes to what's new, that I added this module and put some low level plumbing in there, okay?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. Let's batch move to singlediode_methods in a separate PR

Copy link
Member

@cwhanse cwhanse Jun 29, 2018

Choose a reason for hiding this comment

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

I still find this whatsnew text to be confusing.

  • Implement new methods brentq and newton for solving for points on the single diode equation. brentq uses a bisection method (Brent, 1973) that may be slow but guarantees a solution. newton implements the Newton-Raphson method that is faster but is not guaranteed to converge, however, newton should be safe for well-behaved IV curves. (:issues:408)

Copy link
Member Author

Choose a reason for hiding this comment

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

✔️

using a bisection method (Brent, 1973) bounded by points known to include the
full forward-bias 1st quadrant IV-curve. Also implement a "fast" method using
the Newton-Raphson method that is not bounded, but should be safe for well
behaved IV-curves. (:issue:`408`)
* Implement :func:`~pvlib.pvsystem.bishop88` for explicit calculation of
arbitrary IV curve points using diode voltage instead of cell voltage. This
method is called for ``ivcurve_pnts`` in :func:`~pvlib.pvsystem.singlediode`
Copy link
Member

Choose a reason for hiding this comment

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

Instead of

This method is called for ivcurve_pnts in :func:~pvlib.pvsystem.singlediode if the method is either 'newton' or 'brentq', but the IV curve points will be log spaced instead of linear.

If method is either 'newton' or 'brentq' and ivcurve_pnts in :func:~pvlib.pvsystem.singlediode is provided, the IV curve points will be log spaced instead of linear.

Copy link
Member Author

Choose a reason for hiding this comment

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

✔️

if the method is either ``'newton'`` or ``'brentq'``, but the IV curve points
will be log spaced instead of linear.
* Implement :func:`~pvlib.pvsystem.estimate_voc` to estimate open circuit
voltage by assuming :math:`R_{sh} \to \infty` and :math:`R_s=0` as an upper
bound in bisection method for :func:`~pvlib.pvsystem.singlediode`.
* Combine existing :func:`~pvlib.pvsystem.singlediode` method using Lambert-W
Copy link
Member

@cwhanse cwhanse Jun 29, 2018

Choose a reason for hiding this comment

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

This bullet should be 2nd in the list:

  • Extend ;func;pvlib.pvsystem.singlediode with an additional kwarg method (`lambertw`, `newton`, `brentq`), default is lambertw, to select a method to solve for points on the single diode equation. (rest of text OK)

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved this first before explanation of each method.

Copy link
Member Author

Choose a reason for hiding this comment

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

✔️

with the two new implementations to form a wrapper, that takes an additional
``method`` argument ``('lambertw', 'newton', 'brentq')`` that defaults to a
Lambert-W solution. Selecting either "brentq" or "newton" as the method uses
``bishop88`` with the corresponding search method. (:issue:`410`)
* Add :func:`~pvlib.pvsystem.mpp` method to compute the max power point using
the new "brentq" bounded bisection method.
* Add new module ``pvlib.singlediode_methods`` which contains low-level
functions to support implementing ``bishop88`` and various other methods like
``bishop88_i_from_v``, ``bishop88_v_from_i``, and ``bishop88_mpp``. *Note*:
:func:`pvlib.singlediode_methods.bishop88` and
:func:`pvlib.singlediode_methods.estimate_voc` are also imported into the
``pvlib.pvsystem`` module.


Bug fixes
Expand Down Expand Up @@ -48,5 +76,6 @@ Contributors
* Will Holmgren
* Yu Cao
* Cliff Hansen
* Mark Mikofski
* Alan Mathew

101 changes: 101 additions & 0 deletions pvlib/data/bishop88_numerical_precision.csv

Large diffs are not rendered by default.

Loading