Home

Awesome

made-with-python Documentation Status GitHub license

<a href="https://www.buymeacoffee.com/doriansaba" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-3.svg" alt="Buy Me A Coffee" style="height: 60px" ></a>

fit2gpx -- convert .fit to .gpx

This is a simple Python library for converting .FIT files to .GPX files. It also includes tools to convert Strava data downloads in bulk to GPX.

When: Use Cases

  1. You need to convert .FIT files to pandas dataframe (e.g. for data analysis)
  2. You need to convert .FIT files to .GPX
  3. You need to fix files downloaded from Strava by converting the raw .FIT files to their .GPX counterparts

Why

Motivation

I decided to create this package after spending a few hours searching for a simple solution to quickly convert hundreds of FIT files to GPX. I needed to do this as GIS applications do not parse FIT files. Whilst a few solutions existed, they are command line scripts which offered very little flexibility.

Relevance to Strava

Overview

The fit2gpx module provides two converter classes:

Use Case 1: FIT to pd.DataFrame

Step 1: Import module and create converter object

from fit2gpx import Converter

conv = Converter()

Step 2: Convert FIT file to 2 pd.DataFrame: fit_to_dataframes()

df_lap, df_point = conv.fit_to_dataframes(fname='3323369944.fit')

Use Case 2: FIT to GPX

Import module and create converter object

from fit2gpx import Converter

conv = Converter()          # create standard converter object

Use case 2.1: convert a single FIT file: fit_to_gpx()

gpx = conv.fit_to_gpx(f_in='3323369944.fit', f_out='3323369944.gpx')

Use case 2.2: convert many FIT files to GPX files: fit_to_gpx_bulk()

conv.fit_to_gpx_bulk(dir_in='./project/activities/', dir_out='./project/activities_convert/')

Use Case 3: Strava Bulk Export Tools (FIT to GPX conversion)

Copy the below code, adjusting the input directory (DIR_STRAVA), to fix the Strava Bulk Export problems discussed in the overview.

from fit2gpx import StravaConverter

DIR_STRAVA = 'C:/Users/dorian-saba/Documents/Strava/'

# Step 1: Create StravaConverter object 
# - Note: the dir_in must be the path to the central unzipped Strava bulk export folder 
# - Note: You can specify the dir_out if you wish. By default it is set to 'activities_gpx', which will be created in main Strava folder specified.

strava_conv = StravaConverter(
    dir_in=DIR_STRAVA
)

# Step 2: Unzip the zipped files
strava_conv.unzip_activities()

# Step 3: Add metadata to existing GPX files
strava_conv.add_metadata_to_gpx()

# Step 4: Convert FIT to GPX
strava_conv.strava_fit_to_gpx()

Dependencies

pandas

pandas is a Python package that provides fast, flexible, and expressive data structures designed to make working with "relational" or "labeled" data both easy and intuitive.

gpxpy

gpxpy is a simple Python library for parsing and manipulating GPX files. It can parse and generate GPX 1.0 and 1.1 files. The generated file will always be a valid XML document, but it may not be (strictly speaking) a valid GPX document.

fitdecode

fitdecode is a rewrite of the fitparse module allowing to parse ANT/GARMIN FIT files.