In this Project I am going to predicti fuel flow rate of airplanes during different phases of flight.
There are 8 different phases of flight in the dataset:
0 = Unknown
1 = Preflight
2 = Taxi
3 = Takeoff
4 = Climb
5 = Cruise
6 = Approach
7 = Rollout
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
matplotlib.style.use('fivethirtyeight')
import zipfile
import pandas as pd
from datetime import datetime
from babel.dates import format_timedelta
list_ = []
z = zipfile.ZipFile('CAX_Train_1.zip')
allFiles = z.namelist()
df_from_each_file = (pd.read_csv(z.open(f), index_col=False) for f in allFiles[0:5])
frame = pd.concat(df_from_each_file, ignore_index=True)
def to_dattim(y, m, d, h, mi, s):
return pd.Timestamp(int(y), int(m), int(d), int(h), int(mi), int(s))
a = frame.columns
frame["datetime"] = frame.apply(lambda row: to_dattim(row['Year'], row['Month'], row['Day'], row['Hour'], row['Minute'], row['Second']), axis=1)
temp = frame.groupby(['Flight_instance_ID']).datetime.first()
def minus_first(x,y,z):
return y - temp[x]
frame.datetime = frame.apply(lambda row: minus_first(row['Flight_instance_ID'], row['datetime'],temp), axis=1)
print "Number of columns:",len(a)
import matplotlib.pyplot as plt
import matplotlib.cm
import pandas as pd
from mpl_toolkits.basemap import Basemap
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
from matplotlib.colors import Normalize
fig, ax = plt.subplots(figsize=(16,12))
# coordinates are taken from http://boundingbox.klokantech.com/
coorlist = [-133.15,24.29,-61.52,54.37]
rout_color = "orange"
bg_color = (0.0, 0.0, 0, 1.0)
coast_color = (204/255.0, 0, 153/255.0, 0.7)
fl_color = (204/255.0, 0, 153/255.0, 0.7)
m = Basemap(resolution='f', # c, l, i, h, f or None
projection='merc',
llcrnrlon=coorlist[0], llcrnrlat= coorlist[1], urcrnrlon=coorlist[2], urcrnrlat=coorlist[3])
m.drawcountries()
m.drawcoastlines(color=coast_color, linewidth=1.0)
m.fillcontinents(color=bg_color, lake_color=bg_color)
m.drawmapboundary(fill_color=bg_color)
path = pd.read_csv('ALL_data.csv', index_col=False)
resmap = path.groupby(['Flight_instance_ID'])
for ni, pos in enumerate(resmap):
bla = pos[1]
x1 = list(bla.LONP)
y1 = list(bla.LATP)
x, y = m(x1,y1)
# in case of out of box, gives an error
try:
m.drawgreatcircle(x1[0], y1[0], x1[-1], y1[-1], linewidth=0.5, color=rout_color, alpha = 0.1)
except:
pass
plt.show()
plt.figure(num=None, figsize=(16, 12), dpi=80, facecolor='w', edgecolor='k')
dat = pd.Timestamp('2017-1-1 00:00:00')
for key, grp in frame.groupby(['Flight_instance_ID']):
plt.plot(grp['datetime'].apply(lambda x: x+dat), grp['FF'], lw = 1.5)
plt.xticks(rotation='vertical')
plt.xlim(xmin = dat)
plt.ylabel('Fuel Flow Rate')
plt.xlabel('Time of Flight')
plt.show()
from IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the raw code."></form>''')