<jupyter_start><jupyter_text>Notes15-June-2016Geospatial data of cycle routes obtained with an app from Strava, a fitness tech company. This notebook contains an initial exploration of that data. The data is given in GPX format, an XML like file format for geospatial data. Inital data was collected by <NAME> and Peter over the dates 13 - 15 June 2016. It will be periodically updated.Initial ideas for this analysis include creating an interactive map of all bike routes, colored by person. A time lapsed movie could also be made to show the progression of routes over time.There is low volume of data at this point. At best, we can attempt to give an impression of what a more extensive  data collection effort would give.16-June-2016Tasks:* Revise visualizations to be colored by user.* Add Sarah's data* Make a movie of points over time<jupyter_code>#pip install gpxpy
#pip install folium
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Parse GPX data<jupyter_code>from os import listdir
from os.path import isfile, join
import gpxpy

data_path = '../data/raw/geo/'
data = [f for f in listdir(data_path) if isfile(join(data_path,f)) and f != "README.docx"]

lat, lon = [], []
users = [y.split("_")[1] for y in [x.replace('.gpx', '') for x in data]]
colors = {'phil': 'blue', 
          'agne': 'red', 
          'peter': 'green',
          'sarah': 'purple'}
for activity in data:
    gpx_filename = join(data_path,activity)
    
    with open(gpx_filename, 'r') as f:
        gpx = gpxpy.parse(f)

    activity_lat, activity_lon = [], []
    for track in gpx.tracks:
        for segment in track.segments:
            for point in segment.points:
                activity_lat.append(point.latitude)
                activity_lon.append(point.longitude)
    lat.append(activity_lat)
    lon.append(activity_lon)<jupyter_output><empty_output><jupyter_text>Visualization I* [Visualizing Strava Tracks with Python](http://andykee.com/visualizing-strava-tracks-with-python.html)<jupyter_code>fig = plt.figure(facecolor = '0.05')
ax = plt.Axes(fig, [0., 0., 1., 1.], )
ax.set_aspect('equal')
ax.set_axis_off()
fig.add_axes(ax)

#Plot each activity separately. Else, get connected lines
for activity_lon, activity_lat, user in zip(lon, lat, users):
    plt.plot(activity_lon, activity_lat, color = colors[user], lw = 1.5, alpha = 0.8)<jupyter_output><empty_output><jupyter_text>Visualization II* [deparkes/GPX_Folium_Map.py](https://gist.github.com/deparkes/610b112f74eadbda663806ba8dd83069)* [Trackprofiler](http://www.trackprofiler.com/)* [folium - custom color icons](http://nbviewer.jupyter.org/github/birdage/folium/blob/color_markers/examples/marker_color_icon_examples.ipynb)<jupyter_code>import folium
# Load map centred on Oxford
ox = folium.Map(location=[51.7520, -1.2577], zoom_start=13)

for activity_lon, activity_lat, user in zip(lon, lat, users):
    for i, (x,y) in enumerate(zip(activity_lon, activity_lat)):
        #Map rendering is slow. Thin points. 
        if i % 10 == 0:
            ox.add_child(folium.CircleMarker([y, x], radius=10, 
                                             fill_opacity = 1.0,
                                             fill_color=colors[user], 
                                             color='white', 
                         ))

ox
from datetime import datetime
import os

fig_dir = "./figures"
date = datetime.today().strftime('%Y%m%d')
fstem = '-leaflet.html'
fp = os.path.join(fig_dir, date + fstem)
save = input("Save map? [Y/n]")
if save.lower() == 'y': ox.save(fp)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.115406162464986, 'fraction_numerical': 0.020168067226890758, 'mean_word_length': 3.4470734744707348, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '544551', 'license': 'FTL', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1131, 'n_words': 333, 'path': 'notebooks/0.2-ppope-geo-EDA.ipynb', 'repo_name': 'cycleland/cycleland_ds', 'size': '3574'}