5
5
6
6
from __future__ import division
7
7
8
+ import logging
9
+
8
10
import os
9
11
from collections import OrderedDict
10
12
13
15
14
16
from pvlib import tools
15
17
18
+ LOGGER = logging .getLogger (__name__ )
19
+ LOGGER .setLevel (logging .DEBUG )
20
+
16
21
17
22
def ineichen (apparent_zenith , airmass_absolute , linke_turbidity ,
18
23
altitude = 0 , dni_extra = 1364. ):
@@ -186,6 +191,12 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None,
186
191
# so divide the number from the file by 20 to get the
187
192
# turbidity.
188
193
194
+ # The nodes of the grid are 5' (1/12=0.0833[arcdeg]) apart.
195
+ # From Section 8 of Aerosol optical depth and Linke turbidity climatology
196
+ # http://www.meteonorm.com/images/uploads/downloads/ieashc36_report_TL_AOD_climatologies.pdf
197
+ # 1st row: 89.9583 S, 2nd row: 89.875 S
198
+ # 1st column: 179.9583 W, 2nd column: 179.875 W
199
+
189
200
try :
190
201
import scipy .io
191
202
except ImportError :
@@ -201,10 +212,10 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None,
201
212
linke_turbidity_table = mat ['LinkeTurbidity' ]
202
213
203
214
latitude_index = (
204
- np .around (_linearly_scale (latitude , 90 , - 90 , 1 , 2160 ))
215
+ np .around (_linearly_scale (latitude , 90 , - 90 , 0 , 2160 ))
205
216
.astype (np .int64 ))
206
217
longitude_index = (
207
- np .around (_linearly_scale (longitude , - 180 , 180 , 1 , 4320 ))
218
+ np .around (_linearly_scale (longitude , - 180 , 180 , 0 , 4320 ))
208
219
.astype (np .int64 ))
209
220
210
221
g = linke_turbidity_table [latitude_index ][longitude_index ]
@@ -232,6 +243,33 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None,
232
243
return linke_turbidity
233
244
234
245
246
+ def _linearly_scale (inputmatrix , inputmin , inputmax , outputmin , outputmax ):
247
+ """
248
+ Used by linke turbidity lookup function.
249
+ """
250
+ inputrange = inputmax - inputmin
251
+ outputrange = outputmax - outputmin
252
+ delta = outputrange / inputrange # number of indices per input unit
253
+ inputmin = inputmin + 1.0 / delta / 2.0 # shift index to center
254
+ outputmax = outputmax - 1
255
+ outputmatrix = (inputmatrix - inputmin ) * delta + outputmin
256
+ LOGGER .debug ('outputmatrix: %g' , outputmatrix )
257
+ # TODO: allow wrapping for longitude
258
+ err = IndexError ('Input, %g, is out of range (%g, %g).' %
259
+ (inputmatrix , inputmax - inputrange , inputmax ))
260
+ if outputmatrix > outputmax :
261
+ if np .around (outputmatrix - outputmax , 1 ) <= 0.5 :
262
+ outputmatrix = outputmax
263
+ else :
264
+ raise err
265
+ elif outputmatrix < outputmin :
266
+ if np .around (outputmin - outputmatrix , 1 ) <= 0.5 :
267
+ outputmatrix = outputmin
268
+ else :
269
+ raise err
270
+ return outputmatrix
271
+
272
+
235
273
def haurwitz (apparent_zenith ):
236
274
'''
237
275
Determine clear sky GHI from Haurwitz model.
@@ -281,15 +319,6 @@ def haurwitz(apparent_zenith):
281
319
return df_out
282
320
283
321
284
- def _linearly_scale (inputmatrix , inputmin , inputmax , outputmin , outputmax ):
285
- """ used by linke turbidity lookup function """
286
-
287
- inputrange = inputmax - inputmin
288
- outputrange = outputmax - outputmin
289
- outputmatrix = (inputmatrix - inputmin ) * outputrange / inputrange + outputmin
290
- return outputmatrix
291
-
292
-
293
322
def simplified_solis (apparent_elevation , aod700 = 0.1 , precipitable_water = 1. ,
294
323
pressure = 101325. , dni_extra = 1364. ):
295
324
"""
0 commit comments