Skip to content

Commit 6b03e9d

Browse files
authored
rename losses.py to soiling.py (#937)
* rename losses.py to soiling.py * add soiling to init.py * update example * update error message * correct whatsnew for kimber * correct api.rst
1 parent b91d178 commit 6b03e9d

File tree

6 files changed

+48
-53
lines changed

6 files changed

+48
-53
lines changed

docs/examples/plot_greensboro_kimber_soiling.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# %%
99
# This example shows basic usage of pvlib's Kimber Soiling model [1]_ with
10-
# :py:meth:`pvlib.losses.soiling_kimber`.
10+
# :py:func:`pvlib.soiling.kimber`.
1111
#
1212
# References
1313
# ----------
@@ -33,7 +33,7 @@
3333
import pathlib
3434
from matplotlib import pyplot as plt
3535
from pvlib.iotools import read_tmy3
36-
from pvlib.losses import soiling_kimber
36+
from pvlib.soiling import kimber
3737
import pvlib
3838

3939
# get full path to the data directory
@@ -45,7 +45,7 @@
4545
greensboro_rain = greensboro.Lprecipdepth
4646
# calculate soiling with no wash dates and cleaning threshold of 25-mm of rain
4747
THRESHOLD = 25.0
48-
soiling_no_wash = soiling_kimber(greensboro_rain, cleaning_threshold=THRESHOLD)
48+
soiling_no_wash = kimber(greensboro_rain, cleaning_threshold=THRESHOLD)
4949
soiling_no_wash.name = 'soiling'
5050
# daily rain totals
5151
daily_rain = greensboro_rain.iloc[:-1].resample('D').sum()

docs/sphinx/source/api.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,8 @@ Functions for fitting diode models
310310

311311
Other
312312
-----
313-
314313
.. autosummary::
315314
:toctree: generated/
316-
317315
pvsystem.retrieve_sam
318316
pvsystem.systemdef
319317
pvsystem.scale_voltage_current_power
@@ -332,8 +330,8 @@ Effects on PV System Output
332330
.. autosummary::
333331
:toctree: generated/
334332

335-
losses.soiling_hsu
336-
losses.soiling_kimber
333+
soiling.hsu
334+
soiling.kimber
337335

338336

339337

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ API Changes
1010
* :py:func:`pvlib.iotools.read_tmy3` when coerced to a single year now returns
1111
indices that are monotonically increasing. Therefore, the last index will be
1212
January 1, 00:00 of the *next* year. (:pull:`910`)
13+
* Renamed ``pvlib.losses`` to :py:mod:`pvlib.soiling`. Additional loss
14+
models will go into code modules named for the loss or effect type.
15+
(:issue:`935`, :issue:`891`)
16+
* Renamed ``pvlib.losses.soiling_hsu`` to :py:func:`pvlib.soiling.hsu`
17+
(:issue:`935`)
1318

1419
Enhancements
1520
~~~~~~~~~~~~
@@ -19,7 +24,8 @@ Enhancements
1924
* Add :py:func:`~pvlib.pvsystem.PVSystem.faiman` and added
2025
``temperature_model='faiman'`` option to :py:class:`~pvlib.modelchain.ModelChain`
2126
(:pull:`897`) (:issue:`836`).
22-
* Add Kimber soiling model :py:func:`pvlib.losses.soiling_kimber`. (:pull:`860`)
27+
* Add Kimber soiling model :py:func:`pvlib.soiling.kimber`. (:pull:`860`,
28+
:issue`935`)
2329
* Add :func:`~pvlib.iotools.read_pvgis_tmy` for files downloaded using the
2430
PVGIS tool. (:issue:`880`)
2531
* Add new module :py:mod:`pvlib.snow` to contain models related to snow coverage and effects on a PV system. (:pull:`764`)

pvlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
from pvlib import modelchain # noqa: F401
1515
from pvlib import singlediode # noqa: F401
1616
from pvlib import bifacial # noqa: F401
17-
from pvlib import losses # noqa: F401
17+
from pvlib import soiling # noqa: F401
1818
from pvlib import snow # noqa: F401

pvlib/losses.py renamed to pvlib/soiling.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
This module contains functions for losses of various types: soiling, mismatch,
4-
snow cover, etc.
3+
This module contains functions for soiling models
54
"""
65

76
import datetime
@@ -10,8 +9,8 @@
109
from pvlib.tools import cosd
1110

1211

13-
def soiling_hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10,
14-
depo_veloc=None, rain_accum_period=pd.Timedelta('1h')):
12+
def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10,
13+
depo_veloc=None, rain_accum_period=pd.Timedelta('1h')):
1514
"""
1615
Calculates soiling ratio given particulate and rain data using the model
1716
from Humboldt State University (HSU).
@@ -66,7 +65,7 @@ def soiling_hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10,
6665
try:
6766
from scipy.special import erf
6867
except ImportError:
69-
raise ImportError("The soiling_hsu function requires scipy.")
68+
raise ImportError("The pvlib.soiling.hsu function requires scipy.")
7069

7170
# never use mutable input arguments
7271
if depo_veloc is None:
@@ -96,9 +95,9 @@ def soiling_hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10,
9695
return soiling_ratio
9796

9897

99-
def soiling_kimber(rainfall, cleaning_threshold=6, soiling_loss_rate=0.0015,
100-
grace_period=14, max_soiling=0.3, manual_wash_dates=None,
101-
initial_soiling=0, rain_accum_period=24):
98+
def kimber(rainfall, cleaning_threshold=6, soiling_loss_rate=0.0015,
99+
grace_period=14, max_soiling=0.3, manual_wash_dates=None,
100+
initial_soiling=0, rain_accum_period=24):
102101
"""
103102
Calculates fraction of energy lost due to soiling given rainfall data and
104103
daily loss rate using the Kimber model.

pvlib/tests/test_losses.py renamed to pvlib/tests/test_soiling.py

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66
import pandas as pd
77
from pandas.util.testing import assert_series_equal
8-
from pvlib.losses import soiling_hsu, soiling_kimber
8+
from pvlib.soiling import hsu, kimber
99
from pvlib.iotools import read_tmy3
1010
from conftest import (
1111
requires_scipy, needs_pandas_0_22, DATA_DIR)
@@ -75,7 +75,7 @@ def rainfall_input():
7575

7676
@requires_scipy
7777
@needs_pandas_0_22
78-
def test_soiling_hsu_no_cleaning(rainfall_input, expected_output):
78+
def test_hsu_no_cleaning(rainfall_input, expected_output):
7979
"""Test Soiling HSU function"""
8080

8181
rainfall = rainfall_input
@@ -85,15 +85,15 @@ def test_soiling_hsu_no_cleaning(rainfall_input, expected_output):
8585
tilt = 0.
8686
expected_no_cleaning = expected_output
8787

88-
result = soiling_hsu(rainfall=rainfall, cleaning_threshold=10., tilt=tilt,
89-
pm2_5=pm2_5, pm10=pm10, depo_veloc=depo_veloc,
90-
rain_accum_period=pd.Timedelta('1h'))
88+
result = hsu(rainfall=rainfall, cleaning_threshold=10., tilt=tilt,
89+
pm2_5=pm2_5, pm10=pm10, depo_veloc=depo_veloc,
90+
rain_accum_period=pd.Timedelta('1h'))
9191
assert_series_equal(result, expected_no_cleaning)
9292

9393

9494
@requires_scipy
9595
@needs_pandas_0_22
96-
def test_soiling_hsu(rainfall_input, expected_output_2):
96+
def test_hsu(rainfall_input, expected_output_2):
9797
"""Test Soiling HSU function with cleanings"""
9898

9999
rainfall = rainfall_input
@@ -104,21 +104,21 @@ def test_soiling_hsu(rainfall_input, expected_output_2):
104104
expected = expected_output_2
105105

106106
# three cleaning events at 4:00-6:00, 8:00-11:00, and 17:00-20:00
107-
result = soiling_hsu(rainfall=rainfall, cleaning_threshold=0.5, tilt=tilt,
108-
pm2_5=pm2_5, pm10=pm10, depo_veloc=depo_veloc,
109-
rain_accum_period=pd.Timedelta('3h'))
107+
result = hsu(rainfall=rainfall, cleaning_threshold=0.5, tilt=tilt,
108+
pm2_5=pm2_5, pm10=pm10, depo_veloc=depo_veloc,
109+
rain_accum_period=pd.Timedelta('3h'))
110110

111111
assert_series_equal(result, expected)
112112

113113

114114
@requires_scipy
115115
@needs_pandas_0_22
116-
def test_soiling_hsu_defaults(rainfall_input, expected_output_1):
116+
def test_hsu_defaults(rainfall_input, expected_output_1):
117117
"""
118118
Test Soiling HSU function with default deposition velocity and default rain
119119
accumulation period.
120120
"""
121-
result = soiling_hsu(
121+
result = hsu(
122122
rainfall=rainfall_input, cleaning_threshold=0.5, tilt=0.0, pm2_5=1.0,
123123
pm10=2.0)
124124
assert np.allclose(result.values, expected_output_1)
@@ -132,50 +132,45 @@ def greensboro_rain():
132132

133133

134134
@pytest.fixture
135-
def expected_kimber_soiling_nowash():
135+
def expected_kimber_nowash():
136136
return pd.read_csv(
137137
DATA_DIR / 'greensboro_kimber_soil_nowash.dat',
138138
parse_dates=True, index_col='timestamp')
139139

140140

141141
@needs_pandas_0_22
142-
def test_kimber_soiling_nowash(greensboro_rain,
143-
expected_kimber_soiling_nowash):
142+
def test_kimber_nowash(greensboro_rain, expected_kimber_nowash):
144143
"""Test Kimber soiling model with no manual washes"""
145144
# Greensboro typical expected annual rainfall is 8345mm
146145
assert greensboro_rain.sum() == 8345
147146
# calculate soiling with no wash dates
148-
soiling_nowash = soiling_kimber(greensboro_rain)
147+
nowash = kimber(greensboro_rain)
149148
# test no washes
150-
assert np.allclose(
151-
soiling_nowash.values,
152-
expected_kimber_soiling_nowash['soiling'].values)
149+
assert np.allclose(nowash.values, expected_kimber_nowash['soiling'].values)
153150

154151

155152
@pytest.fixture
156-
def expected_kimber_soiling_manwash():
153+
def expected_kimber_manwash():
157154
return pd.read_csv(
158155
DATA_DIR / 'greensboro_kimber_soil_manwash.dat',
159156
parse_dates=True, index_col='timestamp')
160157

161158

162159
@needs_pandas_0_22
163-
def test_kimber_soiling_manwash(greensboro_rain,
164-
expected_kimber_soiling_manwash):
160+
def test_kimber_manwash(greensboro_rain, expected_kimber_manwash):
165161
"""Test Kimber soiling model with a manual wash"""
166162
# a manual wash date
167163
manwash = [datetime.date(1990, 2, 15), ]
168164
# calculate soiling with manual wash
169-
soiling_manwash = soiling_kimber(
170-
greensboro_rain, manual_wash_dates=manwash)
165+
manwash = kimber(greensboro_rain, manual_wash_dates=manwash)
171166
# test manual wash
172167
assert np.allclose(
173-
soiling_manwash.values,
174-
expected_kimber_soiling_manwash['soiling'].values)
168+
manwash.values,
169+
expected_kimber_manwash['soiling'].values)
175170

176171

177172
@pytest.fixture
178-
def expected_kimber_soiling_norain():
173+
def expected_kimber_norain():
179174
# expected soiling reaches maximum
180175
soiling_loss_rate = 0.0015
181176
max_loss_rate = 0.3
@@ -186,19 +181,18 @@ def expected_kimber_soiling_norain():
186181

187182

188183
@needs_pandas_0_22
189-
def test_kimber_soiling_norain(greensboro_rain,
190-
expected_kimber_soiling_norain):
184+
def test_kimber_norain(greensboro_rain, expected_kimber_norain):
191185
"""Test Kimber soiling model with no rain"""
192186
# a year with no rain
193187
norain = pd.Series(0, index=greensboro_rain.index)
194188
# calculate soiling with no rain
195-
soiling_norain = soiling_kimber(norain)
189+
norain = kimber(norain)
196190
# test no rain, soiling reaches maximum
197-
assert np.allclose(soiling_norain.values, expected_kimber_soiling_norain)
191+
assert np.allclose(norain.values, expected_kimber_norain)
198192

199193

200194
@pytest.fixture
201-
def expected_kimber_soiling_initial_soil():
195+
def expected_kimber_initial_soil():
202196
# expected soiling reaches maximum
203197
soiling_loss_rate = 0.0015
204198
max_loss_rate = 0.3
@@ -209,13 +203,11 @@ def expected_kimber_soiling_initial_soil():
209203

210204

211205
@needs_pandas_0_22
212-
def test_kimber_soiling_initial_soil(greensboro_rain,
213-
expected_kimber_soiling_initial_soil):
206+
def test_kimber_initial_soil(greensboro_rain, expected_kimber_initial_soil):
214207
"""Test Kimber soiling model with initial soiling"""
215208
# a year with no rain
216209
norain = pd.Series(0, index=greensboro_rain.index)
217210
# calculate soiling with no rain
218-
soiling_norain = soiling_kimber(norain, initial_soiling=0.1)
211+
norain = kimber(norain, initial_soiling=0.1)
219212
# test no rain, soiling reaches maximum
220-
assert np.allclose(
221-
soiling_norain.values, expected_kimber_soiling_initial_soil)
213+
assert np.allclose(norain.values, expected_kimber_initial_soil)

0 commit comments

Comments
 (0)