Skip to content

Commit

Permalink
scale luminance so that ghi=1
Browse files Browse the repository at this point in the history
  • Loading branch information
christian34 committed Nov 26, 2024
1 parent c2ee663 commit 1253a56
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 39 deletions.
4 changes: 2 additions & 2 deletions example/notebooks/Sky irradiance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -898,9 +898,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
31 changes: 16 additions & 15 deletions example/notebooks/Sky luminance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"id": "be342dc1",
"metadata": {},
"source": [
"## Estimate sky luminance"
"## Estimate sky relative luminance"
]
},
{
Expand All @@ -299,12 +299,12 @@
"source": [
"* Sky luminance is estimated from sky irradiances, using Perez all weather sky model (R. Perez, R. Seals, J. Michalsky, \"All-weather model for sky luminance distribution—Preliminary configuration and validation\", Solar Energy, Volume 50, Issue 3, 1993, Pages 235-245)\n",
"* Luminance is computed every steradian of the sky hemisphere\n",
"* For other strategies, see 'sky_luminance modeling strategies' companion tutorial"
"* Luminance are scaled to ensure a global horizontal irradiance of 1"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"id": "ede65060",
"metadata": {},
"outputs": [],
Expand All @@ -315,7 +315,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"id": "43f643de",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -347,13 +347,13 @@
"id": "dad34005",
"metadata": {},
"source": [
"Sky discretisation allow to split the sky in a limited number of direction for efficiency of light modelling.\n",
"You can use football like dicretisation (sky_turtle) or a latitude/longitude regular grid (sky_dirs)"
"* Sky discretisation allow to split the sky in a limited number of direction for efficiency of light modelling.\n",
"* other strategies can be found in the companon tutorial"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 8,
"id": "83710a79",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -388,16 +388,17 @@
"id": "f4360e2f",
"metadata": {},
"source": [
"##### light sources are given as elevation, azimuth, relative_luminance tuples, that can be scaled to \n",
"##### light sources are given as elevation, azimuth, relative_luminance tuples, that can be scaled to :\n",
" * global luminance ('Wm2' [W.m-2.s-1])\n",
" * PAR luminance ('PPFD', [micromol.m-2.s-1])\n",
" * global energy emmited over the time period ('MJ', [MJ.m-2])\n",
" * PAR emitted over the time-periode ('molPAR', [mol.m-2]) "
" * global luminance integrated over the time period ('MJ', [MJ.m-2])\n",
" * PAR luminance integrated over the time-periode ('molPAR', [mol.m-2])\n",
" Other Strategies can be found in companion tutorial"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 9,
"id": "5673473a",
"metadata": {},
"outputs": [],
Expand All @@ -407,7 +408,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 10,
"id": "b0334e5c-848a-4513-be95-47d6960be33c",
"metadata": {},
"outputs": [],
Expand All @@ -417,22 +418,22 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 11,
"id": "c9b5a01a-35d1-4e7f-b259-df097b80d6d2",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b0ab6ea2a50f4ecc9f945a2053fa8ac0",
"model_id": "b1858ede48954ca69ae87289e0d774f8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Plot(antialias=3, axes=['x', 'y', 'z'], axes_helper=1.0, axes_helper_colors=[16711680, 65280, 255], background…"
]
},
"execution_count": 9,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
28 changes: 6 additions & 22 deletions src/alinea/astk/meteorology/sky_luminance.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ def all_weather_relative_luminance(grid, sun_zenith, sun_azimuth, clearness, bri


def sky_luminance(grid, sky_type='soc', sky_irradiance=None):
"""Normalised sky luminance map for different conditions, periods and sky types
Luminance are normalised so that sum(luminance) = 1.
"""Relative sky luminance map for different conditions, periods and sky types
Luminance are scaled so that total sky horizontal irradiance equals one.
Args:
sky_type (str): sky type, one of ('soc', 'uoc', 'clear_sky', 'sun_soc', 'blended', 'all_weather')
sky_type (str): sky type, one of ('soc', 'uoc', 'clear_sky', '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'
"""
Expand All @@ -232,17 +232,14 @@ 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()
elif sky_type == 'clear_sky':
for row in irrad.itertuples():
_lum = w_c * cie_relative_luminance(grid=grid,
sun_zenith=row.sun_zenith,
sun_azimuth=row.sun_azimuth,
type='clear_sky')
_lum /= _lum.sum()
_hi = sky_hi(grid, _lum)
lum += (row.ghi / _hi * _lum)
lum /= lum.sum()
elif sky_type == 'all_weather':
for row in irrad.itertuples():
brightness = all_weather_sky_brightness(row.dates, row.dhi, row.sun_zenith)
Expand All @@ -252,21 +249,8 @@ def sky_luminance(grid, sky_type='soc', sky_irradiance=None):
sun_azimuth=row.sun_azimuth,
brightness=brightness,
clearness=clearness)
_lum /= _lum.sum()
_hi = sky_hi(grid, _lum)
lum += (row.ghi / _hi * _lum)
lum /= lum.sum()
elif sky_type == 'sun_soc':
lum = w_c * cie_relative_luminance(grid=grid, type='soc')
# scale to total luminance of sky
lum /= lum.sum()
hi = sky_hi(grid, lum)
lum *= (irrad.dhi.sum() / hi)
for row in irrad.itertuples():
daz, dz = map(lambda x: numpy.diff(x)[0], (azimuth, zenith))
i, j = int(row.sun_zenith // dz), int(row.sun_azimuth // daz)
lum[i, j] += row.dni
lum /= lum.sum()
elif sky_type == 'blended':
soc = w_c * cie_relative_luminance(grid=grid, type='soc')
for row in irrad.itertuples():
Expand All @@ -277,14 +261,14 @@ def sky_luminance(grid, sky_type='soc', sky_irradiance=None):
epsilon = all_weather_sky_clearness(row.dni, row.dhi, row.sun_zenith)
f_clear = f_clear_sky(epsilon)
_lum = f_clear * cs + (1 - f_clear) * soc
_lum /= _lum.sum()
_hi = sky_hi(grid, _lum)
lum += (row.ghi / _hi * _lum)
lum /= lum.sum()
else:
raise ValueError('undefined sky type: ' + sky_type)

return lum
# scale so that ghi = 1
hi = sky_hi(grid, lum)
return lum / hi


def scale_sky_sources(sky_sources, sky_irradiance, scale='Wm2', diffuse_only=False):
Expand Down

0 comments on commit 1253a56

Please sign in to comment.