Skip to content

Commit

Permalink
debug/improve luminance tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
christian34 committed Nov 24, 2024
1 parent e52df06 commit 314d36e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 89 deletions.
158 changes: 78 additions & 80 deletions example/notebooks/Sky luminance.ipynb

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions src/alinea/astk/meteorology/sky_luminance.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,14 @@ def all_weather_relative_luminance(grid, sun_zenith, sun_azimuth, clearness, bri
return gradation * indicatrix


def sky_luminance(grid, sky_type='soc', sky_irradiance=None):
def sky_luminance(grid, sky_type='soc', sky_irradiance=None, how='relative'):
"""Normalised sky luminance map for different conditions, periods and sky types
Args:
sky_type (str): sky type, one of ('soc', 'uoc', 'clear_sky', 'sun_soc', 'blended', 'all_weather')
sky_irradiance: a datetime indexed dataframe specifying sky irradiances for the period, such as returned by
astk.sky_irradiance.sky_irradiance. Needed for all sky_types except 'uoc' and 'soc'
sky_irradianceadiance: a datetime indexed dataframe specifying sky irradiances for the period, such as returned by
astk.sky_irradianceadiance.sky_irradianceadiance. Needed for all sky_types except 'uoc' and 'soc'
lum : a string specifying how the luminance is expressed. Could be 'relative' (sum(lum=1)), 'Wm2', 'MJ' or 'PPFD'
"""

azimuth, zenith, az_c, z_c, w_c = grid
Expand All @@ -232,7 +233,6 @@ def sky_luminance(grid, sky_type='soc', sky_irradiance=None):
if sky_type in ('soc', 'uoc'):
lum = w_c * cie_relative_luminance(grid=grid, type=sky_type)
lum /= lum.sum()
return lum
elif sky_type == 'clear_sky':
for row in irrad.itertuples():
_lum = w_c * cie_relative_luminance(grid=grid,
Expand All @@ -243,7 +243,6 @@ def sky_luminance(grid, sky_type='soc', sky_irradiance=None):
_hi = sky_hi(grid, _lum)
lum += (row.ghi / _hi * _lum)
lum /= lum.sum()
return lum
elif sky_type == 'all_weather':
for row in irrad.itertuples():
brightness = all_weather_sky_brightness(row.dates, row.dhi, row.sun_zenith)
Expand All @@ -257,7 +256,6 @@ def sky_luminance(grid, sky_type='soc', sky_irradiance=None):
_hi = sky_hi(grid, _lum)
lum += (row.ghi / _hi * _lum)
lum /= lum.sum()
return lum
elif sky_type == 'sun_soc':
lum = w_c * cie_relative_luminance(grid=grid, type='soc')
# scale to total luminance of sky
Expand All @@ -269,7 +267,6 @@ def sky_luminance(grid, sky_type='soc', sky_irradiance=None):
i, j = int(row.sun_zenith // dz), int(row.sun_azimuth // daz)
lum[i, j] += row.dni
lum /= lum.sum()
return lum
elif sky_type == 'blended':
soc = w_c * cie_relative_luminance(grid=grid, type='soc')
for row in irrad.itertuples():
Expand All @@ -284,9 +281,18 @@ def sky_luminance(grid, sky_type='soc', sky_irradiance=None):
_hi = sky_hi(grid, _lum)
lum += (row.ghi / _hi * _lum)
lum /= lum.sum()
return lum
else:
raise ValueError('undefined sky type: ' + sky_type)

if how == 'PPFD':
lum *= sky_irradiance.ppfd.mean()
elif how == 'Wm2':
lum *= sky_irradiance.ghi.mean()
elif how == 'MJ':
lum *= sky_irradiance.ghi.sum() * 3600 / 1e5
else:
pass
return lum



Expand Down
4 changes: 3 additions & 1 deletion src/alinea/astk/sky_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def _polar(az, z):
smap = numpy.zeros_like(luminance_map)
for i, w in enumerate(slum):
smap[targets==i] = w
return slum, smap
elevation, azimuth= zip(*directions)
sky_sources = list(zip(elevation, azimuth, slum))
return sky_sources, smap


def show_sky(grid, sky, cmap='jet', shading='flat'):
Expand Down

0 comments on commit 314d36e

Please sign in to comment.