bycycle-tools / bycycle

Cycle-by-cycle analysis of neural oscillations.

Home Page:https://bycycle-tools.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Negative amplitude consistency values

iinnpp opened this issue · comments

I have noticed that amplitude consistency ('amp_consistency' in computed df) values are not limited to interval [0, 1] even though amp_consistency_threshold should be set between 0 and 1.
Other consistency values (period_consistency and monotonicity) seems to be within [0,1]. I am wondering whether the amplitude consistency is handled differently/not normalized?

(bycycle v 1.0.0)

The code I have used to test:

from neurodsp.sim import sim_combined
from bycycle.features import compute_features, compute_shape_features
from bycycle.plts import plot_burst_detect_summary

# simulate bursty oscillation
n_seconds = 0.5
fs = 1000
components = {'sim_bursty_oscillation': {'freq': 150, 'enter_burst': .4, 'leave_burst': .4},
              'sim_powerlaw': {'exponent': -2}}
sig = sim_combined(n_seconds, fs, components)

# do bycycle
thresholds = {'amp_fraction_threshold': 0.3,
              'amp_consistency_threshold': 0.5,
              'period_consistency_threshold': 0.5,
              'monotonicity_threshold': 0.8,
              'min_n_cycles': 3}
df = compute_features(sig, fs, f_range=(100, 200), threshold_kwargs=thresholds)
plot_burst_detect_summary(df, sig, fs, thresholds)

The outcome:
amp_consistency_test

Hi @iinnpp, thanks for the bug report!

This bug occurs when a peak has a lower voltage than adjacent troughs. The amp_bug branch fixes this by taking the absolute value of volt_decay and volt_rise. However, cycles with a peak that isn't a peak should probably receive a nan value. Ideally, this should be fixed when determining the location of cyclepoints.

Hi @ryanhammonds, thanks a lot for a super quick fix!

Resolved in #92 with a zero-floor on amp_consistency.