Wolfram Blog
Mariusz Jankowski

A Rat Race, or a Great Way to Start the Day

March 24, 2015 — Mariusz Jankowski

Recently, during a particularly severe patch of winter weather and much too much shoveling of snow off my driveway, I decided, with help from the Wolfram Language, to bring back memories of fairer weather by looking at commuting to work on a bicycle.

This past year, I finally succumbed to the increasingly common practice of recording personal activity data. Over the last few years, I’d noted that my rides had become shorter and easier as the season progressed, so I was mildly interested in verifying this improvement in personal fitness. Using nothing more than a smart phone and a suitable application, I recorded 27 rides between home and work, and then used the Wolfram Language to read, analyze, and visualize the results.

Here is a Google Earth image showing my morning bike route covering a distance of a little under 11 miles, running from east to west.

Morning commute to work

To transfer data from the smart phone, I used GPX (GPS Exchange Format), a file format supported by major GPS device manufacturers and available in many software applications. A typical GPX file includes time-stamped location and elevation data, and the Wolfram Language returns this data as a list of rules, descriptively named Geometry, PointElevation, and PointTimestamp.

This displays a fragment of one of the GPX data files:

GPX data file with time-stamped location and elevation data

Taking advantage of new geographic data and computation functionality in the Wolfram Language and the available time and position data, I quickly and easily created an animation of the day’s ride (for details of functions, position, and time, see the Initializations in the attached CDF). Click the Play button to view animation.

Creating animation for morning bike ride

More interestingly, and with just a bit more effort, I next compared all the morning rides of the season in a single animated race, in effect a rat race to work! The season’s leader is shown in yellow, of course!

All morning rides in a race to work

The results of this rat race are as follows:

Results of bike riding rat race

Now for a quick peek at ride times in chronological order. This clearly supports my earlier observation that ride times improved as the season progressed, and as I logged more miles on the road bike.

Ride times in chronological order displayed as bar graph

While the preceding calculations and visualizations are nice, we can do much more. The GPX files contain time-stamped elevation data, so not only does this allow easy visualization of the common road profile, but even better: detection of downhill and uphill segments of the route via new signal processing peak detection functionality.

First, here is the standard road profile:

Standard road profile with visualization

Prior to locating the peaks and valleys, I smooth the elevation data so as to capture only the large-scale local maxima and minima in the signal. To accomplish this, I first use uniform linear resampling to correct for the highly irregular intervals at which the data was captured, then blur it with a GaussianFilter.

Smooth elevation data capturing large-scale maxima and minima only

The smoothing operation removes spurious peaks and valleys in the elevation data. I determine the remaining large-scale peaks using FindPeaks and segment the route into ascending and descending sections.

Determining large-scale peaks with FindPeaks

This shows the uphill and downhill sections of the morning ride on an elevation plot:

Uphill and downhill sections on elevation plot

For an arguably even more useful visualization, here are the rising and falling segments of the ride on a map:

Rise and fall segments of bike ride on map

The approximate distances of the uphill and downhill sections are readily available from the ascend and descend lists computed earlier. The following result confirms the simple truth that going to work is always harder (i.e., uphill), and therefore less pleasant than the return trip.

Results from uphill downhill going to and from work

I am already looking forward to the next season of riding and more fun in analyzing my data using the Wolfram Language.

Download this post as a Computable Document Format (CDF) file.

Leave a Comment

2 Comments


Jan Brugård

Nice post Mariusz. I started to do some work on something similar a few days ago actually. Now I can cut some corners by using your code. :-)

Posted by Jan Brugård    March 24, 2015 at 4:14 pm
Michael Stern

I used to do this sort of analysis with heart rate data, but transferring the raw data to Mathematica became enough of a hassle that I stopped. My HRM can upload automatically to RunKeeper, and Mathematica can download data from runkeeper but, for whatever reason, not the HRM data. I wish that would be fixed.

Posted by Michael Stern    March 26, 2015 at 3:55 pm


Leave a comment

Loading...

Or continue as a guest (your comment will be held for moderation):