From c8c3758525a376846244ace0c79e7efd7ac54e3e Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Wed, 20 May 2020 16:34:20 -0600 Subject: [PATCH 01/27] bug fixes to hsu soiling function. Addresses (#970) --- pvlib/soiling.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pvlib/soiling.py b/pvlib/soiling.py index 1b7aadc73d..0bdc6228a5 100644 --- a/pvlib/soiling.py +++ b/pvlib/soiling.py @@ -40,7 +40,7 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, Concentration of airborne particulate matter (PM) with aerodynamicdiameter less than 10 microns. [g/m^3] - depo_veloc : dict, default {'2_5': 0.4, '10': 0.09} + depo_veloc : dict, default {'2_5': 0.0009, '10': 0.004} Deposition or settling velocity of particulates. [m/s] rain_accum_period : Timedelta, default 1 hour @@ -69,7 +69,7 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, # never use mutable input arguments if depo_veloc is None: - depo_veloc = {'2_5': 0.004, '10': 0.0009} + depo_veloc = {'2_5': 0.0009, '10': 0.004} # accumulate rainfall into periods for comparison with threshold accum_rain = rainfall.rolling(rain_accum_period, closed='right').sum() @@ -77,7 +77,7 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, cleaning_times = accum_rain.index[accum_rain >= cleaning_threshold] horiz_mass_rate = pm2_5 * depo_veloc['2_5']\ - + np.maximum(pm10 - pm2_5, 0.) * depo_veloc['10'] + + np.maximum(pm10 - pm2_5, 0.) * depo_veloc['10'] * 3600 tilted_mass_rate = horiz_mass_rate * cosd(tilt) # assuming no rain # tms -> tilt_mass_rate From 3a77400c8fd7c6912741ea7db80c5733ef9b9523 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Tue, 9 Jun 2020 11:28:11 -0600 Subject: [PATCH 02/27] Made changes to the soiling tests Addresses (#970) --- pvlib/tests/test_soiling.py | 67 ++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index b80dd13547..eafe11ddf5 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -19,48 +19,40 @@ def expected_output(): end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') expected_no_cleaning = pd.Series( - data=[0.884980357535360, 0.806308930084762, 0.749974647038078, - 0.711804155175089, 0.687489866078621, 0.672927554408964, - 0.664714899337491, 0.660345851212099, 0.658149551658860, - 0.657104593968981, 0.656633344364056, 0.656431630729954, - 0.656349579062171, 0.656317825078228, 0.656306121502393, - 0.656302009396500, 0.656300630853678, 0.656300189543417, - 0.656300054532516, 0.656300015031680, 0.656300003971846, - 0.656300001006533, 0.656300000244750, 0.656300000057132], + data=[0.97230454, 0.95036146, 0.93039061, 0.91177978, 0.89427556, + 0.8777455 , 0.86211038, 0.84731759, 0.83332881, 0.82011354, + 0.80764549, 0.79590056, 0.78485556, 0.77448749, 0.76477312, + 0.75568883, 0.74721046, 0.73931338, 0.73197253, 0.72516253, + 0.7188578 , 0.71303268, 0.7076616 , 0.70271919], index=dt) - return expected_no_cleaning - @pytest.fixture def expected_output_1(): - return np.array([ - 0.99927224, 0.99869067, 0.99815393, 0.99764437, 1.0, - 0.99927224, 0.99869067, 0.99815393, 1.0, 1.0, - 0.99927224, 0.99869067, 0.99815393, 0.99764437, 0.99715412, - 0.99667873, 0.99621536, 0.99576203, 0.99531731, 0.9948801, - 0.99444954, 0.99402494, 0.99360572, 0.99319142]) - + dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), + end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') + expected_output_1 = pd.Series( + data=[0.9872406 , 0.97706269, 0.96769693, 0.95884032, 1., + 0.9872406 , 0.97706269, 0.96769693, 1. , 1. , + 0.9872406 , 0.97706269, 0.96769693, 0.95884032, 0.95036001, + 0.94218263, 0.93426236, 0.92656836, 0.91907873, 0.91177728, + 0.9046517 , 0.89769238, 0.89089165, 0.88424329], + index=dt) + return expected_output_1 @pytest.fixture -def expected_output_2(expected_output): - # Sample output (calculated manually) +def expected_output_2(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') + expected_output_2 = pd.Series( + data = [0.97229869, 0.95035106, 0.93037619, 0.91176175, 1., + 1. , 1. , 0.97229869, 1. , 1. , + 1. , 1. , 0.97229869, 0.95035106, 0.93037619, + 0.91176175, 0.89425431, 1. , 1. , 1. , + 1. , 0.97229869, 0.95035106, 0.93037619], + index=dt) - expected_no_cleaning = expected_output - - expected = pd.Series(index=dt, dtype='float64') - expected[dt[:4]] = expected_no_cleaning[dt[:4]] - expected[dt[4:7]] = 1. - expected[dt[7]] = expected_no_cleaning[dt[0]] - expected[dt[8:12]] = 1. - expected[dt[12:17]] = expected_no_cleaning[dt[:5]] - expected[dt[17:21]] = 1. - expected[dt[21:]] = expected_no_cleaning[:3] - - return expected - + return expected_output_2 @pytest.fixture def rainfall_input(): @@ -81,7 +73,7 @@ def test_hsu_no_cleaning(rainfall_input, expected_output): rainfall = rainfall_input pm2_5 = 1.0 pm10 = 2.0 - depo_veloc = {'2_5': 1.0, '10': 1.0} + depo_veloc = {'2_5': 1.0e-5, '10': 1.0e-4} tilt = 0. expected_no_cleaning = expected_output @@ -99,16 +91,15 @@ def test_hsu(rainfall_input, expected_output_2): rainfall = rainfall_input pm2_5 = 1.0 pm10 = 2.0 - depo_veloc = {'2_5': 1.0, '10': 1.0} + depo_veloc = {'2_5': 1.0e-4, '10': 1.0e-4} tilt = 0. - expected = expected_output_2 # three cleaning events at 4:00-6:00, 8:00-11:00, and 17:00-20:00 result = hsu(rainfall=rainfall, cleaning_threshold=0.5, tilt=tilt, pm2_5=pm2_5, pm10=pm10, depo_veloc=depo_veloc, rain_accum_period=pd.Timedelta('3h')) - assert_series_equal(result, expected) + assert_series_equal(result, expected_output_2) @requires_scipy @@ -119,8 +110,8 @@ def test_hsu_defaults(rainfall_input, expected_output_1): accumulation period. """ result = hsu( - rainfall=rainfall_input, cleaning_threshold=0.5, tilt=0.0, pm2_5=1.0, - pm10=2.0) + rainfall=rainfall_input, cleaning_threshold=0.5, tilt=0.0, pm2_5=1.0e-2, + pm10=2.0e-2) assert np.allclose(result.values, expected_output_1) From bff444f6cb059ed37775e40a33f50d730b55e50d Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Tue, 9 Jun 2020 17:40:46 -0600 Subject: [PATCH 03/27] update what's new documentation --- docs/sphinx/source/whatsnew/v0.8.0.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.8.0.rst b/docs/sphinx/source/whatsnew/v0.8.0.rst index dc6bf5015c..382f3b91de 100644 --- a/docs/sphinx/source/whatsnew/v0.8.0.rst +++ b/docs/sphinx/source/whatsnew/v0.8.0.rst @@ -11,6 +11,7 @@ Enhancements Bug fixes ~~~~~~~~~ +* Fixed unit and default value errors in :py:func:`pvlib.soiling.hsu`. (:pull:`XXX`) Testing ~~~~~~~ @@ -32,3 +33,4 @@ Contributors * Cliff Hansen (:ghuser:`cwhanse`) * Kevin Anderson (:ghuser:`kanderso-nrel`) * Mark Mikofski (:ghuser:`mikofski`) +* Joshua S. Stein (:ghuser:`jsstein`) From f412ddb3c56f559de89b63a06cb854e9856845d3 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Wed, 10 Jun 2020 20:15:43 -0600 Subject: [PATCH 04/27] Fixed stickler-ci issues in test_soiling.py --- pvlib/tests/test_soiling.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index eafe11ddf5..e8d8931379 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -44,12 +44,12 @@ def expected_output_1(): def expected_output_2(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') - expected_output_2 = pd.Series( - data = [0.97229869, 0.95035106, 0.93037619, 0.91176175, 1., - 1. , 1. , 0.97229869, 1. , 1. , - 1. , 1. , 0.97229869, 0.95035106, 0.93037619, - 0.91176175, 0.89425431, 1. , 1. , 1. , - 1. , 0.97229869, 0.95035106, 0.93037619], + expected_output_2 = pd.Series( + data=[0.97229869, 0.95035106, 0.93037619, 0.91176175, 1., + 1. , 1. , 0.97229869, 1. , 1. , + 1. , 1. , 0.97229869, 0.95035106, 0.93037619, + 0.91176175, 0.89425431, 1. , 1. , 1. , + 1. , 0.97229869, 0.95035106, 0.93037619], index=dt) return expected_output_2 @@ -110,8 +110,8 @@ def test_hsu_defaults(rainfall_input, expected_output_1): accumulation period. """ result = hsu( - rainfall=rainfall_input, cleaning_threshold=0.5, tilt=0.0, pm2_5=1.0e-2, - pm10=2.0e-2) + rainfall=rainfall_input, cleaning_threshold=0.5, tilt=0.0, i + pm2_5=1.0e-2,pm10=2.0e-2) assert np.allclose(result.values, expected_output_1) From db6bb166a6961a66839d30bf7a3fb18e744f3546 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Wed, 10 Jun 2020 20:50:11 -0600 Subject: [PATCH 05/27] Fixed errant character in test --- pvlib/tests/test_soiling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index e8d8931379..ac15053adf 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -110,7 +110,7 @@ def test_hsu_defaults(rainfall_input, expected_output_1): accumulation period. """ result = hsu( - rainfall=rainfall_input, cleaning_threshold=0.5, tilt=0.0, i + rainfall=rainfall_input, cleaning_threshold=0.5, tilt=0.0, pm2_5=1.0e-2,pm10=2.0e-2) assert np.allclose(result.values, expected_output_1) From 13bf88f0b8223c7aee54e85bdc90eb377d31b413 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Fri, 12 Jun 2020 11:31:35 -0600 Subject: [PATCH 06/27] allowed function to accept aribtrary time intervals --- pvlib/soiling.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pvlib/soiling.py b/pvlib/soiling.py index 0bdc6228a5..9ee94e5435 100644 --- a/pvlib/soiling.py +++ b/pvlib/soiling.py @@ -12,8 +12,8 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, depo_veloc=None, rain_accum_period=pd.Timedelta('1h')): """ - Calculates soiling ratio given particulate and rain data using the model - from Humboldt State University (HSU). + Calculates soiling ratio given particulate and rain data using the + Fixed Velocity model from Humboldt State University (HSU). The HSU soiling model [1]_ returns the soiling ratio, a value between zero and one which is equivalent to (1 - transmission loss). Therefore a soiling @@ -75,9 +75,16 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, accum_rain = rainfall.rolling(rain_accum_period, closed='right').sum() # cleaning is True for intervals with rainfall greater than threshold cleaning_times = accum_rain.index[accum_rain >= cleaning_threshold] + + # determine the time intervals in seconds (dt_sec) + dt = rainfall.index.values # datetimes in nanoseconds + dt2 = np.roll(dt.copy(),1) # shift array values by one place + dt3 = np.delete((dt-dt2)/1e9,0) # subtract shifted values from original and convert to seconds + # append the last value to the end so there are the same number of elements in the array + dt_sec = np.append(dt3,dt3[-1]).astype('float64') horiz_mass_rate = pm2_5 * depo_veloc['2_5']\ - + np.maximum(pm10 - pm2_5, 0.) * depo_veloc['10'] * 3600 + + np.maximum(pm10 - pm2_5, 0.) * depo_veloc['10'] * dt_sec tilted_mass_rate = horiz_mass_rate * cosd(tilt) # assuming no rain # tms -> tilt_mass_rate From 820b87c79d412931557d9593375de1fa4dc3e803 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Fri, 12 Jun 2020 13:57:57 -0600 Subject: [PATCH 07/27] updated v0.8.0.rst file --- docs/sphinx/source/whatsnew/v0.8.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/sphinx/source/whatsnew/v0.8.0.rst b/docs/sphinx/source/whatsnew/v0.8.0.rst index 382f3b91de..436423c535 100644 --- a/docs/sphinx/source/whatsnew/v0.8.0.rst +++ b/docs/sphinx/source/whatsnew/v0.8.0.rst @@ -12,6 +12,7 @@ Enhancements Bug fixes ~~~~~~~~~ * Fixed unit and default value errors in :py:func:`pvlib.soiling.hsu`. (:pull:`XXX`) +* Added ability for :py:func:`pvlib.soiling.hsu` to accept arbitrary time intervals. (:pull:`XXX`) Testing ~~~~~~~ From ffb3c351444e4ba515d0f2a104f46406ddc6f0f5 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Wed, 17 Jun 2020 15:41:27 -0600 Subject: [PATCH 08/27] Add variable time interval functionality and testing to soiling.hsu(), also corrected horiz_mass_rate equation --- pvlib/soiling.py | 4 +-- pvlib/tests/test_soiling.py | 64 +++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/pvlib/soiling.py b/pvlib/soiling.py index 9ee94e5435..3dfd41b532 100644 --- a/pvlib/soiling.py +++ b/pvlib/soiling.py @@ -83,8 +83,8 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, # append the last value to the end so there are the same number of elements in the array dt_sec = np.append(dt3,dt3[-1]).astype('float64') - horiz_mass_rate = pm2_5 * depo_veloc['2_5']\ - + np.maximum(pm10 - pm2_5, 0.) * depo_veloc['10'] * dt_sec + horiz_mass_rate = (pm2_5 * depo_veloc['2_5']\ + + np.maximum(pm10 - pm2_5, 0.) * depo_veloc['10']) * dt_sec tilted_mass_rate = horiz_mass_rate * cosd(tilt) # assuming no rain # tms -> tilt_mass_rate diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index ac15053adf..011699a539 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -19,11 +19,11 @@ def expected_output(): end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') expected_no_cleaning = pd.Series( - data=[0.97230454, 0.95036146, 0.93039061, 0.91177978, 0.89427556, - 0.8777455 , 0.86211038, 0.84731759, 0.83332881, 0.82011354, - 0.80764549, 0.79590056, 0.78485556, 0.77448749, 0.76477312, - 0.75568883, 0.74721046, 0.73931338, 0.73197253, 0.72516253, - 0.7188578 , 0.71303268, 0.7076616 , 0.70271919], + data=[0.96998483, 0.94623958, 0.92468139, 0.90465654, 0.88589707, + 0.86826366, 0.85167258, 0.83606715, 0.82140458, 0.80764919, + 0.79476875, 0.78273241, 0.77150951, 0.76106905, 0.75137932, + 0.74240789, 0.73412165, 0.72648695, 0.71946981, 0.7130361 , + 0.70715176, 0.70178307, 0.69689677, 0.69246034], index=dt) return expected_no_cleaning @@ -32,11 +32,11 @@ def expected_output_1(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') expected_output_1 = pd.Series( - data=[0.9872406 , 0.97706269, 0.96769693, 0.95884032, 1., - 0.9872406 , 0.97706269, 0.96769693, 1. , 1. , - 0.9872406 , 0.97706269, 0.96769693, 0.95884032, 0.95036001, - 0.94218263, 0.93426236, 0.92656836, 0.91907873, 0.91177728, - 0.9046517 , 0.89769238, 0.89089165, 0.88424329], + data=[0.98484972, 0.97277367, 0.96167471, 0.95119603, 1. , + 0.98484972, 0.97277367, 0.96167471, 1. , 1. , + 0.98484972, 0.97277367, 0.96167471, 0.95119603, 0.94118234, + 0.93154854, 0.922242 , 0.91322759, 0.90448058, 0.89598283, + 0.88772062, 0.87968325, 0.8718622 , 0.86425049], index=dt) return expected_output_1 @@ -45,15 +45,29 @@ def expected_output_2(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') expected_output_2 = pd.Series( - data=[0.97229869, 0.95035106, 0.93037619, 0.91176175, 1., - 1. , 1. , 0.97229869, 1. , 1. , - 1. , 1. , 0.97229869, 0.95035106, 0.93037619, - 0.91176175, 0.89425431, 1. , 1. , 1. , - 1. , 0.97229869, 0.95035106, 0.93037619], + data = [0.95036261, 0.91178179, 0.87774818, 0.84732079, 1. , + 1. , 1. , 0.95036261, 1. , 1. , + 1. , 1. , 0.95036261, 0.91178179, 0.87774818, + 0.84732079, 0.8201171 , 1. , 1. , 1. , + 1. , 0.95036261, 0.91178179, 0.87774818], index=dt) - return expected_output_2 +@pytest.fixture +def expected_output_3(): + dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), + end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') + timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] + dt_new = dt + pd.to_timedelta(timedelta,'m') + expected_output_3 = pd.Series( + data = [0.96576705, 0.9387675 , 0.91437615, 0.89186852, 1. , + 1. , 0.95185738, 0.9387675 , 1. , 1. , + 1. , 1. , 0.96576705, 0.92630786, 0.90291005, + 0.88122293, 0.86104089, 1. , 1. , 1. , + 0.96576705, 0.9387675 , 0.91437615, 0.89186852], + index=dt_new) + return expected_output_3 + @pytest.fixture def rainfall_input(): @@ -114,6 +128,24 @@ def test_hsu_defaults(rainfall_input, expected_output_1): pm2_5=1.0e-2,pm10=2.0e-2) assert np.allclose(result.values, expected_output_1) +@requires_scipy +@needs_pandas_0_22 +def test_hsu_variable_time_intervals(rainfall_input, expected_output_3): + """ + Test Soiling HSU function with variable time intervals. + """ + depo_veloc = {'2_5': 1.0e-4, '10': 1.0e-4} + rain = pd.DataFrame(data=rainfall_input) + #define time deltas in minutes + timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] + rain['mins_added'] = pd.to_timedelta(timedelta,'m') + rain['new_time'] = rain.index + rain['mins_added'] + rain_var_times = rain.set_index('new_time').iloc[:,0] + result = hsu( + rainfall=rain_var_times, cleaning_threshold=0.5, tilt=50.0, + pm2_5=1,pm10=2,depo_veloc=depo_veloc, + rain_accum_period=pd.Timedelta('2h')) + assert np.allclose(result.values, expected_output_3) @pytest.fixture def greensboro_rain(): From 5e5e360bfa809e42bb7fd014a5145d11d4f103c7 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Wed, 17 Jun 2020 15:48:45 -0600 Subject: [PATCH 09/27] fixed typo in test_soiling.py --- pvlib/tests/test_soiling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 011699a539..9fe71ff068 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -145,7 +145,7 @@ def test_hsu_variable_time_intervals(rainfall_input, expected_output_3): rainfall=rain_var_times, cleaning_threshold=0.5, tilt=50.0, pm2_5=1,pm10=2,depo_veloc=depo_veloc, rain_accum_period=pd.Timedelta('2h')) - assert np.allclose(result.values, expected_output_3) + assert np.allclose(result, expected_output_3) @pytest.fixture def greensboro_rain(): From bc73f512ce35b88e0e083c5fec02904664ce4f93 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Wed, 17 Jun 2020 16:01:08 -0600 Subject: [PATCH 10/27] fixed stickler-ci errors --- pvlib/tests/test_soiling.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 9fe71ff068..8a29f44cd7 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -22,8 +22,8 @@ def expected_output(): data=[0.96998483, 0.94623958, 0.92468139, 0.90465654, 0.88589707, 0.86826366, 0.85167258, 0.83606715, 0.82140458, 0.80764919, 0.79476875, 0.78273241, 0.77150951, 0.76106905, 0.75137932, - 0.74240789, 0.73412165, 0.72648695, 0.71946981, 0.7130361 , - 0.70715176, 0.70178307, 0.69689677, 0.69246034], + 0.74240789, 0.73412165, 0.72648695, 0.71946981, 0.7130361, + 0.70715176, 0.70178307, 0.69689677, 0.69246034], index=dt) return expected_no_cleaning @@ -36,7 +36,7 @@ def expected_output_1(): 0.98484972, 0.97277367, 0.96167471, 1. , 1. , 0.98484972, 0.97277367, 0.96167471, 0.95119603, 0.94118234, 0.93154854, 0.922242 , 0.91322759, 0.90448058, 0.89598283, - 0.88772062, 0.87968325, 0.8718622 , 0.86425049], + 0.88772062, 0.87968325, 0.8718622 , 0.86425049], index=dt) return expected_output_1 @@ -53,13 +53,14 @@ def expected_output_2(): index=dt) return expected_output_2 + @pytest.fixture def expected_output_3(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] dt_new = dt + pd.to_timedelta(timedelta,'m') - expected_output_3 = pd.Series( + expected_output_3=pd.Series( data = [0.96576705, 0.9387675 , 0.91437615, 0.89186852, 1. , 1. , 0.95185738, 0.9387675 , 1. , 1. , 1. , 1. , 0.96576705, 0.92630786, 0.90291005, From 617e445683f7b7c9ae38086d0c1ca89356998d8a Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Wed, 17 Jun 2020 16:02:42 -0600 Subject: [PATCH 11/27] fixed more formatting errors --- pvlib/soiling.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pvlib/soiling.py b/pvlib/soiling.py index 3dfd41b532..551924746c 100644 --- a/pvlib/soiling.py +++ b/pvlib/soiling.py @@ -12,7 +12,7 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, depo_veloc=None, rain_accum_period=pd.Timedelta('1h')): """ - Calculates soiling ratio given particulate and rain data using the + Calculates soiling ratio given particulate and rain data using the Fixed Velocity model from Humboldt State University (HSU). The HSU soiling model [1]_ returns the soiling ratio, a value between zero @@ -75,13 +75,14 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, accum_rain = rainfall.rolling(rain_accum_period, closed='right').sum() # cleaning is True for intervals with rainfall greater than threshold cleaning_times = accum_rain.index[accum_rain >= cleaning_threshold] - + # determine the time intervals in seconds (dt_sec) dt = rainfall.index.values # datetimes in nanoseconds - dt2 = np.roll(dt.copy(),1) # shift array values by one place - dt3 = np.delete((dt-dt2)/1e9,0) # subtract shifted values from original and convert to seconds - # append the last value to the end so there are the same number of elements in the array - dt_sec = np.append(dt3,dt3[-1]).astype('float64') + dt2 = np.roll(dt.copy(), 1) # shift array values by one place + # subtract shifted values from original and convert to seconds + dt3 = np.delete((dt-dt2)/1e9, 0) + # append last value to end so same number of elements in the array + dt_sec = np.append(dt3, dt3[-1]).astype('float64') horiz_mass_rate = (pm2_5 * depo_veloc['2_5']\ + np.maximum(pm10 - pm2_5, 0.) * depo_veloc['10']) * dt_sec From 875f298d4630ab9ea04e22cdf417d3cc3dc27ee5 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Wed, 17 Jun 2020 16:09:46 -0600 Subject: [PATCH 12/27] more stickler-ci issues fixed --- pvlib/soiling.py | 4 ++-- pvlib/tests/test_soiling.py | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pvlib/soiling.py b/pvlib/soiling.py index 551924746c..5053f4883b 100644 --- a/pvlib/soiling.py +++ b/pvlib/soiling.py @@ -82,9 +82,9 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, # subtract shifted values from original and convert to seconds dt3 = np.delete((dt-dt2)/1e9, 0) # append last value to end so same number of elements in the array - dt_sec = np.append(dt3, dt3[-1]).astype('float64') + dt_sec = np.append(dt3, dt3[-1]).astype('float64') - horiz_mass_rate = (pm2_5 * depo_veloc['2_5']\ + horiz_mass_rate = (pm2_5 * depo_veloc['2_5'] + np.maximum(pm10 - pm2_5, 0.) * depo_veloc['10']) * dt_sec tilted_mass_rate = horiz_mass_rate * cosd(tilt) # assuming no rain diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 8a29f44cd7..1f68ecd9a4 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -60,12 +60,12 @@ def expected_output_3(): end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] dt_new = dt + pd.to_timedelta(timedelta,'m') - expected_output_3=pd.Series( - data = [0.96576705, 0.9387675 , 0.91437615, 0.89186852, 1. , - 1. , 0.95185738, 0.9387675 , 1. , 1. , - 1. , 1. , 0.96576705, 0.92630786, 0.90291005, - 0.88122293, 0.86104089, 1. , 1. , 1. , - 0.96576705, 0.9387675 , 0.91437615, 0.89186852], + expected_output_3 = pd.Series( + data=[0.96576705, 0.9387675 , 0.91437615, 0.89186852, 1. , + 1. , 0.95185738, 0.9387675 , 1. , 1. , + 1. , 1. , 0.96576705, 0.92630786, 0.90291005, + 0.88122293, 0.86104089, 1. , 1. , 1. , + 0.96576705, 0.9387675 , 0.91437615, 0.89186852], index=dt_new) return expected_output_3 @@ -129,6 +129,7 @@ def test_hsu_defaults(rainfall_input, expected_output_1): pm2_5=1.0e-2,pm10=2.0e-2) assert np.allclose(result.values, expected_output_1) + @requires_scipy @needs_pandas_0_22 def test_hsu_variable_time_intervals(rainfall_input, expected_output_3): @@ -137,7 +138,7 @@ def test_hsu_variable_time_intervals(rainfall_input, expected_output_3): """ depo_veloc = {'2_5': 1.0e-4, '10': 1.0e-4} rain = pd.DataFrame(data=rainfall_input) - #define time deltas in minutes + # define time deltas in minutes timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] rain['mins_added'] = pd.to_timedelta(timedelta,'m') rain['new_time'] = rain.index + rain['mins_added'] From 254bffa7cb095592cc48cc67f3f4aabad0f65e92 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Thu, 18 Jun 2020 11:26:54 -0600 Subject: [PATCH 13/27] fixed more stickler-ci issues --- pvlib/soiling.py | 5 +++-- pvlib/tests/test_soiling.py | 41 +++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/pvlib/soiling.py b/pvlib/soiling.py index c5b9f0f759..7eead793a5 100644 --- a/pvlib/soiling.py +++ b/pvlib/soiling.py @@ -84,8 +84,9 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, # append last value to end so same number of elements in the array dt_sec = np.append(dt3, dt3[-1]).astype('float64') - horiz_mass_rate = (pm2_5 * depo_veloc['2_5']\ - + np.maximum(pm10 - pm2_5, 0.) * depo_veloc['10']) * dt_sec + horiz_mass_rate = ( + pm2_5 * depo_veloc['2_5'] + np.maximum(pm10 - pm2_5, 0.) + * depo_veloc['10']) * dt_sec tilted_mass_rate = horiz_mass_rate * cosd(tilt) # assuming no rain # tms -> tilt_mass_rate diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 445f41fc69..7d453b3c08 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -32,11 +32,11 @@ def expected_output_1(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') expected_output_1 = pd.Series( - data=[0.98484972, 0.97277367, 0.96167471, 0.95119603, 1. , - 0.98484972, 0.97277367, 0.96167471, 1. , 1. , + data=[0.98484972, 0.97277367, 0.96167471, 0.95119603, 1. , #noqa: E203 + 0.98484972, 0.97277367, 0.96167471, 1. , 1. , #noqa: E203 0.98484972, 0.97277367, 0.96167471, 0.95119603, 0.94118234, - 0.93154854, 0.922242 , 0.91322759, 0.90448058, 0.89598283, - 0.88772062, 0.87968325, 0.8718622 , 0.86425049], + 0.93154854, 0.922242 , 0.91322759, 0.90448058, 0.89598283, #noqa: E203 + 0.88772062, 0.87968325, 0.8718622 , 0.86425049], #noqa: E203 index=dt) return expected_output_1 @@ -45,26 +45,27 @@ def expected_output_2(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') expected_output_2 = pd.Series( - data = [0.95036261, 0.91178179, 0.87774818, 0.84732079, 1. , - 1. , 1. , 0.95036261, 1. , 1. , - 1. , 1. , 0.95036261, 0.91178179, 0.87774818, - 0.84732079, 0.8201171 , 1. , 1. , 1. , - 1. , 0.95036261, 0.91178179, 0.87774818], + data=[0.95036261, 0.91178179, 0.87774818, 0.84732079, 1. , #noqa: E203 + 1. , 1. , 0.95036261, 1. , 1. , #noqa: E203 + 1. , 1. , 0.95036261, 0.91178179, 0.87774818, #noqa: E203 + 0.84732079, 0.8201171 , 1. , 1. , 1. , #noqa: E203 + 1. , 0.95036261, 0.91178179, 0.87774818], #noqa: E203 index=dt) return expected_output_2 + @pytest.fixture def expected_output_3(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') - timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] - dt_new = dt + pd.to_timedelta(timedelta,'m') + timedelta = [0, 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, -30, -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + dt_new = dt + pd.to_timedelta(timedelta, 'm') expected_output_3 = pd.Series( - data=[0.96576705, 0.9387675 , 0.91437615, 0.89186852, 1. , - 1. , 0.95185738, 0.9387675 , 1. , 1. , - 1. , 1. , 0.96576705, 0.92630786, 0.90291005, - 0.88122293, 0.86104089, 1. , 1. , 1. , - 0.96576705, 0.9387675 , 0.91437615, 0.89186852], + data=[0.96576705, 0.9387675 , 0.91437615, 0.89186852, 1. , #noqa: E203 + 1. , 0.95185738, 0.9387675 , 1. , 1. , #noqa: E203 + 1. , 1. , 0.96576705, 0.92630786, 0.90291005, #noqa: E203 + 0.88122293, 0.86104089, 1. , 1. , 1. , #noqa: E203 + 0.96576705, 0.9387675 , 0.91437615, 0.89186852], #noqa: E203 index=dt_new) return expected_output_3 @@ -138,13 +139,13 @@ def test_hsu_variable_time_intervals(rainfall_input, expected_output_3): depo_veloc = {'2_5': 1.0e-4, '10': 1.0e-4} rain = pd.DataFrame(data=rainfall_input) # define time deltas in minutes - timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] - rain['mins_added'] = pd.to_timedelta(timedelta,'m') + timedelta = [0, 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, -30, -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + rain['mins_added'] = pd.to_timedelta(timedelta, 'm') rain['new_time'] = rain.index + rain['mins_added'] - rain_var_times = rain.set_index('new_time').iloc[:,0] + rain_var_times = rain.set_index('new_time').iloc[:, 0] result = hsu( rainfall=rain_var_times, cleaning_threshold=0.5, tilt=50.0, - pm2_5=1,pm10=2,depo_veloc=depo_veloc, + pm2_5=1, pm10=2, depo_veloc=depo_veloc, rain_accum_period=pd.Timedelta('2h')) assert np.allclose(result, expected_output_3) From 5f83509941d0ce28f93c40ca0d392626e33e7ec0 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Thu, 18 Jun 2020 11:40:57 -0600 Subject: [PATCH 14/27] formatting issues --- pvlib/soiling.py | 2 +- pvlib/tests/test_soiling.py | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pvlib/soiling.py b/pvlib/soiling.py index 7eead793a5..97303435c3 100644 --- a/pvlib/soiling.py +++ b/pvlib/soiling.py @@ -86,7 +86,7 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, horiz_mass_rate = ( pm2_5 * depo_veloc['2_5'] + np.maximum(pm10 - pm2_5, 0.) - * depo_veloc['10']) * dt_sec + * depo_veloc['10']) * dt_sec # noqa: W503 tilted_mass_rate = horiz_mass_rate * cosd(tilt) # assuming no rain # tms -> tilt_mass_rate diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 7d453b3c08..b56fdbee3e 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -32,11 +32,11 @@ def expected_output_1(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') expected_output_1 = pd.Series( - data=[0.98484972, 0.97277367, 0.96167471, 0.95119603, 1. , #noqa: E203 - 0.98484972, 0.97277367, 0.96167471, 1. , 1. , #noqa: E203 + data=[0.98484972, 0.97277367, 0.96167471, 0.95119603, 1., + 0.98484972, 0.97277367, 0.96167471, 1. , 1., 0.98484972, 0.97277367, 0.96167471, 0.95119603, 0.94118234, - 0.93154854, 0.922242 , 0.91322759, 0.90448058, 0.89598283, #noqa: E203 - 0.88772062, 0.87968325, 0.8718622 , 0.86425049], #noqa: E203 + 0.93154854, 0.922242, 0.91322759, 0.90448058, 0.89598283, + 0.88772062, 0.87968325, 0.8718622, 0.86425049], index=dt) return expected_output_1 @@ -45,11 +45,11 @@ def expected_output_2(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') expected_output_2 = pd.Series( - data=[0.95036261, 0.91178179, 0.87774818, 0.84732079, 1. , #noqa: E203 - 1. , 1. , 0.95036261, 1. , 1. , #noqa: E203 - 1. , 1. , 0.95036261, 0.91178179, 0.87774818, #noqa: E203 - 0.84732079, 0.8201171 , 1. , 1. , 1. , #noqa: E203 - 1. , 0.95036261, 0.91178179, 0.87774818], #noqa: E203 + data=[0.95036261, 0.91178179, 0.87774818, 0.84732079, 1., + 1., 1., 0.95036261, 1., 1., + 1., 1., 0.95036261, 0.91178179, 0.87774818, + 0.84732079, 0.8201171, 1., 1., 1., + 1., 0.95036261, 0.91178179, 0.87774818], index=dt) return expected_output_2 @@ -58,14 +58,14 @@ def expected_output_2(): def expected_output_3(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') - timedelta = [0, 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, -30, -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] dt_new = dt + pd.to_timedelta(timedelta, 'm') expected_output_3 = pd.Series( - data=[0.96576705, 0.9387675 , 0.91437615, 0.89186852, 1. , #noqa: E203 - 1. , 0.95185738, 0.9387675 , 1. , 1. , #noqa: E203 - 1. , 1. , 0.96576705, 0.92630786, 0.90291005, #noqa: E203 - 0.88122293, 0.86104089, 1. , 1. , 1. , #noqa: E203 - 0.96576705, 0.9387675 , 0.91437615, 0.89186852], #noqa: E203 + data=[0.96576705, 0.9387675, 0.91437615, 0.89186852, 1., + 1., 0.95185738, 0.9387675, 1., 1., + 1., 1., 0.96576705, 0.92630786, 0.90291005, + 0.88122293, 0.86104089, 1., 1., 1., + 0.96576705, 0.9387675, 0.91437615, 0.89186852], index=dt_new) return expected_output_3 @@ -139,7 +139,7 @@ def test_hsu_variable_time_intervals(rainfall_input, expected_output_3): depo_veloc = {'2_5': 1.0e-4, '10': 1.0e-4} rain = pd.DataFrame(data=rainfall_input) # define time deltas in minutes - timedelta = [0, 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, -30, -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] rain['mins_added'] = pd.to_timedelta(timedelta, 'm') rain['new_time'] = rain.index + rain['mins_added'] rain_var_times = rain.set_index('new_time').iloc[:, 0] From d25d6b2908d6fed5b631729e13daf929ae4f4484 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Thu, 18 Jun 2020 11:46:15 -0600 Subject: [PATCH 15/27] formatting issues --- pvlib/tests/test_soiling.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index b56fdbee3e..c6e15ae74d 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -33,7 +33,7 @@ def expected_output_1(): end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') expected_output_1 = pd.Series( data=[0.98484972, 0.97277367, 0.96167471, 0.95119603, 1., - 0.98484972, 0.97277367, 0.96167471, 1. , 1., + 0.98484972, 0.97277367, 0.96167471, 1., 1., 0.98484972, 0.97277367, 0.96167471, 0.95119603, 0.94118234, 0.93154854, 0.922242, 0.91322759, 0.90448058, 0.89598283, 0.88772062, 0.87968325, 0.8718622, 0.86425049], @@ -58,7 +58,7 @@ def expected_output_2(): def expected_output_3(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') - timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] + timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] # noqa: E231 dt_new = dt + pd.to_timedelta(timedelta, 'm') expected_output_3 = pd.Series( data=[0.96576705, 0.9387675, 0.91437615, 0.89186852, 1., @@ -139,7 +139,7 @@ def test_hsu_variable_time_intervals(rainfall_input, expected_output_3): depo_veloc = {'2_5': 1.0e-4, '10': 1.0e-4} rain = pd.DataFrame(data=rainfall_input) # define time deltas in minutes - timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] + timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] # noqa: E231 rain['mins_added'] = pd.to_timedelta(timedelta, 'm') rain['new_time'] = rain.index + rain['mins_added'] rain_var_times = rain.set_index('new_time').iloc[:, 0] From 551ab85528ef1e4382e8765f5c62787b05089b46 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Thu, 18 Jun 2020 11:49:52 -0600 Subject: [PATCH 16/27] formatting... --- pvlib/tests/test_soiling.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index c6e15ae74d..3fb29dd11b 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -58,7 +58,8 @@ def expected_output_2(): def expected_output_3(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') - timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] # noqa: E231 + timedelta = [0, 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, -30, + -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] dt_new = dt + pd.to_timedelta(timedelta, 'm') expected_output_3 = pd.Series( data=[0.96576705, 0.9387675, 0.91437615, 0.89186852, 1., @@ -139,7 +140,8 @@ def test_hsu_variable_time_intervals(rainfall_input, expected_output_3): depo_veloc = {'2_5': 1.0e-4, '10': 1.0e-4} rain = pd.DataFrame(data=rainfall_input) # define time deltas in minutes - timedelta = [0,0,0,0,0,30,0,30,0,30,0,-30,-30,-30,0,0,0,0,0,0,0,0,0,0] # noqa: E231 + timedelta = [0, 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, -30, + -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] rain['mins_added'] = pd.to_timedelta(timedelta, 'm') rain['new_time'] = rain.index + rain['mins_added'] rain_var_times = rain.set_index('new_time').iloc[:, 0] From 400a992459c4169f1918f016b32d3243498b74b7 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Thu, 18 Jun 2020 11:52:12 -0600 Subject: [PATCH 17/27] formatting..... --- pvlib/tests/test_soiling.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 3fb29dd11b..9aad4ff8ea 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -59,7 +59,7 @@ def expected_output_3(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') timedelta = [0, 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, -30, - -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] dt_new = dt + pd.to_timedelta(timedelta, 'm') expected_output_3 = pd.Series( data=[0.96576705, 0.9387675, 0.91437615, 0.89186852, 1., @@ -141,7 +141,7 @@ def test_hsu_variable_time_intervals(rainfall_input, expected_output_3): rain = pd.DataFrame(data=rainfall_input) # define time deltas in minutes timedelta = [0, 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, -30, - -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] rain['mins_added'] = pd.to_timedelta(timedelta, 'm') rain['new_time'] = rain.index + rain['mins_added'] rain_var_times = rain.set_index('new_time').iloc[:, 0] From f88827611bc13183d25775fe271bb2c88baa1789 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Fri, 19 Jun 2020 16:51:09 -0600 Subject: [PATCH 18/27] changed variable time interval calculation in hsu model and test --- pvlib/soiling.py | 8 ++++---- pvlib/tests/test_soiling.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pvlib/soiling.py b/pvlib/soiling.py index 97303435c3..12077e5394 100644 --- a/pvlib/soiling.py +++ b/pvlib/soiling.py @@ -77,12 +77,12 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, cleaning_times = accum_rain.index[accum_rain >= cleaning_threshold] # determine the time intervals in seconds (dt_sec) - dt = rainfall.index.values # datetimes in nanoseconds - dt2 = np.roll(dt.copy(), 1) # shift array values by one place + dt = rainfall.index + dt2 = np.roll(dt.copy(),1) # subtract shifted values from original and convert to seconds - dt3 = np.delete((dt-dt2)/1e9, 0) + dt3 = np.delete((dt-dt2),0).total_seconds() # append last value to end so same number of elements in the array - dt_sec = np.append(dt3, dt3[-1]).astype('float64') + dt_sec = np.append(dt3[0], dt3).astype('float64') horiz_mass_rate = ( pm2_5 * depo_veloc['2_5'] + np.maximum(pm10 - pm2_5, 0.) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 9aad4ff8ea..05b3595106 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -63,10 +63,10 @@ def expected_output_3(): dt_new = dt + pd.to_timedelta(timedelta, 'm') expected_output_3 = pd.Series( data=[0.96576705, 0.9387675, 0.91437615, 0.89186852, 1., - 1., 0.95185738, 0.9387675, 1., 1., - 1., 1., 0.96576705, 0.92630786, 0.90291005, - 0.88122293, 0.86104089, 1., 1., 1., - 0.96576705, 0.9387675, 0.91437615, 0.89186852], + 1., 0.98093819, 0.9387675, 1., 1., + 1., 1., 0.96576705, 0.9387675 , 0.90291005, + 0.88122293, 0.86104089, 1., 1., 1., + 0.96576705, 0.9387675, 0.91437615, 0.89186852], index=dt_new) return expected_output_3 From 066221566fee5ad49e756ab2bdc29c685fdac677 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Fri, 19 Jun 2020 16:55:47 -0600 Subject: [PATCH 19/27] formatting changes --- pvlib/soiling.py | 4 ++-- pvlib/tests/test_soiling.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pvlib/soiling.py b/pvlib/soiling.py index 12077e5394..20ceb91215 100644 --- a/pvlib/soiling.py +++ b/pvlib/soiling.py @@ -78,9 +78,9 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, # determine the time intervals in seconds (dt_sec) dt = rainfall.index - dt2 = np.roll(dt.copy(),1) + dt2 = np.roll(dt.copy(), 1) # subtract shifted values from original and convert to seconds - dt3 = np.delete((dt-dt2),0).total_seconds() + dt3 = np.delete((dt-dt2), 0).total_seconds() # append last value to end so same number of elements in the array dt_sec = np.append(dt3[0], dt3).astype('float64') diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 05b3595106..7261745fd4 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -63,10 +63,10 @@ def expected_output_3(): dt_new = dt + pd.to_timedelta(timedelta, 'm') expected_output_3 = pd.Series( data=[0.96576705, 0.9387675, 0.91437615, 0.89186852, 1., - 1., 0.98093819, 0.9387675, 1., 1., - 1., 1., 0.96576705, 0.9387675 , 0.90291005, - 0.88122293, 0.86104089, 1., 1., 1., - 0.96576705, 0.9387675, 0.91437615, 0.89186852], + 1., 0.98093819, 0.9387675, 1., 1., + 1., 1., 0.96576705, 0.9387675 , 0.90291005, + 0.88122293, 0.86104089, 1., 1., 1., + 0.96576705, 0.9387675, 0.91437615, 0.89186852], index=dt_new) return expected_output_3 From 6cd354e4aa7fa046352768bb63193847d61b4bd8 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Fri, 19 Jun 2020 16:58:07 -0600 Subject: [PATCH 20/27] formatting --- pvlib/tests/test_soiling.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 7261745fd4..56bc731ca0 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -63,10 +63,10 @@ def expected_output_3(): dt_new = dt + pd.to_timedelta(timedelta, 'm') expected_output_3 = pd.Series( data=[0.96576705, 0.9387675, 0.91437615, 0.89186852, 1., - 1., 0.98093819, 0.9387675, 1., 1., - 1., 1., 0.96576705, 0.9387675 , 0.90291005, - 0.88122293, 0.86104089, 1., 1., 1., - 0.96576705, 0.9387675, 0.91437615, 0.89186852], + 1., 0.98093819, 0.9387675, 1., 1., + 1., 1., 0.96576705, 0.9387675, 0.90291005, + 0.88122293, 0.86104089, 1., 1., 1., + 0.96576705, 0.9387675, 0.91437615, 0.89186852], index=dt_new) return expected_output_3 From 9122281e94d7ac69020f0ca8f7e86cfad510adeb Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Fri, 19 Jun 2020 17:03:08 -0600 Subject: [PATCH 21/27] formatting --- pvlib/tests/test_soiling.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 56bc731ca0..01cd506921 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -63,10 +63,10 @@ def expected_output_3(): dt_new = dt + pd.to_timedelta(timedelta, 'm') expected_output_3 = pd.Series( data=[0.96576705, 0.9387675, 0.91437615, 0.89186852, 1., - 1., 0.98093819, 0.9387675, 1., 1., - 1., 1., 0.96576705, 0.9387675, 0.90291005, - 0.88122293, 0.86104089, 1., 1., 1., - 0.96576705, 0.9387675, 0.91437615, 0.89186852], + 1., 0.98093819, 0.9387675, 1., 1., + 1., 1., 0.96576705, 0.9387675, 0.90291005, + 0.88122293, 0.86104089, 1., 1., 1., + 0.96576705, 0.9387675, 0.91437615, 0.89186852], index=dt_new) return expected_output_3 From b864eb9739b6d5ff9d9c32745f8acf3542921381 Mon Sep 17 00:00:00 2001 From: Joshua Stein Date: Fri, 19 Jun 2020 17:04:51 -0600 Subject: [PATCH 22/27] formatting --- pvlib/tests/test_soiling.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 01cd506921..76c8fcfe2d 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -63,10 +63,10 @@ def expected_output_3(): dt_new = dt + pd.to_timedelta(timedelta, 'm') expected_output_3 = pd.Series( data=[0.96576705, 0.9387675, 0.91437615, 0.89186852, 1., - 1., 0.98093819, 0.9387675, 1., 1., - 1., 1., 0.96576705, 0.9387675, 0.90291005, - 0.88122293, 0.86104089, 1., 1., 1., - 0.96576705, 0.9387675, 0.91437615, 0.89186852], + 1., 0.98093819, 0.9387675, 1., 1., + 1., 1., 0.96576705, 0.9387675, 0.90291005, + 0.88122293, 0.86104089, 1., 1., 1., + 0.96576705, 0.9387675, 0.91437615, 0.89186852], index=dt_new) return expected_output_3 From 020b7d2d6a2418af8c0fef06529df4fcbf559a62 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Wed, 26 Aug 2020 18:39:05 -0600 Subject: [PATCH 23/27] whatsnew PR links --- docs/sphinx/source/whatsnew/v0.8.0.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.8.0.rst b/docs/sphinx/source/whatsnew/v0.8.0.rst index beca0526c5..94b81e1f38 100644 --- a/docs/sphinx/source/whatsnew/v0.8.0.rst +++ b/docs/sphinx/source/whatsnew/v0.8.0.rst @@ -14,8 +14,8 @@ Enhancements Bug fixes ~~~~~~~~~ -* Fixed unit and default value errors in :py:func:`pvlib.soiling.hsu`. (:pull:`XXX`) -* Added ability for :py:func:`pvlib.soiling.hsu` to accept arbitrary time intervals. (:pull:`XXX`) +* Fixed unit and default value errors in :py:func:`pvlib.soiling.hsu`. (:pull:`977`, :pull:`980`) +* Added ability for :py:func:`pvlib.soiling.hsu` to accept arbitrary time intervals. (:pull:`980`) Testing ~~~~~~~ From a8aed0138938c34d75b54085db7af233223158be Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Wed, 26 Aug 2020 18:41:02 -0600 Subject: [PATCH 24/27] remove needs_pandas_22 from test_soiling --- pvlib/tests/test_soiling.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 76c8fcfe2d..58622f709c 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -7,8 +7,7 @@ from pandas.util.testing import assert_series_equal from pvlib.soiling import hsu, kimber from pvlib.iotools import read_tmy3 -from conftest import ( - requires_scipy, needs_pandas_0_22, DATA_DIR) +from conftest import requires_scipy, DATA_DIR import pytest @@ -30,7 +29,7 @@ def expected_output(): @pytest.fixture def expected_output_1(): dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0), - end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') + end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h') expected_output_1 = pd.Series( data=[0.98484972, 0.97277367, 0.96167471, 0.95119603, 1., 0.98484972, 0.97277367, 0.96167471, 1., 1., @@ -82,7 +81,6 @@ def rainfall_input(): @requires_scipy -@needs_pandas_0_22 def test_hsu_no_cleaning(rainfall_input, expected_output): """Test Soiling HSU function""" @@ -100,7 +98,6 @@ def test_hsu_no_cleaning(rainfall_input, expected_output): @requires_scipy -@needs_pandas_0_22 def test_hsu(rainfall_input, expected_output_2): """Test Soiling HSU function with cleanings""" @@ -119,20 +116,17 @@ def test_hsu(rainfall_input, expected_output_2): @requires_scipy -@needs_pandas_0_22 def test_hsu_defaults(rainfall_input, expected_output_1): """ Test Soiling HSU function with default deposition velocity and default rain accumulation period. """ - result = hsu( - rainfall=rainfall_input, cleaning_threshold=0.5, tilt=0.0, - pm2_5=1.0e-2,pm10=2.0e-2) + result = hsu(rainfall=rainfall_input, cleaning_threshold=0.5, tilt=0.0, + pm2_5=1.0e-2,pm10=2.0e-2) assert np.allclose(result.values, expected_output_1) @requires_scipy -@needs_pandas_0_22 def test_hsu_variable_time_intervals(rainfall_input, expected_output_3): """ Test Soiling HSU function with variable time intervals. @@ -165,7 +159,6 @@ def expected_kimber_nowash(): parse_dates=True, index_col='timestamp') -@needs_pandas_0_22 def test_kimber_nowash(greensboro_rain, expected_kimber_nowash): """Test Kimber soiling model with no manual washes""" # Greensboro typical expected annual rainfall is 8345mm @@ -183,7 +176,6 @@ def expected_kimber_manwash(): parse_dates=True, index_col='timestamp') -@needs_pandas_0_22 def test_kimber_manwash(greensboro_rain, expected_kimber_manwash): """Test Kimber soiling model with a manual wash""" # a manual wash date @@ -207,7 +199,6 @@ def expected_kimber_norain(): return np.where(norain > max_loss_rate, max_loss_rate, norain) -@needs_pandas_0_22 def test_kimber_norain(greensboro_rain, expected_kimber_norain): """Test Kimber soiling model with no rain""" # a year with no rain @@ -229,7 +220,6 @@ def expected_kimber_initial_soil(): return np.where(norain > max_loss_rate, max_loss_rate, norain) -@needs_pandas_0_22 def test_kimber_initial_soil(greensboro_rain, expected_kimber_initial_soil): """Test Kimber soiling model with initial soiling""" # a year with no rain From 6cce79775c83ea8ba80004a48bbd8be0b846eb01 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Wed, 26 Aug 2020 18:42:46 -0600 Subject: [PATCH 25/27] move time interval note from bug fixes to enhancements --- docs/sphinx/source/whatsnew/v0.8.0.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.8.0.rst b/docs/sphinx/source/whatsnew/v0.8.0.rst index 0a7c1a0606..361035b8e8 100644 --- a/docs/sphinx/source/whatsnew/v0.8.0.rst +++ b/docs/sphinx/source/whatsnew/v0.8.0.rst @@ -52,12 +52,11 @@ Enhancements * Added *racking_model*, *module_type*, and *temperature_model_parameters* to PVSystem, LocalizedPVSystem, SingleAxisTracker, and LocalizedSingleAxisTracker repr methods. (:issue:`1027`) +* Added ability for :py:func:`pvlib.soiling.hsu` to accept arbitrary time intervals. (:pull:`980`) Bug fixes ~~~~~~~~~ * Fixed unit and default value errors in :py:func:`pvlib.soiling.hsu`. (:pull:`977`, :pull:`980`) -* Added ability for :py:func:`pvlib.soiling.hsu` to accept arbitrary time intervals. (:pull:`980`) -* Fixed unit and default value errors in :py:func:`pvlib.soiling.hsu`. (:pull:`XXX`) * Handle NUL characters and fix version column dtype in :py:func:`~pvlib.iotools.crn.read_crn`. (:issue:`1025`) From 89b045232532d6eca17727dda046eee703f3a3c9 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Wed, 26 Aug 2020 18:45:59 -0600 Subject: [PATCH 26/27] stickler --- pvlib/tests/test_soiling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/tests/test_soiling.py b/pvlib/tests/test_soiling.py index 6af40a6121..200bcfe59f 100644 --- a/pvlib/tests/test_soiling.py +++ b/pvlib/tests/test_soiling.py @@ -122,7 +122,7 @@ def test_hsu_defaults(rainfall_input, expected_output_1): accumulation period. """ result = hsu(rainfall=rainfall_input, cleaning_threshold=0.5, tilt=0.0, - pm2_5=1.0e-2,pm10=2.0e-2) + pm2_5=1.0e-2, pm10=2.0e-2) assert np.allclose(result.values, expected_output_1) From fb3f71e0080f91cc237b699e6446bb5c3cc9f78b Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Wed, 26 Aug 2020 19:43:37 -0600 Subject: [PATCH 27/27] review improvements --- pvlib/soiling.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pvlib/soiling.py b/pvlib/soiling.py index 20ceb91215..4e7096b0c6 100644 --- a/pvlib/soiling.py +++ b/pvlib/soiling.py @@ -78,15 +78,15 @@ def hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, # determine the time intervals in seconds (dt_sec) dt = rainfall.index - dt2 = np.roll(dt.copy(), 1) # subtract shifted values from original and convert to seconds - dt3 = np.delete((dt-dt2), 0).total_seconds() - # append last value to end so same number of elements in the array - dt_sec = np.append(dt3[0], dt3).astype('float64') + dt_diff = (dt[1:] - dt[:-1]).total_seconds() + # ensure same number of elements in the array, assuming that the interval + # prior to the first value is equal in length to the first interval + dt_sec = np.append(dt_diff[0], dt_diff).astype('float64') horiz_mass_rate = ( pm2_5 * depo_veloc['2_5'] + np.maximum(pm10 - pm2_5, 0.) - * depo_veloc['10']) * dt_sec # noqa: W503 + * depo_veloc['10']) * dt_sec tilted_mass_rate = horiz_mass_rate * cosd(tilt) # assuming no rain # tms -> tilt_mass_rate