def test_polygon2d_to_from_dict():
    """Test the to/from dict of Polygon2D objects."""
    pts = (Point2D(0, 0), Point2D(2, 0), Point2D(2, 2), Point2D(0, 2))
    polygon = Polygon2D(pts)
    polygon_dict = polygon.to_dict()
    new_polygon = Polygon2D.from_dict(polygon_dict)
    assert isinstance(new_polygon, Polygon2D)
    assert new_polygon.to_dict() == polygon_dict
示例#2
0
    def from_dict(cls, data):
        """Initialize an Transformer from a dictionary.

        Args:
            data: A dictionary representation of an Transformer object.
        """
        assert data['type'] == 'Transformer', 'Expected Transformer ' \
            'dictionary. Got {}.'.format(data['type'])
        props = TransformerProperties.from_dict(data['properties'])
        geo = Polygon2D.from_dict(data['geometry'])
        trans = cls(data['identifier'], geo, props)
        if 'display_name' in data and data['display_name'] is not None:
            trans.display_name = data['display_name']
        return trans
示例#3
0
    def from_dict(cls, data):
        """Initialize an Substation from a dictionary.

        Args:
            data: A dictionary representation of an Substation object.
        """
        # check the type of dictionary
        assert data['type'] == 'Substation', 'Expected Substation ' \
            'dictionary. Got {}.'.format(data['type'])
        geo = Polygon2D.from_dict(data['geometry'])
        trans = cls(data['identifier'], geo)
        if 'display_name' in data and data['display_name'] is not None:
            trans.display_name = data['display_name']
        return trans
示例#4
0
    def from_dict_abridged(cls, data, properties):
        """Initialize a Transformer from an abridged dictionary.

        Args:
            data: A TransformerAbridged dictionary.
            properties: A dictionary with identifiers of TransformerProperties
                as keys and Python TransformerProperties objects as values.
        """
        assert data['type'] == 'TransformerAbridged', \
            'Expected TransformerAbridged. Got {}.'.format(data['type'])
        try:
            props = properties[data['properties']]
        except KeyError as e:
            raise ValueError('Failed to find "{}" in properties.'.format(e))
        geo = Polygon2D.from_dict(data['geometry'])
        trans = cls(data['identifier'], geo, props)
        if 'display_name' in data and data['display_name'] is not None:
            trans.display_name = data['display_name']
        return trans
示例#5
0
    def generate_faces(self):
        polygon = Polygon2D.from_dict({"type": "Polygon2D",
                                       "vertices": [(-self.xy / 2, -self.xy / 2), (self.xy / 2, -self.xy / 2),
                                                    (self.xy / 2, self.xy / 2), (-self.xy / 2, self.xy / 2)]})
        mesh = Mesh2D.from_polygon_grid(polygon, x_dim=self.subsurface_size, y_dim=self.subsurface_size)
        self.faces_top = [Face3D([Point3D(mesh.vertices[vertex].x, mesh.vertices[vertex].y, 0) for vertex in face]) for
                          face in mesh.faces]

        pt0 = Point3D(-self.xy / 2, -self.xy / 2, 0)
        pt1 = Point3D(self.xy / 2, -self.xy / 2, 0)
        pt2 = Point3D(self.xy / 2, self.xy / 2, 0)
        pt3 = Point3D(-self.xy / 2, self.xy / 2, 0)
        pt4 = Point3D(-self.xy / 2, -self.xy / 2, -self.depth)
        pt5 = Point3D(self.xy / 2, -self.xy / 2, -self.depth)
        pt6 = Point3D(self.xy / 2, self.xy / 2, -self.depth)
        pt7 = Point3D(-self.xy / 2, self.xy / 2, -self.depth)

        self.face_bottom = Face3D([pt7, pt6, pt5, pt4])
        self.face_south = Face3D([pt4, pt5, pt1, pt0])
        self.face_east = Face3D([pt5, pt6, pt2, pt1])
        self.face_north = Face3D([pt6, pt7, pt3, pt2])
        self.face_west = Face3D([pt7, pt4, pt0, pt3])