From 1c3c2291ad67d12cb0bdbc7767b70d6c952d995d Mon Sep 17 00:00:00 2001 From: Will Holmgren Date: Thu, 12 Mar 2015 18:03:23 -0700 Subject: [PATCH 1/3] move scipy import to inside ineichen --- pvlib/clearsky.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index abe6b4f604..b86d9944af 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -12,7 +12,6 @@ import numpy as np import pandas as pd -import scipy.io from pvlib import tools from pvlib import irradiance @@ -127,9 +126,17 @@ def ineichen(time, location, linke_turbidity=None, # so divide the number from the file by 20 to get the # turbidity. + try: + import scipy.io + except ImportError: + raise ImportError('The Linke turbidity lookup table requires scipy. ' + + 'You can still use clearsky.ineichen if you ' + + 'supply your own turbidities.') + # consider putting this code at module level this_path = os.path.dirname(os.path.abspath(__file__)) logger.debug('this_path={}'.format(this_path)) + mat = scipy.io.loadmat(os.path.join(this_path, 'data', 'LinkeTurbidities.mat')) linke_turbidity = mat['LinkeTurbidity'] LatitudeIndex = np.round_(_linearly_scale(location.latitude,90,- 90,1,2160)) From 41841fe9064290c7af4ba086cadd455abcade471 Mon Sep 17 00:00:00 2001 From: Will Holmgren Date: Thu, 12 Mar 2015 18:12:12 -0700 Subject: [PATCH 2/3] update whatsnew --- docs/sphinx/source/whatsnew/v0.1.0.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/whatsnew/v0.1.0.txt b/docs/sphinx/source/whatsnew/v0.1.0.txt index d52699c226..07b2ee0914 100644 --- a/docs/sphinx/source/whatsnew/v0.1.0.txt +++ b/docs/sphinx/source/whatsnew/v0.1.0.txt @@ -40,6 +40,9 @@ Other changes * Adding logging calls, removing print calls. * Improved PEP8 compliance. * Added ``/pvlib/data`` for lookup tables, test, and tutorial data. +* Limited the scope of ``clearsky.py``'s ``scipy`` dependency. + ``clearsky.ineichen`` will work without ``scipy`` so long as + the Linke Turbidity is supplied as a keyword argument. (:issue:`13`) Documentation @@ -55,7 +58,7 @@ Documentation Testing ~~~~~~~ -* Tests are cleaner and more thorough. They are still no where near complete. +* Tests are cleaner and more thorough. They are still nowhere near complete. * Using Coveralls to measure test coverage. * Using TravisCI for automated testing. * Using ``nosetests`` for more concise test code. From 55bce4a68a5156e9016a01f4f57cf5d60a404f48 Mon Sep 17 00:00:00 2001 From: Will Holmgren Date: Thu, 12 Mar 2015 18:18:54 -0700 Subject: [PATCH 3/3] tweak clearsky tests --- pvlib/test/test_clearsky.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pvlib/test/test_clearsky.py b/pvlib/test/test_clearsky.py index 997f937c9e..d16dfb3d92 100644 --- a/pvlib/test/test_clearsky.py +++ b/pvlib/test/test_clearsky.py @@ -30,6 +30,7 @@ def test_ineichen_required(): # the clearsky function should lookup the linke turbidity on its own + # will fail without scipy clearsky.ineichen(times, tus) def test_ineichen_supply_linke(): @@ -37,11 +38,11 @@ def test_ineichen_supply_linke(): def test_ineichen_solpos(): clearsky.ineichen(times, tus, linke_turbidity=3, - solarposition_method='pyephem') + solarposition_method='pyephem') def test_ineichen_airmass(): clearsky.ineichen(times, tus, linke_turbidity=3, - airmass_model='simple') + airmass_model='simple') def test_ineichen_keys(): clearsky_data = clearsky.ineichen(times, tus, linke_turbidity=3) @@ -60,7 +61,7 @@ def test_haurwitz_keys(): # test DISC def test_disc_keys(): - clearsky_data = clearsky.ineichen(times, tus) + clearsky_data = clearsky.ineichen(times, tus, linke_turbidity=3) disc_data = clearsky.disc(clearsky_data['GHI'], ephem_data['zenith'], ephem_data.index) assert 'DNI_gen_DISC' in disc_data.columns