Ejemplo n.º 1
0
def generate_gps_output(cdata):
    """
    Generate Output
    """
    # Generate output
    first = True
    lat1 = 0
    lon1 = 0
    for point in cdata:
        # If GPS Data
        if point['type'] == 'G':
            # Calculate bearing and distance bewteen points
            if first:
                first = False
                bearing = 0
                distance = 0
            else:
                distance = geo.great_circle(lat1, lon1, point['latitude'],
                                            point['longitude'])
                if distance < 0.01:
                    continue
                bearing = geo.bearing(lat1, lon1, point['latitude'],
                                      point['longitude'])

            if point['altitude'] == "-":
                print("%s,%0.6f,%0.6f,%0.6f,%s,%d,%0.2f" %
                      (point['type'], point['latitude'], point['longitude'],
                       point['mileage'], point['altitude'], bearing, distance))
            else:
                print("%s,%0.6f,%0.6f,%0.6f,%0.6f,%d,%0.2f" %
                      (point['type'], point['latitude'], point['longitude'],
                       point['mileage'], point['altitude'], bearing, distance))
            lat1 = point['latitude']
            lon1 = point['longitude']
Ejemplo n.º 2
0
 def test_bearing(self):
     self.assertAlmostEqual(
         geo.bearing(
             40.0167, -105.2833,
             -33.9333, 137.65
         ),
         -104.04,
         places=2
     )
Ejemplo n.º 3
0
def test_bearing():
    p1 = Location(52.3710, 4.9006)
    p2 = Location(51.8448, 5.8631)

    d = distance(p1.latitude, p1.longitude, None, p2.latitude, p2.longitude,
                 None)
    eq_(int(d), 88000)

    bearing = geo.bearing(p1, p2)
    eq_(bearing, 131.292906976903)
Ejemplo n.º 4
0
def test_bearing():
    p1 = Location(52.3710, 4.9006)
    p2 = Location(51.8448, 5.8631)

    d = distance(p1.latitude, p1.longitude, None,
                 p2.latitude, p2.longitude, None)
    eq_(int(d), 88000)

    bearing = geo.bearing(p1, p2)
    eq_(bearing, 131.292906976903)
Ejemplo n.º 5
0
def smooth_data(tc, input_data=None, mileage_threshold=0.01, track_threshold=45, write_file=True):
    (first, last, pixel_per_mile) = tc['mileposts']

    data = []
    used = 0
    for line_no, obj in pirail.read(tc['data_file'], classes=['TPV'], args={
            'start-mileage': first,
            'end-mileage': last,
        }):

        if obj['num_used'] < pirail.GPS_THRESHOLD:
            continue

        try:
            data.append(obj)
        except KeyError as ex:
            print("skipped", ex, obj)

    # Ensure the list is sorted by mileage
    data = sorted(data, key=lambda k: k['mileage'], reverse=False)

    # smooth, looking at all measurements +/-
    smooth_data = []
    for i in range(0, len(data)):
        lat = [data[i]['lat']]
        lon = [data[i]['lon']]
        alt = [data[i]['alt']]
        mileage = data[i]['mileage']
        # work backwards
        j = i-1
        while j >= 0 and data[j]['mileage'] >= mileage-mileage_threshold/2:
            lat.append(data[j]['lat'])
            lon.append(data[j]['lon'])
            alt.append(data[j]['alt'])
            j -= 1
        # work forwards
        j = i + 1
        while j < len(data) and data[j]['mileage'] <= mileage+mileage_threshold/2:
            lat.append(data[j]['lat'])
            lon.append(data[j]['lon'])
            alt.append(data[j]['alt'])
            j += 1
        # Average
        new_lat = avg_3_of_5(lat)
        new_lon = avg_3_of_5(lon)
        new_alt = avg_3_of_5(alt)
        mileage, certainty = tc['G'].find_mileage(new_lat, new_lon)
        obj = {
            'class': data[i]['class'],
            'speed': data[i]['speed'],
            'eps': data[i]['eps'],
            'lat': new_lat,
            'lon': new_lon,
            'alt': new_alt,
            'mileage': mileage,
            'certainty': certainty,
            'track': data[i]['track']
        }

        if i == 0:
            smooth_data.append(obj)
            last_obj = obj
        else:
            d = geo.great_circle(last_obj['lat'], last_obj['lon'],
                                 obj['lat'], obj['lon'])
            b = geo.bearing(last_obj['lat'], last_obj['lon'],
                            obj['lat'], obj['lon'])

            if d > mileage_threshold:
                #print("Inserted: %f @ %d" % (d,b))
                smooth_data.append(obj)
                last_obj = obj

    # Ensure we're still sorted
    smooth_data = sorted(smooth_data, key=lambda k: k['mileage'], reverse=False)

    for i in range(1,len(smooth_data)):
        b = geo.bearing(smooth_data[i-1]['lat'], smooth_data[i-1]['lon'],
                        smooth_data[i]['lat'], smooth_data[i]['lon'])
        smooth_data[i]['track'] = b
    if len(smooth_data) > 2:
        smooth_data[0]['track'] = smooth_data[1]['track']

    # save result
    if write_file:
        with open("smoothdata_tmp.csv", "w") as f:
            f.write("Mileage,Latitude,Longitude,Altitude,Track\n")
            for obj in smooth_data:
                f.write("%f %f %f %f %f\n" % (
                        obj['mileage'],
                        obj['lat'],
                        obj['lon'],
                        obj['alt'],
                        obj['track'],
                        ))

    #print("Smooth=%d" % len(smooth_data))
    return smooth_data
