Skip to main content

Load, analyze and plot GPS data from GPX files with numpy/pandas

Project description

About

Load GPS data from GPX files into Python as a numpy arrays and pandas DataFrames. Initial parsing done using the gpxpy package. Trajectory plotting on a map available using mplleaflet.

Quick Start

Install

pip install gpxo

Load Track

import gpxo
track = gpxo.Track('ExampleTrack.gpx')

(it is possible to indicate which track or segment to consider during instantiation, by default it is the first one). track.data is a pandas DataFrame containing time, position, elevation etc.; usual pandas methods can be used to analyze, manipulate and plot data. Individual columns are also available as numpy arrays as attributes of the class (see below).

Detailed Contents

Track class

Load, inspect and plot GPX data using the Track class, with the following methods and attributes.

Methods

  • smooth(): smooth position and elevation data (see gpxo.smooth() below),
  • plot(): plot trajectory data using a combination of shortnames (see shortnames below); also takes matplotlib.pyplot.plot() arguments/kwargs,
  • map(): plot trajectory on a map, using mplleaflet.show(),
  • closest_to(): find index of point in trajectory closest to a (lat, long) point.

Basic Attributes

(some may not be available depending on actual data present in the GPX file)

  • latitude (numpy array): latitude in °,
  • longitude (numpy array): longitude in °,
  • elevation (numpy array): elevation in meters,
  • time (numpy array): local time expressed as a datetime.datetime.

Property attributes

(Read-only, and calculated/updated from basic attributes; some may not be available depending on actual data present in the GPX file)

  • seconds (numpy array): total number of seconds since beginning of track,
  • distance (numpy array): total distance (km) since beginning of track,
  • velocity (numpy array): instantaneous velocity (km/h),
  • compass (numpy array): instantaneous compass bearing (°),
  • data (pandas DataFrame): all above attributes in a single dataframe.

Miscellaneous

Outside of the Track class, the following standalone function is also available:

  • compass(pt1, pt2): compass bearing (°) between pt1 (lat1, long1) and pt2 (lat2, long2),
  • closest_pt(pt, trajectory): index of closest pt in trajectory (latitudes, longitudes) to specified pt (lat, long),
  • smooth(x, n, window): smooth 1-d array with a moving window of size n and type window.

Short names

Short name Corresponding data
t time
s duration (s)
d distance (km)
v velocity (km/h)
z elevation (m)
c compass (°)

Examples

See Jupyter Notebook Examples.ipynb (https://github.com/ovinc/gpxo/blob/master/Examples.ipynb) for a detailed example using real GPX data.

Quick example: show the path of a GPX file on a map with color-coding corresponding to elevation:

import gpxo
track = gpxo.Track('ExampleTrack.gpx')
track.map(plot='scatter', c=track.elevation, cmap='plasma')

Troubleshooting

In case of the following error:

'XAxis' object has no attribute '_gridOnMajor

when using the map() method, try downgrading Matplotlib to version <= 3.3.2 or install a forked version of mplleaflet (see https://github.com/jwass/mplleaflet/issues/75).

Information

Requirements

Python >= 3.6

Dependencies

(automatically installed by pip if necessary)

Author

Olivier Vincent

(ovinc.py@gmail.com)

License

BSD 3-Clause (see LICENCE file)

BSD 3-Clause License

Copyright (c) 2020, Olivier VINCENT All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpxo-0.1.6.tar.gz (3.5 MB view details)

Uploaded Source

Built Distribution

gpxo-0.1.6-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file gpxo-0.1.6.tar.gz.

File metadata

  • Download URL: gpxo-0.1.6.tar.gz
  • Upload date:
  • Size: 3.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for gpxo-0.1.6.tar.gz
Algorithm Hash digest
SHA256 ef56bae181e9f3c5b6f824d17b01c5ea70a4a802ea60e5d93079e7e5a5b1f2a9
MD5 42633db327c4352c1f51bb7aef79e4e8
BLAKE2b-256 5840eab89a56552888cb767e704bee55effd5d722a7c8c5133f8233fcff93310

See more details on using hashes here.

File details

Details for the file gpxo-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: gpxo-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for gpxo-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b9f6e78f3371745e75bde1f11498bdecf7a2a90d2c6d4ae9cc4da142a8805164
MD5 0db7c54f7bf703244300bed68e051da0
BLAKE2b-256 e992edf02142404619d3a1353d29d35689bce16a0729148630aaf339f4e204e1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page