def basemap_plot_paths(filename): m = Basemap(projection='merc', resolution='i', **map_bounds['europe']) fig = plt.figure() ax = Axes3D(fig) ax.add_collection3d(m.drawcoastlines(linewidth=0.25)) ax.add_collection3d(m.drawcountries(linewidth=0.35)) collection = py1090.FlightCollection() #with py1090.Connection() as connection: with open(filename, 'r') as connection: collection.add_list(connection) for flight in collection: if flight.hexident in blacklist_hexidents: continue path = list(flight.path) if len(path) > 1: lats, lons, alts = np.array(path).T x, y = m(lons, lats) m.plot(x, y, alts, ".-") plt.title("Flights in file '{:s}'".format(filename)) plt.show()
def basemap_plot_distances(filename, home): # number of sections N = 120 bins = np.zeros(N) collection = py1090.FlightCollection() #with py1090.Connection() as file: with open(filename, 'r') as file: collection.add_list(file) for flight in collection: if flight.hexident in blacklist_hexidents: continue for lat, lon, alt in flight.path: bearing = bearing_between(home[0], home[1], lat, lon) distance = distance_between(home[0], home[1], lat, lon) if distance > 500e3: print( "Warning: coordinates", lat, ",", lon, "sent by plane", flight.hexident, "are very far away, skipping for now, you may consider blacklisting though." ) continue bin = round(bearing * N / (2 * math.pi)) % N if distance > bins[bin]: bins[bin] = distance m = Basemap(projection='stere', resolution='i', lat_0=home[0], lon_0=home[1], width=bins.max() * 2, height=bins.max() * 2) fig = plt.figure() ax_map = fig.add_subplot(111) m.drawcoastlines() m.fillcontinents(color='white', lake_color='white') m.drawcountries() ax_polar = fig.add_axes(ax_map.get_position(), polar=True, frameon=False) ax_polar.set_autoscale_on(False) ax_polar.set_ylim(0, bins.max() / 1000) ax_polar.fill(np.linspace(0, 2 * math.pi, N) - math.pi / 2, bins / 1000, alpha=0.5) ax_polar.xaxis.set_ticklabels([]) plt.title("Maximal distance: {:.1f} km".format(bins.max() / 1000)) plt.show()
def collection_example(): with py1090.Connection() as connection: collection = py1090.FlightCollection() while True: print("Number of flights in collection:", len(collection)) for line in connection: message = py1090.Message.from_string(line) collection.add(message)
def collection_example(): with py1090.Connection('dvbtadsb') as connection: collection = py1090.FlightCollection() while True: print("Number of flights in collection:", len(collection)) for flight in collection: print(flight.callsign," ",flight.flight_id," ",flight.sqwk," ",flight.last_position) a=0 for line in connection: message = py1090.Message.from_string(line) collection.add(message) # print("got msg: ",message) if a>10: break a=a+1
def basemap_plot_positions(filename): m = Basemap(projection='merc', resolution='i', **map_bounds['europe']) m.drawcoastlines() m.fillcontinents(color='white', lake_color='white') m.drawcountries() collection = py1090.FlightCollection() #with py1090.Connection() as connection: with open(filename, 'r') as connection: collection.add_list(connection) for flight in collection: if flight.hexident in blacklist_hexidents: continue path = list(flight.path) if len(path) > 1: lats, lons, alts = np.array(path).T x, y = m(lons, lats) m.plot(x, y, ".-") plt.title("Flights in file '{:s}'".format(filename)) plt.show()