Skip to main content

Package for detecting HFOs

Project description

HFODetector

PyPI version PyPI - Downloads GitHub code size in bytes

HFODetector is Python package that that is capable of detecting HFOs with either a STE or an MNI detector. Detection speed is increased by using multiprocessing.

Bibtex

If you find our project is useful in your research, please cite:

Zhang, Y., Liu, L., Ding, Y., Chen, X., Monsoor, T., Daida, A., ... & Roychowdhury, V. (2023). PyHFO: Lightweight Deep Learning-powered End-to-End High-Frequency Oscillations Analysis Application. bioRxiv, 2023-08.

Installation

pip install HFODetector

Run time comparison (in minutes)

Linux Linux Windows Windows OS X OS X
STE MNI STE MNI STE MNI
RIPPLELAB 372.83 5647.12 - - - -
pyHFO single-core 57.43 971.35 34.57 933.31 35.90 659.63
pyHFO multi-core 5.18 83.30 9.03 113.59 7.56 114.35

The testing data we are using is 19 patients 10 min data in Refining epileptogenic high-frequency oscillations using deep learning: A novel reverse engineering approach paper.

** Single-core: n-jobs =1 for all machines,

** Multi-core: n-jobs = 32 for Linux (AMD Ryzen Threadripper 2950X), n-jobs = 8 for Windows(Intel i9-13900K) and Mac machines(Apple M1 Pro).

Example usage

STE detector

To use the STE detector, import ste from HFODetector, then a detector can be initialized with the desired parameters by calling ste.STEDetector. To use it to detect HFOs from an .edf file, call the detect_edf method. The detect_edf method takes a path to an edf file as input and returns a tuple containing the channel names and start and end timestamps of detected HFOs. The following code snippet shows how to use the STE detector.

import numpy as np
import pandas as pd
from HFODetector import ste

if __name__ == "__main__":
    edf_path = "example.edf" #change this to your edf path
    detector = ste.STEDetector(sample_freq=2000, filter_freq=[80, 500], 
                rms_window=3*1e-3, min_window=6*1e-3, min_gap=10 * 1e-3, 
                epoch_len=600, min_osc=6, rms_thres=5, peak_thres=3,
                n_jobs=32, front_num=1)
    channel_names, start_end = detector.detect_edf(edf_path)
    # channel_names is a list that is the same length as the number of channels in the edf
    # start_end is a nested list with the same length as channel_names. start_end[i][j][0] and start_end[i][j][1] 
    # will give the start and end index respectively for the jth detected HFO in channel channel_names[i]
    channel_names = np.concatenate([[channel_names[i]]*len(start_end[i]) for i in range(len(channel_names))])
    start_end = [start_end[i] for i in range(len(start_end)) if len(start_end[i])>0]
    start_end = np.concatenate(start_end)
    HFO_ste_df = pd.DataFrame({"channel":channel_names,"start":start_end[:,0],"end":start_end[:,1]})

Which results a pandas dataframe HFO_ste_df a sample is displayed below:

This dataframe has the following 3 columns:

  • channel : name of the channel corresponding to the detected HFO
  • start : start timestamp of the detected HFO in milliseconds
  • end : end timestamp of the detected HFO in milliseconds

MNI detector

To use the MNI detector, import mni from HFODetector, then a detector can be initialized with the desired parameters by calling mni.MNIDetector. To use it to detect HFOs from an .edf file, call the detect_edf method. The detect_edf method takes a path to an edf file as input and returns a tuple containing the channel names and start and end timestamps of detected HFOs. The following code snippet shows how to use the MNI detector.

import numpy as np
import pandas as pd
from HFODetector import mni

if __name__ == "__main__":
    edf_path = "example_edf.edf" #change this to your edf path
    sample_freq=2000 #change this to your sample frequency
    detector = mni.MNIDetector(sample_freq, filter_freq=[80, 500], 
                epoch_time=10, epo_CHF=60, per_CHF=95/100, 
                min_win=10*1e-3, min_gap=10*1e-3, thrd_perc=99.9999/100, 
                base_seg=125*1e-3, base_shift=0.5, base_thrd=0.67, base_min=5,
                n_jobs=32, front_num=1)
    channel_names, start_end = detector.detect_edf(edf_path)
    # channel_names is a list that is the same length as the number of channels in the edf
    # start_end is a nested list with the same length as channel_names. start_end[i][j][0] and start_end[i][j][1] 
    # will give the start and end index respectively for the jth detected HFO in channel channel_names[i]
    channel_names = np.concatenate([[channel_names[i]]*len(start_end[i]) for i in range(len(channel_names))])
    start_end = [start_end[i] for i in range(len(start_end)) if len(start_end[i])>0]
    start_end = np.concatenate(start_end)
    HFO_mni_df = pd.DataFrame({"channel":channel_names,"start":start_end[:,0],"end":start_end[:,1]})

Which results a pandas dataframe HFO_mni_df a sample is displayed below:

This dataframe has the following 3 columns:

  • channel : name of the channel corresponding to the detected HFO
  • start : start timestamp of the detected HFO in milliseconds
  • end : end timestamp of the detected HFO in milliseconds

Contributors:

Department of Electrical and Computer Engineering, University of California, Los Angeles

Division of Pediatric Neurology, Department of Pediatrics, UCLA Mattel Children’s Hospital David Geffen School of Medicine

Contacts:

Please create a github issue or email the following people for further information

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

HFODetector-0.0.24.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

HFODetector-0.0.24-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file HFODetector-0.0.24.tar.gz.

File metadata

  • Download URL: HFODetector-0.0.24.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for HFODetector-0.0.24.tar.gz
Algorithm Hash digest
SHA256 1713f045e8b31ed64ee5abb44e29a520c3a7dd9d928838ed0ed6ac4bc2a601d3
MD5 7586e1b3a74a36efb90bb996124d82a3
BLAKE2b-256 2bceb1064b0d77b8da74b82b729cbb7197e8f12a629c6b65d94fbae52dd9ccc5

See more details on using hashes here.

File details

Details for the file HFODetector-0.0.24-py3-none-any.whl.

File metadata

  • Download URL: HFODetector-0.0.24-py3-none-any.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for HFODetector-0.0.24-py3-none-any.whl
Algorithm Hash digest
SHA256 ac7d8320871871263a476341233beb2ce46c2d5fb9bd186843e0b6fc18fbc7b1
MD5 08ed43997b164bc756d339a8924d7a0f
BLAKE2b-256 4a1e4205013c89154b3f4007551a3ada4e3b54c2e1237c35b147d5d17365d1a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page