Skip to content

Commit

Permalink
Adding CRP
Browse files Browse the repository at this point in the history
Hypnogram -> Annotation
readthedocs fix
0.1.0a
  • Loading branch information
xmival00 committed Jan 3, 2024
1 parent c896398 commit c69843c
Show file tree
Hide file tree
Showing 22 changed files with 344 additions and 46 deletions.
12 changes: 10 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ sphinx:
formats:
- pdf

# Optionally set the version of Python and requirements required to build your docs
build:
os: ubuntu-22.04
tools:
python: "3.6"

sphinx:
configuration: docs/source/conf.py

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.6
install:
- requirements: docs/requirements.txt
- method: pip
path: .
path: .
32 changes: 27 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,47 @@ Installation
Cite
"""""""""""""""""""""""""""
When use whole, parts, or are inspired by, we appreciate you acknowledge and refer these journal papers:
This toolbox was developed during multiple projects we appreciate you acknowledge when using or inspired by this toolbox.
The toolbox as a whole was developed during the following projects:

| F. Mivalt et V. Kremen et al., “Electrical brain stimulation and continuous behavioral state tracking in ambulatory humans,” J. Neural Eng., vol. 19, no. 1, p. 016019, Feb. 2022, doi: 10.1088/1741-2552/ac4bfd.
| V. Sladky et al., “Distributed brain co-processor for tracking spikes, seizures and behaviour during electrical brain stimulation,” Brain Commun., vol. 4, no. 3, May 2022, doi: 10.1093/braincomms/fcac115.
For different modules, please see below.

| Mivalt F, Kremen V, Sladky V, Balzekas I, Nejedly P, Gregg N, Lundstrom BN, Lepkova K, Pridalova T, Brinkmann BH, et al. Electrical brain stimulation and continuous behavioral state tracking in ambulatory humans. J Neural Eng (2022) Available at: http://iopscience.iop.org/article/10.1088/1741-2552/ac4bfd
Sleep classification and feature extraction
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

| F. Mivalt et V. Kremen et al., “Electrical brain stimulation and continuous behavioral state tracking in ambulatory humans,” J. Neural Eng., vol. 19, no. 1, p. 016019, Feb. 2022, doi: 10.1088/1741-2552/ac4bfd.
| Gerla, V., Kremen, V., Macas, M., Dudysova, D., Mladek, A., Sos, P., & Lhotska, L. (2019). Iterative expert-in-the-loop classification of sleep PSG recordings using a hierarchical clustering. Journal of Neuroscience Methods, 317(February), 61?70. https://doi.org/10.1016/j.jneumeth.2019.01.013
| F. Mivalt et V. Sladky et al., “Automated sleep classification with chronic neural implants in freely behaving canines,” J. Neural Eng., vol. 20, no. 4, p. 046025, Aug. 2023, doi: 10.1088/1741-2552/aced21.
| Gerla, V., Kremen, V., Macas, M., Dudysova, D., Mladek, A., Sos, P., & Lhotska, L. (2019). Iterative expert-in-the-loop classification of sleep PSG recordings using a hierarchical clustering. Journal of Neuroscience Methods, 317(February), 61?70. https://doi.org/10.1016/j.jneumeth.2019.01.013
| Kremen, V., Brinkmann, B. H., Van Gompel, J. J., Stead, S. (Matt) M., St Louis, E. K., & Worrell, G. A. (2018). Automated Unsupervised Behavioral State Classification using Intracranial Electrophysiology. Journal of Neural Engineering. https://doi.org/10.1088/1741-2552/aae5ab

| Kremen, V., Duque, J. J., Brinkmann, B. H., Berry, B. M., Kucewicz, M. T., Khadjevand, F., G.A. Worrell, G. A. (2017). Behavioral state classification in epileptic brain using intracranial electrophysiology. Journal of Neural Engineering, 14(2), 026001. https://doi.org/10.1088/1741-2552/aa5688

Seizure detection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| V. Sladky et al., “Distributed brain co-processor for tracking spikes, seizures and behaviour during electrical brain stimulation,” Brain Commun., vol. 4, no. 3, May 2022, doi: 10.1093/braincomms/fcac115.
Artificial Signal Generation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

| F. Mivalt et al., “Deep Generative Networks for Algorithm Development in Implantable Neural Technology,” in 2022 IEEE International Conference on Systems, Man, and Cybernetics (SMC), Oct. 2022, pp. 1736–1741, doi: 10.1109/SMC53654.2022.9945379.

Evoked Response Potential Analysis
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

| K. J. Miller et al., “Canonical Response Parameterization: Quantifying the structure of responses to single-pulse intracranial electrical brain stimulation,” PLOS Comput. Biol., vol. 19, no. 5, p. e1011105, May 2023, doi: 10.1371/journal.pcbi.1011105.

Acknowledgement
"""""""""
"""""""""""""""""""

