def test_create_track_crs(simple_gps_df, simple_gps_raw_data):
    x, y, z, t, _, _, _ = simple_gps_raw_data

    # Compute projected coordinates
    proj = pyproj.Proj(2154)
    xy_proj = [proj(i, j) for i, j in zip(x, y)]
    x_proj = [i[0] for i in xy_proj]
    y_proj = [i[1] for i in xy_proj]

    df = simple_gps_df.copy()
    df["x"] = x_proj
    df["y"] = y_proj
    res = gda.GpsPoints(
        df,
        x_col="x",
        y_col="y",
        z_col="z",
        time_col="t",
        crs=2154,
        local_crs=4326,
    )

    # Check results
    check_gps_data(res, *simple_gps_raw_data)
    assert res.crs.to_epsg() == 4326
def test_create_track_sort(simple_gps_df, simple_gps_raw_data):
    x, y, z, t, _, _, _ = simple_gps_raw_data

    df = simple_gps_df.loc[[2, 0, 1]]
    res = gda.GpsPoints(
        df, x_col="x", y_col="y", z_col="z", time_col="t", time_sort=True)

    check_gps_data(res, *simple_gps_raw_data)
    assert np.equal(res.xy, np.vstack((x, y)).T).all()
    assert res.crs.to_epsg() == 4326

    res_no_sort = gda.GpsPoints(
        df, x_col="x", y_col="y", z_col="z", time_col="t", time_sort=False)

    x, y, z, t, _ = df.values.T.tolist()
    check_gps_data(res_no_sort, x, y, z, t)
    assert res_no_sort.crs.to_epsg() == 4326
def test_equal_track(simple_gps_data):
    new = gda.GpsPoints(simple_gps_data)

    assert new.equals(simple_gps_data)
    assert np.equal((new == simple_gps_data), np.array(
        [
            [True, True, False, False, False],
            [True, True, True, True, True],
            [True, True, True, True, True]
        ])).all(axis=None)
def test_create_track(simple_gps_raw_data):
    x, y, z, t, _, _, _ = simple_gps_raw_data
    df = pd.DataFrame({"x": x, "y": y, "z": z, "t": t})

    # Constructor with args
    new = gda.GpsPoints(df, x_col="x", y_col="y", z_col="z", time_col="t")

    check_gps_data(new, *simple_gps_raw_data)
    assert new.base_columns == ["geometry", "z", "datetime"]

    # Constructor with kwargs
    new_kw = gda.GpsPoints(data=df, x_col="x", y_col="y", z_col="z", time_col="t")

    check_gps_data(new_kw, *simple_gps_raw_data)
    assert new_kw.base_columns == ["geometry", "z", "datetime"]

    # Use projection argument
    new_proj = gda.GpsPoints(new, local_crs=4326)

    check_gps_data(new_proj, *simple_gps_raw_data)
    assert new_proj.base_columns == ["geometry", "z", "datetime"]
def test_rest_time_with_far_points():
    x = [i * 10.0 for i in range(11)] + [i * 10.0 for i in range(9, -1, -1)]
    y = [0] * 21
    z = [0] * 21
    t = ["2019/06/16-09:55:{:0}".format(i) for i in range(21)]
    df = pd.DataFrame({"x": x, "y": y, "z": z, "t": t})
    data = gda.GpsPoints(df, x_col="x", y_col="y", z_col="z", time_col="t")

    res = gda.time_analysis.compute_rest_time(data, 5)

    assert (res.loc[[0, 20]] == 0.5).all()
    assert (res[1:-1] == 1).all()
def test_simple_rest_time():
    x = [i for i in range(20)]
    y = [0] * 20
    z = [0] * 20
    t = ["2019/06/16-09:55:{:0}".format(i) for i in range(20)]
    df = pd.DataFrame({"x": x, "y": y, "z": z, "t": t})
    data = gda.GpsPoints(df, x_col="x", y_col="y", z_col="z", time_col="t")

    res = gda.time_analysis.compute_rest_time(data, 5)

    assert np.equal(res[:5], range(5, 10)).all()
    assert (res[5:-5] == 10).all()
    assert np.equal(res[-5:], range(9, 4, -1)).all()
