Beispiel #1
0
def trajectory_point_generator(start_airport,
                               end_airport,
                               start_time,
                               object_id='ANON',
                               desired_speed=800,
                               seconds_between_points=60,
                               minimum_num_points=10):
    """trajectory_point_generator(start_airport: Airport,
                                  end_airport: Airport,
                                  start_time=Timestamp (datetime.datetime),
                                  object_id='ANON' (string),
                                  desired_speed=60 (float, km/h),
                                  seconds_between_points=60 (int),
                                  minimum_num_points=10 (int)) -> iterable of points

    Generate a sequence of points that go from the starting airport to
    the ending airport with the desired speed and time between points.
    """

    start_position = TerrestrialTrajectoryPoint()
    start_position[0] = start_airport.position[0]
    start_position[1] = start_airport.position[1]

    end_position = TerrestrialTrajectoryPoint()
    end_position[0] = end_airport.position[0]
    end_position[1] = end_airport.position[1]

    travel_time = time_between_positions(start_position,
                                         end_position,
                                         desired_speed=desired_speed)

    num_points = num_points_between_positions(
        start_position,
        end_position,
        desired_speed=desired_speed,
        seconds_between_points=seconds_between_points)

    if num_points < minimum_num_points:
        num_points = minimum_num_points

    start_position.object_id = object_id
    start_position.timestamp = start_time
    end_position.object_id = object_id
    end_position.timestamp = start_time + travel_time

    point_list = [start_position]
    if num_points == 2:
        point_list.append(end_position)
    else:
        interpolant_increment = 1.0 / (num_points - 1)
        for i in range(1, num_points - 1):
            interpolant = i * interpolant_increment
            point_list.append(
                geomath.interpolate(start_position, end_position, interpolant))
        point_list.append(end_position)

    return point_list
Beispiel #2
0
def test_terrestrial_distance():

    error_count = 0

    albuquerque = TerrestrialTrajectoryPoint(-106.6504, 35.0844)
    dallas = TerrestrialTrajectoryPoint(-96.8716, 32.8205)
    el_paso = TerrestrialTrajectoryPoint(-106.4850, 31.7619)
    san_antonio = TerrestrialTrajectoryPoint(-98.6544, 29.4813)
    houston = TerrestrialTrajectoryPoint(-74.0060, 29.8168)

    ep_to_dal = TerrestrialTrajectory.from_position_list([el_paso, dallas])
    sa_to_hou = TerrestrialTrajectory.from_position_list(
        [san_antonio, houston])
    sa_to_abq = TerrestrialTrajectory.from_position_list(
        [san_antonio, albuquerque])

    print("Testing Terrestrial Distance")

    expected = 369.764
    actual = geomath.distance(albuquerque, el_paso)
    error_count += verify_result(
        actual, expected,
        "TerrestrialTrajectoryPoint to TerrestrialTrajectoryPoint")

    expected = 349.276
    actual = geomath.distance(ep_to_dal, sa_to_hou)
    error_count += verify_result(
        actual, expected, "TerrestrialTrajectory to TerrestrialTrajectory")

    expected = 0.0
    actual = geomath.distance(ep_to_dal, sa_to_abq)
    error_count += verify_result(
        actual, expected,
        "TerrestrialTrajectory to TerrestrialTrajectory Intersecting")

    expected = 975.674
    actual = geomath.distance(albuquerque, sa_to_hou)
    error_count += verify_result(
        actual, expected,
        "TerrestrialTrajectoryPoint to TerrestrialTrajectory")

    actual = geomath.distance(sa_to_hou, albuquerque)
    error_count += verify_result(
        actual, expected,
        "TerrestrialTrajectory to TerrestrialTrajectoryPoint")

    return error_count
def make_sample_trajectory():
    coordinates = [(0, 80), (90, 80), (180, 80), (-90, 80), (0, 80)]

    time_strings = [
        "2000-01-01 00:00:00", "2000-01-01 02:00:00", "2000-01-01 03:00:00",
        "2000-01-01 04:00:00", "2000-01-01 06:00:00"
    ]

    trajectory = TerrestrialTrajectory()
    for (coords, time_string) in zip(coordinates, time_strings):
        point = TerrestrialTrajectoryPoint(coords)
        point.object_id = 'terrestrial_dg_test'
        point.timestamp = datetime.datetime.strptime(time_string,
                                                     '%Y-%m-%d %H:%M:%S')
        trajectory.append(point)

    return trajectory
