mne-tools / mne-hfo

Estimate/compute high-frequency oscillations (HFOs) from iEEG data that are BIDS and MNE compatible using a scikit-learn-style API.
http://mne.tools/mne-hfo/
BSD 3-Clause "New" or "Revised" License
13 stars 16 forks source link

More detectors: MorphologyDetector #3

Open adam2392 opened 3 years ago

adam2392 commented 3 years ago

Describe the problem

These are detectors that kind of have some open-source matlab code, so we can make an attempt at porting this over into mne-hfo.

Describe your solution

Import over morphologydetector: https://github.com/HFO-detect/HFO-detect-matlab/blob/master/hfo-detect-toolbox/Morphology%20Detector/func_doMorphologyDetector.m

Describe possible alternatives

Both detectors seem to have a very large number of hyperparameters, so it might be difficult to match them perfectly.

adam2392 commented 3 years ago

Zurich was kind enough to send over the following detector matlab repo:

https://github.com/ZurichNCH/Automatic-High-Frequency-Oscillation-Detector

adam2392 commented 3 years ago

It seems the morphology detector has quite a bit of hyperparmaeters, and pipelines including a baseline step, so it would be good to sketch this out first.

adam2392 commented 3 years ago

Hyperparameters list I'm getting:

  1. (optional) baseline signal: passed in baseline signal, else algorithm tries to compute baseline by itself
  2. maxNoisemuV: threshold for selecting indices of the baseline signal. Either preset, or set as a standard deviation of the signal (probably best to set it as a standard deviation)
  3. baselineThreshold: threshold used for event selection based on the baseline envelope
  4. Filtbaselinethreshold: value for event selection based on baseline filtered signal

General algorithm:

  1. Load data (scikit-learn API style) and perform checks. See other detectors for how data validiation takes place.
  2. Band-pass filter and compute the envelope: BP filter with FIR filter for all channels. Upper envelope of the filtered signal is then computed.
  3. Find baseline for signal on every channel
  4. Find events of interest
  5. Post detection statistics

Sub-Functions to implement

  1. compute_envelope (I think already implemented, but needs to verify that it is the same)
  2. filterSignal is zero-phase forward/reverse IIR filtering, with coefficients set in parameters, non-recursive.

Baseline

A big chunk of code seems to be dedicated to "defining" a baseline.

  1. stockwelltransform
  2. calculate entropy (not sure if this is on the stockwell, or raw signal)
  3. get time intervals with threshold high entropy
  4. compute the channel baseline
  5. set baseline threshold
adam2392 commented 3 years ago

Hi @cleemesser! if you're interested in helping develop this repo out, I managed to refactor RMS/Linelenght detectors into a scikit-learn API and just working on the entire pipeline now.

Thsi isssue is one of the main ones now in my head to get this repo operational. The Morphology detector has some open-access validation data online and it's also available in matlab (just needs Python conversion).

If you're interested in contributing more, perhaps we should setup a call?