예제 #1
0
def test_init_graphic_con():
    """Test the initialization of GraphicContainer objects."""
    mesh2d = Mesh2D.from_grid(num_x=2, num_y=2)
    mesh3d = Mesh3D.from_mesh2d(mesh2d)
    data = [0, 1, 2, 3]
    graphic_con = GraphicContainer(data, mesh3d.min, mesh3d.max)

    str(graphic_con)  # Test the GraphicContainer representation

    assert len(graphic_con) == 4
    assert graphic_con[0] == 0
    assert graphic_con[-1] == 3
    for item in graphic_con:
        assert isinstance(item, (float, int))

    assert len(graphic_con.values) == 4
    assert isinstance(graphic_con.legend, Legend)
    assert graphic_con.value_colors == graphic_con.legend.value_colors

    assert graphic_con.legend_parameters.is_base_plane_default is False
    assert graphic_con.legend_parameters.is_segment_height_default is False
    assert graphic_con.legend_parameters.is_segment_width_default is True
    assert graphic_con.legend_parameters.is_text_height_default is True
    assert graphic_con.legend_parameters.base_plane != Plane()

    assert isinstance(graphic_con.lower_title_location, Plane)
    assert isinstance(graphic_con.upper_title_location, Plane)
    assert graphic_con.lower_title_location != Plane()
    assert graphic_con.upper_title_location != Plane()
예제 #2
0
def test_remove_faces():
    """Test the Mesh3D remove_faces method."""
    mesh_2d = Mesh2D.from_grid(Point2D(1, 1), 8, 2, 0.25, 1)
    mesh = Mesh3D.from_mesh2d(mesh_2d)
    assert len(mesh.vertices) == 27
    assert len(mesh.faces) == 16
    assert mesh.area == 4

    pattern_1 = []
    for i in range(4):
        pattern_1.extend([True, False, False, False])
    mesh_1, vert_pattern = mesh.remove_faces(pattern_1)
    assert len(mesh_1.vertices) == 16
    assert len(mesh_1.faces) == 4
    assert mesh_1.area == 1
    for face in mesh_1.faces:
        for i in face:
            mesh_1[i]  # make sure all face indices reference current vertices

    pattern_2 = []
    for i in range(8):
        pattern_2.extend([True, False])
    mesh_2, vert_pattern = mesh.remove_faces(pattern_2)
    assert len(mesh_2.vertices) == 18
    assert len(mesh_2.faces) == 8
    assert mesh_2.area == 2
    for face in mesh_2.faces:
        for i in face:
            mesh_2[i]  # make sure all face indices reference current vertices
예제 #3
0
 def _compute_colored_mesh3d(self):
     """Compute a colored mesh from this object's data collection."""
     _colored_mesh3d = Mesh3D.from_mesh2d(
         self.colored_mesh2d,
         Plane(o=Point3D(0, 0, self._container.min_point.z)))
     if self.z_dim != 0:
         _colored_mesh3d = _colored_mesh3d.height_field_mesh(
             self.data_collection.values, (0, self.z_dim))
     return _colored_mesh3d
예제 #4
0
def test_from_mesh3d():
    mesh_2d = Mesh2D.from_grid(Point2D(1, 1), 8, 2, 0.25, 1)
    mesh = Mesh3D.from_mesh2d(mesh_2d)
    sg = SensorGrid.from_mesh3d('sg_1', mesh)

    assert len(sg.sensors) == 16
    assert len(sg.mesh.vertices) == 27
    assert len(sg.mesh.faces) == 16
    assert mesh.area == 4
예제 #5
0
    def test_init_graphic_con_invalid(self):
        """Test the initialization of GraphicContainer objects with invalid inputs."""
        mesh2d = Mesh2D.from_grid(num_x=2, num_y=2)
        mesh3d = Mesh3D.from_mesh2d(mesh2d)
        data = [0, 1, 2, 3, 4]

        with pytest.raises(Exception):
            GraphicContainer(data, mesh3d.min, mesh3d.max,
                             data_type=Temperature(), unit='NotAUnit')
