def test_input_speed(spd):
    """
    Check incorrect speed inputs raise error
    """
    with pytest.raises(AssertionError):
        create_aircraft(aircraft_id, type, latitude, longitude, heading, spd,
                        altitude, flight_level)
def test_input_alt_fl(alt, fl):
    """
    Check incorrect combination of altitude and flight level inputs raise error
    """
    with pytest.raises(AssertionError):
        create_aircraft(aircraft_id, type, latitude, longitude, heading, speed,
                        alt, fl)
def test_input_aircraft_info(acid, tp):
    """
    Check incorrect aircraft_id and type inputs raise error
    """
    with pytest.raises(AssertionError):
        create_aircraft(acid, tp, latitude, longitude, heading, speed,
                        altitude, flight_level)
Exemple #4
0
def test_aircraft_position():
    cmd = reset_simulation()
    assert cmd == True

    cmd = create_aircraft(
        aircraft_id=aircraft_id,
        type=type,
        latitude=latitude,
        longitude=longitude,
        heading=heading,
        flight_level=flight_level,
        speed=speed,
    )
    assert cmd == True

    cmd = create_aircraft(
        aircraft_id=aircraft_id_2,
        type=type_2,
        latitude=latitude_2,
        longitude=longitude_2,
        heading=heading_2,
        flight_level=flight_level_2,
        speed=speed_2,
    )
    assert cmd == True

    pos = aircraft_position(aircraft_id)
    assert isinstance(pos, pd.DataFrame)
    assert len(pos.index) == 1
    assert pos.loc[aircraft_id]["aircraft_type"] == type
    assert pos.loc[aircraft_id]["latitude"] == pytest.approx(0, abs=1e-5)
    assert pos.loc[aircraft_id]["longitude"] == pytest.approx(0, abs=1e-5)
    assert pos.loc[aircraft_id]["vertical_speed"] == 0
    # flight level is returned in feet
    assert pos.loc[aircraft_id]["current_flight_level"] == flight_level * 100
    assert pos.loc[aircraft_id]["ground_speed"] == 0

    # check that dataframe has sim_t attribute
    assert isinstance(pos.sim_t, float)

    pos = aircraft_position([aircraft_id, aircraft_id_2])
    assert len(pos.index) == 2
    assert pos.loc[aircraft_id_2]["aircraft_type"] == type_2
    assert pos.loc[aircraft_id_2]["latitude"] == pytest.approx(0, abs=1e-5)
    assert pos.loc[aircraft_id_2]["longitude"] == pytest.approx(0, abs=1e-5)
    assert pos.loc[aircraft_id_2]["vertical_speed"] == 0
    # flight level is returned in feet
    assert pos.loc[aircraft_id_2]["current_flight_level"] == flight_level_2 * 100
    assert pos.loc[aircraft_id_2]["ground_speed"] == 0
Exemple #5
0
def test_wrong_id():
    """
    Expect a row in a dataframe with NAN if requested aircraft not in simulation.
    """
    cmd = reset_simulation()
    assert cmd == True

    pos = aircraft_position(aircraft_id)
    # print(pos)
    assert pos.loc[aircraft_id].isnull().all()

    cmd = create_aircraft(
        aircraft_id=aircraft_id,
        type=type,
        latitude=latitude,
        longitude=longitude,
        heading=heading,
        flight_level=flight_level,
        speed=speed,
    )
    assert cmd == True

    pos = aircraft_position([aircraft_id, aircraft_id_2])
    assert len(pos.index) == 2
    assert pos.loc[aircraft_id_2].isnull().all()
def test_output_create_aircraft():

    # reset so that no aircraft exist
    reset_simulation()

    output = create_aircraft(aircraft_id, type, latitude, longitude, heading,
                             speed, altitude, flight_level)
    assert output == True

    with pytest.raises(HTTPError):
        create_aircraft(
            aircraft_id,
            type,
            latitude,
            longitude,
            heading,
            speed,
            altitude,
            flight_level,
        )
