コード例 #1
0
def from_rooms_radial(model_file, grid_size, offset, include_mesh, keep_out,
                      wall_offset, dir_count, start_vector, mesh_radius, room,
                      write_json, folder, output_file):
    """Generate SensorGrids of radial directions around positions from room floors.

    \b
    Args:
        model_file: Full path to a HBJSON or HBPkl Model file.
    """
    try:
        # re-serialize the Model and extract rooms and units
        model = Model.from_file(model_file)
        rooms = model.rooms if room is None or len(room) == 0 else \
            [r for r in model.rooms if r.identifier in room]
        grid_size = parse_distance_string(grid_size, model.units)
        offset = parse_distance_string(offset, model.units)
        wall_offset = parse_distance_string(wall_offset, model.units)
        vec = [float(v) for v in start_vector.split()]
        st_vec = Vector3D(*vec)

        # loop through the rooms and generate sensor grids
        sensor_grids = []
        remove_out = not keep_out
        for room in rooms:
            sg = room.properties.radiance.generate_sensor_grid_radial(
                grid_size,
                offset=offset,
                remove_out=remove_out,
                wall_offset=wall_offset,
                dir_count=dir_count,
                start_vector=st_vec,
                mesh_radius=mesh_radius)
            if sg is not None:
                sensor_grids.append(sg)
        if not include_mesh:
            for sg in sensor_grids:
                sg.mesh = None

        # write the sensor grids to the output file or folder
        if folder is None:
            if write_json:
                output_file.write(
                    json.dumps([sg.to_dict() for sg in sensor_grids]))
            else:
                output_file.write('\n'.join(
                    [sg.to_radiance() for sg in sensor_grids]))
        else:
            if write_json:
                for sg in sensor_grids:
                    sg.to_json(folder)
            else:
                for sg in sensor_grids:
                    sg.to_file(folder)
    except Exception as e:
        _logger.exception('Grid generation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
コード例 #2
0
def extruded_border(model_json, depth, outdoor, output_file):
    """Add extruded borders to all windows in walls.

    \b
    Args:
        model_json: Full path to a Honeybee Model JSON file.
    """
    try:
        # serialize the Model to Python
        parsed_model = Model.from_file(model_json)
        indoor = not outdoor

        # generate the overhangs for all walls of rooms
        depth = parse_distance_string(depth, parsed_model.units)
        for room in parsed_model.rooms:
            for face in room.faces:
                if isinstance(face.boundary_condition, Outdoors) and \
                        isinstance(face.type, Wall):
                    for ap in face.apertures:
                        ap.extruded_border(depth, indoor)

        # write the new model out to the file or stdout
        output_file.write(json.dumps(parsed_model.to_dict()))
    except Exception as e:
        _logger.exception('Model extruded border failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
コード例 #3
0
def from_rooms(model_json, grid_size, offset, include_mesh, keep_out, room,
               write_json, folder, output_file):
    """Generate SensorGrids from the Room floors of a honeybee model.

    \b
    Args:
        model_json: Full path to a Model JSON file.
    """
    try:
        # re-serialize the Model and extract rooms and units
        model = Model.from_hbjson(model_json)
        rooms = model.rooms if room is None or len(room) == 0 else \
            [r for r in model.rooms if r.identifier in room]
        grid_size = parse_distance_string(grid_size, model.units)
        offset = parse_distance_string(offset, model.units)

        # loop through the rooms and generate sensor grids
        sensor_grids = []
        remove_out = not keep_out
        for room in rooms:
            sg = room.properties.radiance.generate_sensor_grid(
                grid_size, offset=offset, remove_out=remove_out)
            sensor_grids.append(sg)
        if not include_mesh:
            for sg in sensor_grids:
                sg.mesh = None

        # write the sensor grids to the output file or folder
        if folder is None:
            if write_json:
                output_file.write(
                    json.dumps([sg.to_dict() for sg in sensor_grids]))
            else:
                output_file.write('\n'.join(
                    [sg.to_radiance() for sg in sensor_grids]))
        else:
            if write_json:
                for sg in sensor_grids:
                    sg.to_json(folder)
            else:
                for sg in sensor_grids:
                    sg.to_file(folder)
    except Exception as e:
        _logger.exception('Model translation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
コード例 #4
0
def windows_by_ratio_rect(model_json, ratio, aperture_height, sill_height,
                          horizontal_separation, vertical_separation,
                          output_file):
    """Add apertures to all outdoor walls of a model given a ratio.

    Note that this method removes any existing apertures and doors from the Walls.
    Any rectangular portions of walls will have customized rectangular apertures
    using the various inputs.

    \b
    Args:
        model_json: Full path to a Honeybee Model JSON file.
        ratio: A number between 0 and 1 (but not perfectly equal to 1)
            for the desired ratio between window area and wall area.
    """
    try:
        # serialize the Model and check the Model tolerance
        parsed_model = Model.from_file(model_json)
        assert parsed_model.tolerance != 0, \
            'Model must have a non-zero tolerance to use windows-by-ratio-rect.'
        tol, units = parsed_model.tolerance, parsed_model.units

        # convert distance strings to floats
        aperture_height = parse_distance_string(aperture_height, units)
        sill_height = parse_distance_string(sill_height, units)
        horizontal_separation = parse_distance_string(horizontal_separation,
                                                      units)
        vertical_separation = parse_distance_string(vertical_separation, units)

        # generate the windows for all walls of rooms
        for room in parsed_model.rooms:
            for face in room.faces:
                if isinstance(face.boundary_condition, Outdoors) and \
                        isinstance(face.type, Wall):
                    face.apertures_by_ratio_rectangle(ratio, aperture_height,
                                                      sill_height,
                                                      horizontal_separation,
                                                      vertical_separation, tol)

        # write the new model out to the file or stdout
        output_file.write(json.dumps(parsed_model.to_dict()))
    except Exception as e:
        _logger.exception('Model windows by ratio rect failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
コード例 #5
0
def overhang(model_json, depth, angle, vertical_offset, per_window, outdoor,
             output_file):
    """Add overhangs to all outdoor walls or windows in walls.

    \b
    Args:
        model_json: Full path to a Honeybee Model JSON file.
    """
    try:
        # serialize the Model to Python and check the Model tolerance
        parsed_model = Model.from_file(model_json)
        assert parsed_model.tolerance != 0, \
            'Model must have a non-zero tolerance to use overhang.'
        tol, units = parsed_model.tolerance, parsed_model.units
        indoor = not outdoor

        # generate the overhangs for all walls of rooms
        depth = parse_distance_string(depth, units)
        overhangs = []
        for room in parsed_model.rooms:
            for face in room.faces:
                if isinstance(face.boundary_condition, Outdoors) and \
                        isinstance(face.type, Wall):
                    if per_window:
                        for ap in face.apertures:
                            overhangs.extend(
                                ap.overhang(depth, angle, indoor, tol))
                    else:
                        overhangs.extend(
                            face.overhang(depth, angle, indoor, tol))

        # move the overhangs if an offset has been specified
        vertical_offset = parse_distance_string(vertical_offset, units)
        if vertical_offset != 0:
            m_vec = Vector3D(0, 0, vertical_offset)
            for shd in overhangs:
                shd.move(m_vec)

        # write the new model out to the file or stdout
        output_file.write(json.dumps(parsed_model.to_dict()))
    except Exception as e:
        _logger.exception('Model overhang failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
コード例 #6
0
def louvers_by_spacing(model_json, spacing, depth, angle, offset, horizontal,
                       max_count, per_window, outdoor, no_flip, output_file):
    """Add louvers to all outdoor walls or windows in walls.

    \b
    Args:
        model_json: Full path to a Honeybee Model JSON file.
    """
    try:
        # serialize the Model to Python and check the Model tolerance
        parsed_model = Model.from_file(model_json)
        assert parsed_model.tolerance != 0, \
            'Model must have a non-zero tolerance to use overhang.'
        tol, units = parsed_model.tolerance, parsed_model.units
        indoor = not outdoor
        flip_start = not no_flip
        cont_vec = Vector2D(0, 1) if horizontal else Vector2D(1, 0)

        # generate the overhangs for all walls of rooms
        spacing = parse_distance_string(spacing, units)
        depth = parse_distance_string(depth, units)
        offset = parse_distance_string(offset, units)
        for room in parsed_model.rooms:
            for face in room.faces:
                if isinstance(face.boundary_condition, Outdoors) and \
                        isinstance(face.type, Wall):
                    if per_window:
                        for ap in face.apertures:
                            ap.louvers_by_distance_between(
                                spacing, depth, offset, angle, cont_vec,
                                flip_start, indoor, tol, max_count)
                    else:
                        face.louvers_by_distance_between(
                            spacing, depth, offset, angle, cont_vec,
                            flip_start, indoor, tol, max_count)

        # write the new model out to the file or stdout
        output_file.write(json.dumps(parsed_model.to_dict()))
    except Exception as e:
        _logger.exception('Model louver generation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
コード例 #7
0
def test_parse_distance_string():
    """Test the parse_distance_string method."""
    assert parse_distance_string('5', 'Meters') == 5
    assert parse_distance_string('5', 'Feet') == 5

    assert parse_distance_string('5m', 'Meters') == 5
    assert parse_distance_string('5m', 'Feet') == pytest.approx(16.4041995,
                                                                rel=1e-3)
    assert parse_distance_string('5ft', 'Feet') == 5
    assert parse_distance_string('5ft', 'Meters') == pytest.approx(1.524,
                                                                   rel=1e-3)

    assert parse_distance_string('5000mm', 'Meters') == pytest.approx(5,
                                                                      rel=1e-3)
    assert parse_distance_string('500cm', 'Meters') == pytest.approx(5,
                                                                     rel=1e-3)

    assert parse_distance_string('5 ft', 'Meters') == pytest.approx(1.524,
                                                                    rel=1e-3)

    with pytest.raises(ValueError):
        assert parse_distance_string('5 smoots', 'Meters')
コード例 #8
0
def add_room_sensors(model_json, grid_size, offset, include_mesh, keep_out, wall_offset,
                     room, output_file):
    """Add SensorGrids to a honeybee model generated from the Room's floors.

    The grids will have the rooms referenced in their room_identifier property.

    \b
    Args:
        model_json: Full path to a Model JSON file.
    """
    try:
        # re-serialize the Model and extract rooms and units
        model = Model.from_hbjson(model_json)
        rooms = model.rooms if room is None or len(room) == 0 else \
            [r for r in model.rooms if r.identifier in room]
        grid_size = parse_distance_string(grid_size, model.units)
        offset = parse_distance_string(offset, model.units)
        wall_offset = parse_distance_string(wall_offset, model.units)

        # loop through the rooms and generate sensor grids
        sensor_grids = []
        remove_out = not keep_out
        for room in rooms:
            sg = room.properties.radiance.generate_sensor_grid(
                grid_size, offset=offset, remove_out=remove_out, wall_offset=wall_offset)
            if sg is not None:
                sensor_grids.append(sg)
        if not include_mesh:
            for sg in sensor_grids:
                sg.mesh = None
        model.properties.radiance.add_sensor_grids(sensor_grids)

        # write the Model JSON string
        output_file.write(json.dumps(model.to_dict()))
    except Exception as e:
        _logger.exception('Model translation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
コード例 #9
0
def enclosure_info_grid(model_json, grid_file, air_boundary_distance,
                        output_file):
    """Get a JSON of radiant enclosure information from a .pts file of a sensor grid.

    \b
    Args:
        model_json: Full path to a Model JSON file (HBJSON) or a Model pkl (HBpkl) file.
        grid-file: Full path to a sensor grid file (.pts).
    """
    try:
        # re-serialize the Model
        model = Model.from_file(model_json)
        grid = sensorgrid.SensorGrid.from_file(grid_file)
        ab_distance = parse_distance_string(air_boundary_distance, model.units)
        # write out the list of radiant enclosure JSON info
        output_file.write(
            json.dumps(grid.enclosure_info_dict(model, ab_distance)))
    except Exception as e:
        _logger.exception(
            'Creation of radiant enclosure info failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)