Esempio n. 1
0
    def _my_lb_line_constructor(_line):
        """Cus' the 'to_line_segment' method has an error (thinks second pt is a vector) """

        p1 = to_point3d(_line.PointAtStart)
        p2 = to_point3d(_line.PointAtEnd) 
        line = LineSegment3D.from_end_points(p1, p2)
        
        return line
def human_height_points(position, height, pt_count):
    """Get a list of points and a line representing the human geometry.

    Args:
        position: Rhino point for the position of the human.
        height: Number for the height of the human.
        pt_count: Integer for the number of points representing the human.

    Returns:
         A tuple with human points as first element and human line as second.
         Both geomtries are Rhino geometries.
    """
    lb_feet_pt = to_point3d(position).move(Vector3D(0, 0, height / 100))
    lb_hum_line = LineSegment3D(lb_feet_pt, Vector3D(0, 0, height))
    lb_pts = [lb_hum_line.midpoint] if pt_count == 1 else \
        lb_hum_line.subdivide_evenly(pt_count - 1)
    if len(lb_pts) == pt_count - 1:  # sometimes tolerance kills the last point
        lb_pts.append(lb_feet_pt.move(Vector3D(0, 0, height)))
    h_points = [from_point3d(pt) for pt in lb_pts]
    return h_points, from_linesegment3d(lb_hum_line)
        'plot the wind rose. Got: {}'.format(_dir_count_)

    if north_ is not None:  # process the north_
        try:
            north_ = math.degrees(
                to_vector2d(north_).angle_clockwise(Vector2D(0, 1)))
        except AttributeError:  # north angle instead of vector
            north_ = float(north_)
            assert -360.0 <= north_ <= 360.0, 'The north orientation must be greater ' \
                'then -360 and less then 360 to plot the wind rose. ' \
                'Got: {}'.format(north_)
    else:
        north_ = 0.0

    # set default values for the chart dimensions
    _center_pt_ = to_point3d(
        _center_pt_) if _center_pt_ is not None else Point3D()
    center_pt_2d = Point2D(_center_pt_.x, _center_pt_.y)

    # set defaults frequency hours and distance so chart is same scale as other LB plots
    if _freq_hours_ is None:
        _freq_hours_ = 50.0
    if _freq_dist_ is None:
        _freq_dist_ = 5.0 / conversion_to_meters()

    # set default show_freq and _show_calmrose_
    _show_calmrose_ = False if _show_calmrose_ is None else _show_calmrose_
    _show_freq_ = True if _show_freq_ is None else _show_freq_

    # set up empty lists of objects to be filled
    all_wind_avg_val = []
    all_wind_frequency = []
Esempio n. 4
0
        title_array.append('{}: {}'.format(key, val))
    return '\n'.join(title_array)


if all_required_inputs(ghenv.Component):
    # process all of the global inputs for the sunpath
    if north_ is not None:  # process the north_
        try:
            north_ = math.degrees(
                to_vector2d(north_).angle_clockwise(Vector2D(0, 1)))
        except AttributeError:  # north angle instead of vector
            north_ = float(north_)
    else:
        north_ = 0
    if _center_pt_ is not None:  # process the center point into a Point2D
        center_pt, center_pt3d = to_point2d(_center_pt_), to_point3d(
            _center_pt_)
        z = center_pt3d.z
    else:
        center_pt, center_pt3d = Point2D(), Point3D()
        z = 0
    _scale_ = 1 if _scale_ is None else _scale_  # process the scale into a radius
    radius = (100 * _scale_) / conversion_to_meters()
    solar_time_ = False if solar_time_ is None else solar_time_  # process solar time
    projection_ = projection_.title() if projection_ is not None else None

    # create a intersection of the input hoys_ and the data hoys
    if len(data_) > 0 and len(hoys_) > 0:
        all_aligned = all(data_[0].is_collection_aligned(d) for d in data_[1:])
        assert all_aligned, 'All collections input to data_ must be aligned for ' \
            'each Sunpath.\nGrafting the data_ and suplying multiple grafted ' \
            '_center_pt_ can be used to view each data on its own path.'
