Skip to content

Conversation

jacobsimon
Copy link
Collaborator

@jacobsimon jacobsimon commented Aug 2, 2025

Summary

Adds a new method detect_oscillatory_events to the filtering module that allows for detection of ripple-like intervals in signals. Based on this EEG processing example.

Example

Screenshot 2025-08-02 at 2 38 15 PM

Todo

  • Will follow-up with a new user guide as discussed demonstrating usage on real data

Open questions

  • Still having trouble getting the sphinx docs to consistently compile - believe this is a local dev issue.
  • We discussed using apply_bandpass instead of filtfilt but I think as written, both may be necessary unless we think it's ok to skip the smoothing step—or could use Tsd.smooth here?
  • Does the testing approach make sense / seem adequate here?

@jacobsimon jacobsimon requested a review from gviejo as a code owner August 2, 2025 18:46
Copy link
Contributor

@gviejo gviejo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly minor comments but everything else is good.

Parameters
----------
lfp : Tsd
Should be a single channel raw lfp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary raw lfp. I would just say

Suggested change
Should be a single channel raw lfp
1-dimensional time series

min_inter_duration : float
The minimum duration between two events otherwise they are merged (in seconds)
wsize : int, optional
The size of the window for digitial filtering
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The size of the window for digitial filtering
The size of the window for digital filtering

the power, amplitude, and peak_time
"""
lfp = lfp.restrict(epoch)
frequency = lfp.rate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be passed as a parameter 'fs' with default None.
If it's None, use tsd.rate. If it's a Number, use the passed fs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interval set of detected events with metadata containing
the power, amplitude, and peak_time
"""
lfp = lfp.restrict(epoch)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lfp = lfp.restrict(epoch)
tsd = tsd.restrict(epoch)

It can be anything

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to data in 84fc658

peak_times = []

for s, e in osc_ep.values:
seg = signal.restrict(nap.IntervalSet(s, e))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can be faster with :

Suggested change
seg = signal.restrict(nap.IntervalSet(s, e))
seg = signal.get(s, e)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 84fc658

"freq_band, thresh_band, start, end",
[
((10, 30), (1, 10), 0, 2),
((40, 60), (1, 10), 3, 5),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be one more case which is the absence of detected events.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added! I've noticed certain freq ranges seem to produce false positives though - going to keep testing a bit

@gviejo
Copy link
Contributor

gviejo commented Sep 10, 2025

Could you try to merge dev? The issue with the elife link should have been fixed within dev.

@jacobsimon jacobsimon changed the base branch from main to dev September 11, 2025 16:47
@jacobsimon jacobsimon merged commit 6751c8b into pynapple-org:dev Sep 13, 2025
18 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants