Skip to content

Commit

Permalink
feat(lightsource): Add schemas for skies and light sources
Browse files Browse the repository at this point in the history
This commit adds schemas for all skies and matrices.

Resolves #131
  • Loading branch information
chriswmackey authored and Chris Mackey committed May 20, 2020
1 parent 1dbc26b commit a237ceb
Show file tree
Hide file tree
Showing 12 changed files with 44,296 additions and 5 deletions.
9 changes: 6 additions & 3 deletions docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from honeybee_schema.model import Model
from honeybee_schema.energy.simulation import SimulationParameter
from honeybee_schema.radiance.asset import SensorGrid, View
from honeybee_schema.radiance.lightsource import CertainIrradiance, CIE, \
ClimateBased, SunMatrix, SkyMatrix

import json
import argparse
Expand Down Expand Up @@ -117,7 +119,7 @@
}

openapi = get_openapi(
[SensorGrid, View],
[SensorGrid, View, CertainIrradiance, CIE, ClimateBased, SunMatrix, SkyMatrix],
title='Honeybee Radiance Asset Schema',
description='This is the documentation for Honeybee Radiance Asset schema.',
version=VERSION, info=info,
Expand All @@ -126,7 +128,7 @@
json.dump(openapi, out_file, indent=2)

openapi = get_openapi(
[View],
[SensorGrid, View, CertainIrradiance, CIE, ClimateBased, SunMatrix, SkyMatrix],
title='Honeybee Radiance Asset Schema',
description='This is the documentation for Honeybee Radiance Asset Schema.',
version=VERSION, inheritance=True, info=info,
Expand All @@ -137,4 +139,5 @@

# add the mapper file
with open('./docs/radiance-asset_mapper.json', 'w') as out_file:
json.dump(class_mapper([SensorGrid, View]), out_file, indent=2)
json.dump(class_mapper([SensorGrid, View, CertainIrradiance, CIE, ClimateBased,
SunMatrix, SkyMatrix]), out_file, indent=2)
4 changes: 2 additions & 2 deletions honeybee_schema/energy/designday.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Simulation Parameter Schema"""
"""Design Day Schema"""
from pydantic import Field, constr, validator
from typing import Union, List
from enum import Enum
Expand Down Expand Up @@ -129,7 +129,7 @@ class ASHRAEClearSky(_SkyCondition):
ge=0,
le=1.2,
description='Value between 0 and 1.2 that will get multiplied by the '
'irradinace to correct for factors like elevation above sea level.'
'irradiance to correct for factors like elevation above sea level.'
)


Expand Down
178 changes: 178 additions & 0 deletions honeybee_schema/radiance/lightsource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
"""SensorGrid and Sensor Schema"""
from pydantic import Field, constr
from typing import Optional

from .._base import NoExtraBaseModel
from .wea import Wea


class _GlowHemisphere(NoExtraBaseModel):
"""Hidden base class for Ground and SkyHemisphere."""

r_emittance: float = Field(
default=1.0,
ge=0,
le=1,
description='A value between 0 and 1 for the red channel emittance.'
)

g_emittance: float = Field(
default=1.0,
ge=0,
le=1,
description='A value between 0 and 1 for the green channel emittance.'
)

b_emittance: float = Field(
default=1.0,
ge=0,
le=1,
description='A value between 0 and 1 for the blue channel of the emittance.'
)


class Ground(_GlowHemisphere):
"""Ground component of the sky sphere."""

type: constr(regex='^Ground$') = 'Ground'


class SkyHemisphere(_GlowHemisphere):
"""SkyHemisphere component of the sky sphere."""

type: constr(regex='^SkyHemisphere$') = 'SkyHemisphere'


class SkyDome(NoExtraBaseModel):
"""Base class for all sky domes."""

type: constr(regex='^SkyDome$') = 'SkyDome'

ground_hemisphere: Optional[Ground] = Field(
default=Ground(),
description='Optional ground glow source.'
)

sky_hemisphere: Optional[SkyHemisphere] = Field(
default=SkyHemisphere(),
description='Optional sky hemisphere glow source.'
)


class _PointInTime(SkyDome):
"""Hidden base class for all point-in-time sky domes."""

ground_reflectance: float = Field(
default=0.2,
ge=0,
le=1,
description='A value between 0 and 1 for the ground reflectance.'
)


class _SkyWithSun(_PointInTime):
"""Hidden base class for all altitude/azimuth sky domes."""

altitude: float = Field(
...,
ge=-90,
le=90,
description='The solar altitude measured in degrees above the horizon.'
'Negative values indicate cases where the sun is below the horizon '
'(eg. twilight conditions).'
)

azimuth: float = Field(
...,
ge=0,
le=360,
description='The solar altitude measured in degrees above the horizon.'
'The azimuth is measured in degrees east of North. East is 90, South is 180 and '
'West is 270. Note that this input is different from Radiance convention. In '
'Radiance the azimuth degrees are measured in west of South.'
)


class CertainIrradiance(_PointInTime):
"""Sky with evenly distributed light at a certain irradiance value."""

type: constr(regex='^CertainIrradiance$') = 'CertainIrradiance'

irradiance: float = Field(
default=558.659,
ge=0,
description='A value for the horizontal diffuse irradiance value in W/m2.'
)


class CIE(_SkyWithSun):
"""CIE sky similar to using Radiance's gensky command."""

type: constr(regex='^CIE$') = 'CIE'

sky_type: int = Field(
0,
ge=0,
le=5,
description='An integer between 0..5 to indicate CIE Sky Type.'
'\n0 = Sunny with sun.'
'\n1 = Sunny without sun.'
'\n2 = Intermediate with sun.'
'\n3 = Intermediate without sun.'
'\n4 = Cloudy sky.'
'\n5 = Uniform cloudy sky.'
)


class ClimateBased(_SkyWithSun):
"""Point-in-time Climate-based sky."""

type: constr(regex='^ClimateBased$') = 'ClimateBased'

direct_normal_irradiance: float = Field(
...,
ge=0,
description='Direct normal irradiance (W/m2).'
)

diffuse_horizontal_irradiance: float = Field(
...,
ge=0,
description='Diffuse horizontal irradiance (W/m2).'
)


class SunMatrix(NoExtraBaseModel):
"""Annual Climate-based Sun matrix."""

type: constr(regex='^SunMatrix$') = 'SunMatrix'

wea: Wea = Field(
...,
description='A Ladybug wea schema.'
)

north: float = Field(
0,
ge=-360,
le=360,
description='A number between -360 and 360 for the counterclockwise '
'difference between the North and the positive Y-axis in degrees. '
'90 is West and 270 is East.'
)


class SkyMatrix(SunMatrix):
"""Annual Climate-based Sky matrix."""

type: constr(regex='^SkyMatrix$') = 'SkyMatrix'

density: int = Field(
1,
ge=1,
description='Sky patch subdivision density. This values is similar to '
'-m option in gendaymtx command. Default is 1 which means 145 sky patches '
'and 1 patch for the ground. One can add to the resolution typically by '
'factors of two (2, 4, 8, ...) which yields a higher resolution sky using '
'the Reinhart patch subdivision.'
)
100 changes: 100 additions & 0 deletions honeybee_schema/radiance/wea.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""Wea Schema"""
from pydantic import Field, constr, confloat
from typing import List
import datetime

from .._base import NoExtraBaseModel


class Location(NoExtraBaseModel):
"""Used to specify latitude and longitude of a location on the Earth."""

type: constr(regex='^Location$') = 'Location'

latitude: float = Field(
...,
ge=-90,
le=90,
description='Location latitude between -90 and 90.'
)

longitude: float = Field(
...,
ge=-180,
le=180,
description='Location longitude between -180 (west) and 180 (east).'
)

time_zone: float = Field(
default=None,
ge=-12,
le=14,
description='Time zone between -12 hours (west) and +14 hours (east). '
'If None, the time zone will be an estimated integer value derived from '
'the longitude in accordance with solar time.'
)

elevation: float = Field(
default=0,
description='A number for elevation of the location in meters.'
)

city: str = Field(
default='-',
description='Name of the city as a string.'
)

state: str = Field(
default='-',
description='Optional state in which the city is located.'
)

country: str = Field(
default='-',
description='Name of the country as a string.'
)

station_id: str = Field(
default=None,
description='Optional ID of the location if the location is '
'representing a weather station.'
)

source: str = Field(
default=None,
description='Optional source of data (e.g. TMY, TMY3).'
)


class Wea(NoExtraBaseModel):
"""Used to represent the contents of a Wea file."""

type: constr(regex='^Wea$') = 'Wea'

location: Location = Field(
...,
description='Location object to note latitude, longitude and time zone.'
)

direct_normal_irradiance: List[confloat(ge=0)] = Field(
...,
description='A list of numbers for the annual direct normal irradiance '
'in W/m2.'
)

diffuse_horizontal_irradiance: List[confloat(ge=0)] = Field(
...,
description='A list of numbers for the annual diffuse horizontal irradiance '
'in W/m2.'
)

timestep: int = Field(
1,
ge=0,
description='An integer to set the number of time steps per hour.'
)

is_leap_year: bool = Field(
False,
description='A boolean to indicate if values are representing a leap year.'
)
17 changes: 17 additions & 0 deletions samples/light_source/sky_certian_irradiance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"type": "CertainIrradiance",
"irradiance": 55.865921787709496,
"ground_reflectance": 0.2,
"ground_hemisphere": {
"type": "Ground",
"r_emittance": 1.0,
"g_emittance": 1.0,
"b_emittance": 1.0
},
"sky_hemisphere": {
"type": "SkyHemisphere",
"r_emittance": 1.0,
"g_emittance": 1.0,
"b_emittance": 1.0
}
}
19 changes: 19 additions & 0 deletions samples/light_source/sky_cie.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "CIE",
"altitude": 38.186734,
"azimuth": 270.410387,
"sky_type": 0,
"ground_reflectance": 0.2,
"ground_hemisphere": {
"type": "Ground",
"r_emittance": 1.0,
"g_emittance": 1.0,
"b_emittance": 1.0
},
"sky_hemisphere": {
"type": "SkyHemisphere",
"r_emittance": 1.0,
"g_emittance": 1.0,
"b_emittance": 1.0
}
}
20 changes: 20 additions & 0 deletions samples/light_source/sky_climate_based.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "ClimateBased",
"altitude": 38.186734,
"azimuth": 270.410387,
"direct_normal_irradiance": 702,
"diffuse_horizontal_irradiance": 225,
"ground_reflectance": 0.2,
"ground_hemisphere": {
"type": "Ground",
"r_emittance": 1.0,
"g_emittance": 1.0,
"b_emittance": 1.0
},
"sky_hemisphere": {
"type": "SkyHemisphere",
"r_emittance": 1.0,
"g_emittance": 1.0,
"b_emittance": 1.0
}
}
Loading

0 comments on commit a237ceb

Please sign in to comment.