-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_gpx copy.py
71 lines (60 loc) · 1.87 KB
/
plot_gpx copy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import gpxo
import sys
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from fit_tool.fit_file import FitFile
from fit_tool.profile.messages.record_message import RecordMessage
def plot_gpxo(filepath):
track = gpxo.Track(filepath)
track.map(plot='scatter', c=track.elevation, cmap='plasma')
track.map(plot='scatter', c=track.elevation, cmap='plasma')
track.show()
def plot_fit_file(filepath):
""" Analyze a FIT file
"""
print(f'Loading activity file...')
app_fit = FitFile.from_file(filepath)
timestamp1 = []
power1 = []
distance1 = []
speed1 = []
cadence1 = []
for record in app_fit.records:
message = record.message
if isinstance(message, RecordMessage):
timestamp1.append(message.timestamp)
distance1.append(message.distance)
power1.append(message.power)
speed1.append(message.speed)
cadence1.append(message.cadence)
start_timestamp = timestamp1[0]
time1 = np.array(timestamp1)
power1 = np.array(power1)
speed1 = np.array(speed1)
cadence1 = np.array(cadence1)
time1 = (time1 - start_timestamp) / 1000.0 # seconds
#
# Plot the data
#
ax1 = plt.subplot(311)
ax1.plot(time1, power1, '-o', label='app [W]')
ax1.legend(loc="upper right")
plt.xlabel('Time (s)')
plt.ylabel('Power (W)')
plt.subplot(312, sharex=ax1)
plt.plot(time1, speed1, '-o', label='app [m/s]')
plt.legend(loc="upper right")
plt.xlabel('Time (s)')
plt.ylabel('speed (m/s)')
plt.subplot(313, sharex=ax1)
plt.plot(time1, cadence1, '-o', label='app [rpm]')
plt.legend(loc="upper right")
plt.xlabel('Time (s)')
plt.ylabel('cadence (rpm)')
plt.show()
if __name__ == "__main__":
filepath = sys.argv[1]
plot_fit_file(filepath)