Beispiel #1
0
def test_find_intersecting_airsigs(monkeypatch):
    def mockreturn(s1, s2, airsig):
        return airsig

    monkeypatch.setattr(calculations, 'find_intersection', mockreturn)
    airsigs = [AirSigmet()]
    route = [(LatLon(0, 0), LatLon(1, 1))]
    result = calculations.find_intersecting_airsigs(airsigs, route)
    assert airsigs == result
Beispiel #2
0
def test_airsigmet_points():
    airsig = AirSigmet()
    p1 = OrderedDict(latitude=0, longitude=0)
    p2 = OrderedDict(latitude=1, longitude=1)
    airsig.area = [Points(**p1), Points(**p2)]
    perimeter = [(LatLon(*p1.values()), LatLon(*p2.values())),
                 (LatLon(*p2.values()), LatLon(*p1.values()))]
    result = calculations.airsigmet_points(airsig)
    assert perimeter == result
Beispiel #3
0
def test_get_flight_route_data():
    faflightid = 'abc123'
    departure_time = 0
    client = MockClient(faflightid, faflightid, departure_time)
    segments = [
        (LatLon(0, 0), LatLon(1, 1)),
    ]
    result = calculations.get_flight_route_data(client, faflightid)
    assert segments == result
Beispiel #4
0
def test_find_intersection():
    start1 = LatLon(0, 0)
    end1 = LatLon(0, 2)
    airsig = AirSigmet()
    airsig.area = [
        Points(latitude=1, longitude=1),
        Points(latitude=-1, longitude=1)
    ]
    result = calculations.find_intersection(start1, end1, airsig)
    assert [LatLon(0, 1), LatLon(0, 1)] == result
def calculate_route_in_KM_GPS(gps_dataset):
    row_index = 0
    accumulated_d = 0
    published_weather = False
    try_again_soon = False
    for row in gps_dataset:
        if (row_index > 1):
            t_Longitude = float(row[2])
            t_Latitude = float(row[3])
            if (published_weather == False):
                #is_rain(t_Latitude,t_Longitude)
                is_rain(31.2680245, 34.7971712)
                published_weather = True
            t_minus_1_Longitude = float(gps_dataset[row_index - 1][2])
            t_minus_1_Latitude = float(gps_dataset[row_index - 1][3])
            x = LatLon(t_Latitude, t_Longitude)
            y = LatLon(t_minus_1_Latitude, t_minus_1_Longitude)
            d = x.distanceTo(y)  # 9.64 km
            if (try_again_soon == False):
                if (row_index % 51 == 0):
                    try:
                        #max_speed = maxspeed(t_Latitude, t_Longitude, 100)
                        max_speed = maxspeed(31.561134, 34.803414, 100)
                    except:
                        print("An exception occurred")
                        try_again_soon = True
                    if (len(max_speed) > 0 and try_again_soon == False):
                        print("road name: ", max_speed[0]['name'])
                        print("max speed allowed: ",
                              max_speed[0]['speed_limit'])
                    else:
                        try_again_soon = True
            else:
                try_again_soon = False
                if (row_index % 5 == 0):
                    try:
                        max_speed = maxspeed(t_Latitude, t_Longitude, 100)
                    except:
                        print("An exception occurred")
                        try_again_soon = True
                    if (len(max_speed) > 0 and try_again_soon == False):
                        print("max speed allowed: ",
                              max_speed[0]['speed_limit'])
                        try_again_soon = False
                    else:
                        try_again_soon = True
            #print (d)
            accumulated_d = accumulated_d + d  ## total distance in meters
        row_index = row_index + 1
    print("total meters driven: ", str(accumulated_d))
Beispiel #6
0
def load_route():
    with open("DecodeFlightRoute.json") as f:
        route = json.load(f)
    points = [
        LatLon(waypoint.get("latitude"), waypoint.get("longitude")) for
        waypoint in route.get('data', [])
    ]
    segments = list(zip(points, points[1:]))
    return segments
Beispiel #7
0
def airsigmet_points(airsig: AirSigmet) -> List[Tuple[LatLon, LatLon]]:
    """
    Create a list of tuples containing all the latitude and longitude points defining an airmet/
    sigmet area.

    :param airsig: The Airmet/Sigmet in question.
    :return: List of tuples defining the area.
    """
    points = [
        (
            LatLon(x.latitude, x.longitude),
            LatLon(y.latitude, y.longitude)
        ) for x, y in zip(airsig.area, airsig.area[1:])
    ]
    points.append((
        LatLon(airsig.area[-1].latitude, airsig.area[-1].longitude),
        LatLon(airsig.area[0].latitude, airsig.area[0].longitude),
    ))
    return points
Beispiel #8
0
def airport_latlon(airport: str) -> LatLon:
    """
    Find the latitude and longitude of an airport given that airport's 4-letter ICAO identifier.

    :param airport:  Airport's 4-letter ICAO identifier.
    :return: LatLon object containing the airports latitude and longitude.
    """
    db_listing = AIRPORT_DATA.get(airport)
    lat = db_listing[6]
    long = db_listing[7]
    return LatLon(parseDMS(lat, sep=':'), parseDMS(long, sep=':'))
Beispiel #9
0
def get_flight_route_data(client, flight_id) -> list:
    """
    Get the waypoint fixes and their latitudes and longitudes for the flight route.

    :param client:
    :param flight_id:
    :return:
    """
    try:
        route = client.service.DecodeFlightRoute(flight_id)
    except Fault:
        msg = f'Could not find route data for flight_id: {flight_id}'
        logger.error(msg)
        return []
    points = []
    for waypoint in route['data']:
        points.append(
            LatLon(waypoint["latitude"], waypoint["longitude"])
        )
    segments = list(zip(points, points[1:]))
    return segments
Beispiel #10
0
    def translate_node_to_gps_coords(self, node):
        if not self.anchored_base_node or not self.calculated_base_node:
            return node.x, node.y

        # Set up coordinate transforms
        anchored_base, calculated_base = LatLon(
            *config.ANCHORED_BASE_GPS), LatLon(*config.CALCULATED_BASE_GPS)
        virtual_base_distance = self.calculated_base_node.x  # TODO: actually calculate this
        real_base_distance = anchored_base.distanceTo(calculated_base)
        distance_scale = real_base_distance / virtual_base_distance
        heading_offset = mean([
            anchored_base.initialBearingTo(calculated_base),
            calculated_base.initialBearingTo(anchored_base) - 180
        ]) - 90
        # Transform node virtual coordinates
        new_x, new_y = self.rotate_point(
            (node.x * distance_scale, node.y * distance_scale), heading_offset)
        n_d, n_a = math.sqrt(math.pow(new_x, 2) +
                             math.pow(new_y, 2)), 90 - math.degrees(
                                 math.atan2(-new_y, new_x))

        # Add to anchored base GPS coords
        node_gps = anchored_base.destination(n_d, n_a)
        return node_gps.latlon2(ndigits=6)
Beispiel #11
0
def test_airport_latlon():
    kord = (41.97859955, -87.90480042)
    kord_latlon = LatLon(*kord)
    result = calculations.airport_latlon("KORD")
    assert kord_latlon == result
Beispiel #12
0
def test_test_equality():
    latlon1 = LatLon(0, 0)
    latlon2 = latlon1
    result = calculations.test_equality(latlon1, latlon2)
    assert result is True