def modifierset_partial_exterior(directory):
    mod_set = ModifierSet('Generic_Exterior_Visible_Modifier_Set')
    mod_set.wall_set.exterior_modifier = modifiers.generic_wall_exterior
    mod_set.floor_set.exterior_modifier = modifiers.generic_floor_exterior
    mod_set.roof_ceiling_set.exterior_modifier = modifiers.generic_roof_exterior
    dest_file = os.path.join(directory, 'modifierset_partial_exterior.json')
    with open(dest_file, 'w') as fp:
        json.dump(mod_set.to_dict(False, True), fp, indent=4)
Beispiel #2
0
def test_dict_to_object_modifier_set():
    """Test the dict_to_object method with Modifier objects."""
    default_set = ModifierSet('Tinted_Window_Set')
    glass_material = Glass.from_single_transmittance('test_glass', 0.6)
    glass_material_dark = Glass.from_single_transmittance(
        'test_glass_dark', 0.3)
    default_set.aperture_set.exterior_modifier = glass_material
    default_set.aperture_set.skylight_modifier = glass_material_dark

    mod_set_dict = default_set.to_dict()
    new_mod_set = dict_to_object(mod_set_dict)
    assert isinstance(new_mod_set, ModifierSet)
def load_modifier_set_object(mset_dict):
    """Load a modifier set object from a dictionary and add it to the lib dict."""
    try:
        if mset_dict['type'] == 'ModifierSetAbridged':
            modifierset = ModifierSet.from_dict_abridged(mset_dict, _loaded_modifiers)
        else:
            modifierset = ModifierSet.from_dict(mset_dict)
        modifierset.lock()
        assert mset_dict['identifier'] not in _default_mod_sets, 'Cannot overwrite ' \
            'default modifier set "{}".'.format(mset_dict['identifier'])
        _loaded_modifier_sets[mset_dict['identifier']] = modifierset
    except (TypeError, KeyError, ValueError):
        pass  # not a Honeybee ModifierSet JSON; possibly a comment
Beispiel #4
0
def model_complete_multiroom_radiance(directory):
    triple_pane = Glass.from_single_transmittance('Triple_Pane_0.35', 0.35)
    first_floor = Room.from_box('First_Floor', 10, 10, 3, origin=Point3D(0, 0, 0))
    second_floor = Room.from_box('Second_Floor', 10, 10, 3, origin=Point3D(0, 0, 3))
    for face in first_floor[1:5]:
        face.apertures_by_ratio(0.2, 0.01)
        face.apertures[0].properties.radiance.modifier = triple_pane
    for face in second_floor[1:5]:
        face.apertures_by_ratio(0.2, 0.01)

    pts_1 = [Point3D(0, 0, 6), Point3D(0, 10, 6), Point3D(10, 10, 6), Point3D(10, 0, 6)]
    pts_2 = [Point3D(0, 0, 6), Point3D(5, 0, 9), Point3D(5, 10, 9), Point3D(0, 10, 6)]
    pts_3 = [Point3D(10, 0, 6), Point3D(10, 10, 6), Point3D(5, 10, 9), Point3D(5, 0, 9)]
    pts_4 = [Point3D(0, 0, 6), Point3D(10, 0, 6), Point3D(5, 0, 9)]
    pts_5 = [Point3D(10, 10, 6), Point3D(0, 10, 6), Point3D(5, 10, 9)]
    face_1 = Face('AtticFace1', Face3D(pts_1))
    face_2 = Face('AtticFace2', Face3D(pts_2))
    face_3 = Face('AtticFace3', Face3D(pts_3))
    face_4 = Face('AtticFace4', Face3D(pts_4))
    face_5 = Face('AtticFace5', Face3D(pts_5))
    attic = Room('Attic', [face_1, face_2, face_3, face_4, face_5], 0.01, 1)

    mod_set = ModifierSet('Attic_Modifier_Set')
    polyiso = Plastic.from_single_reflectance('PolyIso', 0.45)
    mod_set.roof_ceiling_set.exterior_modifier = polyiso
    attic.properties.radiance.modifier_set = mod_set

    Room.solve_adjacency([first_floor, second_floor, attic], 0.01)

    model = Model('Multi_Room_Radiance_House', [first_floor, second_floor, attic])

    dest_file = os.path.join(directory, 'model_complete_multiroom_radiance.json')
    with open(dest_file, 'w') as fp:
        json.dump(model.to_dict(), fp, indent=4)