def test_create_track_no_haversine(simple_gps_raw_data):
    x, y, z, t, dt, _, _ = simple_gps_raw_data
    df = pd.DataFrame({"x": x, "y": y, "z": z, "t": t})
    new = GpsPointsNoHaversine(df, x_col="x", y_col="y", z_col="z", time_col="t")

    dist = [float('nan'), 0.141421, 0.141421]
    vel = [float('nan'), 0.00614875462, 0.001047565602]

    check_gps_data(new, x, y, z, t, dt, dist, vel)
    assert new.base_columns == ["geometry", "z", "datetime"]

    new_proj = gda.GpsPoints(new, local_crs=4326)

    check_gps_data(new, x, y, z, t, dt, dist, vel)
    assert new_proj.base_columns == ["geometry", "z", "datetime"]
def test_rest_time_with_loops():
    x = [i for i in range(11)] + [i for i in range(9, -1, -1)]
    y = [0] * 21
    z = [0] * 21
    t = ["2019/06/16-09:55:{:0}".format(i) for i in range(21)]
    df = pd.DataFrame({"x": x, "y": y, "z": z, "t": t})
    data = gda.GpsPoints(df, x_col="x", y_col="y", z_col="z", time_col="t")

    res = gda.time_analysis.compute_rest_time(data, 5)

    assert np.equal(res[:5], range(5, 10)).all()
    assert res[5] == 20
    assert np.equal(res[6:11], range(18, 9, -2)).all()
    assert np.equal(res[10:15], range(10, 19, 2)).all()
    assert res[15] == 20
    assert np.equal(res[-5:], range(9, 4, -1)).all()
Пример #9
0
def test_save_load_gps_points_crs(simple_gps_raw_data, simple_gps_data,
                                  gpkg_filepath):
    # Add column to keep
    simple_gps_data["test_col"] = 1

    # Project data
    projected = gda.GpsPoints(simple_gps_data, local_crs=2154)

    # Save to temporary file
    gda.io.save(projected, gpkg_filepath)

    # Load to GpsPoints
    res = gda.load_gps_points(gpkg_filepath)

    # Check results
    x, y, z, t, dt, dist, vel = simple_gps_raw_data
    check_gps_data(res, projected.x, projected.y, projected.z, t, dt, dist,
                   vel)
    assert res.equals(projected[res.columns])
    assert (res.test_col == 1).all()
    assert projected.crs.to_epsg() == 2154
    assert res.crs.to_epsg() == 2154
def test_create_track_proj(simple_gps_df, simple_gps_raw_data):
    x, y, z, t, dt, _, _ = simple_gps_raw_data

    df = simple_gps_df.loc[[2, 0, 1]]
    res = gda.GpsPoints(
        df,
        x_col="x",
        y_col="y",
        z_col="z",
        time_col="t",
        local_crs=2154,
    )

    # Compute projected results
    proj = pyproj.Proj(2154)
    xy_proj = [proj(i, j) for i, j in zip(x, y)]
    x_proj = [i[0] for i in xy_proj]
    y_proj = [i[1] for i in xy_proj]

    # Check results
    dist_res = [np.nan, 20707.888, 20682.199]
    vel_res = [np.nan, 900.343, 153.201]
    check_gps_data(res, x_proj, y_proj, z, t, dt, dist_res, vel_res)
    assert res.crs.to_epsg() == 2154
Пример #11
0
def simple_gps_data(simple_gps_df):
    return gda.GpsPoints(simple_gps_df,
                         x_col="x",
                         y_col="y",
                         z_col="z",
                         time_col="t")