From c51a4d64f4b0c06c5e6692b093bdc22c0e446ef1 Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Thu, 11 Jul 2019 22:27:07 -0400 Subject: [PATCH 01/19] Resolve merge conflicts. The upstream what's new file had been updated. --- docs/sphinx/source/whatsnew/v0.7.0.rst | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.7.0.rst b/docs/sphinx/source/whatsnew/v0.7.0.rst index 98a2dc6469..18508a6374 100644 --- a/docs/sphinx/source/whatsnew/v0.7.0.rst +++ b/docs/sphinx/source/whatsnew/v0.7.0.rst @@ -7,12 +7,23 @@ This is a major release that drops support for Python 2 and Python 3.4. We recommend all users of v0.6.3 upgrade to this release after checking API compatibility notes. -**Python 2.7 support ended on June 1, 2019**. (:issue:`501`) - +**Python 2.7 support ended on June 1, 2019.** (:issue:`501`) **Minimum numpy version is now 1.10.4. Minimum pandas version is now 0.18.1.** +Bug fixes +~~~~~~~~~ +* Fix handling of keyword arguments in `forecasts.get_processed_data`. + (:issue:`745`) + +Testing +~~~~~~~ +* Added 30 minutes to timestamps in `test_psm3.csv` to match change in NSRDB (:issue:`733`) +* Added tests for methods in bifacial.py. + Contributors ~~~~~~~~~~~~ * Mark Campanellli (:ghuser:`markcampanelli`) * Will Holmgren (:ghuser:`wholmgren`) +* Oscar Dowson (:ghuser:`odow`) +* Alexander Morgan (:ghuser:`alexandermorgan`) \ No newline at end of file From a603c2b6aa52e25aa549ea5c73e6d1a7986ca14b Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Tue, 16 Jul 2019 12:35:36 -0400 Subject: [PATCH 02/19] Copy whatsnew file from upstream. --- docs/sphinx/source/whatsnew/v0.7.0.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.7.0.rst b/docs/sphinx/source/whatsnew/v0.7.0.rst index 580d5f6f03..a8b2f21ebd 100644 --- a/docs/sphinx/source/whatsnew/v0.7.0.rst +++ b/docs/sphinx/source/whatsnew/v0.7.0.rst @@ -7,7 +7,6 @@ This is a major release that drops support for Python 2 and Python 3.4. We recommend all users of v0.6.3 upgrade to this release after checking API compatibility notes. -**Python 2.7 support ended on June 1, 2019.** (:issue:`501`) **Python 2.7 support ended on June 1, 2019**. (:issue:`501`) **Minimum numpy version is now 1.10.4. Minimum pandas version is now 0.18.1.** @@ -19,7 +18,6 @@ Bug fixes Testing ~~~~~~~ * Added 30 minutes to timestamps in `test_psm3.csv` to match change in NSRDB (:issue:`733`) -* Added tests for methods in bifacial.py. Contributors @@ -27,4 +25,3 @@ Contributors * Mark Campanellli (:ghuser:`markcampanelli`) * Will Holmgren (:ghuser:`wholmgren`) * Oscar Dowson (:ghuser:`odow`) -* Alexander Morgan (:ghuser:`alexandermorgan`) From 078146f5d02b742ebf6ac887cb2882d1f68caa43 Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Tue, 16 Jul 2019 12:37:55 -0400 Subject: [PATCH 03/19] Remove unnecessary np.around(). Instead of rounding to one decimal place, then comparing to .5, just compare to .55 right away which preserves the same behavior as before. If you want to stay true to the comment on line 314, use <= .5 in comparison instead as before, but still drop the np.around(). --- pvlib/clearsky.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index 6543244e30..b9deab112f 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -313,12 +313,12 @@ def _linearly_scale(inputmatrix, inputmin, inputmax, outputmin, outputmax): (inputmatrix, inputmax - inputrange, inputmax)) # round down if input is within half an index or else raise index error if outputmatrix > outputmax: - if np.around(outputmatrix - outputmax, 1) <= 0.5: + if outputmatrix - outputmax < 0.55: outputmatrix = outputmax else: raise err elif outputmatrix < outputmin: - if np.around(outputmin - outputmatrix, 1) <= 0.5: + if outputmin - outputmatrix < 0.55: outputmatrix = outputmin else: raise err From ee4594901023fb7008e7dcd9dd22f6c9aae8232a Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Tue, 16 Jul 2019 20:27:38 -0400 Subject: [PATCH 04/19] Use <= .5 as comparisons in _linearly_scale. --- pvlib/clearsky.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index b9deab112f..5a99e86263 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -313,12 +313,12 @@ def _linearly_scale(inputmatrix, inputmin, inputmax, outputmin, outputmax): (inputmatrix, inputmax - inputrange, inputmax)) # round down if input is within half an index or else raise index error if outputmatrix > outputmax: - if outputmatrix - outputmax < 0.55: + if outputmatrix - outputmax < 0.5: outputmatrix = outputmax else: raise err elif outputmatrix < outputmin: - if outputmin - outputmatrix < 0.55: + if outputmin - outputmatrix < 0.5: outputmatrix = outputmin else: raise err From fba6d376b473b0fd2662e0df8c168b3910706407 Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Tue, 16 Jul 2019 20:29:09 -0400 Subject: [PATCH 05/19] Correct previous commit, use <= .5. --- pvlib/clearsky.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index 5a99e86263..cac08aacb6 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -313,12 +313,12 @@ def _linearly_scale(inputmatrix, inputmin, inputmax, outputmin, outputmax): (inputmatrix, inputmax - inputrange, inputmax)) # round down if input is within half an index or else raise index error if outputmatrix > outputmax: - if outputmatrix - outputmax < 0.5: + if outputmatrix - outputmax <= 0.5: outputmatrix = outputmax else: raise err elif outputmatrix < outputmin: - if outputmin - outputmatrix < 0.5: + if outputmin - outputmatrix <= 0.5: outputmatrix = outputmin else: raise err From 3e7a53df2528605f37a7db2170f9125f9b90ef41 Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Tue, 16 Jul 2019 20:33:25 -0400 Subject: [PATCH 06/19] Update what's new file. Closes #754 --- docs/sphinx/source/whatsnew/v0.7.0.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.7.0.rst b/docs/sphinx/source/whatsnew/v0.7.0.rst index a8b2f21ebd..17b4e9a8a2 100644 --- a/docs/sphinx/source/whatsnew/v0.7.0.rst +++ b/docs/sphinx/source/whatsnew/v0.7.0.rst @@ -14,6 +14,8 @@ Bug fixes ~~~~~~~~~ * Fix handling of keyword arguments in `forecasts.get_processed_data`. (:issue:`745`) +* Fix rounding issue in `clearsky._linearly_scale`. + (:issue:`754`) Testing ~~~~~~~ @@ -25,3 +27,4 @@ Contributors * Mark Campanellli (:ghuser:`markcampanelli`) * Will Holmgren (:ghuser:`wholmgren`) * Oscar Dowson (:ghuser:`odow`) +* Alexander Morgan (:ghuser:`alexandermorgan`) From 48f4d9c2ab60180d2e0c6012a81bc07dba654e2e Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Sat, 20 Jul 2019 10:22:14 -0400 Subject: [PATCH 07/19] Compare to 0.500001 for margin of error. --- pvlib/clearsky.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index cac08aacb6..125a246da3 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -313,12 +313,12 @@ def _linearly_scale(inputmatrix, inputmin, inputmax, outputmin, outputmax): (inputmatrix, inputmax - inputrange, inputmax)) # round down if input is within half an index or else raise index error if outputmatrix > outputmax: - if outputmatrix - outputmax <= 0.5: + if outputmatrix - outputmax <= 0.500001: outputmatrix = outputmax else: raise err elif outputmatrix < outputmin: - if outputmin - outputmatrix <= 0.5: + if outputmin - outputmatrix <= 0.500001: outputmatrix = outputmin else: raise err From b49e6b5736ff544a03b3c9477f46b609420596ff Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Sat, 20 Jul 2019 21:59:13 -0400 Subject: [PATCH 08/19] Rename _linearly_scale -> _degrees_to_index, refactor. This commit reduces inputs to just two, refactors some calculations, and mainly tries to be much clearer with the documentation. --- pvlib/clearsky.py | 75 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index 125a246da3..3071ffa528 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -195,12 +195,8 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None, pvlib_path = os.path.dirname(os.path.abspath(__file__)) filepath = os.path.join(pvlib_path, 'data', 'LinkeTurbidities.h5') - latitude_index = ( - np.around(_linearly_scale(latitude, 90, -90, 0, 2160)) - .astype(np.int64)) - longitude_index = ( - np.around(_linearly_scale(longitude, -180, 180, 0, 4320)) - .astype(np.int64)) + latitude_index = _degrees_to_index(latitude, degree_type='latitude') + longitude_index = _degrees_to_index(longitude, degree_type='longitude') lt_h5_file = tables.open_file(filepath) try: @@ -301,28 +297,63 @@ def _calendar_month_middles(year): return middles -def _linearly_scale(inputmatrix, inputmin, inputmax, outputmin, outputmax): - """linearly scale input to output, used by Linke turbidity lookup""" +def _degrees_to_index(degrees, degree_type): + """Transform input degrees to an output index integer. The Linke + turbidity lookup tables have three dimensions, latitude, longitude, and + month. Specify a degree value and either 'latitude' or 'longitude' to get + the appropriate index number for the first two of these index numbers. + + Parameters + ---------- + degrees : float + Degrees of either latitude or longitude. + degree_type : string + Specify whether degrees arg is latitude or longitude. Must be set to + either 'latitude' or 'longitude' or an error will be raised. + + Returns + ------- + index : np.int16 + The latitude or longitude index number to use when looking up values + in the Linke turbidity lookup table. + """ + # Assign inputmin, inputmax, and outputmax based on degree type. + if degree_type == 'latitude': + inputmin = 90 + inputmax = -90 + outputmax = 2160 + elif degree_type == 'longitude': + inputmin = -180 + inputmax = 180 + outputmax = 4320 + else: + raise IndexError("degree_type must be 'latitude' or 'longitude'.") + inputrange = inputmax - inputmin - outputrange = outputmax - outputmin - delta = outputrange/inputrange # number of indices per input unit - inputmin = inputmin + 1.0 / delta / 2.0 # shift to center of index - outputmax = outputmax - 1 # shift index to zero indexing - outputmatrix = (inputmatrix - inputmin) * delta + outputmin + scale = outputmax/inputrange # number of indices per degree + center = inputmin + 1 / scale / 2 # shift to center of index + outputmax -= 1 # shift index to zero indexing + index = (degrees - center) * scale err = IndexError('Input, %g, is out of range (%g, %g).' % - (inputmatrix, inputmax - inputrange, inputmax)) - # round down if input is within half an index or else raise index error - if outputmatrix > outputmax: - if outputmatrix - outputmax <= 0.500001: - outputmatrix = outputmax + (degrees, inputmin, inputmax)) + + # If the index is still out of bounds after rounding, raise an error. + if index > outputmax: + if index - outputmax <= 0.500001: + index = outputmax else: raise err - elif outputmatrix < outputmin: - if outputmin - outputmatrix <= 0.500001: - outputmatrix = outputmin + elif index < 0: + if -index <= 0.500001: + index = 0 else: raise err - return outputmatrix + # If the index wasn't set to outputmax or 0, round it and case it as an + # integer so it can be used in integer-based indexing. + else: + index = int(np.around(index)) + + return index def haurwitz(apparent_zenith): From 5af90e6f0163bfd219e1ecb7264d10aa62885625 Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Sat, 20 Jul 2019 22:02:05 -0400 Subject: [PATCH 09/19] Add test for clearsky._degrees_to_index(). Tests that an invalid value for the degree_type argument raises an error. --- pvlib/test/test_clearsky.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pvlib/test/test_clearsky.py b/pvlib/test/test_clearsky.py index ee291345f9..3a5c124762 100644 --- a/pvlib/test/test_clearsky.py +++ b/pvlib/test/test_clearsky.py @@ -519,6 +519,13 @@ def monthly_lt_nointerp(lat, lon, time=months): monthly_lt_nointerp(38.2, -181) # exceeds min longitude +def test_degrees_to_index_1(): + """Test that _degrees_to_index raises an error when something other than + 'latitude' or 'longitude' is passed.""" + with pytest.raises(IndexError): # invalid value for degree_type argument + clearsky._degrees_to_index(degrees=22.0, degree_type='width') + + @pytest.fixture def detect_clearsky_data(): test_dir = os.path.dirname(os.path.abspath( From 83f8b5d71d65a8f4f6658d9b498d0fd4053a1a42 Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Sat, 20 Jul 2019 22:04:25 -0400 Subject: [PATCH 10/19] Remove try/except/finally. The exception that is being checked for here is already checked for in the _degrees_to_index method, so there's no need to do the check again. So this removes the except portion, and just keeps the try and finally parts. --- pvlib/clearsky.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index 3071ffa528..19644f26fe 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -199,14 +199,8 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None, longitude_index = _degrees_to_index(longitude, degree_type='longitude') lt_h5_file = tables.open_file(filepath) - try: - lts = lt_h5_file.root.LinkeTurbidity[latitude_index, - longitude_index, :] - except IndexError: - raise IndexError('Latitude should be between 90 and -90, ' - 'longitude between -180 and 180.') - finally: - lt_h5_file.close() + lts = lt_h5_file.root.LinkeTurbidity[latitude_index, longitude_index, :] + lt_h5_file.close() if interp_turbidity: linke_turbidity = _interpolate_turbidity(lts, time) From 4c855d0ca2933c63fbd15609076eb163cd66162e Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Sat, 20 Jul 2019 22:06:52 -0400 Subject: [PATCH 11/19] Update parameter type description. --- pvlib/clearsky.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index 19644f26fe..1cc6b3789d 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -299,7 +299,7 @@ def _degrees_to_index(degrees, degree_type): Parameters ---------- - degrees : float + degrees : float or int Degrees of either latitude or longitude. degree_type : string Specify whether degrees arg is latitude or longitude. Must be set to From 5abb179e1a9dddcfc3ff752cf7e259dddb4a6e34 Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Sat, 20 Jul 2019 22:22:01 -0400 Subject: [PATCH 12/19] Fix linting errors. --- pvlib/clearsky.py | 12 ++++++------ pvlib/test/test_clearsky.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index 1cc6b3789d..0921a9cd1a 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -292,9 +292,9 @@ def _calendar_month_middles(year): def _degrees_to_index(degrees, degree_type): - """Transform input degrees to an output index integer. The Linke - turbidity lookup tables have three dimensions, latitude, longitude, and - month. Specify a degree value and either 'latitude' or 'longitude' to get + """Transform input degrees to an output index integer. The Linke + turbidity lookup tables have three dimensions, latitude, longitude, and + month. Specify a degree value and either 'latitude' or 'longitude' to get the appropriate index number for the first two of these index numbers. Parameters @@ -308,7 +308,7 @@ def _degrees_to_index(degrees, degree_type): Returns ------- index : np.int16 - The latitude or longitude index number to use when looking up values + The latitude or longitude index number to use when looking up values in the Linke turbidity lookup table. """ # Assign inputmin, inputmax, and outputmax based on degree type. @@ -342,11 +342,11 @@ def _degrees_to_index(degrees, degree_type): index = 0 else: raise err - # If the index wasn't set to outputmax or 0, round it and case it as an + # If the index wasn't set to outputmax or 0, round it and case it as an # integer so it can be used in integer-based indexing. else: index = int(np.around(index)) - + return index diff --git a/pvlib/test/test_clearsky.py b/pvlib/test/test_clearsky.py index 3a5c124762..06c63b69b1 100644 --- a/pvlib/test/test_clearsky.py +++ b/pvlib/test/test_clearsky.py @@ -520,7 +520,7 @@ def monthly_lt_nointerp(lat, lon, time=months): def test_degrees_to_index_1(): - """Test that _degrees_to_index raises an error when something other than + """Test that _degrees_to_index raises an error when something other than 'latitude' or 'longitude' is passed.""" with pytest.raises(IndexError): # invalid value for degree_type argument clearsky._degrees_to_index(degrees=22.0, degree_type='width') From 5d3033fcc50fa9cbd790a1da239b3ede07dc77a4 Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Sun, 21 Jul 2019 11:34:25 -0400 Subject: [PATCH 13/19] Fix typo. --- pvlib/clearsky.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index 0921a9cd1a..1366d54741 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -342,7 +342,7 @@ def _degrees_to_index(degrees, degree_type): index = 0 else: raise err - # If the index wasn't set to outputmax or 0, round it and case it as an + # If the index wasn't set to outputmax or 0, round it and cast it as an # integer so it can be used in integer-based indexing. else: index = int(np.around(index)) From 1e1b4b229957b4c3ed63a8acf50f0dbf37c5e7a4 Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Mon, 22 Jul 2019 15:48:16 -0400 Subject: [PATCH 14/19] Give more detail in what's new description. --- docs/sphinx/source/whatsnew/v0.7.0.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/whatsnew/v0.7.0.rst b/docs/sphinx/source/whatsnew/v0.7.0.rst index 17b4e9a8a2..b10684a1a0 100644 --- a/docs/sphinx/source/whatsnew/v0.7.0.rst +++ b/docs/sphinx/source/whatsnew/v0.7.0.rst @@ -14,7 +14,9 @@ Bug fixes ~~~~~~~~~ * Fix handling of keyword arguments in `forecasts.get_processed_data`. (:issue:`745`) -* Fix rounding issue in `clearsky._linearly_scale`. +* Fix rounding issue in `clearsky._linearly_scale`, a function that converts + longitude or latitude degree to an index number in a Linke turbidity lookup + table. Also rename the function to `clearsky._degrees_to_index`. (:issue:`754`) Testing From 6d087bd011167ee983ab81a80dfad906459ffa94 Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Mon, 22 Jul 2019 15:57:00 -0400 Subject: [PATCH 15/19] Rename arg, use context manager, and add more tech. documentation. --- pvlib/clearsky.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index 1366d54741..6b11e42dc8 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -151,9 +151,9 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None, ---------- time : pandas.DatetimeIndex - latitude : float + latitude : numeric - longitude : float + longitude : numeric filepath : None or string, default None The path to the ``.h5`` file. @@ -195,12 +195,11 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None, pvlib_path = os.path.dirname(os.path.abspath(__file__)) filepath = os.path.join(pvlib_path, 'data', 'LinkeTurbidities.h5') - latitude_index = _degrees_to_index(latitude, degree_type='latitude') - longitude_index = _degrees_to_index(longitude, degree_type='longitude') + latitude_index = _degrees_to_index(latitude, coordinate='latitude') + longitude_index = _degrees_to_index(longitude, coordinate='longitude') - lt_h5_file = tables.open_file(filepath) - lts = lt_h5_file.root.LinkeTurbidity[latitude_index, longitude_index, :] - lt_h5_file.close() + with tables.open_file(filepath) as lt_h5_file: + lts = lt_h5_file.root.LinkeTurbidity[latitude_index, longitude_index, :] if interp_turbidity: linke_turbidity = _interpolate_turbidity(lts, time) @@ -291,7 +290,7 @@ def _calendar_month_middles(year): return middles -def _degrees_to_index(degrees, degree_type): +def _degrees_to_index(degrees, coordinate): """Transform input degrees to an output index integer. The Linke turbidity lookup tables have three dimensions, latitude, longitude, and month. Specify a degree value and either 'latitude' or 'longitude' to get @@ -301,7 +300,7 @@ def _degrees_to_index(degrees, degree_type): ---------- degrees : float or int Degrees of either latitude or longitude. - degree_type : string + coordinate : string Specify whether degrees arg is latitude or longitude. Must be set to either 'latitude' or 'longitude' or an error will be raised. @@ -312,16 +311,16 @@ def _degrees_to_index(degrees, degree_type): in the Linke turbidity lookup table. """ # Assign inputmin, inputmax, and outputmax based on degree type. - if degree_type == 'latitude': + if coordinate == 'latitude': inputmin = 90 inputmax = -90 outputmax = 2160 - elif degree_type == 'longitude': + elif coordinate == 'longitude': inputmin = -180 inputmax = 180 outputmax = 4320 else: - raise IndexError("degree_type must be 'latitude' or 'longitude'.") + raise IndexError("coordinate must be 'latitude' or 'longitude'.") inputrange = inputmax - inputmin scale = outputmax/inputrange # number of indices per degree @@ -332,6 +331,8 @@ def _degrees_to_index(degrees, degree_type): (degrees, inputmin, inputmax)) # If the index is still out of bounds after rounding, raise an error. + # 0.50001 is used in comparisons instead of 0.5 to allow for a small + # margin of error which can occur when dealing with floating point numbers. if index > outputmax: if index - outputmax <= 0.500001: index = outputmax From f2e3cd8d3c0514f2d3a59f39c393458599238f5d Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Mon, 22 Jul 2019 15:59:50 -0400 Subject: [PATCH 16/19] Add missing zero in documentation. --- pvlib/clearsky.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index 6b11e42dc8..23b8aaa9e0 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -331,7 +331,7 @@ def _degrees_to_index(degrees, coordinate): (degrees, inputmin, inputmax)) # If the index is still out of bounds after rounding, raise an error. - # 0.50001 is used in comparisons instead of 0.5 to allow for a small + # 0.500001 is used in comparisons instead of 0.5 to allow for a small # margin of error which can occur when dealing with floating point numbers. if index > outputmax: if index - outputmax <= 0.500001: From dd432e47dc7a96c0d598efcb0b31d6c8c70b74df Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Mon, 22 Jul 2019 16:02:38 -0400 Subject: [PATCH 17/19] Break up line so it's < 80 characters. --- pvlib/clearsky.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index 23b8aaa9e0..cd83848549 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -199,7 +199,8 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None, longitude_index = _degrees_to_index(longitude, coordinate='longitude') with tables.open_file(filepath) as lt_h5_file: - lts = lt_h5_file.root.LinkeTurbidity[latitude_index, longitude_index, :] + lts = lt_h5_file.root.LinkeTurbidity[latitude_index, + longitude_index, :] if interp_turbidity: linke_turbidity = _interpolate_turbidity(lts, time) From 2351bf43337ccd6c64d39e5ddb625b87c880cf36 Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Mon, 22 Jul 2019 16:39:40 -0400 Subject: [PATCH 18/19] Change arg type to float or int. --- pvlib/clearsky.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index cd83848549..cd5dda9ff5 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -151,9 +151,9 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None, ---------- time : pandas.DatetimeIndex - latitude : numeric + latitude : float or int - longitude : numeric + longitude : float or int filepath : None or string, default None The path to the ``.h5`` file. From ac8bb1df8eca93584dd10cec7b0e331e7c06226e Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Mon, 22 Jul 2019 16:41:16 -0400 Subject: [PATCH 19/19] Update argument name in test_degrees_to_index_1(). --- pvlib/test/test_clearsky.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/test/test_clearsky.py b/pvlib/test/test_clearsky.py index 06c63b69b1..44d2e586a7 100644 --- a/pvlib/test/test_clearsky.py +++ b/pvlib/test/test_clearsky.py @@ -522,8 +522,8 @@ def monthly_lt_nointerp(lat, lon, time=months): def test_degrees_to_index_1(): """Test that _degrees_to_index raises an error when something other than 'latitude' or 'longitude' is passed.""" - with pytest.raises(IndexError): # invalid value for degree_type argument - clearsky._degrees_to_index(degrees=22.0, degree_type='width') + with pytest.raises(IndexError): # invalid value for coordinate argument + clearsky._degrees_to_index(degrees=22.0, coordinate='width') @pytest.fixture