Code Monkey home page Code Monkey logo

strava-local-heatmap's Introduction

strava_local_heatmap.py

Python script to reproduce the Strava Global Heatmap (www.strava.com/heatmap) with local GPX files

Optimized for cycling activities 🚴

Features

  • Minimal Python dependencies (numpy+matplotlib)
  • Fast (parse 3x faster than gpxpy.parse)

Usage

Command-line options

usage: strava_local_heatmap.py [-h] [--dir DIR] [--filter FILTER] [--year YEAR [YEAR ...]]
                               [--bounds BOUND BOUND BOUND BOUND] [--output OUTPUT] [--zoom ZOOM] [--sigma SIGMA]
                               [--orange] [--csv]

optional arguments:
  -h, --help            show this help message and exit
  --dir DIR             GPX files directory (default: gpx)
  --filter FILTER       GPX files glob filter (default: *.gpx)
  --year YEAR [YEAR ...]
                        GPX files year(s) filter (default: all)
  --bounds BOUND BOUND BOUND BOUND
                        heatmap bounding box as lat_min, lat_max, lon_min, lon_max (default: -90 +90 -180 +180)
  --output OUTPUT       heatmap name (default: heatmap.png)
  --zoom ZOOM           heatmap zoom level 0-19 or -1 for auto (default: -1)
  --sigma SIGMA         heatmap Gaussian kernel sigma in pixel (default: 1)
  --orange              not a heatmap...
  --csv                 also save the heatmap data to a CSV file

Note: ZOOM is OpenStreetMap zoom level (the number following map= in www.openstreetmap.org/#map=)

On the use of histogram equalization: https://medium.com/strava-engineering/the-global-heatmap-now-6x-hotter

Examples

command output
strava_local_heatmap.py heatmap.png
strava_local_heatmap.py --orange orange.png
strava_local_heatmap.py --csv See https://umap.openstreetmap.fr/en/map/demo-heatmap_261644 (by @badele)

Projects using strava_local_heatmap.py

JeSuisUnDesDeux

Troubleshooting

Arch Linux: sudo pacman -S tk (see here)

strava-local-heatmap's People

Contributors

badele avatar chrinimue avatar remisalmon 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  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  avatar  avatar  avatar  avatar

strava-local-heatmap's Issues

ERROR during import of DJI flight logs

First: Great tool and thank you for your effort!

By importing GPX-tracks from my DJI drone I get in some trouble.

RuntimeWarning: invalid value encountered in true_divide
  data = (data-data.min())/(data.max()-data.min()) # normalize to [0,1]

The heatmap is saved but without any tracks. I pinpointed the error to line 239f. It looks like the data array is not correctly assigned.

    for i, j in ij_data:
        data[i-sigma_pixel:i+sigma_pixel, j-sigma_pixel:j+sigma_pixel] += 1.0

At the end the data array contains only zeros.

I uploaded the gpx track here for debugging (just rename it to *.gpx):
DJIFlightRecord_2022-02-09_16-07-50.txt

I am ready to support, but at the moment I am not able to find the problem. ;-)
Thanks in advance.
nico

Separation of code and data

I really like the script and its output and would like to use it in more flexible ways. It currently expects the data to be in a flat directory full of GPX files. One can only take all files in that directory of specify a glob that matches them. I have a hierarchy of directories where I have like one for cycling, then one for different types of trips. I would like to have one heatmap with my shopping, my recreational tours, and so on. But then I want to have one one layer up with all the GPX files below, so basically */*.gpx and *.gpx. As one can only pass one glob, it doesn't work.

Ideally one could refactor the heatmap code into a library such that one can use that as part of a driver script. I see that there is a pull request that tries to introduces some part of this but uses the now outdated setup.py mechanism instead of Poetry.

I'd be happy to refactor the code, but wanted to talk to you first. Are you still active with this code? Shall I go ahead and refactor, should I do a hard fork or something in between?

Black background / no tiles

Wikimedia tile server is offline. I tried experimenting with others such as openstreetmap, for example like this:

OSM_TILE_SERVER = 'https://tile.openstreetmap.org/{}/{}/{}.png'

I can download these tiles manually, but for some reason, the generated output is still a big black background. There's no warnings or errors during run.

Unexpected results when using year filter on "large" dataset

Problem

When using the year filter and at the end the script uses only about 500 tracks from over 15000 (1 year out of 10) my plotted heatmap is nearly completely black.

Assumption

When calculating the strenght/glow/... when drawing the heatmap seems to work with the count of all files and not only filtered ones. So when taking into account all the tracks from all years the tracks from 2022 will only be a tiny part of them resulting in a nearly black image. But I am not able to find that place in the code.

Examples

All data:
heatmap-dresden-all_thumb

Filtered by year 2022:
heatmap-dresden-2022_thumb
There are some red pixels in the original image. So it wants to show some data.

Used Tracks for 2022:
trackmap-dresden-2022_tumb

Possible workaround (well, not really)

In addition to one folder containing all files on could create separate folders for each year .... but at he same time this would make the year filter obsolete.

Number of files limit?

Hello,

I tried to process thousands of files but then I saw the memory growing growing and then the process get killed...
Is there a plan to may-be better manage memory when using lot of files?

Forcing the output size?

Hello,

I'v been pulling my hairs on this for quite few days now and I'm struggling to find a simple way to have the output at a specific size with the route centered (i.e: 1080x1920, or 800x800..). Not sure if that's currently possible but would love advice on direction as the level of maths in it is a way beyond my understanding...

Merci

Error

Hi

I have the following error reading some GPX file. I guess one GPX could be corrupted but it could be good that the program is more robust and walk over:
Reading activity_Afternoon_spring_walk_on_19_04_2021_22MWC2ctUdab3XyRBzGowTNJtTM.gpx
Reading activity_Afternoon_walk_in_the_β˜€οΈon_28_02_2021_22MR1PQbnlYKSLZy3ZatOHsNev7.gpx
Traceback (most recent call last):
File "C:\temp\GPX\strava_local_heatmap.py", line 349, in
main(args)
File "C:\temp\GPX\strava_local_heatmap.py", line 123, in main
for line in file:
File "C:\Users*
*\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 433: character maps to

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.