gc_plots/ride_data.py

53 lines
1.1 KiB
Python

import numpy as np
from scipy.signal import butter, filtfilt
sample_freq = 1.0
cutoff_freq = 0.05
order = 1
def butter_lowpass_filter(data, cutoff, fs, order=5):
b, a = butter(order, cutoff, fs=fs, btype="low", analog=False)
y = filtfilt(b, a, data)
return y
activity = GC.activity()
power = np.array(activity["power"])
seconds = np.array(activity["seconds"])
GC.setChart(
title="Ride Data",
type=GC.CHART_LINE,
animate=False,
legpos=GC_ALIGN_TOP,
stack=False,
)
GC.addCurve(
name="Power",
x=seconds,
y=power,
xaxis="Time",
yaxis="Power",
color="yellow",
line=GC_LINE_SOLID,
symbol=GC_SYMBOL_NONE,
size=3,
opacity=100,
opengl=False,
)
GC.addCurve(
name="Power Smoothed",
x=seconds,
y=butter_lowpass_filter(power, cutoff_freq, sample_freq, order),
xaxis="Time",
yaxis="Power",
color="red",
line=GC_LINE_SOLID,
symbol=GC_SYMBOL_NONE,
size=3,
opacity=100,
opengl=False,
)
GC.setAxis("Power", min=0, max=800, type=GC.AXIS_CONTINUOUS)
GC.setAxis('Time', type=GC.AXIS_TIME)