Beispiel #5
0
def test_duplicate():
    """Test what happens to radiance properties when duplicating a Room."""
    custom_set = ModifierSet('Custom_Modifier_Set')
    room_original = Room.from_box('Shoe_Box', 5, 10, 3)
    room_original.properties.radiance.modifier_set = generic_modifier_set_visible_exterior

    room_dup_1 = room_original.duplicate()

    assert room_original.properties.radiance.modifier_set == \
        room_dup_1.properties.radiance.modifier_set

    assert room_original.properties.radiance.host is room_original
    assert room_dup_1.properties.radiance.host is room_dup_1
    assert room_original.properties.radiance.host is not \
        room_dup_1.properties.radiance.host

    assert room_original.properties.radiance.modifier_set == \
        room_dup_1.properties.radiance.modifier_set
    room_dup_1.properties.radiance.modifier_set = custom_set
    assert room_original.properties.radiance.modifier_set != \
        room_dup_1.properties.radiance.modifier_set

    prefix = 'Opt1'
    room_dup_1.add_prefix('Opt1')
    assert room_dup_1.identifier.startswith('Opt1')

    room_dup_2 = room_dup_1.duplicate()

    assert room_dup_1.properties.radiance.modifier_set == \
        room_dup_2.properties.radiance.modifier_set
    room_dup_2.properties.radiance.modifier_set = None
    assert room_dup_1.properties.radiance.modifier_set != \
        room_dup_2.properties.radiance.modifier_set
Beispiel #6
0
def test_set_modifier_set():
    """Test the auto-assigning of Room properties."""
    room = Room.from_box('Shoe_Box', 5, 10, 3, 90, Point3D(0, 0, 3))
    door_verts = [[1, 0, 0.1], [2, 0, 0.1], [2, 0, 3], [1, 0, 3]]
    room[3].add_door(Door.from_vertices('test_door', door_verts))
    room[1].apertures_by_ratio(0.4, 0.01)
    room[1].apertures[0].overhang(0.5, indoor=False)
    room[1].apertures[0].overhang(0.5, indoor=True)
    room[1].apertures[0].move_shades(Vector3D(0, 0, -0.5))

    assert room.properties.radiance.modifier_set == generic_modifier_set_visible

    room.properties.radiance.modifier_set = generic_modifier_set_visible_exterior
    assert room[1].apertures[0].properties.radiance.modifier == \
        generic_modifier_set_visible_exterior.aperture_set.window_modifier

    insect_screen_set = ModifierSet('Insect_Screen_Set')
    insect_screen_set.aperture_set.window_modifier = \
        generic_exterior_window_insect_screen_solar
    room.properties.radiance.modifier_set = insect_screen_set
    assert room[1].apertures[0].properties.radiance.modifier == \
        generic_exterior_window_insect_screen_solar

    with pytest.raises(AttributeError):
        room[1].properties.radiance.modifier.r_reflectance = 0.3
    with pytest.raises(AttributeError):
        room[5].properties.radiance.modifier.r_reflectance = 0.3
    with pytest.raises(AttributeError):
        room[3].doors[0].properties.radiance.modifier.r_reflectance = 0.3
Beispiel #7
0
def test_from_dict():
    """Test the Room from_dict method with radiance properties."""
    custom_set = ModifierSet('CustomModifierSet')
    room = Room.from_box('Shoe_Box', 5, 10, 3)
    room.properties.radiance.modifier_set = custom_set

    rd = room.to_dict()
    new_room = Room.from_dict(rd)
    assert new_room.properties.radiance.modifier_set.identifier == 'CustomModifierSet'
    assert new_room.to_dict() == rd
