On a trail run with Lukas we felt to be lost quite often. Even though we had planned the tour beforehand and had a GPX file.
But we don't have navigation watches (yet) and getting your phone out of the pocket is a bit tedious. So I want to compare our
planned and actual route using Python.
Loading GPX Data
First gpxpy is used to load the GPX files. The data gets summarized and saved
for later in a pandas DataFrame. Furthermore the elevation difference, cumulative distance
and vertical speed are calculated
importosimportpandasaspdimportmatplotlib.pyplotaspltimportgpxpyfromgeopyimportdistanceimportfoliumdefload_gpx(file_name):gpx=gpxpy.parse(open(file_name))track=gpx.tracks[0]segment=track.segments[0]print(f"File: {file_name}")print(f"Points: {len(segment.points)}")print(f"Length: {segment.length_2d()/1000:.1f} km")print(f"Up: {segment.get_uphill_downhill().uphill:.0f} m")print(f"Down: {segment.get_uphill_downhill().downhill:.0f} m\n")# Load the data into a Pandas dataframe (by way of a list)data=[]forpoint_idx,pointinenumerate(segment.points):data.append([point.longitude,point.latitude,point.elevation,point.time,segment.get_speed(point_idx)])columns=['long','lat','ele','time','speed']gpx_df=pd.DataFrame(data,columns=columns)# Calculate elevation diff, cumulative distance and vertical speedgpx_df['ele_d']=gpx_df.ele.diff(1)gpx_df=get_distance(gpx_df)ifsegment.has_times():gpx_df['td']=(gpx_df.time.diff(1)).astype('timedelta64[s]')gpx_df['vert_speed']=gpx_df.ele_d/gpx_df.tdreturngpx_dfdefget_distance(_df):_df=_df.reset_index(drop=True)_df['dist']=0.0forpntin_df.index[1:]:_df.dist.iat[pnt]=distance.distance((_df.lat.iat[pnt-1],_df.long.iat[pnt-1]),(_df.lat.iat[pnt],_df.long.iat[pnt])).meters+_df.dist.iat[pnt-1]return_dftour='brecherspitz'df_plan=load_gpx(os.path.join(tour,'plan.gpx'))df_track=load_gpx(os.path.join(tour,'track.gpx'))
The summary yields interesting results. We know that we didn't follow the path all the time but we
definitely didn't do more than 1000 m extra vertical. Also 5km more seems too much. So it's time do look closer to the GPS data.
Elevation profile with wrong peaks and more than 1000 m extra vertical
Analyzing and plotting the data reveals its some flaws. First the elevation profile has some false peaks at 5, 7, 12 and 24 km. They are
caused by me using my phone as a tracker which doesn't have the best GPS module and no barometer.
Speed: we were running with up to 120 m/s
Also the speed shows some faulty peaks which often correlate with the wrong elevation data. We were not more than ten times faster (~120 m/s) than Usain Bolt. Even during our downhills 😉. The time data only has second accuracy. So this can lead to wrong speed if the two datapoints
are to close together.
Vertical speed: 15 m/s vertical isn't too bad either
Vertical speed shows a similar story with a 15 m/s maximum.
Map
Looking at the coordinates itself it stands out that on the bottom right the GPS was jumping around and that we lost the trail or took a wrong
turn from time to time.
Due to the bad GPS data I had to do a lot of filtering but we did roughly a 10% longer run in distance and elevation. So I think it was not too bad. But we felt lost without a trail for quite a few times. But we were pretty close to the trail. So I didn't expect too much difference in the metrics.