Sunday, 9 August 2015

Airline Routing

Airline routes are more complex and need to get update our airline route charts to avoid any accidents. The below python program allows you to manipulate the given set of data and find out the distribution of different flight distances.

We need to calculate Geo distance which is quite different from our normal distance calculation as the former deals with longitudes and latitudes.

import matplotlib.pyplot as plt
import csv 
import geo_distance


We are working with two different input dataset1 - airports.dat to get airport details and dataset2 - routes.dat to get route details. And now we've to calculate geo_distance from both these data and record it in a list distance[]

d = open("airports.dat.txt")
latitudes = {}
longitudes = {}
distances = []
for row in csv.reader(d):
  airport_id = row[0]
  latitudes[airport_id] = float(row[6]) 
  longitudes[airport_id] = float(row[7])
f = open("routes.dat")
for row in csv.reader(f):
  source_airport = row[3]
  dest_airport = row[5]
if source_airport in latitudes and   dest_airport in latitudes:
  source_lat = latitudes[source_airport]
  source_long = longitudes[source_airport]
  dest_lat = latitudes[dest_airport]
  dest_long = longitudes[dest_airport]        
distances.append(geo_distance.distance(source_lat,source_long,dest_lat,dest_long))

Histogram:

Let's create a histogram with hist()


plt.hist(distances, 100, facecolor='b')
plt.xlabel("Distance (km)") 
plt.ylabel("Number of flights")
.

  







No comments:

Post a Comment