import endaq
endaq.plot.utilities.set_theme()
import plotly.graph_objects as go

#Get Accel
accel = endaq.ide.get_primary_sensor_data('https://info.endaq.com/hubfs/ford_f150.ide',measurement_type='accel',
    time_mode='datetime')

#Filter
accel = endaq.calc.filters.butterworth(accel,low_cutoff=2)

#Get Peak Indexes
indexes = endaq.calc.stats.find_peaks(
    accel, time_distance=2,
    threshold_reference="rms", threshold_multiplier=5.0)

#Generate a Dataframe with Just the Peak Events
df_peaks = accel.iloc[indexes]

#Generate Shaded Bar Plot of All Data
fig = endaq.plot.rolling_min_max_envelope(accel, plot_as_bars=True, opacity=0.7)

#Add Peaks & Display
fig.add_trace(
    go.Scatter(
        x=df_peaks.index,
        y=df_peaks.abs().max(axis=1).to_numpy(),
        mode='markers', name='Peak Events', marker_symbol='x', marker_color='white'
        )
    )
fig.show()