def test_compute_bounding_box_after_pickle():
    error_count = 0

    albuquerque = TerrestrialTrajectoryPoint(-106.6504, 35.0844)
    albuquerque.timestamp = datetime.datetime(year=2020,
                                              month=1,
                                              day=1,
                                              hour=12)
    san_francisco = TerrestrialTrajectoryPoint(-122.4194, 37.7749)
    san_francisco.timestamp = albuquerque.timestamp + datetime.timedelta(
        hours=3)
    tokyo = TerrestrialTrajectoryPoint(-221.6917, 35.6895)
    tokyo.timestamp = albuquerque.timestamp + datetime.timedelta(hours=12)

    trajectory_generator = TrajectoryPointSource()
    trajectory_generator.start_point = albuquerque
    trajectory_generator.end_point = tokyo
    trajectory_generator.num_points = 20

    print("DEBUG: TerrestrialTrajectory: {}".format(TerrestrialTrajectory))
    albuquerque_to_tokyo = TerrestrialTrajectory.from_position_list(
        list(trajectory_generator.points()))

    expected_min_corner = tracktable.domain.domain_class_for_object(
        albuquerque, 'BasePoint')()
    expected_max_corner = tracktable.domain.domain_class_for_object(
        albuquerque, 'BasePoint')()

    expected_min_corner[0] = min(albuquerque[0], tokyo[0])
    expected_min_corner[1] = min(albuquerque[1], tokyo[1])
    expected_max_corner[0] = max(albuquerque[0], tokyo[0])
    expected_max_corner[1] = max(albuquerque[1], tokyo[1])

    bbox_before_pickling = geomath.compute_bounding_box(albuquerque_to_tokyo)

    store = io.BytesIO()
    pickle.dump(albuquerque_to_tokyo, store)
    store.seek(0)
    restored_trajectory = pickle.load(store)
    bbox_after_pickling = geomath.compute_bounding_box(restored_trajectory)

    print("Bounding box before pickling: ({} {}) - ({} {})".format(
        bbox_before_pickling.min_corner[0], bbox_before_pickling.min_corner[1],
        bbox_before_pickling.max_corner[0],
        bbox_before_pickling.max_corner[1]))
    print("Bounding box after pickling: ({} {}) - ({} {})".format(
        bbox_after_pickling.min_corner[0], bbox_after_pickling.min_corner[1],
        bbox_after_pickling.max_corner[0], bbox_after_pickling.max_corner[1]))

    bbox_min_delta = (bbox_after_pickling.min_corner[0] -
                      bbox_before_pickling.min_corner[0],
                      bbox_after_pickling.min_corner[1] -
                      bbox_before_pickling.min_corner[1])
    bbox_max_delta = (bbox_after_pickling.max_corner[0] -
                      bbox_before_pickling.max_corner[0],
                      bbox_after_pickling.max_corner[1] -
                      bbox_before_pickling.max_corner[1])

    if (math.fabs(bbox_min_delta[0]) > 0.01
            or math.fabs(bbox_min_delta[1]) > 0.01
            or math.fabs(bbox_max_delta[0]) > 0.01
            or math.fabs(bbox_max_delta[1]) > 0.01):
        print(
            ("ERROR: Expected delta between bounding box before and after "
             "pickling to be zero.  Delta for minimum corner is {}.  "
             "Delta for maximum corner is {}.").format(bbox_min_delta,
                                                       bbox_max_delta))
        error_count += 1

    return error_count
