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()


<bound method Element.keys of <Element '{http://www.topografix.com/GPX/1/1}gpx' at 0x104861c10>>

In [4]:
root.attrib


Out[4]:
{'creator': '',
 'version': '1.1',
 '{http://www.w3.org/2001/XMLSchema-instance}schemaLocation': 'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd'}

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]:
[<Element 'trk' at 0x10486a350>,
 <Element 'trk' at 0x104956550>,
 <Element 'trk' at 0x104956e10>,
 <Element 'trk' at 0x104a93cd0>,
 <Element 'trk' at 0x104aa7210>]

In [8]:
root.getchildren()[1].getchildren()[1].getchildren()[0].getchildren()[1].text


Out[8]:
'2010-02-27T22:36:44Z'

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)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-4a4d8e34cb15> in <module>()
      1 import bokeh.plotting as bp
      2 bp.output_notebook()
----> 3 bp.Plot(lons, lats)
      4 #p = bp.figure(title="test trip", x_axis_label='x', y_axis_label='y')
      5 

TypeError: __init__() takes exactly 1 argument (3 given)

In [32]:
%pylab inline
pylab.plot(lons,lats)


Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['figure', 'show']
`%matplotlib` prevents importing * from pylab and numpy
Out[32]:
[<matplotlib.lines.Line2D at 0x109f52350>]

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]:
Latitude           float64
Longitude          float64
Elevation          float64
Bearing            float64
PlanarDistance     float64
Speed              float64
Acceleration       float64
Power              float64
TotalEnergyUsed    float64
PeriodMS             int64
Time                 int64
dtype: object

In [19]:
df


