Advertisement
Guest User

airdata-histogram

a guest
Aug 9th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import csv
  3. import geo_distance #for calculating dist b/w lats. and longs.
  4.  
  5. d = open("airports.dat.txt")
  6. latitudes = {}
  7. longitudes = {}
  8. distances = []
  9. for row in csv.reader(d):
  10.     airport_id = row[0]
  11.     latitudes[airport_id] = float(row[6])
  12.     longitudes[airport_id] = float(row[7])
  13.  
  14. distances = []
  15. f = open("routes.dat")
  16. for row in csv.reader(f):
  17.     source_airport = row[3]
  18.     dest_airport = row[5]
  19.     if source_airport in latitudes and dest_airport in latitudes:
  20.         source_lat = latitudes[source_airport]
  21.         source_long = longitudes[source_airport]
  22.         dest_lat = latitudes[dest_airport]
  23.         dest_long = longitudes[dest_airport]
  24.         distances.append(geo_distance.distance(source_lat,source_long,dest_lat,dest_long))        
  25. #print distances        
  26. plt.hist(distances, 100, facecolor='b')
  27. plt.xlabel("Distance (km)")
  28. plt.ylabel("Number of flights")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement