@@ -153,7 +153,7 @@ def ineichen(apparent_zenith, airmass_absolute, linke_turbidity,
153153def lookup_linke_turbidity (time , latitude , longitude , filepath = None ,
154154 interp_turbidity = True ):
155155 """
156- Look up the Linke Turibidity from the ``LinkeTurbidities.mat ``
156+ Look up the Linke Turibidity from the ``LinkeTurbidities.h5 ``
157157 data file supplied with pvlib.
158158
159159 Parameters
@@ -165,18 +165,18 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None,
165165 longitude : float
166166
167167 filepath : None or string, default None
168- The path to the ``.mat `` file.
168+ The path to the ``.h5 `` file.
169169
170170 interp_turbidity : bool, default True
171171 If ``True``, interpolates the monthly Linke turbidity values
172- found in ``LinkeTurbidities.mat `` to daily values.
172+ found in ``LinkeTurbidities.h5 `` to daily values.
173173
174174 Returns
175175 -------
176176 turbidity : Series
177177 """
178178
179- # The .mat file 'LinkeTurbidities.mat ' contains a single 2160 x 4320 x 12
179+ # The .h5 file 'LinkeTurbidities.h5 ' contains a single 2160 x 4320 x 12
180180 # matrix of type uint8 called 'LinkeTurbidity'. The rows represent global
181181 # latitudes from 90 to -90 degrees; the columns represent global longitudes
182182 # from -180 to 180; and the depth (third dimension) represents months of
@@ -194,18 +194,15 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None,
194194 # 1st column: 179.9583 W, 2nd column: 179.875 W
195195
196196 try :
197- import scipy . io
197+ import tables
198198 except ImportError :
199- raise ImportError ('The Linke turbidity lookup table requires scipy . '
199+ raise ImportError ('The Linke turbidity lookup table requires tables . '
200200 'You can still use clearsky.ineichen if you '
201201 'supply your own turbidities.' )
202202
203203 if filepath is None :
204204 pvlib_path = os .path .dirname (os .path .abspath (__file__ ))
205- filepath = os .path .join (pvlib_path , 'data' , 'LinkeTurbidities.mat' )
206-
207- mat = scipy .io .loadmat (filepath )
208- linke_turbidity_table = mat ['LinkeTurbidity' ]
205+ filepath = os .path .join (pvlib_path , 'data' , 'LinkeTurbidities.h5' )
209206
210207 latitude_index = (
211208 np .around (_linearly_scale (latitude , 90 , - 90 , 0 , 2160 ))
@@ -214,7 +211,14 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None,
214211 np .around (_linearly_scale (longitude , - 180 , 180 , 0 , 4320 ))
215212 .astype (np .int64 ))
216213
217- lts = linke_turbidity_table [latitude_index ][longitude_index ]
214+ lt_h5_file = tables .open_file (filepath )
215+ try :
216+ lts = lt_h5_file .root .LinkeTurbidity [latitude_index , longitude_index , :]
217+ except IndexError :
218+ raise IndexError ('Latitude should be between 90 and -90, '
219+ 'longitude between -180 and 180.' )
220+ finally :
221+ lt_h5_file .close ()
218222
219223 if interp_turbidity :
220224 linke_turbidity = _interpolate_turbidity (lts , time )
0 commit comments