Out[19]:
Latitude Longitude Elevation Bearing PlanarDistance Speed Acceleration Power TotalEnergyUsed PeriodMS Time
0 40.429277 -79.915235 414.87 137.49 7.47 7.474 0.000 5044.7621 0.0000 1000 1267328212000
1 40.429232 -79.915169 415.15 137.49 7.47 7.474 0.000 5044.7826 1.4013 1000 1267328213000
2 40.429187 -79.915104 415.44 137.50 5.49 5.508 -1.965 -7649.4367 2.8027 1000 1267328214000
3 40.429153 -79.915057 414.96 137.50 3.17 3.187 -2.322 -1559.9135 0.6778 1000 1267328215000
4 40.429136 -79.915027 415.33 137.50 3.17 3.187 0.000 5118.6085 0.2445 1000 1267328216000
5 40.429119 -79.914997 415.70 180.00 0.08 0.382 -2.804 -308.7879 1.6663 1000 1267328217000
6 40.429119 -79.914996 416.07 137.50 0.68 0.978 0.596 -3115.3693 1.5806 1000 1267328218000
7 40.429116 -79.914989 415.37 317.49 0.52 0.703 -0.275 5667.9888 0.7152 1000 1267328219000
8 40.429117 -79.914983 415.84 137.50 1.16 1.228 0.526 -1491.0638 2.2896 1000 1267328220000
9 40.429112 -79.914971 415.43 137.50 2.50 2.513 1.284 1793.1045 1.8754 1000 1267328221000
10 40.429100 -79.914946 415.19 180.00 0.42 0.429 -2.084 -208.7012 2.3735 1000 1267328222000
11 40.429100 -79.914941 415.12 317.49 3.45 3.450 3.021 14194.6221 2.3155 1000 1267328223000
12 40.429109 -79.914980 415.19 317.49 3.45 3.450 -0.000 1687.1831 6.2585 1000 1267328224000
13 40.429118 -79.915019 415.26 317.49 1.98 1.981 -1.469 -1777.0268 6.7272 1000 1267328225000
14 40.429124 -79.915041 415.15 317.49 1.98 1.981 -0.000 -205.5291 6.2335 1000 1267328226000
15 40.429130 -79.915063 415.03 137.50 2.32 2.323 0.342 3760.1195 6.1765 1000 1267328227000
16 40.429120 -79.915039 415.22 317.50 0.71 0.734 -1.589 979.5038 7.2209 1000 1267328228000
17 40.429126 -79.915036 415.39 317.49 0.54 0.564 -0.170 2186.1234 7.4930 1000 1267328229000
18 40.429129 -79.915041 415.56 317.49 0.37 0.488 -0.076 281.8783 8.1003 1000 1267328230000
19 40.429132 -79.915043 415.87 137.50 0.34 0.524 0.036 -1847.2930 8.1786 1000 1267328231000
20 40.429130 -79.915040 415.47 137.50 0.34 0.344 -0.180 233.9016 7.6654 1000 1267328232000
21 40.429127 -79.915039 415.47 137.50 0.44 0.515 0.171 3472.8639 7.7304 1000 1267328233000
22 40.429123 -79.915039 415.73 137.50 0.34 1.026 0.512 -4571.4421 8.6951 1000 1267328234000
23 40.429120 -79.915040 414.76 137.50 0.14 0.508 -0.519 5693.4348 7.4252 1000 1267328235000
24 40.429119 -79.915039 415.25 180.00 0.17 0.753 0.246 -3534.8509 9.0068 1000 1267328236000
25 40.429119 -79.915037 414.51 317.50 0.33 0.373 -0.381 193.0235 8.0249 1000 1267328237000
26 40.429122 -79.915037 414.68 317.50 0.48 0.476 0.103 383.1245 8.0785 1000 1267328238000
27 40.429126 -79.915039 414.67 317.50 0.24 0.285 -0.191 233.1981 8.1849 1000 1267328239000
28 40.429128 -79.915040 414.83 137.50 0.20 0.656 0.372 7914.0676 8.2497 1000 1267328240000
29 40.429127 -79.915038 415.45 137.50 0.34 0.441 -0.216 223.7499 10.4480 1000 1267328241000
... ... ... ... ... ... ... ... ... ... ... ...
2912 40.301759 -79.520379 440.82 139.36 1.37 1.440 -0.048 -1954.6107 7276.7025 1000 1267331124000
2913 40.301757 -79.520395 440.40 139.36 1.07 1.075 -0.365 -374.0244 7276.1595 1000 1267331125000
2914 40.301754 -79.520407 440.30 139.36 0.75 0.793 -0.282 -1123.9519 7276.0556 1000 1267331126000
2915 40.301749 -79.520413 440.06 139.36 0.45 0.790 -0.003 -3152.6801 7275.7434 1000 1267331127000
2916 40.301745 -79.520414 439.41 139.36 0.28 0.280 -0.510 185.1996 7274.8677 1000 1267331128000
2917 40.301743 -79.520412 439.41 139.36 0.20 0.847 0.567 10528.6265 7274.9191 1000 1267331129000
2918 40.301742 -79.520410 440.23 319.36 0.14 0.406 -0.441 175.6547 7277.8437 1000 1267331130000
2919 40.301743 -79.520409 439.85 319.36 0.11 0.241 -0.165 237.7181 7277.8925 1000 1267331131000
2920 40.301744 -79.520409 440.07 319.36 0.11 0.188 -0.054 261.0446 7277.9586 1000 1267331132000
2921 40.301745 -79.520409 440.22 0.00 0.00 0.214 0.026 284.5905 7278.0311 1000 1267331133000
2922 40.301745 -79.520409 440.00 0.00 0.00 0.520 0.306 522.8135 7278.1101 1000 1267331134000
2923 40.301745 -79.520409 440.52 180.00 0.08 0.527 0.007 -2505.9326 7278.2554 1000 1267331135000
2924 40.301745 -79.520408 440.00 0.00 0.00 0.088 -0.439 226.1376 7277.5593 1000 1267331136000
2925 40.301745 -79.520408 439.91 180.00 0.08 0.094 0.006 257.2054 7277.6221 1000 1267331137000
2926 40.301745 -79.520407 439.95 0.00 0.00 0.362 0.268 420.4603 7277.6935 1000 1267331138000
2927 40.301745 -79.520407 439.59 0.00 0.00 0.143 -0.219 234.4522 7277.8103 1000 1267331139000
2928 40.301745 -79.520407 439.74 0.00 0.00 0.119 -0.024 257.5864 7277.8755 1000 1267331140000
2929 40.301745 -79.520407 439.62 0.00 0.00 0.449 0.330 497.1193 7277.9470 1000 1267331141000
2930 40.301745 -79.520407 440.07 139.36 0.24 0.631 0.182 7294.4191 7278.0851 1000 1267331142000
2931 40.301743 -79.520408 440.65 139.36 0.37 0.474 -0.157 237.6009 7280.1113 1000 1267331143000
2932 40.301740 -79.520410 440.36 139.36 0.48 0.650 0.176 5664.1997 7280.1773 1000 1267331144000
2933 40.301736 -79.520412 440.80 139.36 0.48 0.644 -0.005 -2023.0898 7281.7507 1000 1267331145000
2934 40.301732 -79.520414 440.37 139.36 0.24 0.325 -0.319 209.8555 7281.1887 1000 1267331146000
2935 40.301730 -79.520415 440.14 0.00 0.00 0.504 0.179 437.0130 7281.2470 1000 1267331147000
2936 40.301730 -79.520415 439.64 180.00 0.08 0.715 0.211 8794.3088 7281.3684 1000 1267331148000
2937 40.301730 -79.520414 440.35 319.36 0.14 0.990 0.275 -4793.2507 7283.8113 1000 1267331149000
2938 40.301731 -79.520413 439.37 180.00 0.08 1.000 0.010 11991.8342 7282.4798 1000 1267331150000
2939 40.301731 -79.520412 440.37 0.00 0.00 0.317 -0.683 148.3459 7285.8109 1000 1267331151000
2940 40.301731 -79.520412 440.05 0.00 0.00 0.000 -0.317 240.0000 7285.8521 1000 1267331152000
2941 40.301731 -79.520412 440.05 0.00 0.00 0.000 0.000 0.0000 7285.9188 1000 1267331153000

2942 rows × 11 columns


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]:
<bokeh.plotting.Figure at 0x108f89cd0>

In [21]:
bp.show(p2)



In [ ]: