Skip to content

Commit b2a17e4

Browse files
btautecwhanse
andauthored
Added irradiance_loss_pvsyst function to pvsystem (#1000)
* Added irradiance_loss_pvsyst function to pvsystem module and method to pvsystem class. * Updated formatting * fixing loss equation formatting Co-authored-by: Cliff Hansen <[email protected]> * Fix math formatting * Added Tests * fix formatting in tests * more test formatting fixes * Updated v0.8.0 What's New * Added Issue Number to v0.8.0 What's New * Update pvlib/pvsystem.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/pvsystem.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/pvsystem.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/tests/test_pvsystem.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/tests/test_pvsystem.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/tests/test_pvsystem.py Co-authored-by: Cliff Hansen <[email protected]> * Updated params and output to be percents * fix indents * Changed function to generic combine_loss_factors * Changed function to generic combine_loss_factors * fixed test typo * indentation fix * whitespace fix * Moved combine_loss_factors to PV System Effects * Apply suggestions from code review Co-authored-by: Cliff Hansen <[email protected]> * fill_method docstring update * fill_method docstring update * Update v0.8.0.rst * Update pvsystem.py * Update test_pvsystem.py * Update v0.8.0.rst Co-authored-by: Cliff Hansen <[email protected]>
1 parent a5c24f0 commit b2a17e4

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

docs/sphinx/source/api.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,13 @@ Other
369369
Effects on PV System Output
370370
===========================
371371

372+
Loss models
373+
^^^^^^^^^^^
374+
.. autosummary::
375+
:toctree: generated/
376+
377+
pvsystem.combine_loss_factors
378+
372379
.. autosummary::
373380
:toctree: generated/
374381

docs/sphinx/source/whatsnew/v0.8.0.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ Enhancements
9292
PVSystem, LocalizedPVSystem, SingleAxisTracker, and
9393
LocalizedSingleAxisTracker repr methods. (:issue:`1027`)
9494
* Added ability for :py:func:`pvlib.soiling.hsu` to accept arbitrary time intervals. (:pull:`980`)
95+
* Add :py:func:`pvlib.pvsystem.combine_loss_factors` as general purpose
96+
function to combine loss factors with a common index.
97+
Partialy addresses :issue:`988`. Contributed by Brock Taute :ghuser:`btaute`
9598

9699
Bug fixes
97100
~~~~~~~~~

pvlib/pvsystem.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,6 +2310,48 @@ def pvwatts_losses(soiling=2, shading=3, snow=0, mismatch=2, wiring=2,
23102310
return losses
23112311

23122312

2313+
def combine_loss_factors(index, *losses, fill_method='ffill'):
2314+
r"""
2315+
Combines Series loss fractions while setting a common index.
2316+
2317+
The separate losses are compounded using the following equation:
2318+
2319+
.. math::
2320+
2321+
L_{total} = 1 - [ 1 - \Pi_i ( 1 - L_i ) ]
2322+
2323+
:math:`L_{total}` is the total loss returned
2324+
:math:`L_i` is each individual loss factor input
2325+
2326+
Note the losses must each be a series with a DatetimeIndex.
2327+
All losses will be resampled to match the index parameter using
2328+
the fill method specified (defaults to "fill forward").
2329+
2330+
Parameters
2331+
----------
2332+
index : DatetimeIndex
2333+
The index of the returned loss factors
2334+
2335+
*losses : Series
2336+
One or more Series of fractions to be compounded
2337+
2338+
fill_method : {'ffill', 'bfill', 'nearest'}, default 'ffill'
2339+
Method to use for filling holes in reindexed DataFrame
2340+
2341+
Returns
2342+
-------
2343+
Series
2344+
Fractions resulting from the combination of each loss factor
2345+
"""
2346+
combined_factor = 1
2347+
2348+
for loss in losses:
2349+
loss = loss.reindex(index, method=fill_method)
2350+
combined_factor *= (1 - loss)
2351+
2352+
return 1 - combined_factor
2353+
2354+
23132355
snlinverter = deprecated('0.8', alternative='inverter.sandia',
23142356
name='snlinverter', removal='0.9')(inverter.sandia)
23152357

pvlib/tests/test_pvsystem.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,18 @@ def test_PVSystem_pvwatts_ac_kwargs(mocker):
12991299
assert out < pdc
13001300

13011301

1302+
def test_combine_loss_factors():
1303+
test_index = pd.date_range(start='1990/01/01T12:00', periods=365, freq='D')
1304+
loss_1 = pd.Series(.10, index=test_index)
1305+
loss_2 = pd.Series(.05, index=pd.date_range(start='1990/01/01T12:00',
1306+
periods=365*2, freq='D'))
1307+
loss_3 = pd.Series(.02, index=pd.date_range(start='1990/01/01',
1308+
periods=12, freq='MS'))
1309+
expected = pd.Series(.1621, index=test_index)
1310+
out = pvsystem.combine_loss_factors(test_index, loss_1, loss_2, loss_3)
1311+
assert_series_equal(expected, out)
1312+
1313+
13021314
@fail_on_pvlib_version('0.9')
13031315
def test_deprecated_09(cec_inverter_parameters, adr_inverter_parameters):
13041316
# deprecated function pvsystem.snlinverter

0 commit comments

Comments
 (0)