Esempio n. 1
0
def test_ts_ground_elements_surfaces():
    """Check timeseries ground elements are created correctly"""

    # Create timeseries coords
    gnd_element_coords = TsLineCoords.from_array(
        np.array([[[-1, -1], [0, 0]], [[1, 1], [0, 0]]]))
    pt_coords_1 = TsPointCoords.from_array(np.array([[-0.5, -1], [0, 0]]))
    pt_coords_2 = TsPointCoords.from_array(np.array([[0.5, 0], [0, 0]]))

    # Create gnd element
    gnd_element = TsGroundElement(
        gnd_element_coords,
        list_ordered_cut_pts_coords=[pt_coords_1, pt_coords_2])

    # Check that structures contain the correct number of ts surfaces
    assert len(gnd_element.surface_list) == 3
    assert len(gnd_element.surface_dict[0]['left']) == 1
    assert len(gnd_element.surface_dict[1]['left']) == 2
    assert len(gnd_element.surface_dict[0]['right']) == 2
    assert len(gnd_element.surface_dict[1]['right']) == 1
    # Check that the objects are the same
    assert (
        gnd_element.surface_list[0] == gnd_element.surface_dict[0]['left'][0])
    assert (
        gnd_element.surface_list[0] == gnd_element.surface_dict[1]['left'][0])
    assert (
        gnd_element.surface_list[1] == gnd_element.surface_dict[0]['right'][0])
    assert (
        gnd_element.surface_list[1] == gnd_element.surface_dict[1]['left'][1])
    assert (
        gnd_element.surface_list[2] == gnd_element.surface_dict[0]['right'][1])
    assert (
        gnd_element.surface_list[2] == gnd_element.surface_dict[1]['right'][0])
    # Now check surfaces lengths
    np.testing.assert_allclose(gnd_element.surface_list[0].length, [0.5, 0])
    np.testing.assert_allclose(gnd_element.surface_list[1].length, [1, 1])
    np.testing.assert_allclose(gnd_element.surface_list[2].length, [0.5, 1])
    # Check coords of surfaces
    np.testing.assert_allclose(gnd_element.surface_list[0].b1.x, [-1, -1])
    np.testing.assert_allclose(gnd_element.surface_list[0].b2.x, [-0.5, -1])
Esempio n. 2
0
def test_ts_ground_to_geometry():

    # There should be an overlap
    shadow_coords = np.array([[[[0, 0], [0, 0]], [[2, 1], [0, 0]]],
                              [[[1, 2], [0, 0]], [[5, 5], [0, 0]]]])
    overlap = [True, False]
    cut_point_coords = [TsPointCoords.from_array(np.array([[2, 2], [0, 0]]))]

    # Test with overlap
    ts_ground = TsGround.from_ordered_shadows_coords(
        shadow_coords, flag_overlap=overlap, cut_point_coords=cut_point_coords)

    # Run some checks for index 0
    pvground = ts_ground.at(0,
                            merge_if_flag_overlap=False,
                            with_cut_points=False)
    assert pvground.n_surfaces == 4
    assert pvground.list_segments[0].illum_collection.n_surfaces == 2
    assert pvground.list_segments[0].shaded_collection.n_surfaces == 2
    assert pvground.list_segments[0].shaded_collection.length == 5
    np.testing.assert_allclose(pvground.shaded_length, 5)

    # Run some checks for index 1
    pvground = ts_ground.at(1, with_cut_points=False)
    assert pvground.n_surfaces == 5
    assert pvground.list_segments[0].illum_collection.n_surfaces == 3
    assert pvground.list_segments[0].shaded_collection.n_surfaces == 2
    assert pvground.list_segments[0].shaded_collection.length == 4
    np.testing.assert_allclose(pvground.shaded_length, 4)

    # Run some checks for index 0, when merging
    pvground = ts_ground.at(0,
                            merge_if_flag_overlap=True,
                            with_cut_points=False)
    assert pvground.n_surfaces == 3
    assert pvground.list_segments[0].illum_collection.n_surfaces == 2
    assert pvground.list_segments[0].shaded_collection.n_surfaces == 1
    assert pvground.list_segments[0].shaded_collection.length == 5
    np.testing.assert_allclose(pvground.shaded_length, 5)

    # Run some checks for index 0, when merging and with cut points
    pvground = ts_ground.at(0,
                            merge_if_flag_overlap=True,
                            with_cut_points=True)
    assert pvground.n_surfaces == 4
    assert pvground.list_segments[0].illum_collection.n_surfaces == 2
    assert pvground.list_segments[0].shaded_collection.n_surfaces == 2
    assert pvground.list_segments[0].shaded_collection.length == 5
    np.testing.assert_allclose(pvground.shaded_length, 5)