GithubHelp home page GithubHelp logo

dodo-saba / fit2gpx Goto Github PK

View Code? Open in Web Editor NEW
77.0 4.0 17.0 243 KB

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

License: GNU General Public License v3.0

Python 100.00%
python gpx gpx-files gpx-writer gpx-data fit strava strava-data converter file-format

fit2gpx's Introduction

made-with-python Documentation Status GitHub license

Buy Me A Coffee

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.

  • FIT is a GIS data file format used by Garmin GPS sport devices and Garmin software
  • GPX is an XML based format for GPS tracks.

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

  • Pre-GPDR, you could bulk export all your Strava activities as GPX files.
  • Post-GDPR, you can export an archive of your account. Whilst this includes much more data, activity GPS files are now downloaded in their original file format (eg. GPX or FIT format, some gzipped, some not) and named like 2500155647.gpx, 2500155647.gpx.gz, 2500155647.fit, and 2500155647.fit.gz.
  • How to bulk export you Strava Data

Overview

The fit2gpx module provides two converter classes:

  • Converter: used to convert a single or multiple FIT files to pandas dataframes or GPX files
  • StravaConverter: used to fix all the Strava Bulk Export problems in three steps:
    1. Unzip GPX and FIT files
    2. Add activity metadata to existing GPX files
    3. Convert FIT files to GPX including activity metadata from Strava)

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')
  • df_laps: information per lap: lap number, start time, total distance, total elapsed time, max speed, max heart rate, average heart rate
  • df_points: information per track point: longitude, latitude, altitude, timestamp, heart rate, cadence, speed, power, temperature
    • Note the 'enhanced_speed' and 'enhanced_altitude' are also extracted. Where overlap exists with their default counterparts, values are identical. However, the default or enhanced speed/altitude fields may be empty depending on the device used to record (detailed information).

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.

fit2gpx's People

Contributors

agostonszabo avatar bananer avatar dodo-saba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fit2gpx's Issues

Altitude/Elevation returns NaN

Hi, thanks a lot for this tool!
Altitude/Elevation returns NaN both when reading fit (Strava) to df or when exporting to gpx.
Please, find attached one of my activities.
Thank you and best,

Pedro
8718041686.fit.gz

need more instructions.

Hi
Since I'm not a programmer but I do know how to follow instructions I'm stuck at yours. How exactly can I achieve converting a bunch of FIT files in a directory?

I'm confused about where to put code from the instructions.

Add a CLI

Would it be possible to embed a CLI inside the package, to even more simplify its usage? A very naive version (the one from the README) would be perfect eg something like:

fit2gpx <input_folder> <output_folder>

I don't know how hard it is to embedded an exec, but that would be awesome! And thanks a lot for this package :)

df_acts has NaN values

Was getting error below. Somewhere in the 'activites.csv' file there are NaN values that cause an issue. Not sure what the best way to fix it is, but simply adding a line 'df_acts = df_acts.fillna('')' worked for me.

Traceback (most recent call last):
File "gpxconvert.py", line 20, in
strava_conv.strava_fit_to_gpx()
File "env/lib/python3.8/site-packages/fit2gpx.py", line 341, in strava_fit_to_gpx
md = df_acts.loc[df_acts['Filename'].str.contains(f_activity)].iloc[0, :].to_dict()
File "env/lib/python3.8/site-packages/pandas/core/indexing.py", line 967, in getitem
return self._getitem_axis(maybe_callable, axis=axis)
File "env/lib/python3.8/site-packages/pandas/core/indexing.py", line 1181, in _getitem_axis
elif com.is_bool_indexer(key):
File "/env/lib/python3.8/site-packages/pandas/core/common.py", line 144, in is_bool_indexer
raise ValueError(na_msg)
ValueError: Cannot mask with non-boolean array containing NA / NaN values

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.