Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rflperry committed Jan 3, 2022
0 parents commit ee8b30c
Show file tree
Hide file tree
Showing 10 changed files with 716 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Ronan Perry

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# strava_local_heatmap.py

Python script to create static and animated heatmaps from Strava *.fit* files

## Usage

* Download your bulk data (https://support.strava.com/hc/en-us/articles/216918437-Exporting-your-Data-and-Bulk-Export)
* Install the python dependencies from `requirements.txt`
* Run `python strava_local_heatmap.py`

### Command-line options

```
usage: create_map.py [-h] [--dir DIR] [--filter FILTER] [--year YEAR [YEAR ...]]
[--bounds BOUND BOUND BOUND BOUND] [--output OUTPUT] [--zoom ZOOM] [--sigma SIGMA]
[--orange] [--alpha] [--gif] [--fps] [--max-time] [--csv]
optional arguments:
-h, --help show this help message and exit
--dir DIR FIT files directory (default: activities)
--filter FILTER FIT files glob filter (default: *.fit)
--year YEAR [YEAR ...]
FIT 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 Uses the strava background color scheme
--alpha Intensity of background color scheme (default: 0.7)
--gif Creates an animated gif rather than static image
--fps Frames per second if gif
--max-time Maximum duration of the gif, in seconds
--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=](https://www.openstreetmap.org))

On the use of histogram equalization: [https://medium.com/strava-engineering/the-global-heatmap-now-6x-hotter](https://medium.com/strava-engineering/the-global-heatmap-now-6x-hotter-23fc01d301de)

## Examples

command|output
-------|------
`python create_map.py --dir data/archive_01-02-2021/activities/ --bounds 48.457 48.605 8.88 9.146 --orange --output outputs/tuebingen_heatmap`|![tuebingen_heatmap.png](outputs/tuebingen_heatmap.png)
`python create_map.py --dir data/archive_01-02-2021/activities/ --bounds 48.457 48.605 8.88 9.146 --orange --output outputs/tuebingen_heatmap --gif`|![tuebingen_gif.png](outputs/tuebingen_heatmap.gif)

### Python Requirements

```
numpy
matplotlib
fitdecode
pandas
Pillow
imageio
```

Run `pip install -r requirements.txt` from the repository folder to install.
40 changes: 40 additions & 0 deletions create_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from argparse import ArgumentParser, Namespace
from src.generate_heatmaps import generate_gif, generate_heatmap

if __name__ == '__main__':
parser = ArgumentParser(description='Generate a PNG heatmap from local Strava fit files')
# epilog='Report issues to https://github.com/remisalmon/Strava-local-heatmap/issues')

parser.add_argument('--dir', default='activities/',
help='fit files directory')
parser.add_argument('--filter', default='*.fit*',
help='fit files glob filter (default: *.fit*)')
parser.add_argument('--year', nargs='+', default=[],
help='fit files year(s) filter (default: all)')
parser.add_argument('--bounds', type=float, nargs=4, metavar='BOUND', default=[-90.0, +90.0, -180.0, +180.0],
help='heatmap bounding box as lat_min, lat_max, lon_min, lon_max (default: -90 +90 -180 +180)')
parser.add_argument('--output', default='heatmap',
help='file name (default: heatmap)')
parser.add_argument('--gif', action='store_true',
help='heatmap name (default: heatmap.png)')
parser.add_argument('--zoom', type=int, default=-1,
help='heatmap zoom level 0-19 or -1 for auto (default: -1)')
parser.add_argument('--sigma', type=int, default=2,
help='heatmap Gaussian kernel sigma in pixel (default: 2)')
parser.add_argument('--orange', action='store_true',
help='non-grayscale background')
parser.add_argument('--csv', action='store_true',
help='also save the heatmap data to a CSV file')
parser.add_argument('--alpha', type=float, default=0.6,
help='alpha value for background, between 0 and 1 (default: 0.6)')
# parser.add_argument('--crop', action='store_true',
# help='crop min/max lat/lon bounds based on data.')
parser.add_argument('--fps', type=int, default=4,
help='gif frames per second (default=4)')

args = parser.parse_args()

if args.gif:
generate_gif(args)
else:
generate_heatmap(args)
Binary file added fonts/FreeMono.ttf
Binary file not shown.
Binary file added fonts/FreeMonoBold.ttf
Binary file not shown.
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
numpy>=1.20
matplotlib>=3.4
fitdecode
pandas
Pillow
imageio
Empty file added src/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions src/generate_gif.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Tools for generating a sheatmap gif from latitude and longitude data.
MIT License
Copyright (c) 2021 Ronan Perry
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

# imports
import os
import glob
import time

import numpy as np
import matplotlib.pyplot as plt

from urllib.error import URLError
from urllib.request import Request, urlopen
from .parse_fit import get_dataframes
Loading

0 comments on commit ee8b30c

Please sign in to comment.