Ejemplo n.º 6
0
 def test_bearing(self):
     self.assertAlmostEqual(geo.bearing(40.0167, -105.2833, -33.9333,
                                        137.65),
                            -104.04,
                            places=2)
Ejemplo n.º 7
0
    def test_bearing(self):
        result = bearing(Wgs84Point(46.30440, 8.04091), Wgs84Point(46.56138, 8.33753))
        self.assertAlmostEqual(0.6701, result, places=4)

        result = bearing(Wgs84Point(46.928876, 8.339587), Wgs84Point(46.945041, 8.427873))
        self.assertAlmostEqual(1.30824, result, places=4)
Ejemplo n.º 8
0
def smooth_data(tc, input_data=None, mileage_threshold=0.01, track_threshold=45, write_file=True):
    (first, last, pixel_per_mile) = tc['mileposts']
    if input_data is None:
        input_data = tc['D']

    print("Input=%d" % len(input_data))
    data = []
    used = 0
    for obj in input_data:
        if obj['class'] == "SKY":
            used=0
            for s in obj['satellites']:
                if s['used']:
                    used += 1
            print(used, len(obj['satellites']))
            continue
        elif obj['class'] != "TPV":
            continue

        if used < GPS_THRESHOLD:
            print(used, "less than", GPS_THRESHOLD)
            continue

        print(obj)

        used = 0

        mileage = obj['mileage']
        if not (first <= mileage <= last):
            continue
        #if obj['speed'] <= obj['eps']:
        #    print("too slow", obj)
        #    continue
        try:
            print(mileage)
            new_obj = {
                'class': obj['class'],
                'speed': obj['speed'],
                'eps': obj['eps'],
                'lat': obj['lat'],
                'lon': obj['lon'],
                'alt': obj['alt'],
                'track': obj['track'],
                'mileage': obj['mileage'],
            }
            data.append(new_obj)
        except KeyError as ex:
            print("skipped", ex, obj)

    # Ensure the list is sorted by mileage
    data = sorted(data, key=lambda k: k['mileage'], reverse=False)

    # smooth, looking at all measurements +/-
    smooth_data = []
    for i in range(0, len(data)):
        lat = [data[i]['lat']]
        lon = [data[i]['lon']]
        alt = [data[i]['alt']]
        mileage = data[i]['mileage']
        # work backwards
        j = i-1
        while j >= 0 and data[j]['mileage'] >= mileage-mileage_threshold/2:
            lat.append(data[j]['lat'])
            lon.append(data[j]['lon'])
            alt.append(data[j]['alt'])
            j -= 1
        # work forwards
        j = i + 1
        while j < len(data) and data[j]['mileage'] <= mileage+mileage_threshold/2:
            lat.append(data[j]['lat'])
            lon.append(data[j]['lon'])
            alt.append(data[j]['alt'])
            j += 1
        # Average
        new_lat = avg_3_of_5(lat)
        new_lon = avg_3_of_5(lon)
        new_alt = avg_3_of_5(alt)
        mileage, certainty = tc['G'].find_mileage(new_lat, new_lon)
        obj = {
            'class': data[i]['class'],
            'speed': data[i]['speed'],
            'eps': data[i]['eps'],
            'lat': new_lat,
            'lon': new_lon,
            'alt': new_alt,
            'mileage': mileage,
            'certainty': certainty,
            'track': data[i]['track']
        }

        if i == 0:
            smooth_data.append(obj)
            last_obj = obj
        else:
            d = geo.great_circle(last_obj['lat'], last_obj['lon'],
                                 obj['lat'], obj['lon'])
            b = geo.bearing(last_obj['lat'], last_obj['lon'],
                            obj['lat'], obj['lon'])

            if d > mileage_threshold:
                print("Inserted: %f @ %d" % (d,b))
                smooth_data.append(obj)
                last_obj = obj

    # Ensure we're still sorted
    smooth_data = sorted(smooth_data, key=lambda k: k['mileage'], reverse=False)

    for i in range(1,len(smooth_data)):
        b = geo.bearing(smooth_data[i-1]['lat'], smooth_data[i-1]['lon'],
                        smooth_data[i]['lat'], smooth_data[i]['lon'])
        smooth_data[i]['track'] = b
    if len(smooth_data) > 2:
        smooth_data[0]['track'] = smooth_data[1]['track']

    # save result
    if write_file:
        with open("smoothdata_tmp.csv", "w") as f:
            f.write("Mileage,Latitude,Longitude,Altitude,Track\n")
            for obj in smooth_data:
                f.write("%f %f %f %f %f\n" % (
                        obj['mileage'],
                        obj['lat'],
                        obj['lon'],
                        obj['alt'],
                        obj['track'],
                        ))

    print("Smooth=%d" % len(smooth_data))
    return smooth_data