18
18
import math
19
19
import os
20
20
import sys
21
-
22
- from solar_utils_exceptions import SOLPOS_Error
23
- from solar_utils_exceptions import SPECTRL2_Error
21
+ from solar_utils .exceptions import SOLPOS_Error , SPECTRL2_Error
24
22
25
23
_DIRNAME = os .path .dirname (__file__ )
26
24
if sys .platform == 'win32' :
35
33
PLATFORM = 'darwin'
36
34
SOLPOSAM = 'libsolposAM.dylib'
37
35
SPECTRL2 = 'libspectrl2.dylib'
38
-
39
36
SOLPOSAMDLL = os .path .join (_DIRNAME , PLATFORM , SOLPOSAM )
40
37
SPECTRL2DLL = os .path .join (_DIRNAME , PLATFORM , SPECTRL2 )
41
38
42
39
43
- def _int2bits (x ):
40
+ def _int2bits (err_code ):
44
41
"""
45
42
Convert integer to bits.
46
43
47
44
:param x: integer to convert
48
45
:returns: log(x, 2)
49
46
"""
50
- return int (math .log (x , 2 ))
47
+ return int (math .log (err_code , 2 ))
51
48
52
49
53
50
def solposAM (location , datetime , weather ):
@@ -63,11 +60,11 @@ def solposAM(location, datetime, weather):
63
60
:type weather: list of floats
64
61
:returns: angles, airmass
65
62
:rtype: float
66
- :raises: :exc:`~solar_utils.solar_utils_exceptions .SOLPOS_Error`
63
+ :raises: :exc:`~solar_utils.exceptions .SOLPOS_Error`
67
64
"""
68
65
# load the DLL
69
- solposAMdll = ctypes .cdll .LoadLibrary (SOLPOSAMDLL )
70
- solposAM = solposAMdll .solposAM
66
+ solposAM_dll = ctypes .cdll .LoadLibrary (SOLPOSAMDLL )
67
+ _solposAM = solposAM_dll .solposAM
71
68
# cast Python types as ctypes
72
69
_location = (ctypes .c_float * 3 )(* location )
73
70
_datetime = (ctypes .c_int * 6 )(* datetime )
@@ -79,14 +76,14 @@ def solposAM(location, datetime, weather):
79
76
orientation = (ctypes .c_float * 2 )()
80
77
shadowband = (ctypes .c_float * 3 )()
81
78
# call DLL
82
- code = solposAM (_location , _datetime , _weather , angles , airmass , settings ,
83
- orientation , shadowband )
79
+ err_code = _solposAM (_location , _datetime , _weather , angles , airmass ,
80
+ settings , orientation , shadowband )
84
81
# return results if successful, otherwise raise SOLPOS_Error
85
- if code == 0 :
82
+ if err_code == 0 :
86
83
return angles , airmass
87
84
else :
88
- # convert code to bits
89
- _code = _int2bits (code )
85
+ # convert err_code to bits
86
+ _code = _int2bits (err_code )
90
87
data = {'location' : location ,
91
88
'datetime' : datetime ,
92
89
'weather' : weather ,
@@ -99,7 +96,7 @@ def solposAM(location, datetime, weather):
99
96
100
97
101
98
def spectrl2 (units , location , datetime , weather , orientation ,
102
- atmosphericConditions , albedo ):
99
+ atmospheric_conditions , albedo ):
103
100
"""
104
101
Calculate solar spectrum by calling functions exported by
105
102
:data:`SPECTRL2DLL`.
@@ -114,14 +111,14 @@ def spectrl2(units, location, datetime, weather, orientation,
114
111
:type weather: list of floats
115
112
:param orientation: tilt and aspect [degrees]
116
113
:type orientation: list of floats
117
- :param atmosphericConditions : alpha, assym, ozone, tau500 and watvap
118
- :type atmosphericConditions : list of floats
114
+ :param atmospheric_conditions : alpha, assym, ozone, tau500 and watvap
115
+ :type atmospheric_conditions : list of floats
119
116
:param albedo: 6 wavelengths and 6 reflectivities
120
117
:type albedo: list of lists of floats
121
118
:returns: specdif, specdir, specetr, specglo and specx
122
119
:rtype: float
123
- :raises: :exc:`~solar_utils.solar_utils_exceptions .SPECTRL2_Error`,
124
- :exc:`~solar_utils.solar_utils_exceptions .SOLPOS_Error`
120
+ :raises: :exc:`~solar_utils.exceptions .SPECTRL2_Error`,
121
+ :exc:`~solar_utils.exceptions .SOLPOS_Error`
125
122
126
123
.. seealso::
127
124
:func:`solposAM`
@@ -133,23 +130,22 @@ def spectrl2(units, location, datetime, weather, orientation,
133
130
>>> datetime = [1999, 7, 22, 9, 45, 37]
134
131
>>> weather = [1006.0, 27.0]
135
132
>>> orientation = [33.65, 135.0]
136
- >>> atmosphericConditions = [1.14, 0.65, -1.0, 0.2, 1.36]
133
+ >>> atmospheric_conditions = [1.14, 0.65, -1.0, 0.2, 1.36]
137
134
>>> albedo = [0.3, 0.7, 0.8, 1.3, 2.5, 4.0] + ([0.2] * 6)
138
135
>>> (specdif, specdir, specetr, specglo,
139
136
specx) = spectrl2(units, location, datetime, weather, orientation,
140
- atmosphericConditions , albedo)
137
+ atmospheric_conditions , albedo)
141
138
"""
142
- # requires 'solpos.dll'
143
139
# load the DLL
144
- ctypes .cdll .LoadLibrary (SOLPOSAMDLL )
145
- spectrl2DLL = ctypes .cdll .LoadLibrary (SPECTRL2DLL )
146
- spectrl2 = spectrl2DLL .spectrl2
140
+ ctypes .cdll .LoadLibrary (SOLPOSAMDLL ) # requires 'solpos.dll'
141
+ spectrl2_dll = ctypes .cdll .LoadLibrary (SPECTRL2DLL )
142
+ _spectrl2 = spectrl2_dll .spectrl2
147
143
# cast Python types as ctypes
148
144
_location = (ctypes .c_float * 3 )(* location )
149
145
_datetime = (ctypes .c_int * 6 )(* datetime )
150
146
_weather = (ctypes .c_float * 2 )(* weather )
151
147
_orientation = (ctypes .c_float * 2 )(* orientation )
152
- _atmosphericConditions = (ctypes .c_float * 5 )(* atmosphericConditions )
148
+ _atmospheric_conditions = (ctypes .c_float * 5 )(* atmospheric_conditions )
153
149
_albedo = (ctypes .c_float * 12 )(* albedo )
154
150
# allocate space for results
155
151
specdif = (ctypes .c_float * 122 )()
@@ -162,21 +158,23 @@ def spectrl2(units, location, datetime, weather, orientation,
162
158
settings = (ctypes .c_int * 2 )()
163
159
shadowband = (ctypes .c_float * 3 )()
164
160
# call DLL
165
- code = spectrl2 (units , _location , _datetime , _weather , _orientation ,
166
- _atmosphericConditions , _albedo , specdif , specdir , specetr ,
167
- specglo , specx , angles , airmass , settings , shadowband )
161
+ err_code = _spectrl2 (
162
+ units , _location , _datetime , _weather , _orientation ,
163
+ _atmospheric_conditions , _albedo , specdif , specdir , specetr , specglo ,
164
+ specx , angles , airmass , settings , shadowband
165
+ )
168
166
# return results if successful, otherwise raise exception
169
- if code == 0 :
167
+ if err_code == 0 :
170
168
return specdif , specdir , specetr , specglo , specx
171
- elif code < 0 :
169
+ elif err_code < 0 :
172
170
data = {'units' : units ,
173
- 'tau500' : atmosphericConditions [3 ],
174
- 'watvap' : atmosphericConditions [4 ],
175
- 'assym' : atmosphericConditions [1 ]}
176
- raise SPECTRL2_Error (code , data )
171
+ 'tau500' : atmospheric_conditions [3 ],
172
+ 'watvap' : atmospheric_conditions [4 ],
173
+ 'assym' : atmospheric_conditions [1 ]}
174
+ raise SPECTRL2_Error (err_code , data )
177
175
else :
178
- # convert code to bits
179
- _code = _int2bits (code )
176
+ # convert err_code to bits
177
+ _code = _int2bits (err_code )
180
178
data = {'location' : location ,
181
179
'datetime' : datetime ,
182
180
'weather' : weather ,
0 commit comments