Source code for

# coding=utf-8
"""Shade Energy Properties."""
from honeybee.typing import clean_rad_string
from honeybee.checkdup import is_equivalent

from import ShadeConstruction
from ..schedule.ruleset import ScheduleRuleset
from ..schedule.fixedinterval import ScheduleFixedInterval

from ..lib.constructions import generic_context
from ..lib.constructionsets import generic_construction_set

[docs]class ShadeEnergyProperties(object): """Energy Properties for Honeybee Shade. Args: host: A honeybee_core Shade object that hosts these properties. construction: An optional ShadeConstruction object to set the reflectance and specularity of the Shade. The default is set by a ConstructionSet if the shade is the parent to an object. Otherwise, if it is an orphaned shade, the default is a completely diffuse construction with 0.2 visible and solar reflectance. transmittance_schedule: An optional schedule to set the transmittance of the shade, which can vary throughout the day or year. Default is None for a completely opaque object. Properties: * host * construction * transmittance_schedule * is_construction_set_on_object """ __slots__ = ('_host', '_construction', '_transmittance_schedule') def __init__(self, host, construction=None, transmittance_schedule=None): """Initialize Shade energy properties.""" self._host = host = construction self.transmittance_schedule = transmittance_schedule @property def host(self): """Get the Shade object hosting these properties.""" return self._host @property def construction(self): """Get or set a ShadeConstruction for the shade. If the construction is not set on the shade-level, then it will be assigned based on the ConstructionSet assigned to the parent Room. If the parent Room's ConstructionSet has no construction for the Shade type, it will be assigned using the honeybee default generic ConstructionSet. If there is no parent Room, it will be the generic context construction. """ if self._construction: # set by user return self._construction elif not self._host.has_parent: return generic_context if self._host.is_detached else \ generic_construction_set.shade_construction else: c_set = self._parent_construction_set(self._host.parent) if c_set is None: c_set = generic_construction_set return c_set.shade_construction @construction.setter def construction(self, value): if value is not None: assert isinstance(value, ShadeConstruction), \ 'Expected ShadeConstruction. Got {}.'.format(type(value)) value.lock() # lock editing in case construction has multiple references self._construction = value @property def transmittance_schedule(self): """Get or set the transmittance schedule of the shade.""" return self._transmittance_schedule @transmittance_schedule.setter def transmittance_schedule(self, value): if value is not None: assert isinstance(value, (ScheduleRuleset, ScheduleFixedInterval)), \ 'Expected schedule for shade transmittance schedule. ' \ 'Got {}.'.format(type(value)) if value.schedule_type_limit is not None: assert value.schedule_type_limit.unit == 'fraction', 'Transmittance ' \ 'schedule should be fractional [Dimensionless]. Got a schedule ' \ 'of unit_type [{}].'.format(value.schedule_type_limit.unit_type) value.lock() # lock editing in case schedule has multiple references self._transmittance_schedule = value @property def is_construction_set_on_object(self): """Boolean noting if construction is assigned on the level of this Shade. This is opposed to having the construction assigned by a ConstructionSet. """ return self._construction is not None
[docs] def reset_construction_to_set(self): """Reset the construction and transmittance schedule of this Shade to default. This means that the Shade's construction will be assigned by a ConstructionSet. """ self._construction = None self._transmittance_schedule = None
[docs] def radiance_modifier_solar(self): """Get a Radiance modifier that combines the construction and transmittance. Note that only the first value from the transmittance schedule will be used to create the Trans modifier and so this method is really only intended for cases of constant transmittance schedules. If there is no transmittance schedule, a plastic material will be returned. """ return self._radiance_modifier(
[docs] def radiance_modifier_visible(self): """Get a Radiance modifier that combines the construction and transmittance. Note that only the first value from the transmittance schedule will be used to create the Trans modifier and so this method is really only intended for cases of constant transmittance schedules. If there is no transmittance schedule, a plastic material will be returned. """ return self._radiance_modifier(
[docs] @classmethod def from_dict(cls, data, host): """Create ShadeEnergyProperties from a dictionary. Note that the dictionary must be a non-abridged version for this classmethod to work. Args: data: A dictionary representation of ShadeEnergyProperties with the format below. host: A Shade object that hosts these properties. .. code-block:: python { "type": 'ShadeEnergyProperties', "construction": {}, # A ShadeConstruction dictionary "transmittance_schedule": {} # A transmittance schedule dictionary } """ assert data['type'] == 'ShadeEnergyProperties', \ 'Expected ShadeEnergyProperties. Got {}.'.format(data['type']) new_prop = cls(host) if 'construction' in data and data['construction'] is not None: = ShadeConstruction.from_dict(data['construction']) if 'transmittance_schedule' in data and \ data['transmittance_schedule'] is not None: sch_dict = data['transmittance_schedule'] if sch_dict['type'] == 'ScheduleRuleset': new_prop.transmittance_schedule = \ ScheduleRuleset.from_dict(data['transmittance_schedule']) elif sch_dict['type'] == 'ScheduleFixedInterval': new_prop.transmittance_schedule = \ ScheduleFixedInterval.from_dict(data['transmittance_schedule']) else: raise ValueError( 'Expected non-abridged Schedule dictionary for Shade ' 'transmittance_schedule. Got {}.'.format(sch_dict['type'])) return new_prop
[docs] def apply_properties_from_dict(self, abridged_data, constructions, schedules): """Apply properties from a ShadeEnergyPropertiesAbridged dictionary. Args: abridged_data: A ShadeEnergyPropertiesAbridged dictionary (typically coming from a Model). constructions: A dictionary of constructions with constructions identifiers as keys, which will be used to re-assign constructions. schedules: A dictionary of schedules with schedule identifiers as keys, which will be used to re-assign schedules. """ if 'construction' in abridged_data and abridged_data['construction'] is not None: try: = constructions[abridged_data['construction']] except KeyError: raise ValueError('Shade construction "{}" was not found in ' 'constructions.'.format(abridged_data['construction'])) if 'transmittance_schedule' in abridged_data and \ abridged_data['transmittance_schedule'] is not None: self.transmittance_schedule = \ schedules[abridged_data['transmittance_schedule']]
[docs] def to_dict(self, abridged=False): """Return energy properties as a dictionary. Args: abridged: Boolean to note whether the full dictionary describing the object should be returned (False) or just an abridged version (True). Default: False. """ base = {'energy': {}} base['energy']['type'] = 'ShadeEnergyProperties' if not \ abridged else 'ShadeEnergyPropertiesAbridged' if self._construction is not None: base['energy']['construction'] = \ self._construction.identifier if abridged else \ self._construction.to_dict() if self.transmittance_schedule is not None: base['energy']['transmittance_schedule'] = \ self.transmittance_schedule.identifier if abridged else \ self.transmittance_schedule.to_dict() return base
[docs] def duplicate(self, new_host=None): """Get a copy of this object. Args: new_host: A new Shade object that hosts these properties. If None, the properties will be duplicated with the same host. """ _host = new_host or self._host return ShadeEnergyProperties(_host, self._construction, self._transmittance_schedule)
[docs] def is_equivalent(self, other): """Check to see if these energy properties are equivalent to another object. This will only be True if all properties match (except for the host) and will otherwise be False. """ if not is_equivalent(self._construction, other._construction): return False if not is_equivalent( self._transmittance_schedule, other._transmittance_schedule): return False return True
def _radiance_modifier(self, ref): """Get a Radiance modifier that respects the transmittance schedule. Args: ref: The reflectance to be used in the modifier. """ # check to be sure that the honeybee-radiance installed try: from honeybee_radiance.modifier.material import Trans except ImportError as e: raise ImportError('honeybee_radiance library must be installed to use ' 'Shade radiance_modifier methods. {}'.format(e)) # create the modifier from the properties if self.transmittance_schedule is None: return else: mod_id = '{}_mod'.format(clean_rad_string( if isinstance(self.transmittance_schedule, ScheduleRuleset): trans = self.transmittance_schedule.default_day_schedule.values[0] else: trans = self.transmittance_schedule.values[0] avg_ref = (1 - trans) * ref return Trans.from_average_properties( mod_id, average_reflectance=avg_ref, average_transmittance=trans,, is_diffusing=False) @staticmethod def _parent_construction_set(host_parent): """Recursively search through host parents to find a ConstructionSet.""" if hasattr(, 'construction_set'): # we found the room with the construction set return elif host_parent.has_parent: # we found an aperture or face that could have a room with a construction set return ShadeEnergyProperties._parent_construction_set(host_parent.parent) else: # there is no parent room return None
[docs] def ToString(self): return self.__repr__()
def __repr__(self): return 'Shade Energy Properties: [host: {}]'.format(