In [1]:
import io as fio
fname = '/Users/astyler/projects/ChargeCarData/gpx/illah/20100227.gpx'
ft = fio.open(fname)
ft.close()
In [2]:
import xml.etree.ElementTree as ET
tree = ET.parse(fname)
root = tree.getroot()
In [3]:
print root.keys()
In [4]:
root.attrib
Out[4]:
In [5]:
def get_element_by_tag(element, tag):
if element.tag.endswith(tag):
yield element
for child in element:
for g in get_element_by_tag(child, tag):
yield g
In [6]:
def stripnamespace(xmltree):
for node in xmltree.getiterator():
if '}' in node.tag:
node.tag = node.tag.split('}', 1)[1]
In [7]:
stripnamespace(root)
root.getchildren()
Out[7]:
In [8]:
root.getchildren()[1].getchildren()[1].getchildren()[0].getchildren()[1].text
Out[8]:
In [9]:
vals = list()
for node in root.iter('trkpt'):
vals.append(dict(node.items()+[('ele',node.getchildren()[0].text),('time',node.getchildren()[1].text)]))
In [10]:
lats = [val['lat'] for val in vals]
lons = [val['lon'] for val in vals]
In [13]:
import bokeh.plotting as bp
bp.output_notebook()
bp.Plot(lons, lats)
#p = bp.figure(title="test trip", x_axis_label='x', y_axis_label='y')
# add a line renderer with legend and line thickness
#p.line(lons, lats, legend="pos", line_width=2)
#p.update()
# show the results
bp.show(p)
In [32]:
%pylab inline
pylab.plot(lons,lats)
Out[32]:
In [18]:
import pandas
fname2 = '/Users/astyler/projects/ChargeCarData/csv/illah20100227_1.csv'
df = pandas.read_csv(fname2)
df.dtypes
#convert_numeric=True)
Out[18]:
In [19]:
df
Out[19]:
In [25]:
#%pylab inline
#df.plot(x='Longitude',y='Latitude',c='Power')
%matplotlib notebook
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
threedee = plt.figure().gca(projection='3d')
threedee.plot(df.Longitude, df.Latitude, df.Power)
threedee.set_xlabel('Lon')
threedee.set_ylabel('Lat')
threedee.set_zlabel('Power')
plt.show()
In [20]:
p2 = bp.figure()
p2.line(df.Longitude, df.Latitude, legend="y=x")
Out[20]:
In [21]:
bp.show(p2)
In [ ]: