22
22
sky_irradiance ,
23
23
clear_sky_irradiances ,
24
24
horizontal_irradiance )
25
- from .meteorology .sky_luminance import cie_relative_luminance
25
+ from .meteorology .sky_luminance import sky_luminance
26
26
from .meteorology .sun_position import sun_position
27
+ from .sky_map import sky_grid , sky_map
28
+
27
29
28
30
# default location and dates
29
31
_daydate = '2000-06-21'
@@ -77,9 +79,8 @@ def sky_discretisation(turtle_sectors=46, nb_az=None, nb_el=None):
77
79
return elevations_h [:nb_sect ], azimuths_h [:nb_sect ], sky_fraction
78
80
79
81
80
- def sky_radiance_distribution (sky_elevation , sky_azimuth , sky_fraction ,
81
- sky_type = 'soc' , sun_elevation = None ,
82
- sun_azimuth = None , avoid_sun = True ):
82
+ def sky_radiance_distribution (sky_elevation , sky_azimuth ,
83
+ sky_type = 'soc' , sky_irradiance = None ):
83
84
"""Normalised sky radiance distribution as a function of sky type for a
84
85
finite set of directions sampling the sky hemisphere.
85
86
@@ -88,43 +89,20 @@ def sky_radiance_distribution(sky_elevation, sky_azimuth, sky_fraction,
88
89
sampling the sky hemisphere
89
90
sky_azimuth: (float or list of float) azimuth (degrees, from North,
90
91
positive clockwise) of directions sampling the sky hemisphere
91
- sky_fraction: (float or list of float) fraction of sky associated to
92
- directions sampling the sky hemisphere
93
- sky_type: (str) one of 'soc' (standard overcast sky),
94
- 'uoc' (uniform luminance)
95
- 'clear_sky' (standard clear sky low turbidity)
96
- sun_elevation: sun elevation (degrees). Only needed for clear_sky
97
- sun_azimuth: sun azimuth (degrees, from North, positive clockwise).
98
- Only needed for clear_sky
99
- avoid_sun (bool): avoid sampling radiance distribution toward directions
100
- directly pointing to solar disc
92
+ sky_type (str): sky type, one of ('soc', 'uoc', 'clear_sky', 'blended', 'all_weather')
93
+ sky_irradiance: a datetime indexed dataframe specifying sky irradiances for the period, such as returned by
94
+ astk.sky_irradiance.sky_irradiance. Needed for all sky_types except 'uoc' and 'soc'
101
95
102
96
Returns:
103
- the relative radiance(s) associated to the sky directions
97
+ a list relative_luminance
104
98
"""
105
99
106
- el = numpy .radians (sky_elevation )
107
- az = numpy .radians (sky_azimuth )
108
- sky_fraction = numpy .array (sky_fraction )
109
-
110
- if sun_elevation is not None :
111
- sun_elevation = numpy .radians (sun_elevation )
112
- if sun_azimuth is not None :
113
- sun_azimuth = numpy .radians (sun_azimuth )
114
-
115
- if avoid_sun and sky_type == 'clear_sky' :
116
- delta_el = abs (el - sun_elevation )
117
- delta_az = abs (az - sun_azimuth )
118
- sun_disc = numpy .radians (0.553 )
119
- az += numpy .where ((delta_az < sun_disc ) & (delta_el < sun_disc ), sun_disc ,
120
- 0 )
121
-
122
- lum = cie_relative_luminance (el , az , sun_elevation , sun_azimuth ,
123
- type = sky_type )
124
- rad_dist = lum * sky_fraction
125
- rad_dist /= sum (rad_dist )
126
-
127
- return rad_dist
100
+ grid = sky_grid ()
101
+ lum = sky_luminance (grid , sky_type , sky_irradiance )
102
+ directions = [* zip (sky_elevation , sky_azimuth )]
103
+ sky_sources , smap = sky_map (grid , lum , directions )
104
+ slum = list (zip (* sky_sources ))[2 ]
105
+ return horizontal_irradiance (slum , sky_elevation )
128
106
129
107
130
108
def sun_sources (irradiance = 1 , dates = None , daydate = _daydate ,
@@ -173,10 +151,7 @@ def sky_sources(sky_type='soc', irradiance=1, turtle_sectors=46, dates=None, day
173
151
altitude = _altitude , timezone = _timezone ):
174
152
""" Light sources representing standard cie sky types in 46 directions
175
153
Args:
176
- sky_type:(str) type of sky luminance model. One of :
177
- 'soc' (standard overcast sky),
178
- 'uoc' (uniform overcast sky)
179
- 'clear_sky' (standard clear sky)
154
+ sky_type (str): sky type, one of ('soc', 'uoc', 'clear_sky', 'blended', 'all_weather')
180
155
irradiance: (float) sum of horizontal irradiance of all sources. If None
181
156
diffuse horizontal clear_sky irradiance are used for clear_sky type and
182
157
20% attenuated clear_sky global horizontal irradiances are used for
@@ -197,49 +172,23 @@ def sky_sources(sky_type='soc', irradiance=1, turtle_sectors=46, dates=None, day
197
172
198
173
source_elevation , source_azimuth , source_fraction = sky_discretisation (turtle_sectors )
199
174
175
+ c_sky = sky_irradiance (dates = dates , daydate = daydate ,
176
+ longitude = longitude , latitude = latitude ,
177
+ altitude = altitude , timezone = timezone )
200
178
if sky_type == 'soc' or sky_type == 'uoc' :
201
- radiance = sky_radiance_distribution (source_elevation , source_azimuth ,
202
- source_fraction ,
203
- sky_type = sky_type )
204
- source_irradiance = horizontal_irradiance (radiance , source_elevation )
179
+ source_irradiance = sky_radiance_distribution (source_elevation , source_azimuth ,
180
+ sky_type = sky_type )
205
181
if irradiance is None :
206
- sky_irradiance = clear_sky_irradiances (dates = dates , daydate = daydate ,
207
- longitude = longitude ,
208
- latitude = latitude ,
209
- altitude = altitude ,
210
- timezone = timezone )
211
- irradiance = sum (sky_irradiance ['ghi' ]) * 0.2
212
-
213
- elif sky_type == 'clear_sky' :
214
- sun = sun_position (dates = dates , daydate = daydate , latitude = latitude ,
215
- longitude = longitude , altitude = altitude ,
216
- timezone = timezone )
217
- c_sky = clear_sky_irradiances (dates = dates , daydate = daydate ,
218
- longitude = longitude , latitude = latitude ,
219
- altitude = altitude , timezone = timezone )
220
- c_sky = pandas .concat ([sun , c_sky ], axis = 1 )
182
+ irradiance = sum (c_sky ['ghi' ]) * 0.2
183
+ else :
184
+ source_irradiance = sky_radiance_distribution (source_elevation , source_azimuth ,
185
+ sky_type = sky_type , sky_irradiance = c_sky )
221
186
if irradiance is None :
222
187
irradiance = sum (c_sky ['dhi' ])
223
188
224
- # temporal weigths : use dhi (diffuse horizontal irradiance)
225
- c_sky ['wsky' ] = c_sky ['dhi' ] / sum (c_sky ['dhi' ])
226
- source_irradiance = numpy .zeros_like (source_fraction )
227
- for i , row in c_sky .iterrows ():
228
- rad = sky_radiance_distribution (source_elevation , source_azimuth ,
229
- source_fraction ,
230
- sky_type = 'clear_sky' ,
231
- sun_elevation = row ['elevation' ],
232
- sun_azimuth = row ['azimuth' ],
233
- avoid_sun = True )
234
- source_irradiance += (
235
- horizontal_irradiance (rad , source_elevation ) * row ['wsky' ])
236
- else :
237
- raise ValueError (
238
- 'unknown type: ' + sky_type +
239
- ' (should be one of uoc, soc, clear_sky' )
240
-
241
189
source_irradiance /= sum (source_irradiance )
242
190
source_irradiance *= irradiance
191
+
243
192
return source_elevation , source_azimuth , source_irradiance
244
193
245
194
@@ -307,16 +256,13 @@ def sun_sky_sources(ghi=None, dhi=None, attenuation=None, model='blended',
307
256
sun = sun_sources (irradiance = f_sun , dates = dates ,
308
257
daydate = daydate , latitude = latitude , longitude = longitude ,
309
258
altitude = altitude , timezone = timezone )
259
+ source_elevation , source_azimuth , source_fraction = sky_discretisation ()
310
260
311
261
if model == 'blended' and f_sun > 0 :
312
- f_clear_sky , f_soc = f_clear_sky (sky_irr , f_sun )
313
- sky_el , sky_az , soc = sky_sources (sky_type = 'soc' , irradiance = f_soc )
314
- _ , _ , csky = sky_sources (sky_type = 'clear_sky' ,
315
- irradiance = f_clear_sky , dates = dates ,
316
- daydate = daydate , latitude = latitude ,
317
- longitude = longitude , altitude = altitude ,
318
- timezone = timezone )
319
- sky = sky_el , sky_az , soc + csky
262
+ source_irradiance = sky_radiance_distribution (source_elevation , source_azimuth ,
263
+ sky_type = 'blended' , sky_irradiance = sky_irr )
264
+ source_irradiance *= (1 - f_sun )
265
+ sky = source_elevation , source_azimuth , source_irradiance
320
266
elif model == 'sun_soc' or f_sun == 0 :
321
267
sky = sky_sources (sky_type = 'soc' , irradiance = 1 - f_sun )
322
268
elif f_sun == 0 :
@@ -325,6 +271,7 @@ def sun_sky_sources(ghi=None, dhi=None, attenuation=None, model='blended',
325
271
raise ValueError (
326
272
'unknown model: ' + model +
327
273
' (should be one of: soc_sun, blended)' )
274
+
328
275
return sky_irr , sun , sky
329
276
330
277
0 commit comments