def test_loss_of_separation():
    """
    Tests loss_of_separation returns correct separation score.
    """
    cmd = reset_simulation()
    assert cmd == True

    cmd = create_aircraft(
        aircraft_id=aircraft_id,
        type=type,
        latitude=latitude,
        longitude=longitude,
        heading=heading,
        flight_level=flight_level,
        speed=speed,
    )
    assert cmd == True

    cmd = create_aircraft(
        aircraft_id=aircraft_id_2,
        type=type_2,
        latitude=latitude_2,
        longitude=longitude_2,
        heading=heading_2,
        flight_level=flight_level_2,
        speed=speed_2,
    )
    assert cmd == True

    score1 = loss_of_separation(aircraft_id, aircraft_id_2)
    assert score1 == 0

    score2 = loss_of_separation(aircraft_id, aircraft_id)
    assert score2 == -1

    score3 = loss_of_separation(aircraft_id_2, aircraft_id_2)
    assert score3 == -1

    new_aircraft_id = "TST3003"
    score4 = loss_of_separation(aircraft_id, new_aircraft_id)
    assert np.isnan(score4)
def test_wrong_id():
    """
    Test separation functions when one of provided IDs does not exist in simulation.
    """
    cmd = reset_simulation()
    assert cmd == True

    separation0 = euclidean_separation(from_aircraft_id=aircraft_id)
    assert isinstance(separation0, pd.DataFrame)
    assert np.isnan(separation0.loc[aircraft_id, aircraft_id])

    cmd = create_aircraft(
        aircraft_id=aircraft_id,
        type=type,
        latitude=latitude,
        longitude=longitude,
        heading=heading,
        flight_level=flight_level,
        speed=speed,
    )
    assert cmd == True

    separation1 = geodesic_separation(
        from_aircraft_id=[aircraft_id, aircraft_id_2],
        to_aircraft_id=[aircraft_id, aircraft_id_2],
    )
    assert isinstance(separation1, pd.DataFrame)
    assert np.isnan(separation1.loc[aircraft_id, aircraft_id_2])

    separation2 = great_circle_separation(
        from_aircraft_id=[aircraft_id, aircraft_id_2],
        to_aircraft_id=aircraft_id)
    assert isinstance(separation2, pd.DataFrame)
    assert np.isnan(separation2.loc[aircraft_id_2, aircraft_id])

    separation3 = vertical_separation(
        from_aircraft_id=aircraft_id,
        to_aircraft_id=[aircraft_id, aircraft_id_2])
    assert isinstance(separation3, pd.DataFrame)
    assert np.isnan(separation3.loc[aircraft_id, aircraft_id_2])

    separation4 = euclidean_separation(from_aircraft_id=aircraft_id,
                                       to_aircraft_id=aircraft_id_2)
    assert isinstance(separation4, pd.DataFrame)
    assert np.isnan(separation4.loc[aircraft_id, aircraft_id_2])
Exemple #9
0
def test_change_speed():
    cmd = reset_simulation()
    assert cmd == True

    aircraft_id = "TST1001"
    type = "B744"
    latitude = 0
    longitude = 0
    heading = 0
    flight_level = 250
    speed = 265

    cmd = create_aircraft(
        aircraft_id=aircraft_id,
        type=type,
        latitude=latitude,
        longitude=longitude,
        heading=heading,
        flight_level=flight_level,
        speed=speed,
    )
    assert cmd == True

    # Check the altitude.
    position = aircraft_position(aircraft_id)

    # In the returned data frame aircraft_id is uppercase.
    aircraft_id = aircraft_id.upper()
    # Aircaft initial speed differs from specified speed.
    assert position.loc[aircraft_id]["ground_speed"] > 200

    # Test with an invalid speed.
    invalid_speed = -1
    with pytest.raises(AssertionError):
        change_speed(aircraft_id=aircraft_id, speed=invalid_speed)

    # Give the command to change speed.
    new_speed = 400
    cmd = change_speed(aircraft_id=aircraft_id, speed=new_speed)
    assert cmd == True