예제 #6
0
def test_to_from_dict():
    """Test the to/from dict methods."""
    mesh2d = Mesh2D.from_grid(num_x=2, num_y=2)
    mesh3d = Mesh3D.from_mesh2d(mesh2d)
    data = [0, 1, 2, 3]
    graphic_con = GraphicContainer(data, mesh3d.min, mesh3d.max)

    graphic_con_dict = graphic_con.to_dict()
    new_graphic_con = GraphicContainer.from_dict(graphic_con_dict)
    assert new_graphic_con.to_dict() == graphic_con_dict
예제 #7
0
def test_init_graphic_con_vertex_based():
    """Test the initialization of ResultMesh objects with vertex-based input."""
    mesh2d = Mesh2D.from_grid(num_x=2, num_y=2)
    mesh3d = Mesh3D.from_mesh2d(mesh2d)
    data = [0, 1, 2, 3, 4, 5, 6, 7, 8]
    graphic_con = GraphicContainer(data, mesh3d.min, mesh3d.max)

    assert len(graphic_con) == 9
    assert graphic_con[0] == 0
    assert graphic_con[-1] == 8

    assert len(graphic_con.values) == 9
    assert isinstance(graphic_con.legend_parameters, LegendParameters)
    assert isinstance(graphic_con.legend, Legend)
    assert graphic_con.value_colors == graphic_con.legend.value_colors
예제 #8
0
    def test_init_graphic_con_data_type_ordinal(self):
        """Test the ResultMesh objects with a DataType with unit_descr."""
        mesh2d = Mesh2D.from_grid(num_x=2, num_y=2)
        mesh3d = Mesh3D.from_mesh2d(mesh2d)
        data = [-1, 0, 1, 2]
        graphic_con = GraphicContainer(data, mesh3d.min, mesh3d.max,
                                       data_type=PredictedMeanVote(), unit='PMV')

        assert graphic_con.legend_parameters.min == -3
        assert graphic_con.legend_parameters.max == 3
        assert graphic_con.legend_parameters.segment_count == 7
        assert graphic_con.legend_parameters.is_title_default is False
        assert graphic_con.legend_parameters.title == 'PMV'
        assert graphic_con.legend.segment_text == ['Cold', 'Cool', 'Slightly Cool',
                                                   'Neutral',
                                                   'Slightly Warm', 'Warm', 'Hot']
예제 #9
0
def test_mesh3d_from_mesh2d():
    """Test the initialization of Mesh3D objects from_mesh2d."""
    pts = (Point2D(0, 0), Point2D(0, 2), Point2D(2, 2), Point2D(2, 0))
    mesh_2d = Mesh2D(pts, [(0, 1, 2, 3)])
    plane = Plane(Vector3D(1, 0, 0), Point3D(0, 0, 0))

    mesh = Mesh3D.from_mesh2d(mesh_2d, plane)
    assert len(mesh.vertices) == 4
    assert len(mesh.faces) == 1
    assert mesh[0] == Point3D(0, 0, 0)
    assert mesh[1] == Point3D(0, 0, -2)
    assert mesh[2] == Point3D(0, -2, -2)
    assert mesh[3] == Point3D(0, -2, 0)
    assert mesh.area == 4
    assert mesh.min == Point3D(0, -2, -2)
    assert mesh.max == Point3D(0, 0, 0)
    assert mesh.center == Point3D(0, -1, -1)
예제 #10
0
    def test_init_graphic_con_data_type(self):
        """Test the initialization of GraphicContainer objects with a DataType."""
        mesh2d = Mesh2D.from_grid(num_x=2, num_y=2)
        mesh3d = Mesh3D.from_mesh2d(mesh2d)
        data = [-1, 0, 1, 2]
        graphic_con = GraphicContainer(data, mesh3d.min, mesh3d.max,
                                       data_type=Temperature())

        assert graphic_con.legend_parameters.is_title_default is False
        assert graphic_con.legend_parameters.title == 'C'

        legend_par = LegendParameters()
        legend_par.vertical = False
        graphic_con = GraphicContainer(data, mesh3d.min, mesh3d.max,
                                       legend_par, data_type=Temperature())

        assert graphic_con.legend_parameters.is_title_default is False
        assert graphic_con.legend_parameters.title == 'Temperature (C)'
