예제 #1
0
    def from_dict(cls, ag_dict):
        """Create a sensor grid from a dictionary in the following format.

        .. code-block:: python

            {
            "type": "SensorGrid",
            "identifier": str,  # SensorGrid identifier
            "display_name": str,  # SensorGrid display name
            "sensors": [],  # list of Sensor dictionaries
            'room_identifier': str,  # optional room identifier
            'group_identifier': str,  # optional group identifier
            'light_path':  []  # optional list of lists for light path
            }
        """
        assert ag_dict['type'] == 'SensorGrid', \
            'Expected SensorGrid dictionary. Got {}.'.format(ag_dict['type'])
        sensors = (Sensor.from_dict(sensor) for sensor in ag_dict['sensors'])
        new_obj = cls(identifier=ag_dict["identifier"], sensors=sensors)
        if 'display_name' in ag_dict and ag_dict['display_name'] is not None:
            new_obj.display_name = ag_dict['display_name']
        if 'room_identifier' in ag_dict and ag_dict[
                'room_identifier'] is not None:
            new_obj.room_identifier = ag_dict['room_identifier']
        if 'group_identifier' in ag_dict and ag_dict[
                'group_identifier'] is not None:
            new_obj.group_identifier = ag_dict['group_identifier']
        if 'light_path' in ag_dict and ag_dict['light_path'] is not None:
            new_obj.light_path = ag_dict['light_path']
        if 'mesh' in ag_dict and ag_dict['mesh'] is not None:
            new_obj.mesh = Mesh3D.from_dict(ag_dict['mesh'])
        if 'base_geometry' in ag_dict and ag_dict['base_geometry'] is not None:
            new_obj.base_geometry = \
                tuple(Face3D.from_dict(face) for face in ag_dict['base_geometry'])
        return new_obj
예제 #2
0
def test_mesh3d_to_from_dict():
    """Test the to/from dict of Mesh3D objects."""
    pts = (Point3D(0, 0), Point3D(0, 2), Point3D(2, 2), Point3D(2, 0))
    mesh = Mesh3D(pts, [(0, 1, 2, 3)])
    mesh_dict = mesh.to_dict()
    new_mesh = Mesh3D.from_dict(mesh_dict)
    assert isinstance(new_mesh, Mesh3D)
    assert new_mesh.to_dict() == mesh_dict
예제 #3
0
def test_mesh3d_to_from_json():
    """Test the to/from dict with JSON serialization of Mesh3D objects."""
    pts = (Point3D(0, 0), Point3D(0, 2), Point3D(2, 2), Point3D(2, 0))
    mesh = Mesh3D(pts, [(0, 1, 2, 3)])
    mesh_dict = mesh.to_dict()
    geo_file = './tests/json/json_mesh.json'
    with open(geo_file, 'w') as fp:
        json.dump(mesh_dict, fp)
    with open(geo_file, 'r') as fp:
        new_mesh_dict = json.load(fp)
    new_mesh = Mesh3D.from_dict(new_mesh_dict)
    assert isinstance(new_mesh, Mesh3D)
    assert new_mesh.to_dict() == mesh_dict
    os.remove(geo_file)
예제 #4
0
def test_init_solar_envelope():
    """Test the initialization of Sunpath and basic properties."""
    # get sun positions
    sunpath = Sunpath(latitude=40.72, longitude=-74.02)
    sun_vecs = []
    for hour in range(8, 16):
        sun = sunpath.calculate_sun(12, 21, hour)
        sun_vecs.append(sun.sun_vector)

    # load the site and the context
    site_mesh_file = './tests/assets/geo/mesh.json'
    with open(site_mesh_file) as json_file:
        site_mesh_data = json.load(json_file)
    site_mesh = Mesh3D.from_dict(site_mesh_data)
    context_file = './tests/assets/geo/faces.json'
    with open(context_file) as json_file:
        context_data = json.load(json_file)
    context_faces = [Face3D.from_dict(con) for con in context_data]

    # initialize solar envelope
    envelope = SolarEnvelope(site_mesh, context_faces, sun_vecs, solar_rights=True)
    str(envelope)  # test the string representation
    envelope_mesh = envelope.envelope_mesh()
    assert isinstance(envelope_mesh, Mesh3D)