Exemple #10
0
import time

reset_simulation()

aircraft_id = "TST1001"
type = "B744"
latitude = 0
longitude = 0
heading = 0
flight_level = 250
speed = 200

cmd = create_aircraft(aircraft_id = aircraft_id,
                      type = type,
                      latitude = latitude,
                      longitude = longitude,
                      heading = heading,
                      flight_level = flight_level,
                      speed = speed)


t = time.time()
print('Waiting...')
while True:
    pos = all_positions()
    # print(format_runtime(time.time()-start))

    if time.time()-t > 3:
        print("Sending synchronous commands...")
        t = time.time()
        for i in range(300, 400, 10):
def test_separation(expected_great_circle):
    """
    Tests that all separation functions return a dataframe using a variety of inputs.
    """
    cmd = reset_simulation()
    assert cmd == True

    cmd = create_aircraft(
        aircraft_id=aircraft_id,
        type=type,
        latitude=latitude,
        longitude=longitude,
        heading=heading,
        flight_level=flight_level,
        speed=speed,
    )
    assert cmd == True

    cmd = create_aircraft(
        aircraft_id=aircraft_id_2,
        type=type_2,
        latitude=latitude_2,
        longitude=longitude_2,
        heading=heading_2,
        flight_level=flight_level_2,
        speed=speed_2,
    )
    assert cmd == True

    separation1 = geodesic_separation(
        from_aircraft_id=[aircraft_id, aircraft_id_2],
        to_aircraft_id=[aircraft_id, aircraft_id_2],
    )
    assert isinstance(separation1, pd.DataFrame)
    assert separation1.loc[aircraft_id, aircraft_id_2] == pytest.approx(
        1000 * 176.92, 0.01)

    separation2 = great_circle_separation(
        from_aircraft_id=[aircraft_id, aircraft_id_2],
        to_aircraft_id=aircraft_id)
    assert isinstance(separation2, pd.DataFrame)
    expected = expected_great_circle(latitude, longitude, latitude_2,
                                     longitude_2)
    assert separation2.loc[aircraft_id_2,
                           aircraft_id] == pytest.approx(expected, 0.01)

    separation3 = vertical_separation(
        from_aircraft_id=aircraft_id,
        to_aircraft_id=[aircraft_id, aircraft_id_2])
    assert isinstance(separation3, pd.DataFrame)
    ## altitude is provided as flight_level, which must be converted to:
    # feet (*100) and then to metres (*0.3048)
    assert (
        separation3.loc[aircraft_id,
                        aircraft_id_2] == abs(flight_level - flight_level_2) *
        100 * SCALE_FEET_TO_METRES)

    separation4 = euclidean_separation(from_aircraft_id=aircraft_id,
                                       to_aircraft_id=aircraft_id_2)
    assert isinstance(separation4, pd.DataFrame)

    ecef = pyproj.Proj(proj="geocent", ellps="WGS84", datum="WGS84")
    lla = pyproj.Proj(proj="latlong", ellps="WGS84", datum="WGS84")

    from_ECEF = pyproj.transform(lla, ecef, longitude, latitude,
                                 flight_level * 100 * SCALE_FEET_TO_METRES)
    to_ECEF = pyproj.transform(lla, ecef, longitude_2, latitude_2,
                               flight_level_2 * 100 * SCALE_FEET_TO_METRES)

    assert separation4.loc[aircraft_id, aircraft_id_2] == pytest.approx(
        euclidean(from_ECEF, to_ECEF), 0.01)

    separation5 = euclidean_separation(from_aircraft_id=aircraft_id_2)
    assert isinstance(separation5, pd.DataFrame)
    assert separation5.loc[aircraft_id_2, aircraft_id_2] == 0