예제 #11
0
def test_graphic_con_data_type_ordinal_all_same():
    """Test the GraphicContainer with a DataType with unit_descr and all equal values."""
    mesh2d = Mesh2D.from_grid(num_x=2, num_y=2)
    mesh3d = Mesh3D.from_mesh2d(mesh2d)
    data = [0] * 3
    graphic_con = GraphicContainer(data,
                                   mesh3d.min,
                                   mesh3d.max,
                                   data_type=PredictedMeanVote(),
                                   unit='PMV')

    assert graphic_con.legend_parameters.min == -3
    assert graphic_con.legend_parameters.max == 3
    assert graphic_con.legend_parameters.segment_count == 7
    assert not graphic_con.legend_parameters.is_title_default
    assert graphic_con.legend_parameters.title == 'PMV'
    assert graphic_con.legend.segment_text == [
        'Cold', 'Cool', 'Slightly Cool', 'Neutral', 'Slightly Warm', 'Warm',
        'Hot'
    ]
예제 #12
0
def test_init_graphic_con_legend_parameters():
    """Test the initialization of ResultMesh objects with a LegendParameters."""
    mesh2d = Mesh2D.from_grid(num_x=2, num_y=2)
    mesh3d = Mesh3D.from_mesh2d(mesh2d)
    data = [-1, 0, 1, 2]
    legend_par = LegendParameters(base_plane=Plane(o=Point3D(2, 2, 0)))
    legend_par.vertical = False
    legend_par.segment_height = 0.25
    legend_par.segment_width = 0.5
    legend_par.text_height = 0.15
    graphic_con = GraphicContainer(data, mesh3d.min, mesh3d.max, legend_par)

    assert graphic_con.legend_parameters.is_base_plane_default is False
    assert graphic_con.legend_parameters.is_segment_height_default is False
    assert graphic_con.legend_parameters.is_segment_width_default is False
    assert graphic_con.legend_parameters.is_text_height_default is False
    assert graphic_con.legend_parameters.vertical is False
    assert graphic_con.legend_parameters.base_plane.o == Point3D(2, 2, 0)
    assert graphic_con.legend_parameters.segment_height == 0.25
    assert graphic_con.legend_parameters.segment_width == 0.5
    assert graphic_con.legend_parameters.text_height == 0.15
예제 #13
0
def test_remove_faces_only():
    """Test the Mesh3D remove_faces method."""
    mesh_2d = Mesh2D.from_grid(Point2D(1, 1), 8, 2, 0.25, 1)
    mesh = Mesh3D.from_mesh2d(mesh_2d)
    assert len(mesh.vertices) == 27
    assert len(mesh.faces) == 16
    assert mesh.area == 4

    pattern_1 = []
    for i in range(4):
        pattern_1.extend([True, False, False, False])
    mesh_1 = mesh.remove_faces_only(pattern_1)
    assert len(mesh_1.vertices) == 27
    assert len(mesh_1.faces) == 4
    assert mesh_1.area == 1

    pattern_2 = []
    for i in range(8):
        pattern_2.extend([True, False])
    mesh_2 = mesh.remove_faces_only(pattern_2)
    assert len(mesh_2.vertices) == 27
    assert len(mesh_2.faces) == 8
    assert mesh_2.area == 2
예제 #14
0
 def segment_mesh(self):
     """A Ladybug Mesh3D for the legend colors."""
     _mesh_2d = self._segment_mesh_2d()
     return Mesh3D.from_mesh2d(_mesh_2d, self.legend_parameters.base_plane)