Esempio n. 5
0
if all_required_inputs(ghenv.Component):
    # check the _bounce_count_
    _bounce_count_ = 0 if _bounce_count_ is None else _bounce_count_ - 1
    assert _bounce_count_ >= 0, 'The input _bounce_count_ must be greater '  \
        'than zero. Got {}.'.format(_bounce_count_ + 1)
    # process the input sun vector
    lb_vec = to_vector3d(_vector).normalize()
    neg_lb_vec = -lb_vec
    vec = from_vector3d(lb_vec)

    # convert all of the _source_geo and contex into a single Brep for ray tracing
    rtrace_brep = join_geometry_to_brep(_source_geo + context_)

    # autocompute the first and last bounce length if it's unspecified
    if _first_length_ is None or _last_length_ is None:
        max_pt, min_pt = (to_point3d(p)
                          for p in bounding_box_extents(rtrace_brep))
        diag_dist = max_pt.distance_to_point(min_pt)
        _first_length_ = diag_dist if _first_length_ is None else _first_length_
        _last_length_ = diag_dist if _last_length_ is None else _last_length_

    # create the gridded mesh from the _source_geo and set up the starting rays
    study_mesh = to_joined_gridded_mesh3d(_source_geo, _grid_size)
    move_vec = neg_lb_vec * _first_length_
    source_points = [pt + move_vec for pt in study_mesh.face_centroids]
    lb_rays = [Ray3D(pt, lb_vec) for pt in source_points]
    start_rays = [from_ray3d(ray) for ray in lb_rays]

    # trace each ray through the geometry
    cutoff_ang = math.pi / 2
    rtrace_geo = [rtrace_brep]
Esempio n. 6
0
    off_at_min_ = [False] if len(off_at_min_) == 0 else off_at_min_

    # loop through the rooms and assign daylight sensors
    unassigned_rooms = []
    if len(_sensor_points_) == 0:
        for i, room in enumerate(rooms):
            dl_control = room.properties.energy.add_daylight_control_to_center(
                dist_from_floor, longest_list(_ill_setpoint_, i),
                longest_list(_control_fract_, i),
                longest_list(_min_power_in_, i),
                longest_list(_min_light_out_, i), longest_list(off_at_min_, i))
            if dl_control is None:
                unassigned_rooms.append(room.display_name)
    else:
        for i, room in enumerate(rooms):
            sensor_pt = to_point3d(_sensor_points_[i])
            if room.geometry.is_point_inside(sensor_pt):
                dl_control = DaylightingControl(
                    sensor_pt, longest_list(_ill_setpoint_, i),
                    longest_list(_control_fract_, i),
                    longest_list(_min_power_in_, i),
                    longest_list(_min_light_out_, i),
                    longest_list(off_at_min_, i))
                room.properties.energy.daylighting_control = dl_control
            else:
                unassigned_rooms.append(room.display_name)

    # give a warning about any rooms to which a sensor could not be assinged
    for room in unassigned_rooms:
        msg = 'Sensor point for room "{}" does not lie within the room volume.\n' \
            'No daylight sensors have been added to this room.'.format(room)
        result.append(from_arc2d(circle, z))

    # generate the labels and tick marks for the azimuths
    for line in compass.major_azimuth_ticks:
        result.append(from_linesegment2d(line, z))
    for txt, pt in zip(compass.MAJOR_TEXT, compass.major_azimuth_points):
        result.append(
            text_objects(txt, Plane(o=Point3D(pt.x, pt.y, z), x=xaxis),
                         maj_txt, font, 1, 3))
    return result


# set defaults for all of the
if _north_ is not None:  # process the _north_
    try:
        _north_ = math.degrees(
            to_vector2d(_north_).angle_clockwise(Vector2D(0, 1)))
    except AttributeError:  # north angle instead of vector
        _north_ = float(_north_)
else:
    _north_ = 0
if _center_ is not None:  # process the center point into a Point2D
    center_pt, z = to_point2d(_center_), to_point3d(_center_).z
else:
    center_pt, z = Point2D(), 0
_scale_ = 1 if _scale_ is None else _scale_  # process the scale into a radius
radius = (10 * _scale_) / conversion_to_meters()

# create the compass
compass = translate_compass(Compass(radius, center_pt, _north_, 1), z)
Esempio n. 8
0
    time_str = '{} - {}'.format(st, end) if st != end else st
    title_txt = '{} Radiation\n{}\n{}'.format(
        dome_name, time_str, '\n'.join([dat for dat in metadata[4:]]))
    dome_title = text_objects(title_txt, graphic.lower_title_location,
                              graphic.legend_parameters.text_height,
                              graphic.legend_parameters.font)

    return dome_mesh, dome_compass, dome_legend, dome_title, values


if all_required_inputs(ghenv.Component):
    # set defaults for global variables
    _scale_ = 1 if _scale_ is None else _scale_
    radius = (100 * _scale_) / conversion_to_meters()
    if _center_pt_ is not None:  # process the center point into a Point2D
        center_pt3d = to_point3d(_center_pt_)
        z = center_pt3d.z
    else:
        center_pt3d, z = Point3D(), 0

    # deconstruct the sky matrix and derive key data from it
    metadata, direct, diffuse = de_objectify_output(_sky_mtx)
    north = metadata[0]  # first item is the north angle
    sky_type = 1 if len(direct) == 145 else 2  # i for tregenza; 2 for reinhart
    total = [dirr + difr
             for dirr, difr in zip(direct, diffuse)]  # total radiation

    # override the legend default min and max to make sense for domes
    l_par = legend_par_.duplicate(
    ) if legend_par_ is not None else LegendParameters()
    if l_par.min is None:
Esempio n. 9
0
        enth_wb_lines_i = enth_wb_lines_i + small_labels(
            psy_chart, psy_chart.enthalpy_labels,
            psy_chart.enthalpy_label_points, 2, 3)

    # add all of the objects to the bse list
    title.append(title_i)
    temp_lines.append(temp_lines_i)
    rh_lines.append(rh_lines_i)
    hr_lines.append(hr_lines_i)
    enth_wb_lines.append(enth_wb_lines_i)


if all_required_inputs(ghenv.Component):
    # process the base point
    bp = to_point2d(_base_pt_) if _base_pt_ is not None else Point2D()
    z = to_point3d(_base_pt_).z if _base_pt_ is not None else 0

    # create lists to be filled with objects
    title = []
    temp_lines = []
    rh_lines = []
    hr_lines = []
    enth_wb_lines = []
    mesh = []
    legend = []
    points = []
    data_colls = []
    psych_chart = []

    # loop through the input temperatures and humidity and plot psych charts
    for j, (temperature,
def mask_mesh_from_pattern(base_mask, mask_pattern, color):
    """Get a Rhino mesh of a mask from a pattern aligned to the faces of a base mesh."""
    try:
        mask_mesh = base_mask.remove_faces_only(mask_pattern)
    except AssertionError:  # all mesh faces have been removed
        return None
    mask_mesh.colors = [color] * len(mask_mesh.faces)
    return from_mesh3d(mask_mesh)


# process the inputs and set defaults for global variables
_scale_ = 1 if _scale_ is None else _scale_
radius = (100 * _scale_) / conversion_to_meters()
if _center_ is not None:  # process the center point into a Point2D
    try:  # assume that it is a point
        center_pt3d, direction = to_point3d(_center_), None
    except AttributeError:
        plane, is_orient = to_plane(_center_), True
        center_pt3d, direction = plane.o, plane.n
else:
    center_pt3d, direction = Point3D(), None
az_count, alt_count = 72, 18
if _density_:
    az_count = az_count * _density_
    alt_count = alt_count * _density_
if orientation_ is not None:  # process the orientation to a number
    ori_dict = {'north': 0, 'east': 90, 'south': 180, 'west': 270}
    try:  # first check if it's text for the direction
        orientation_ = ori_dict[orientation_.lower()]
    except KeyError:  # it's a number for the orientation
        orientation_ = float(orientation_)
try:  # import the ladybug_rhino dependencies
    from ladybug_rhino.togeometry import to_point3d
    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):
    hb_objs = [obj.duplicate()
               for obj in _hb_objs]  # duplicate the initial objects

    # check that the factor is positive
    assert _factor > 0, 'Input _factor must be greater than 0.'

    # set the default origin
    if _origin_ is not None:
        pt = to_point3d(_origin_)
    else:
        pt = []
        for obj in hb_objs:
            origin = obj.center if not isinstance(obj, Model) else None
            pt.append(origin)

    # scale all of the objects
    if _origin_ is not None:
        for obj in hb_objs:
            obj.scale(_factor, pt)
    else:  # unique origin point for each object
        for i, obj in enumerate(hb_objs):
            obj.scale(_factor, pt[i])

    # add the prefix if specified
Esempio n. 12
0
    from ladybug_rhino.text import text_objects
    from ladybug_rhino.fromobjects import legend_objects
    from ladybug_rhino.grasshopper import all_required_inputs, list_to_data_tree
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # apply any analysis periods and conditional statements to the input collections
    if period_ is not None:
        _data = [coll.filter_by_analysis_period(period_) for coll in _data]
    if statement_ is not None:
        _data = HourlyContinuousCollection.filter_collections_by_statement(
            _data, statement_)

    # set default values for the chart dimensions
    _base_pt_ = to_point3d(_base_pt_) if _base_pt_ is not None else Point3D()
    _x_dim_ = _x_dim_ if _x_dim_ is not None else 1.0 / conversion_to_meters()
    _y_dim_ = _y_dim_ if _y_dim_ is not None else 4.0 / conversion_to_meters()
    _z_dim_ = _z_dim_ if _z_dim_ is not None else 0
    reverse_y_ = reverse_y_ if reverse_y_ is not None else False

    # set up empty lists of objects to be filled
    mesh = []
    title = []
    all_legends = []
    all_borders = []
    all_labels = []

    for i, data_coll in enumerate(_data):
        try:  # sense when several legend parameters are connected
            lpar = legend_par_[i]