Beispiel #1
0
 def _segment_mesh_2d(self, base_pt=Point2D(0, 0)):
     """Mesh2D for the segments in the 2D space of the legend."""
     # get general properties
     _l_par = self.legend_parameters
     n_seg = self.segment_length
     # create the 2D mesh of the legend
     if _l_par.vertical:
         mesh2d = Mesh2D.from_grid(base_pt, 1, n_seg, _l_par.segment_width,
                                   _l_par.segment_height)
     else:
         _base_pt = Point2D(base_pt.x - _l_par.segment_width * n_seg,
                            base_pt.y)
         mesh2d = Mesh2D.from_grid(_base_pt, n_seg, 1, _l_par.segment_width,
                                   _l_par.segment_height)
     # add colors to the mesh
     _seg_colors = self.segment_colors
     if not _l_par.continuous_legend:
         mesh2d.colors = _seg_colors
     else:
         if _l_par.vertical:
             mesh2d.colors = _seg_colors + _seg_colors
         else:
             mesh2d.colors = tuple(col for col in _seg_colors
                                   for i in (0, 1))
     return mesh2d
Beispiel #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
Beispiel #3
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()
Beispiel #4
0
    def _compute_colored_mesh2d(self):
        """Compute a colored mesh from this object's data collection."""
        # generate the base mesh as a stanadard grid
        _colored_mesh2d = Mesh2D.from_grid(self.base_point, self._num_x,
                                           self._num_y, self.x_dim, self.y_dim)

        # remove any faces in the base mesh that do not represent the data
        if not isinstance(self.data_collection, HourlyContinuousCollection):
            # get a pattern of booleans for whether mesh faces should be included
            data_coll_moys = [dt.moy for dt in self.data_collection.datetimes]
            data_coll_moys.append(
                527100)  # extra value for the end of the list
            found_i = 0
            mesh_pattern = []
            for moy in self.analysis_period.moys:
                if moy == data_coll_moys[found_i]:
                    mesh_pattern.append(True)
                    found_i += 1
                else:
                    mesh_pattern.append(False)
            if self._reverse_y:
                hr_diff = (self.analysis_period.end_hour -
                           self.analysis_period.st_hour)
                t_step = self.analysis_period.timestep
                t_diff = t_step * hr_diff + 1 if t_step == 1 or hr_diff != 23 else \
                    t_step * (hr_diff + 1)
                mesh_pat_rev = []
                for i in range(0, len(mesh_pattern), t_diff):
                    mesh_pat_rev.extend(reversed(mesh_pattern[i:i + t_diff]))
                mesh_pattern = mesh_pat_rev
            _colored_mesh2d = _colored_mesh2d.remove_faces_only(mesh_pattern)

        # assign the colors to the mesh
        _colored_mesh2d.colors = self.colors
        return _colored_mesh2d
Beispiel #5
0
    def _compute_colored_mesh2d(self):
        """Compute a colored mesh from this object's data collection."""
        # generate the base mesh as a stanadard grid
        _colored_mesh2d = Mesh2D.from_grid(self.base_point, self._num_x,
                                           self._num_y, self.x_dim, self.y_dim)

        # remove any faces in the base mesh that do not represent the data
        if not isinstance(self.data_collection, HourlyContinuousCollection):
            # get a pattern of booleans for whether mesh faces should be included
            data_coll_moys = [dt.moy for dt in self.data_collection.datetimes]
            data_coll_moys.append(
                527100)  # extra value for the end of the list
            found_i = 0
            mesh_pattern = []
            for moy in self.analysis_period.moys:
                if moy == data_coll_moys[found_i]:
                    mesh_pattern.append(True)
                    found_i += 1
                else:
                    mesh_pattern.append(False)
            _colored_mesh2d = _colored_mesh2d.remove_faces_only(mesh_pattern)

        # assign the colors to the mesh
        _colored_mesh2d.colors = self.colors
        return _colored_mesh2d
Beispiel #6
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
Beispiel #7
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')
Beispiel #8
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
Beispiel #9
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
Beispiel #10
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']
Beispiel #11
0
def test_mesh2d_init_from_grid():
    """Test the initalization of Mesh2D from_grid."""
    mesh = Mesh2D.from_grid(Point2D(1, 1), 8, 2, 0.25, 1)

    assert len(mesh.vertices) == 27
    assert len(mesh.faces) == 16
    assert mesh.area == 4

    assert mesh.min == Point2D(1, 1)
    assert mesh.max == Point2D(3, 3)
    assert mesh.center == Point2D(2, 2)
    assert mesh.centroid == Point2D(2, 2)

    assert len(mesh.face_areas) == 16
    assert mesh.face_areas[0] == 0.25
    assert len(mesh.face_centroids) == 16
    assert mesh._is_color_by_face is False
    assert mesh.colors is None
Beispiel #12
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)'
Beispiel #13
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'
    ]
Beispiel #14
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
Beispiel #15
0
def test_remove_faces_only():
    """Test the Mesh2D remove_faces method."""
    mesh = Mesh2D.from_grid(Point2D(1, 1), 8, 2, 0.25, 1)
    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