<jupyter_start><jupyter_text>Happy 2017We have some GPX files which we want to plot on a nice map.A lot of the the code below is based on [this python4oceanographers blog post](https://ocefpaf.github.io/python4oceanographers/blog/2014/08/18/gpx/). First we import some packages necessary to achieve what we want.<jupyter_code>import matplotlib.pyplot as plt
%matplotlib inline
import numpy
import gpxpy
import mplleaflet
import glob
import os
import pandas

plt.rcParams['figure.figsize'] = (16, 9)  # Size up figures a bit<jupyter_output><empty_output><jupyter_text>To quickly ingest the GPX files, we write (or actually copy from the aforementioned blog post) a parsing function.<jupyter_code>def load_run_data(gpx_path, filter=""):
    gpx_files = glob.glob(os.path.join(gpx_path, filter + "*.gpx"))
    run_data = []
    for file_idx, gpx_file in enumerate(gpx_files): 
        gpx = gpxpy.parse(open(gpx_file, 'r'))
        # Loop through tracks
        for track_idx, track in enumerate(gpx.tracks):
            track_name = track.name
            track_time = track.get_time_bounds().start_time
            track_length = track.length_3d()
            track_duration = track.get_duration()
            track_speed = track.get_moving_data().max_speed
            
            for seg_idx, segment in enumerate(track.segments):
                segment_length = segment.length_3d()
                for point_idx, point in enumerate(segment.points):
                    run_data.append([file_idx, os.path.basename(gpx_file), track_idx, track_name, 
                                     track_time, track_length, track_duration, track_speed, 
                                     seg_idx, segment_length, point.time, point.latitude, 
                                     point.longitude, point.elevation, segment.get_speed(point_idx)])
    return run_data<jupyter_output><empty_output><jupyter_text>For easy handling, we load the GPX tracks in their subfolder to a [Pandas](https://pypi.python.org/pypi/pandas) `dataframe` and display the first few entries of the data frame.<jupyter_code>data = load_run_data(gpx_path='gpxtracks', filter="")
df = pandas.DataFrame(data, columns=['File_Index', 'File_Name', 'Index', 'Name',
                                     'Time', 'Length', 'Duration', 'Max_Speed',
                                     'Segment_Index', 'Segment_Length', 'Point_Time', 'Point_Latitude',
                                     'Point_Longitude', 'Point_Elevation', 'Point_Speed'])
df.head()<jupyter_output><empty_output><jupyter_text>At last we plot the tracks on top of the *awesome* [Stamen watercolor maps](http://maps.stamen.com/watercolor/12/46.9413/7.4310).<jupyter_code>for i in range(max(df['File_Index'])+1):
    plt.plot(df['Point_Longitude'][df['File_Index']==i],
             df['Point_Latitude'][df['File_Index']==i],
             color='black', linewidth=7)
mplleaflet.display(tiles='stamen_wc')
# Save as HTML page, so we can print the image big...
for i in range(max(df['File_Index'])+1):
    plt.plot(df['Point_Longitude'][df['File_Index']==i],
             df['Point_Latitude'][df['File_Index']==i],
             color='black', linewidth=7)
mplleaflet.save_html(tiles='stamen_wc', fileobj='2017.html')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11777301927194861, 'fraction_numerical': 0.012236157846436219, 'mean_word_length': 3.1815856777493607, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '144048', 'license': 'Unlicense', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1014, 'n_words': 230, 'path': '2017.ipynb', 'repo_name': 'habi/2017', 'size': '3269'}