From 96ec25bdce4bbbd85f5b7225f8328b67824af7ec Mon Sep 17 00:00:00 2001 From: Tony Lorenzo Date: Tue, 10 May 2016 08:39:20 -0700 Subject: [PATCH] convert indexing arrays to int to avoid future deprecation --- docs/sphinx/source/whatsnew/v0.3.3.txt | 4 +++- pvlib/clearsky.py | 4 ++-- pvlib/irradiance.py | 13 ++++++++----- pvlib/test/test_irradiance.py | 13 +++++++++++++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.3.3.txt b/docs/sphinx/source/whatsnew/v0.3.3.txt index 16dc8c6c4d..5af1e98a51 100644 --- a/docs/sphinx/source/whatsnew/v0.3.3.txt +++ b/docs/sphinx/source/whatsnew/v0.3.3.txt @@ -35,7 +35,8 @@ Bug fixes * Fix snlinverter and singlediode documentation. They incorrectly said that inverter/module must be a DataFrame, when in reality they can be any dict-like object. (:issue:`157`) - +* Fix numpy 1.11 deprecation warnings caused by some functions using + non-integer indices. Documentation ~~~~~~~~~~~~~ @@ -64,3 +65,4 @@ Contributors * Will Holmgren * Mark Mikofski * Johannes Oos +* Tony Lorenzo diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index fb64a5d473..7a0051679f 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -241,8 +241,8 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None, mat = scipy.io.loadmat(filepath) linke_turbidity_table = mat['LinkeTurbidity'] - latitude_index = np.around(_linearly_scale(latitude, 90, -90, 1, 2160)) - longitude_index = np.around(_linearly_scale(longitude, -180, 180, 1, 4320)) + latitude_index = np.around(_linearly_scale(latitude, 90, -90, 1, 2160)).astype(np.int64) + longitude_index = np.around(_linearly_scale(longitude, -180, 180, 1, 4320)).astype(np.int64) g = linke_turbidity_table[latitude_index][longitude_index] diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index e92ff4919e..863627bb3f 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -1495,7 +1495,6 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True, kt_prime = kt / (1.031 * np.exp(-1.4/(0.9+9.4/airmass)) + 0.1) kt_prime[kt_prime > 0.82] = 0.82 # From SRRL code. consider np.NaN - kt_prime.fillna(0, inplace=True) pvl_logger.debug('kt_prime:\n%s', kt_prime) # wholmgren: @@ -1519,7 +1518,7 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True, # Later, we'll subtract 1 to conform to Python's 0-indexing. # Create kt_prime bins - kt_prime_bin = pd.Series(index=times) + kt_prime_bin = pd.Series(0, index=times, dtype=np.int64) kt_prime_bin[(kt_prime>=0) & (kt_prime<0.24)] = 1 kt_prime_bin[(kt_prime>=0.24) & (kt_prime<0.4)] = 2 kt_prime_bin[(kt_prime>=0.4) & (kt_prime<0.56)] = 3 @@ -1529,7 +1528,7 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True, pvl_logger.debug('kt_prime_bin:\n%s', kt_prime_bin) # Create zenith angle bins - zenith_bin = pd.Series(index=times) + zenith_bin = pd.Series(0, index=times, dtype=np.int64) zenith_bin[(zenith>=0) & (zenith<25)] = 1 zenith_bin[(zenith>=25) & (zenith<40)] = 2 zenith_bin[(zenith>=40) & (zenith<55)] = 3 @@ -1539,7 +1538,7 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True, pvl_logger.debug('zenith_bin:\n%s', zenith_bin) # Create the bins for w based on dew point temperature - w_bin = pd.Series(index=times) + w_bin = pd.Series(0, index=times, dtype=np.int64) w_bin[(w>=0) & (w<1)] = 1 w_bin[(w>=1) & (w<2)] = 2 w_bin[(w>=2) & (w<3)] = 3 @@ -1548,7 +1547,7 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True, pvl_logger.debug('w_bin:\n%s', w_bin) # Create delta_kt_prime binning. - delta_kt_prime_bin = pd.Series(index=times) + delta_kt_prime_bin = pd.Series(0, index=times, dtype=np.int64) delta_kt_prime_bin[(delta_kt_prime>=0) & (delta_kt_prime<0.015)] = 1 delta_kt_prime_bin[(delta_kt_prime>=0.015) & (delta_kt_prime<0.035)] = 2 delta_kt_prime_bin[(delta_kt_prime>=0.035) & (delta_kt_prime<0.07)] = 3 @@ -1562,6 +1561,10 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True, # assignment and Python-style array lookup. dirint_coeffs = coeffs[kt_prime_bin-1, zenith_bin-1, delta_kt_prime_bin-1, w_bin-1] + # convert unassigned bins to nan + # use where to avoid boolean indexing deprecation + dirint_coeffs[np.where((kt_prime_bin == 0) | (zenith_bin == 0) | + (w_bin == 0) | (delta_kt_prime_bin == 0))] = np.nan dni = disc_out['dni'] * dirint_coeffs diff --git a/pvlib/test/test_irradiance.py b/pvlib/test/test_irradiance.py index a5918cacb4..b1ad7fd33b 100644 --- a/pvlib/test/test_irradiance.py +++ b/pvlib/test/test_irradiance.py @@ -216,6 +216,19 @@ def test_dirint_value(): assert_almost_equal(dirint_data.values, np.array([928.85, 688.26]), 1) + +def test_dirint_nans(): + times = pd.DatetimeIndex(start='2014-06-24T12-0700', periods=5, freq='6H') + ghi = pd.Series([np.nan, 1038.62, 1038.62, 1038.62, 1038.62], index=times) + zenith = pd.Series([10.567, np.nan, 10.567, 10.567, 10.567,], index=times) + pressure = pd.Series([93193., 93193., np.nan, 93193., 93193.], index=times) + temp_dew = pd.Series([10, 10, 10, np.nan, 10], index=times) + dirint_data = irradiance.dirint(ghi, zenith, times, pressure=pressure, + temp_dew=temp_dew) + assert_almost_equal(dirint_data.values, + np.array([np.nan, np.nan, np.nan, np.nan, 934.2]), 1) + + def test_dirint_tdew(): times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700']) ghi = pd.Series([1038.62, 254.53], index=times)