Beispiel #8
0
def test_writer_to_rad():
    """Test the Room to_rad method."""
    room = Room.from_box('ClosedOffice', 5, 10, 3)
    custom_set = ModifierSet('Custom_Modifier_Set')
    concrete = Plastic.from_single_reflectance('035Concrete', 0.35)
    custom_set.wall_set.exterior_modifier = concrete
    room.properties.radiance.modifier_set = custom_set

    assert hasattr(room.to, 'rad')
    rad_string = room.to.rad(room)
    assert '035Concrete' in rad_string
Beispiel #9
0
def test_objects_from_lib():
    """Test getting several objects from the library."""
    runner = CliRunner()

    result = runner.invoke(modifiers_by_id,
                           ['generic_wall_0.50', 'generic_floor_0.20'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(Plastic.from_dict(mat_dict[0]), Plastic)

    result = runner.invoke(modifier_sets_by_id,
                           ['Generic_Interior_Solar_Modifier_Set'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(ModifierSet.from_dict(con_dict[0]), ModifierSet)
Beispiel #10
0
def test_to_dict():
    """Test the Room to_dict method with radiance properties."""
    custom_set = ModifierSet('Custom_Modifier_Set')
    room = Room.from_box('Shoe_Box', 5, 10, 3)

    rd = room.to_dict()
    assert 'properties' in rd
    assert rd['properties']['type'] == 'RoomProperties'
    assert 'radiance' in rd['properties']
    assert rd['properties']['radiance']['type'] == 'RoomRadianceProperties'
    assert 'modifier_set' not in rd['properties']['radiance'] or \
        rd['properties']['radiance']['modifier_set'] is None

    room.properties.radiance.modifier_set = custom_set
    rd = room.to_dict()
    assert rd['properties']['radiance']['modifier_set'] is not None
Beispiel #11
0
def test_to_dict_multizone_house():
    """Test the Model to_dict method with a multi-zone house."""
    first_floor = Room.from_box('First_Floor', 10, 10, 3, origin=Point3D(0, 0, 0))
    second_floor = Room.from_box('Second_Floor', 10, 10, 3, origin=Point3D(0, 0, 3))
    for face in first_floor[1:5]:
        face.apertures_by_ratio(0.2, 0.01)
    for face in second_floor[1:5]:
        face.apertures_by_ratio(0.2, 0.01)

    pts_1 = [Point3D(0, 0, 6), Point3D(0, 10, 6), Point3D(10, 10, 6), Point3D(10, 0, 6)]
    pts_2 = [Point3D(0, 0, 6), Point3D(5, 0, 9), Point3D(5, 10, 9), Point3D(0, 10, 6)]
    pts_3 = [Point3D(10, 0, 6), Point3D(10, 10, 6), Point3D(5, 10, 9), Point3D(5, 0, 9)]
    pts_4 = [Point3D(0, 0, 6), Point3D(10, 0, 6), Point3D(5, 0, 9)]
    pts_5 = [Point3D(10, 10, 6), Point3D(0, 10, 6), Point3D(5, 10, 9)]
    face_1 = Face('AtticFace1', Face3D(pts_1))
    face_2 = Face('AtticFace2', Face3D(pts_2))
    face_3 = Face('AtticFace3', Face3D(pts_3))
    face_4 = Face('AtticFace4', Face3D(pts_4))
    face_5 = Face('AtticFace5', Face3D(pts_5))
    attic = Room('Attic', [face_1, face_2, face_3, face_4, face_5], 0.01, 1)

    mod_set = ModifierSet('Attic_Construction_Set')
    mod_set.floor_set.interior_modifier = Plastic('AtticFloor', 0.4)
    mod_set.roof_ceiling_set.exterior_modifier = Plastic('AtticRoof', 0.6)
    attic.properties.radiance.modifier_set = mod_set

    Room.solve_adjacency([first_floor, second_floor, attic], 0.01)

    model = Model('Multi_Zone_Single_Family_House', [first_floor, second_floor, attic])
    model_dict = model.to_dict()

    assert 'radiance' in model_dict['properties']
    assert 'modifiers' in model_dict['properties']['radiance']
    assert 'modifier_sets' in model_dict['properties']['radiance']

    assert len(model_dict['properties']['radiance']['modifiers']) == 2
    assert len(model_dict['properties']['radiance']['modifier_sets']) == 1

    assert model_dict['rooms'][0]['faces'][5]['boundary_condition']['type'] == 'Surface'
    assert model_dict['rooms'][1]['faces'][0]['boundary_condition']['type'] == 'Surface'
    assert model_dict['rooms'][1]['faces'][5]['boundary_condition']['type'] == 'Surface'
    assert model_dict['rooms'][2]['faces'][0]['boundary_condition']['type'] == 'Surface'

    assert model_dict['rooms'][2]['properties']['radiance']['modifier_set'] == \
        mod_set.identifier
Beispiel #12
0
def test_check_duplicate_modifier_set_identifiers():
    """Test the check_duplicate_modifier_set_identifiers method."""
    first_floor = Room.from_box('FirstFloor', 10, 10, 3, origin=Point3D(0, 0, 0))
    second_floor = Room.from_box('SecondFloor', 10, 10, 3, origin=Point3D(0, 0, 3))
    for face in first_floor[1:5]:
        face.apertures_by_ratio(0.2, 0.01)
    for face in second_floor[1:5]:
        face.apertures_by_ratio(0.2, 0.01)
    mod_set_bottom = ModifierSet('Lower_Floor_Modifier_Set')
    first_floor.properties.radiance.modifier_set = mod_set_bottom
    second_floor.properties.radiance.modifier_set = mod_set_bottom

    pts_1 = [Point3D(0, 0, 6), Point3D(0, 10, 6), Point3D(10, 10, 6), Point3D(10, 0, 6)]
    pts_2 = [Point3D(0, 0, 6), Point3D(5, 0, 9), Point3D(5, 10, 9), Point3D(0, 10, 6)]
    pts_3 = [Point3D(10, 0, 6), Point3D(10, 10, 6), Point3D(5, 10, 9), Point3D(5, 0, 9)]
    pts_4 = [Point3D(0, 0, 6), Point3D(10, 0, 6), Point3D(5, 0, 9)]
    pts_5 = [Point3D(10, 10, 6), Point3D(0, 10, 6), Point3D(5, 10, 9)]
    face_1 = Face('AtticFace1', Face3D(pts_1))
    face_2 = Face('AtticFace2', Face3D(pts_2))
    face_3 = Face('AtticFace3', Face3D(pts_3))
    face_4 = Face('AtticFace4', Face3D(pts_4))
    face_5 = Face('AtticFace5', Face3D(pts_5))
    attic = Room('Attic', [face_1, face_2, face_3, face_4, face_5], 0.01, 1)

    mod_set = ModifierSet('Attic_Modifier_Set')
    mod_set.floor_set.interior_modifier = Plastic('AtticFloor', 0.4)
    mod_set.roof_ceiling_set.exterior_modifier = Plastic('AtticRoof', 0.6)
    attic.properties.radiance.modifier_set = mod_set

    Room.solve_adjacency([first_floor, second_floor, attic], 0.01)

    model = Model('Multi_Zone_Single_Family_House', [first_floor, second_floor, attic])

    assert model.properties.radiance.check_duplicate_modifier_set_identifiers(False) == ''
    mod_set.unlock()
    mod_set.identifier = 'Lower_Floor_Modifier_Set'
    mod_set.lock()
    assert model.properties.radiance.check_duplicate_modifier_set_identifiers(False) != ''
    with pytest.raises(ValueError):
        model.properties.radiance.check_duplicate_modifier_set_identifiers(True)
Beispiel #13
0
def test_object_from_lib():
    """Test getting an object from the library."""
    runner = CliRunner()

    result = runner.invoke(modifier_by_id, ['generic_wall_0.50'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(Plastic.from_dict(mat_dict), Plastic)

    result = runner.invoke(modifier_by_id,
                           ['generic_exterior_window_vis_0.64'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(Glass.from_dict(mat_dict), Glass)

    result = runner.invoke(modifier_set_by_id,
                           ['Generic_Interior_Solar_Modifier_Set'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(ModifierSet.from_dict(con_dict), ModifierSet)
    from honeybee_radiance.modifierset import ModifierSet
    from honeybee_radiance.lib.modifiersets import modifier_set_by_identifier
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_radiance:\n\t{}'.format(e))

try:  # import ladybug_rhino dependencies
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # get the base modifier set
    name = clean_and_id_rad_string('ModifierSet') if _name_ is None else \
        clean_rad_string(_name_)
    if base_mod_set_ is None:
        mod_set = ModifierSet(name)
    else:
        if isinstance(base_mod_set_, str):
            base_mod_set_ = modifier_set_by_identifier(base_mod_set_)
        mod_set = base_mod_set_.duplicate()
        mod_set.identifier = name
        if _name_ is not None:
            mod_set.display_name = _name_

    # go through each input modifier subset and assign it to the set
    if len(_exterior_subset_) != 0:
        assert len(
            _exterior_subset_) == 3, 'Input _exterior_subset_ is not valid.'
        if _exterior_subset_[0] is not None:
            mod_set.wall_set.exterior_modifier = _exterior_subset_[0]
        if _exterior_subset_[1] is not None:
try:  # import the honeybee-radiance dependencies
    from honeybee_radiance.modifierset import ModifierSet
    from honeybee_radiance.lib.modifiersets import modifier_set_by_identifier
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_radiance:\n\t{}'.format(e))

try:  # import ladybug_rhino dependencies
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # get the base modifier set
    if base_mod_set_ is None:
        mod_set = ModifierSet(clean_and_id_rad_string(_name))
    else:
        if isinstance(base_mod_set_, str):
            base_mod_set_ = modifier_set_by_identifier(base_mod_set_)
        mod_set = base_mod_set_.duplicate()
        mod_set.identifier = clean_and_id_rad_string(_name)
        mod_set.display_name = _name

    # go through each input modifier subset and assign it to the set
    if len(_exterior_subset_) != 0:
        assert len(
            _exterior_subset_) == 3, 'Input _exterior_subset_ is not valid.'
        if _exterior_subset_[0] is not None:
            mod_set.wall_set.exterior_modifier = _exterior_subset_[0]
        if _exterior_subset_[1] is not None:
            mod_set.roof_ceiling_set.exterior_modifier = _exterior_subset_[1]
from ._loadmodifiers import _loaded_modifiers

import os
import json


# empty dictionary to hold loaded modifier sets
_loaded_modifier_sets = {}


# first load the honeybee defaults
with open(folders.defaults_file) as json_file:
    default_data = json.load(json_file)['modifier_sets']
for mset_dict in default_data:
    modifierset = ModifierSet.from_dict_abridged(mset_dict, _loaded_modifiers)
    modifierset.lock()
    _loaded_modifier_sets[mset_dict['identifier']] = modifierset
_default_mod_sets = set(list(_loaded_modifier_sets.keys()))


# then load modifier sets from the user-supplied files
def load_modifier_set_object(mset_dict):
    """Load a modifier set object from a dictionary and add it to the lib dict."""
    try:
        if mset_dict['type'] == 'ModifierSetAbridged':
            modifierset = ModifierSet.from_dict_abridged(mset_dict, _loaded_modifiers)
        else:
            modifierset = ModifierSet.from_dict(mset_dict)
        modifierset.lock()
        assert mset_dict['identifier'] not in _default_mod_sets, 'Cannot overwrite ' \