Skip to content

Move scipy import in clearsky.py #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/sphinx/source/whatsnew/v0.1.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
* Removed NREL's SPA code to comply with their license (:issue:`9`).


Expand All @@ -56,7 +59,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.
Expand Down
9 changes: 8 additions & 1 deletion pvlib/clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import numpy as np
import pandas as pd
import scipy.io

from pvlib import tools
from pvlib import irradiance
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 4 additions & 3 deletions pvlib/test/test_clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@

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():
clearsky.ineichen(times, tus, linke_turbidity=3)

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)
Expand All @@ -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
Expand Down