Skip to content

Commit

Permalink
feat(radiance.properties): Add Radiance Properties Schema. (#76)
Browse files Browse the repository at this point in the history
* feat(radiance): Adding initial radiance schema materials.

* feat(radiance): Add more materials, and ModifierBase.

For WIP discussion only. Not to be merged.

* docs(radiance): Clarifying recursion error.

* fix(radiance.material): Fix self-ref, and other PR changes.

* feat(radiance.properties): Add Radiance Properties Schema.

* feat(modfiersset): Add Radiance.ModifiersSet object.

* feat(radiance): Change material.py to modfier.py, add subclass.

* fix(radiance): Fix based on latest PR comments.

Add IDdRadianceBaseModel, abridged and non-abridged versions for all ModifierSet objects,, Properties inheritiance changed.

* feat(tests): modifier, modifierset changes and modifier tests.

* tests(Radiance): Tests for Radiance and PR update.

* fix(Radiance): Add Optionals to schema types with None as default.

* fix(Radiance): fix RoomRadianceProperties.

* fix(Modifier): Make modifers arg nullable.

Change to make modifiers consistent with jsons.

* docs(Modifier): Change Void to None in modifierbase modifier default.

Based on recent discussions re: Void.

* fix(Optional): Remove Optional for all fields with None as default.
  • Loading branch information
saeranv committed Apr 21, 2020
1 parent 30d4d31 commit 4ce9e62
Show file tree
Hide file tree
Showing 8 changed files with 597 additions and 11 deletions.
2 changes: 1 addition & 1 deletion honeybee_schema/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class NoExtraBaseModel(BaseModel):
"""Base class for all objects that are not extensible with additional keys.
This effectively includes all objects except for the Properties classes
that are assigned to geometry objects.
"""
Expand Down
37 changes: 37 additions & 0 deletions honeybee_schema/radiance/_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Base class used by radiance schema objects."""
from pydantic import Field, validator, BaseModel
import re
from .._base import NoExtraBaseModel


class IDdRadianceBaseModel(NoExtraBaseModel):
"""Base class for all objects requiring a valid Radiance identifier."""

identifier: str = Field(
...,
description='Text string for a unique Radiance object. Must not contain spaces '
'or special characters. This will be used to identify the object '
'across a model and in the exported Radiance files.'
)

@validator('identifier')
def valid_rad_string(cls, value):
"""Check that a string is valid for Radiance.
This method is modified from the honeybee-core.typing.valid_rad_string method.
"""
try:
illegal_match = re.search(r'[^.A-Za-z0-9_-]', value)
except TypeError:
raise TypeError('Identifier must be a text string. Got {}: {}.'.format(
type(value), value))
assert illegal_match is None, \
'Illegal character "{}" found in identifier'.format(illegal_match.group(0))
assert len(value) > 0, \
'Input identifier "{}" contains no characters.'.format(value)
return value

display_name: str = Field(
default=None,
description='Display name of the object with no character restrictions.'
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# TODO: change to Modifers Schema?
"""Material Schema"""
"""Modfier Schema"""
from pydantic import Field, constr, validator, root_validator
from typing import List, Union
from typing import List, Union, Optional

from .._base import IDdBaseModel, BaseModel
from ._base import IDdRadianceBaseModel, BaseModel


class Void(BaseModel):
Expand All @@ -12,13 +11,13 @@ class Void(BaseModel):
type: constr(regex='^void$') = 'void'


class ModifierBase(IDdBaseModel):
class ModifierBase(IDdRadianceBaseModel):
"""Base class for Radiance Modifiers"""

modifier: Union[
Void, 'Plastic', 'Glass', 'BSDF', 'Glow', 'Light', 'Trans'
] = Field(
default=Void(),
default=None,
description='Material modifier (default: Void).'
)

Expand Down Expand Up @@ -111,8 +110,8 @@ def check_sum_fractions(cls, values):
g_refl = values.get('g_reflectance')
b_refl = values.get('b_reflectance')
identifier = values.get('identifier')
summed = trans_diff + trans_spec + r_refl + g_refl + b_refl
assert summed <= 1, 'The sum of the transmitted diffuse and specular light ' \
summed = trans_diff + trans_spec + (r_refl + g_refl + b_refl) / 3.0
assert summed <= 1, 'The sum of the transmitted and reflected ' \
'fractions cannot be greater than 1, but is {} for modifier {}.'.format(
summed, identifier)
return values
Expand Down Expand Up @@ -147,10 +146,9 @@ class Glass(ModifierBase):
'(default: 0).'
)

refraction_index: float = Field(
refraction_index: Optional[float] = Field(
default=1.52,
ge=0,
le=1,
description='A value between 0 and 1 for the index of refraction '
'(default: 1.52).'
)
Expand Down
Loading

0 comments on commit 4ce9e62

Please sign in to comment.