Beispiel #5
0
def test_compute_bounding_box():

    error_count = 0

    bbox_type = TerrestrialTrajectoryPoint.domain_classes['BoundingBox']
    expected_min_corner = TerrestrialTrajectoryPoint.domain_classes[
        'BasePoint']()
    expected_max_corner = TerrestrialTrajectoryPoint.domain_classes[
        'BasePoint']()

    albuquerque = TerrestrialTrajectoryPoint(-106.6504, 35.0844)
    san_francisco = TerrestrialTrajectoryPoint(-122.4194, 37.7749)
    tokyo = TerrestrialTrajectoryPoint(-221.6917, 35.6895)

    small_traj = TrajectoryPointSource()
    small_traj.start_point = albuquerque
    small_traj.end_point = san_francisco
    small_traj.num_points = 2

    long_traj = TrajectoryPointSource()
    long_traj.start_point = tokyo
    long_traj.end_point = san_francisco
    long_traj.num_points = 2

    #Test smallish basic bounding box
    expected_min_corner[0] = san_francisco[0]
    expected_min_corner[1] = albuquerque[1]
    expected_max_corner[0] = albuquerque[0]
    expected_max_corner[1] = san_francisco[1]
    expected = bbox_type(expected_min_corner, expected_max_corner)

    map_bbox = geomath.compute_bounding_box(small_traj.points())
    error_count += verify_result(expected, map_bbox, "Basic small box")

    #Test larger basic bounding box
    expected_min_corner[0] = tokyo[0]
    expected_min_corner[1] = tokyo[1]
    expected_max_corner[0] = san_francisco[0]
    expected_max_corner[1] = san_francisco[1]
    expected = bbox_type(expected_min_corner, expected_max_corner)

    map_bbox = geomath.compute_bounding_box(long_traj.points())
    error_count += verify_result(expected, map_bbox, "Basic large box")

    #Test smallish bounding box with buffer
    lon_buffer = .2
    lat_buffer = .5
    expected_min_corner[0] = san_francisco[0] - (
        (albuquerque[0] - san_francisco[0]) * lon_buffer)
    expected_min_corner[1] = albuquerque[1] - (
        (san_francisco[1] - albuquerque[1]) * lat_buffer)
    expected_max_corner[0] = albuquerque[0] + (
        (albuquerque[0] - san_francisco[0]) * lon_buffer)
    expected_max_corner[1] = san_francisco[1] + (
        (san_francisco[1] - albuquerque[1]) * lat_buffer)
    expected = bbox_type(expected_min_corner, expected_max_corner)

    map_bbox = geomath.compute_bounding_box(small_traj.points(),
                                            (lon_buffer, lat_buffer))
    error_count += verify_result(expected, map_bbox, "Buffered small box")

    #Test larger basic bounding box with buffer
    lon_buffer = .2
    lat_buffer = .1
    expected_min_corner[0] = tokyo[0] - (
        (san_francisco[0] - tokyo[0]) * lon_buffer)
    expected_min_corner[1] = tokyo[1] - (
        (san_francisco[1] - tokyo[1]) * lat_buffer)
    expected_max_corner[0] = san_francisco[0] + (
        (san_francisco[0] - tokyo[0]) * lon_buffer)
    expected_max_corner[1] = san_francisco[1] + (
        (san_francisco[1] - tokyo[1]) * lat_buffer)
    expected = bbox_type(expected_min_corner, expected_max_corner)

    map_bbox = geomath.compute_bounding_box(long_traj.points(),
                                            (lon_buffer, lat_buffer))
    error_count += verify_result(expected, map_bbox, "Buffered large box")

    #Test cartesian based boxes
    c_bbox_type = Cartesian2dTrajectoryPoint.domain_classes['BoundingBox']
    c_expected_min_corner = Cartesian2dTrajectoryPoint.domain_classes[
        'BasePoint']()
    c_expected_max_corner = Cartesian2dTrajectoryPoint.domain_classes[
        'BasePoint']()

    point0 = Cartesian2dTrajectoryPoint(0, 0)
    point1 = Cartesian2dTrajectoryPoint(1, 1)
    point2 = Cartesian2dTrajectoryPoint(2, 2)

    c_expected_min_corner = Cartesian2dTrajectoryPoint(0, 0)
    c_expected_max_corner = Cartesian2dTrajectoryPoint(2, 2)
    expected = c_bbox_type(c_expected_min_corner, c_expected_max_corner)

    map_bbox = geomath.compute_bounding_box([point0, point1, point2])
    error_count += verify_result(expected, map_bbox, "Basic cartesian box")

    #Test cartesian box with buffer
    x_buffer = .5
    y_buffer = 1.
    c_expected_min_corner[0] = point0[0] - ((point2[0] - point0[0]) * x_buffer)
    c_expected_min_corner[1] = point0[1] - ((point2[1] - point0[1]) * y_buffer)
    c_expected_max_corner[0] = point2[0] + ((point2[0] - point0[0]) * x_buffer)
    c_expected_max_corner[1] = point2[1] + ((point2[1] - point0[1]) * y_buffer)
    expected = c_bbox_type(c_expected_min_corner, c_expected_max_corner)

    map_bbox = geomath.compute_bounding_box([point0, point1, point2],
                                            (x_buffer, y_buffer))
    error_count += verify_result(expected, map_bbox, "Buffered cartesian box")

    # Test error conditions
    map_bbox = geomath.compute_bounding_box([])
    if (map_bbox != None):
        sys.stderr.write('ERROR: Empty point sequence did not return None')
        error_count += 1

    map_bbox = geomath.compute_bounding_box(long_traj.points(), (1.0, ))
    if (map_bbox != None):
        sys.stderr.write('ERROR: Buffer tuple length of 1 did not return None')
        error_count += 1

    map_bbox = geomath.compute_bounding_box(long_traj.points(),
                                            (1.0, 2.0, 3.0))
    if (map_bbox != None):
        sys.stderr.write('ERROR: Buffer tuple length of 3 did not return None')
        error_count += 1

    return error_count
