Example #1
0
def test_distance_and_speed_ones():
    result = cuspatial.distance_and_speed(
        cudf.Series([1]),
        cudf.Series([1]),
        cudf.Series([1]),
        cudf.Series([1]),
        cudf.Series([1]),
    )
    assert_eq(result["meters"], cudf.Series([-2.0]), check_names=False)
    assert_eq(result["speed"], cudf.Series([-2.0]), check_names=False)
Example #2
0
def test_two_trajectories_one_meter_one_second():
    result = cuspatial.distance_and_speed(
        cudf.Series([0.0, 0.001, 0.0, 0.0]),
        cudf.Series([0.0, 0.0, 0.0, 0.001]),
        cudf.Series([0, 1000, 0, 1000]),
        cudf.Series([2, 2]),
        cudf.Series([2, 4]),
    )
    assert_eq(result["meters"], cudf.Series([1.0, 1.0]), check_names=False)
    assert_eq(result["speed"], cudf.Series([1.0, 1.0]), check_names=False)
Example #3
0
def test_distance_and_speed_timestamp_types(timestamp_type):
    result = cuspatial.distance_and_speed(
        cudf.Series([0.0, 0.001, 0.0, 0.0]),  # 1 meter in x
        cudf.Series([0.0, 0.0, 0.0, 0.001]),  # 1 meter in y
        cudf.Series([0, timestamp_type[1], 0,
                     timestamp_type[1]]).astype(timestamp_type[0]),
        cudf.Series([2, 2]),
        cudf.Series([2, 4]),
    )
    assert_eq(
        result,
        cudf.DataFrame({
            "meters": [1.0, 1.0],
            "speed": [1.0, 1.0]
        }),
        check_names=False,
    )
Example #4
0
def test_distance_and_speed_single_trajectory():
    result = cuspatial.distance_and_speed(
        cudf.Series(
            [1.0, 2.0, 3.0, 5.0, 7.0, 1.0, 2.0, 3.0, 6.0, 0.0, 3.0, 6.0]),
        cudf.Series(
            [0.0, 1.0, 2.0, 3.0, 1.0, 3.0, 5.0, 6.0, 5.0, 4.0, 7.0, 4.0]),
        cudf.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
        cudf.Series([5, 4, 3]),
        cudf.Series([5, 9, 12]),
    )
    assert_eq(
        result["meters"],
        cudf.Series([7892.922363, 6812.55908203125, 8485.28125]),
        check_names=False,
    )
    assert_eq(
        result["speed"],
        cudf.Series([1973230.625, 2270853.0, 4242640.5]),
        check_names=False,
    )  # fast!
this_cam = df.loc[df["cameraIdString"] == "HWY_20_AND_LOCUST"]
cam_lon = np.double(this_cam.iloc[0]["originLon"])
cam_lat = np.double(this_cam.iloc[0]["originLat"])

lonlats = cuspatial.read_points_lonlat(data_dir + "locust.location")
ids = cuspatial.read_uint(data_dir + "locust.objectid")
ts = cuspatial.read_its_timestamps(data_dir + "locust.time")

# examine binary representatons
ts_0 = ts.data.to_array()[0]
out1 = format(ts_0, "016x")
print(out1)
out2 = format(ts_0, "064b")
print(out2)

y, m, d, hh, mm, ss, wd, yd, ms, pid = tools.get_ts_struct(ts_0)

xys = cuspatial.lonlat_to_xy_km_coordinates(cam_lon, cam_lat, lonlats["lon"],
                                            lonlats["lat"])
num_traj, trajectories = cuspatial.derive(xys["x"], xys["y"], ids, ts)
#  = num_traj, tid, len, pos =
y, m, d, hh, mm, ss, wd, yd, ms, pid = tools.get_ts_struct(ts_0)
distspeed = cuspatial.distance_and_speed(xys["x"], xys["y"], ts,
                                         trajectories["length"],
                                         trajectories["position"])
print(distspeed)

boxes = cuspatial.spatial_bounds(xys["x"], xys["y"], trajectories["length"],
                                 trajectories["position"])
print(boxes.head())