BEST was developed under projects supported by NIH Brain Initiative UH2&3 NS095495 Neurophysiologically-Based Brain State Tracking & Modulation in Focal Epilepsy, DARPA HR0011-20-2-0028 Manipulating and Optimizing Brain Rhythms for Enhancement of Sleep (Morpheus).
Filip Mivalt was also partially supported by the grant FEKT-K-22-7649 realized within the project Quality Internal Grants of the Brno University of Technology (KInG BUT), Reg. No. CZ.02.2.69/0.0/0.0/19_073/0016948, which is financed from the OP RDE.
Expand Down
2 changes: 1 addition & 1 deletion best/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# LICENSE file in the root directory of this source tree.
import os

__version__ = '0.0.6'
__version__ = '0.1.0a'



Expand Down
6 changes: 6 additions & 0 deletions best/hypnogram/CyberPSG.py → best/annotations/CyberPSG.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ class CyberPSG_XML_Writter:
'Sleep stage W': '00000001-898a-4b80-8ed8-000000000005',
'IED': '00000001-898a-4b80-8ed8-000000000010',
'IED_best': '00000001-898a-4b80-8ed8-000000000011',
'seizure': '00000001-898a-4b80-8ed8-000000000012',
'seizure_best': '00000001-898a-4b80-8ed8-000000000013',
'seizure_05': '00000001-898a-4b80-8ed8-000000000014',
'seizure_05_best': '00000001-898a-4b80-8ed8-000000000015',
'seizure_08': '00000001-898a-4b80-8ed8-000000000016',
'seizure_08_best': '00000001-898a-4b80-8ed8-000000000017',
}


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


"""
A package for a standardized manipulation with hypnogram annotations, saving, loading across different file formats (CyberP{SG, NSRR, ...) but also
A package for a standardized manipulation with annotations annotations, saving, loading across different file formats (CyberP{SG, NSRR, ...) but also
basic analysis of hypnograms. The package is based on pandas.DataFrame.
"""

Expand Down
4 changes: 2 additions & 2 deletions best/hypnogram/analysis.py → best/annotations/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from copy import deepcopy
from tqdm import tqdm

from best.hypnogram.visualisation import plot_hypnogram
from best.hypnogram.utils import merge_annotations, filter_by_key
from best.annotations.visualisation import plot_hypnogram
from best.annotations.utils import merge_annotations, filter_by_key


"""
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions best/hypnogram/io.py → best/annotations/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

from mef_tools.io import MefReader

from best.hypnogram.CyberPSG import CyberPSGFile, CyberPSG_XML_Writter
from best.hypnogram.NSRR import NSRRSleepFile
from best.hypnogram.utils import time_to_utc, create_duration, tile_annotations
from best.annotations.CyberPSG import CyberPSGFile, CyberPSG_XML_Writter
from best.annotations.NSRR import NSRRSleepFile
from best.annotations.utils import time_to_utc, create_duration, tile_annotations
from copy import deepcopy



"""
Tools for loading and saving of hypnogram files.
Tools for loading and saving of annotations files.
"""

_hypnogram_colors = {
Expand Down Expand Up @@ -141,7 +141,7 @@ def _load_CyberPSG(path, tile=None):

def _load_CyberPSG_dataset(paths: list, tile=None, verbose=True):
if verbose:
print('Loading hypnogram Dataset')
print('Loading annotations Dataset')
return [_load_CyberPSG(pth, tile) for pth in tqdm(paths)]
else:
return [_load_CyberPSG(pth, tile) for pth in paths]
Expand Down
10 changes: 5 additions & 5 deletions best/hypnogram/utils.py → best/annotations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _convert_to_timezone(x, tzinfo):

def time_to_local(dfHyp):
"""
Converts the time into the local timezone. Default by python and PC. Does not enter the timezone explicitely. Cannot be used for creating a hypnogram figure.
Converts the time into the local timezone. Default by python and PC. Does not enter the timezone explicitely. Cannot be used for creating a annotations figure.
"""
def convert(x, col_key):
return _convert_to_local(x[col_key])
Expand All @@ -90,7 +90,7 @@ def convert(x, col_key):

def time_to_timezone(dfHyp, tzinfo):
"""
Converts the hypnogram into a timezone. The timezone has to be from a python library dateutil
Converts the annotations into a timezone. The timezone has to be from a python library dateutil
"""
def convert(x, col_key):
return _convert_to_timezone(x[col_key], tzinfo)
Expand All @@ -102,7 +102,7 @@ def convert(x, col_key):

def time_to_timestamp(dfHyp):
"""
Converts the hypnogram time to timestamp.
Converts the annotations time to timestamp.
"""
def convert(x, col_key):
return _convert_to_timestamp(x[col_key])
Expand All @@ -114,7 +114,7 @@ def convert(x, col_key):

def create_duration(dfHyp):
"""
Creates duration for each epoch within the hypnogram. (Faster on timestamp)
Creates duration for each epoch within the annotations. (Faster on timestamp)
"""
def duration(x):
if type(x['start']) in (datetime, Timestamp):
Expand All @@ -127,7 +127,7 @@ def duration(x):

def create_day_indexes(dfHyp, hour=12, tzinfo=tz.tzlocal):
"""
Creates a day index for each epoch within the hypnogram, given the day-time hour supplied as input parameter.
Creates a day index for each epoch within the annotations, given the day-time hour supplied as input parameter.
The format of start and end has to be an integer or a float in a form representing a timestamp, or a timezone aware datetime or Timestamp object.
If the start and end format do not include timezone, the local timezone will be used.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

def plot_hypnogram(orig_df, hypnogram_values=None, hypnogram_colors=None, fontsize=12, fig=None, night_start=22):
"""
Creates a Matplotlib figure of spectrogram from the hypnogram. Time must be in a time-zone aware format.
Creates a Matplotlib figure of spectrogram from the annotations. Time must be in a time-zone aware format.
Parameters
----------
orig_df : hypnogram
orig_df : annotations
hypnogram_values : dict
dict of a y-axis values for each sleep state
hypnogram_colors : dict
Expand Down
11 changes: 5 additions & 6 deletions best/cloud/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from sqlalchemy.pool import NullPool
from sshtunnel import SSHTunnelForwarder

from best.hypnogram.utils import create_day_indexes, time_to_timezone, time_to_timestamp, tile_annotations, create_duration
from best.annotations.utils import create_day_indexes, time_to_timezone, time_to_timestamp, tile_annotations, create_duration
from best.cloud._db_connection_variables import *

import pandas as pd
Expand Down Expand Up @@ -451,8 +451,7 @@ def load_stimulation_day_info(self, patient_id, start_uutc, stop_uutc):
freqs = []
ampls = []
pws = []
for row in df_data.iterrows():
row = row[1]
for _, row in df_data.iterrows():
ampl = [row['curr_Prog'+str(k)+'AmpInMilliamps'] for k in range(4) if not isinstance(row['curr_Prog'+str(k)+'AmpInMilliamps'], type(None))]

freq = row['curr_rate_in_hz']
Expand All @@ -472,9 +471,9 @@ def load_stimulation_day_info(self, patient_id, start_uutc, stop_uutc):
if ampls.__len__() == 0: ampls = None
if pws.__len__() == 0: pws = None
stim_info = {
'freq': np.max(freqs),
'ampl': np.max(ampls),
'pulsewidth': np.max(pws)
'freq': np.nanmax(freqs),
'ampl': np.nanmax(ampls),
'pulsewidth': np.nanmax(pws)
}
return stim_info

Expand Down
Empty file added best/erp/__init__.py
Empty file.
Loading

0 comments on commit c69843c

Please sign in to comment.