Beispiel #6
0
def test_trajectory():
    print("Testing Trajectory class.")
    error_count = 0

    right_now = datetime.datetime.now(pytz.utc)

    boston = TerrestrialTrajectoryPoint(-71.0636, 42.3581)
    boston.timestamp = right_now
    boston.object_id = 'ContinentalExpress'
    boston.set_property('favorite_food', 'baked_beans')
    boston.set_property('name', 'Boston')

    miami = TerrestrialTrajectoryPoint(-80.2241, 25.7877)
    miami.timestamp = right_now + datetime.timedelta(hours=4)
    miami.object_id = 'ContinentalExpress'
    miami.set_property('favorite_food', 'cuban_sandwich')
    miami.set_property('name', 'Miami')

    san_francisco = TerrestrialTrajectoryPoint(-122.4167, 37.7833)
    san_francisco.timestamp = right_now + datetime.timedelta(hours=8)
    san_francisco.object_id = 'ContinentalExpress'
    san_francisco.set_property('favorite_food', 'Ghirardelli chocolate')
    san_francisco.set_property('name', 'San Francisco')

    seattle = TerrestrialTrajectoryPoint(-122.3331, 47.6097)
    seattle.timestamp = right_now + datetime.timedelta(hours=12)
    seattle.object_id = 'ContinentalExpress'
    seattle.set_property('favorite_food', 'seafood')
    seattle.set_property('name', 'Seattle')

    boston_return = TerrestrialTrajectoryPoint(-71.0636, 42.3581)
    boston_return.timestamp = right_now + datetime.timedelta(hours=16)
    boston_return.object_id = 'ContinentalExpress'
    boston_return.set_property('favorite_food', 'baked_beans')
    boston_return.set_property('name', 'Boston')

    round_trip = [boston, miami, san_francisco, seattle, boston_return]

    my_trajectory = TerrestrialTrajectory.from_position_list(round_trip)

    print("Testing from_position_list")
    if len(my_trajectory) != 5:
        sys.stderr.write(
            'ERROR: Expected length of trajectory to be 5 points but it was {}\n'
            .format(len(my_trajectory)))
        error_count += 1

    print("Sanity-checking first and last points")
    restored_point = my_trajectory[0]
    if restored_point != boston:
        sys.stderr.write(
            'ERROR: Expected first point in trajectory to be Boston.  Instead it claims to be {}.  Dumps of original and restored points follow.\n'
            .format(restored_point.property('name')))
        sys.stderr.write(str(boston))
        sys.stderr.write('\n')
        sys.stderr.write(str(my_trajectory[0]))
        sys.stderr.write('\n')

        error_count += 1

    if my_trajectory[-1] != boston_return:
        sys.stderr.write(
            'ERROR: Expected last point in trajectory to be Boston.  Instead it claims to be {}.\n'
            .format(my_trajectory[-1].property('name')))
        error_count += 1

    print("Testing duration")
    duration = my_trajectory.duration
    if (duration != datetime.timedelta(hours=16)):
        sys.stderr.write(
            'ERROR: Expected duration to be 16 hours.  Instead it claims to be {}.\n'
            .format(duration))
        error_count += 1

    print("Testing time_at_fraction, 0.25")
    first_quarter_time = geomath.time_at_fraction(my_trajectory, 0.25)
    delta = my_trajectory[-1].timestamp - right_now
    expected_first_quarter_time = right_now + (delta // 4)
    error_count += verify_time(expected_first_quarter_time, first_quarter_time,
                               "Time at fraction 0.25")

    print("Testing time_at_fraction, 0.75")
    last_quarter_time = geomath.time_at_fraction(my_trajectory, 0.75)
    delta = my_trajectory[-1].timestamp - right_now
    expected_last_quarter_time = right_now + ((3 * delta) // 4)
    error_count += verify_time(expected_last_quarter_time, last_quarter_time,
                               "Time at fraction 0.75")

    print("Testing time_at_fraction, 0.5")
    midpoint_time = geomath.time_at_fraction(my_trajectory, 0.5)
    expected_midpoint_time = (right_now +
                              (my_trajectory[-1].timestamp - right_now) // 2)
    error_count += verify_time(expected_midpoint_time, midpoint_time,
                               "Time at fraction 0.5")

    print("Testing time_at_fraction, 0.0")
    start_time = geomath.time_at_fraction(my_trajectory, 0.0)
    expected_start_time = right_now
    error_count += verify_time(expected_start_time, start_time,
                               "Time at fraction 0.0")

    print("Testing time_at_fraction, 1.0")
    end_time = geomath.time_at_fraction(my_trajectory, 1.0)
    expected_end_time = my_trajectory[-1].timestamp
    error_count += verify_time(expected_end_time, end_time,
                               "Time at fraction 1.0")

    print("Testing time_at_fraction, -0.5")
    before_time = geomath.time_at_fraction(my_trajectory, -0.5)
    expected_before_time = right_now
    error_count += verify_time(expected_before_time, before_time,
                               "Time at fraction -0.5")

    print("Testing time_at_fraction, 1.5")
    after_time = geomath.time_at_fraction(my_trajectory, 1.5)
    expected_after_time = my_trajectory[-1].timestamp
    error_count += verify_time(expected_after_time, after_time,
                               "Time at fraction 1.5")

    print("Testing time_at_fraction, 0.33")
    first_third_time = geomath.time_at_fraction(my_trajectory, 1.0 / 3.0)
    expected_third_quarter_time = (
        right_now + (my_trajectory[-1].timestamp - right_now) // 3)
    error_count += verify_time(expected_third_quarter_time, first_third_time,
                               "Time at fraction 0.33")

    print("Testing time_at_fraction, No Points")
    empty_trajectory = TerrestrialTrajectory()
    empty_time = geomath.time_at_fraction(empty_trajectory, 0.5)
    error_count += verify_time(
        datetime.datetime(1900, 1, 1, 0, 0, 0, 0, pytz.utc), empty_time,
        "Time at fraction (no points)")

    print("Testing point_at_fraction, 0.25")
    first_quarter_point = geomath.point_at_fraction(my_trajectory, 0.25)
    expected_first_quarter_point = TerrestrialTrajectoryPoint(
        -80.2241, 25.7877)
    expected_first_quarter_point.timestamp = right_now + datetime.timedelta(
        hours=4)
    error_count += verify_point(expected_first_quarter_point,
                                first_quarter_point, "Point at fraction 0.25")

    print("Testing point_at_fraction, 0.75")
    third_quarter_point = geomath.point_at_fraction(my_trajectory, 0.75)
    expected_third_quarter_point = TerrestrialTrajectoryPoint(
        -122.3331, 47.6097)
    expected_third_quarter_point.timestamp = right_now + datetime.timedelta(
        hours=12)
    error_count += verify_point(expected_third_quarter_point,
                                third_quarter_point, "Point at fraction 0.75")

    print("Testing point_at_fraction, 0.5")
    mid_point = geomath.point_at_fraction(my_trajectory, 0.5)
    expected_mid_point = TerrestrialTrajectoryPoint(-122.4167, 37.7833)
    expected_mid_point.timestamp = right_now + datetime.timedelta(hours=8)
    error_count += verify_point(expected_mid_point, mid_point,
                                "Point at fraction 0.5")

    print("Testing point_at_fraction, 0.0")
    start_point = geomath.point_at_fraction(my_trajectory, 0.0)
    expected_start_point = TerrestrialTrajectoryPoint(-71.0636, 42.3581)
    expected_start_point.timestamp = right_now
    error_count += verify_point(expected_start_point, start_point,
                                "Point at fraction 0.0")

    print("Testing point_at_fraction, 1.0")
    end_point = geomath.point_at_fraction(my_trajectory, 1.0)
    expected_end_point = TerrestrialTrajectoryPoint(-71.0636, 42.3581)
    expected_end_point.timestamp = right_now + datetime.timedelta(hours=16)
    error_count += verify_point(expected_end_point, end_point,
                                "Point at fraction 1.0")

    print("Testing point_at_fraction, -0.5")
    before_point = geomath.point_at_fraction(my_trajectory, -0.5)
    expected_before_point = TerrestrialTrajectoryPoint(-71.0636, 42.3581)
    expected_before_point.timestamp = right_now
    error_count += verify_point(expected_before_point, before_point,
                                "Point at fraction -0.5")

    print("Testing point_at_fraction, 1.5")
    after_point = geomath.point_at_fraction(my_trajectory, 1.5)
    expected_after_point = TerrestrialTrajectoryPoint(-71.0636, 42.3581)
    expected_after_point.timestamp = right_now + datetime.timedelta(hours=16)
    error_count += verify_point(expected_after_point, after_point,
                                "Point at fraction 1.5")

    print("Testing point_at_fraction, 0.33")
    first_third_point = geomath.point_at_fraction(my_trajectory, 1.0 / 3.0)
    expected_first_third_point = TerrestrialTrajectoryPoint(-92.9849, 31.3181)
    expected_first_third_point.timestamp = (
        right_now + (my_trajectory[-1].timestamp - right_now) // 3)
    error_count += verify_point(expected_first_third_point, first_third_point,
                                "Point at fraction 0.33")

    print("Testing point_at_fraction, No Points")
    no_point = geomath.point_at_fraction(empty_trajectory, 0.5)
    empty_point = TerrestrialTrajectoryPoint.zero()
    error_count += verify_point(no_point, empty_point,
                                "Point at fraction (no points)")

    print("Testing point_at_length_fraction, 0.25")
    first_quarter_point = geomath.point_at_length_fraction(my_trajectory, 0.25)
    expected_first_quarter_point = TerrestrialTrajectoryPoint(
        -87.3824, 29.1092)
    expected_first_quarter_point.timestamp = first_quarter_point.timestamp
    error_count += verify_point(expected_first_quarter_point,
                                first_quarter_point,
                                "Point at length fraction 0.25")

    print("Testing point_at_length_fraction, 0.75")
    third_quarter_point = geomath.point_at_length_fraction(my_trajectory, 0.75)
    expected_third_quarter_point = TerrestrialTrajectoryPoint(
        -106.489, 48.5709)
    expected_third_quarter_point.timestamp = third_quarter_point.timestamp
    error_count += verify_point(expected_third_quarter_point,
                                third_quarter_point,
                                "Point at length fraction 0.75")

    print("Testing point_at_length_fraction, 0.5")
    mid_point = geomath.point_at_length_fraction(my_trajectory, 0.5)
    expected_mid_point = TerrestrialTrajectoryPoint(-116.267, 37.0967)
    expected_mid_point.timestamp = mid_point.timestamp
    error_count += verify_point(expected_mid_point, mid_point,
                                "Point at length fraction 0.5")

    print("Testing point_at_length_fraction, 0.0")
    start_point = geomath.point_at_length_fraction(my_trajectory, 0.0)
    expected_start_point = TerrestrialTrajectoryPoint(-71.0636, 42.3581)
    expected_start_point.timestamp = right_now
    error_count += verify_point(expected_start_point, start_point,
                                "Point at length fraction 0.0")

    print("Testing point_at_length_fraction, 1.0")
    end_point = geomath.point_at_length_fraction(my_trajectory, 1.0)
    expected_end_point = TerrestrialTrajectoryPoint(-71.0636, 42.3581)
    expected_end_point.timestamp = right_now + datetime.timedelta(hours=16)
    error_count += verify_point(expected_end_point, end_point,
                                "Point at length fraction 1.0")

    print("Testing point_at_length_fraction, -0.5")
    before_point = geomath.point_at_length_fraction(my_trajectory, -0.5)
    expected_before_point = TerrestrialTrajectoryPoint(-71.0636, 42.3581)
    expected_before_point.timestamp = right_now
    error_count += verify_point(expected_before_point, before_point,
                                "Point at length fraction -0.5")

    print("Testing point_at_length_fraction, 1.5")
    after_point = geomath.point_at_length_fraction(my_trajectory, 1.5)
    expected_after_point = TerrestrialTrajectoryPoint(-71.0636, 42.3581)
    expected_after_point.timestamp = right_now + datetime.timedelta(hours=16)
    error_count += verify_point(expected_after_point, after_point,
                                "Point at length fraction 1.5")

    print("Testing point_at_length_fraction, 0.33")
    first_third_point = geomath.point_at_length_fraction(
        my_trajectory, 1.0 / 3.0)
    expected_first_third_point = TerrestrialTrajectoryPoint(-96.4035, 32.5023)
    expected_first_third_point.timestamp = first_third_point.timestamp
    error_count += verify_point(expected_first_third_point, first_third_point,
                                "Point at length fraction 0.33")

    print("Testing point_at_length_fraction, No Points")
    no_point = geomath.point_at_length_fraction(empty_trajectory, 0.5)
    empty_point = TerrestrialTrajectoryPoint.zero()
    error_count += verify_point(no_point, empty_point,
                                "Point at length fraction (no points)")

    print("Testing interpolation at timestamp before trajectory")
    before_time = right_now - datetime.timedelta(hours=4)
    before_point = geomath.point_at_time(my_trajectory, before_time)
    error_count += verify_point(boston, before_point,
                                "Point at time (-4 hours)")

    print("Testing interpolation at start timestamp of trajectory")
    start_time = right_now
    start_point = geomath.point_at_time(my_trajectory, start_time)
    error_count += verify_point(boston, start_point, "Point at time (0 hours)")

    print("Testing interpolation at first third timestamp of trajectory")
    first_third_time = right_now + datetime.timedelta(hours=16.0 / 3.0)
    first_third_point = geomath.point_at_time(my_trajectory, first_third_time)
    expected_first_third_point = TerrestrialTrajectoryPoint(-92.9849, 31.3181)
    expected_first_third_point.timestamp = right_now + datetime.timedelta(
        hours=16.0 / 3.0)
    error_count += verify_point(expected_first_third_point, first_third_point,
                                "Point at time (+5.33 hours)")

    print("Testing interpolation at mid timestamp of trajectory")
    mid_time = right_now + datetime.timedelta(hours=8)
    mid_point = geomath.point_at_time(my_trajectory, mid_time)
    error_count += verify_point(san_francisco, mid_point,
                                "Point at time (+8 hours)")

    print("Testing interpolation at end timestamp of trajectory")
    end_time = right_now + datetime.timedelta(hours=16)
    end_point = geomath.point_at_time(my_trajectory, end_time)
    error_count += verify_point(boston_return, end_point,
                                "Point at time (+16 hours)")

    print("Testing interpolation at timestamp after trajectory")
    after_time = right_now + datetime.timedelta(hours=20)
    after_point = geomath.point_at_time(my_trajectory, after_time)
    error_count += verify_point(boston_return, after_point,
                                "Point at time (+20 hours)")

    print("Testing interpolation at timestamp with no points trajectory")
    no_point = geomath.point_at_time(empty_trajectory,
                                     right_now + datetime.timedelta(hours=8))
    empty_point = TerrestrialTrajectoryPoint()
    error_count += verify_point(empty_point, no_point,
                                "Point at time (no points)")

    #    print("Testing pickle support")
    #    picklebuf = StringIO()
    #    pickle.dump(my_trajectory, picklebuf)
    #    restorebuf = StringIO(picklebuf.getvalue())
    #    restored_trajectory = pickle.load(restorebuf)

    #    if my_trajectory != restored_trajectory:
    #        sys.stderr.write('ERROR: Original trajectory is not the same as the one being restored from pickle jar.\n')
    #        sys.stderr.write('Original trajectory: {}'.format(my_trajectory))
    #        sys.stderr.write('Restored trajectory: {}'.format(restored_trajectory))
    #        error_count += 1

    if error_count == 0:
        print("Surface trajectory passed all tests.")

    return error_count
def create_point(lat, lon, id):

    point = TerrestrialTrajectoryPoint(lon, lat)
    point.object_id = id

    return point
Beispiel #8
0
def test_point_type():
    print("Testing point type")

    error_count = 0

    point1 = TerrestrialBasePoint(45, 45)
    point2 = TerrestrialBasePoint(135, 45)

    print("Testing terrestrial base point interpolate, 0.5")
    result = geomath.interpolate(point1, point2, 0.5)
    expected = TerrestrialBasePoint(90, 54.7356)
    error_count += verify_base_point(expected, result,
                                     "Terrestrial Base Point Interpolate 0.5")

    print("Testing terrestrial base point interpolate, 0.3")
    result = geomath.interpolate(point1, point2, 0.3)
    expected = TerrestrialBasePoint(69.7884, 53.0018)
    error_count += verify_base_point(expected, result,
                                     "Terrestrial Base Point Interpolate 0.3")

    print("Testing terrestrial base point interpolate, 1")
    result = geomath.interpolate(point1, point2, 1)
    error_count += verify_base_point(point2, result,
                                     "Terrestrial Base Point Interpolate 1")

    print("Testing terrestrial base point extrapolate, 2")
    result = geomath.extrapolate(point1, point2, 2)
    expected = TerrestrialBasePoint(180, 0)
    error_count += verify_base_point(expected, result,
                                     "Terrestrial Base Point Extrapolate 2")

    point3 = Cartesian2DBasePoint(0, 0)
    point4 = Cartesian2DBasePoint(10, 10)

    print("Testing cartesian2d base point interpolate, 0.5")
    result = geomath.interpolate(point3, point4, 0.5)
    expected = Cartesian2DBasePoint(5, 5)
    error_count += verify_base_point(expected, result,
                                     "Cartesian2D Base Point Interpolate 0.5")

    print("Testing cartesian2d base point interpolate, 0.3")
    result = geomath.interpolate(point3, point4, 0.3)
    expected = Cartesian2DBasePoint(3, 3)
    error_count += verify_base_point(expected, result,
                                     "Cartesian2D Base Point Interpolate 0.3")

    print("Testing cartesian2d base point interpolate, 1")
    result = geomath.interpolate(point3, point4, 1)
    error_count += verify_base_point(point4, result,
                                     "Cartesian2D Base Point Interpolate 1")

    print("Testing cartesian2d base point extrapolate, 1.5")
    result = geomath.extrapolate(point3, point4, 1.5)
    expected = Cartesian2DBasePoint(15, 15)
    error_count += verify_base_point(expected, result,
                                     "Cartesian2D Base Point Extrapolate 1.5")

    point5 = Cartesian3DBasePoint(0, 0, 0)
    point6 = Cartesian3DBasePoint(10, 10, 10)

    print("Testing cartesian3d base point interpolate, 0.5")
    result = geomath.interpolate(point5, point6, 0.5)
    expected = Cartesian3DBasePoint(5, 5, 5)
    error_count += verify_base_point(expected, result,
                                     "Cartesian3D Base Point Interpolate 0.5")

    print("Testing cartesian3d base point interpolate, 0.3")
    result = geomath.interpolate(point5, point6, 0.3)
    expected = Cartesian3DBasePoint(3, 3, 3)
    error_count += verify_base_point(expected, result,
                                     "Cartesian3D Base Point Interpolate 0.3")

    print("Testing cartesian3d base point interpolate, 1")
    result = geomath.interpolate(point5, point6, 1)
    error_count += verify_base_point(point6, result,
                                     "Cartesian3D Base Point Interpolate 1")

    print("Testing cartesian3d base point extrapolate, 1.5")
    result = geomath.extrapolate(point5, point6, 1.5)
    expected = Cartesian3DBasePoint(15, 15, 15)
    error_count += verify_base_point(expected, result,
                                     "Cartesian3D Base Point Extrapolate 1.5")

    point7 = TerrestrialTrajectoryPoint(10, 30)
    point7.timestamp = datetime.strptime("2020-12-01 00:00:00",
                                         "%Y-%m-%d %H:%M:%S")
    point7.object_id = 'FOO'
    point7.set_property('speed', 100.0)
    point7.set_property('heading', 0.0)

    point8 = TerrestrialTrajectoryPoint(14.6929, 35.1023)
    point8.timestamp = datetime.strptime("2020-12-01 00:30:00",
                                         "%Y-%m-%d %H:%M:%S")
    point8.object_id = 'FOO'
    point8.set_property('speed', 150.0)
    point8.set_property('heading', 90.0)

    point9 = TerrestrialTrajectoryPoint(20, 40)
    point9.timestamp = datetime.strptime("2020-12-01 01:00:00",
                                         "%Y-%m-%d %H:%M:%S")
    point9.object_id = 'FOO'
    point9.set_property('speed', 200.0)
    point9.set_property('heading', 180.0)

    print("Testing terrestrial trajectory point interpolate, 0.5")
    result = geomath.interpolate(point7, point9, 0.5)
    error_count += verify_trajectory_point(
        point8, result, "Terrestrial Trajectory Point Interpolate 0.5")

    print("Testing terrestrial trajectory point extrapolate, 2")
    result = geomath.extrapolate(point7, point8, 2)
    error_count += verify_trajectory_point(
        point9, result, "Terrestrial Trajectory Point Extrapolate 2")

    point10 = Cartesian2DTrajectoryPoint(5, 5)
    point10.timestamp = datetime.strptime("2020-12-01 00:00:00",
                                          "%Y-%m-%d %H:%M:%S")
    point10.object_id = 'FOO'
    point10.set_property('speed', 10.0)
    point10.set_property('heading', 0.0)

    point11 = Cartesian2DTrajectoryPoint(10, 10)
    point11.timestamp = datetime.strptime("2020-12-01 00:30:00",
                                          "%Y-%m-%d %H:%M:%S")
    point11.object_id = 'FOO'
    point11.set_property('speed', 15.0)
    point11.set_property('heading', 90.0)

    point12 = Cartesian2DTrajectoryPoint(15, 15)
    point12.timestamp = datetime.strptime("2020-12-01 01:00:00",
                                          "%Y-%m-%d %H:%M:%S")
    point12.object_id = 'FOO'
    point12.set_property('speed', 20.0)
    point12.set_property('heading', 180.0)

    print("Testing cartesian2d trajectory point interpolate, 0.5")
    result = geomath.interpolate(point10, point12, 0.5)
    error_count += verify_trajectory_point(
        point11, result, "Cartesian2D Trajectory Point Interpolate 0.5")

    print("Testing cartesian2d trajectory point extrapolate, 2")
    result = geomath.extrapolate(point10, point11, 2)
    error_count += verify_trajectory_point(
        point12, result, "Cartesian2D Trajectory Point Extrapolate 2")

    point13 = Cartesian3DTrajectoryPoint(5, 5, 5)
    point13.timestamp = datetime.strptime("2020-12-01 00:00:00",
                                          "%Y-%m-%d %H:%M:%S")
    point13.object_id = 'FOO'
    point13.set_property('speed', 10.0)
    point13.set_property('heading', 0.0)

    point14 = Cartesian3DTrajectoryPoint(10, 10, 10)
    point14.timestamp = datetime.strptime("2020-12-01 00:30:00",
                                          "%Y-%m-%d %H:%M:%S")
    point14.object_id = 'FOO'
    point14.set_property('speed', 15.0)
    point14.set_property('heading', 90.0)

    point15 = Cartesian3DTrajectoryPoint(15, 15, 15)
    point15.timestamp = datetime.strptime("2020-12-01 01:00:00",
                                          "%Y-%m-%d %H:%M:%S")
    point15.object_id = 'FOO'
    point15.set_property('speed', 20.0)
    point15.set_property('heading', 180.0)

    print("Testing cartesian3d trajectory point interpolate, 0.5")
    result = geomath.interpolate(point13, point15, 0.5)
    error_count += verify_trajectory_point(
        point14, result, "Cartesian3D Trajectory Point Interpolate 0.5")

    print("Testing cartesian3d trajectory point extrapolate, 2")
    result = geomath.extrapolate(point13, point14, 2)
    error_count += verify_trajectory_point(
        point15, result, "Cartesian3D Trajectory Point Extrapolate 2")

    return error_count