Skip to content

Commit 06d9d37

Browse files
committed
initial commit
0 parents  commit 06d9d37

File tree

12 files changed

+1623
-0
lines changed

12 files changed

+1623
-0
lines changed

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# generally ignore anything, BUT ...
2+
*
3+
# any files including a dot
4+
!*.*
5+
# any subdictionaries
6+
!*/
7+
# ignore temporary MATLAB files
8+
*.m~
9+
# ignore python cache files cache
10+
*__pycache__/*
11+
*.cache*
12+
# ignore .mat files, except tutorial file
13+
*.mat
14+
# ignore utility folder for now
15+
*util/
16+
#!*util/1160_rest_EEG_Rlm_Fhl_rdSeg_Art_EC.mat
17+
# ignore any output images
18+
*.png
19+
# ignore any csf files
20+
*.csv
21+
# ignore Mac profile files
22+
.DS_Store
23+
# ignore any files ending with _
24+
._*

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# eBOSC: extended Better OSCillation Detection
2+
3+
## Overview
4+
--------
5+
6+
**eBOSC** (extended Better OSCillation detection) is a toolbox (or a set of scripts) that can be used to detect the occurrence of rhythms in continuous signals (i.e., at the single trial level). It uses a static aperiodic ‘background’ spectrum as the basis to define a ‘power threshold’ that continuous signals have to exceed in order to qualify as ‘rhythmic’. As such, it leverages the observation that stochastic components of the frequency spectrum of neural data are aharacterized by a '1/f'-like power spectrum. An additional ‘duration threshold’ can be set up in advance, or rhythmic episodes can be filtered by duration following detection to ensure that detected rhythmic episodes have a rather sustained vs. transient appearance.
7+
8+
## Documentation
9+
-------------
10+
11+
A project wiki for eBOSC is available [here](https://github.com/jkosciessa/eBOSC/wiki).
12+
13+
* [Motivation](https://github.com/jkosciessa/eBOSC/wiki/Pitfalls)
14+
* [Tutorial](https://github.com/jkosciessa/eBOSC/wiki/Tutorial)
15+
* [Version update/Legacy information](https://github.com/jkosciessa/eBOSC/wiki/Legacy)
16+
17+
Simulation scripts and data files regarding the 2020 NeuroImage paper can be found at https://github.com/jkosciessa/eBOSC_resources_NI2020.
18+
19+
## Installation
20+
-------------
21+
22+
After downloading, simply add the toolbox path. The toolbox requires a version of MATLAB and has been tested with R2017b.
23+
24+
Note: If you use the 'Download ZIP' button to retrieve the repository, the .mat example file may not be downloaded due to a problem in GitHub's lfs implementation. Using 'git clone' to copy the repository should work to retrieve the file.
25+
26+
## Credits
27+
-------------
28+
29+
If you find the method useful, please cite the following papers:
30+
31+
Kosciessa, J. Q., Grandy, T. H., Garrett, D. D., & Werkle-Bergner, M. (2020). Single-trial characterization of neural rhythms: Potential and challenges. NeuroImage, 206, 116331. http://doi.org/10.1016/j.neuroimage.2019.116331
32+
33+
Whitten, T. A., Hughes, A. M., Dickson, C. T., & Caplan, J. B. (2011). A better oscillation detection method robustly extracts EEG rhythms across brain state changes: The human alpha rhythm as a test case. NeuroImage, 54(2), 860–874. http://doi.org/10.1016/j.neuroimage.2010.08.064
34+
35+
## License
36+
-------------
37+
38+
eBOSC is an extension of the BOSC library and partially uses scripts from the original toolbox. These functions are included in the 'external' folder of the current package.
39+
40+
The eBOSC library (and the original BOSC library) are free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
41+
42+
The eBOSC library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

code_of_conduct.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
# Contributor Covenant Code of Conduct
3+
4+
## Our Pledge
5+
6+
In the interest of fostering an open and welcoming environment, we as
7+
contributors and maintainers pledge to make participation in our project and
8+
our community a harassment-free experience for everyone, regardless of age, body
9+
size, disability, ethnicity, sex characteristics, gender identity and expression,
10+
level of experience, education, socio-economic status, nationality, personal
11+
appearance, race, religion, or sexual identity and orientation.
12+
13+
## Our Standards
14+
15+
Examples of behavior that contributes to creating a positive environment
16+
include:
17+
18+
* Using welcoming and inclusive language
19+
* Being respectful of differing viewpoints and experiences
20+
* Gracefully accepting constructive criticism
21+
* Focusing on what is best for the community
22+
* Showing empathy towards other community members
23+
24+
Examples of unacceptable behavior by participants include:
25+
26+
* The use of sexualized language or imagery and unwelcome sexual attention or
27+
advances
28+
* Trolling, insulting/derogatory comments, and personal or political attacks
29+
* Public or private harassment
30+
* Publishing others' private information, such as a physical or electronic
31+
address, without explicit permission
32+
* Other conduct which could reasonably be considered inappropriate in a
33+
professional setting
34+
35+
## Our Responsibilities
36+
37+
Project maintainers are responsible for clarifying the standards of acceptable
38+
behavior and are expected to take appropriate and fair corrective action in
39+
response to any instances of unacceptable behavior.
40+
41+
Project maintainers have the right and responsibility to remove, edit, or
42+
reject comments, commits, code, wiki edits, issues, and other contributions
43+
that are not aligned to this Code of Conduct, or to ban temporarily or
44+
permanently any contributor for other behaviors that they deem inappropriate,
45+
threatening, offensive, or harmful.
46+
47+
## Scope
48+
49+
This Code of Conduct applies within all project spaces, and it also applies when
50+
an individual is representing the project or its community in public spaces.
51+
Examples of representing a project or community include using an official
52+
project e-mail address, posting via an official social media account, or acting
53+
as an appointed representative at an online or offline event. Representation of
54+
a project may be further defined and clarified by project maintainers.
55+
56+
## Enforcement
57+
58+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
59+
reported by contacting the project team at [email protected]. All
60+
complaints will be reviewed and investigated and will result in a response that
61+
is deemed necessary and appropriate to the circumstances. The project team is
62+
obligated to maintain confidentiality with regard to the reporter of an incident.
63+
Further details of specific enforcement policies may be posted separately.
64+
65+
Project maintainers who do not follow or enforce the Code of Conduct in good
66+
faith may face temporary or permanent repercussions as determined by other
67+
members of the project's leadership.
68+
69+
## Attribution
70+
71+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
72+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
73+
74+
[homepage]: https://www.contributor-covenant.org
75+
76+
For answers to common questions about this code of conduct, see
77+
https://www.contributor-covenant.org/faq
78+

ebosc/BOSC.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/usr/bin/env python3# -*- coding: utf-8 -*-"""BOSC (Better Oscillation Detection) function libraryRewritten from MATLAB to Python by Julian Q. KosciessaThe original license information follows:---This file is part of the Better OSCillation detection (BOSC) library.The BOSC library is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.The BOSC library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with Foobar. If not, see <http://www.gnu.org/licenses/>.Copyright 2010 Jeremy B. Caplan, Adam M. Hughes, Tara A. Whittenand Clayton T. Dickson.---"""def BOSC_tf(eegsignal,F,Fsample,wavenumber): import numpy as np st=1./(2*np.pi*(F/wavenumber)) A=1./np.sqrt(st*np.sqrt(np.pi)) # initialize the time-frequency matrix B = np.zeros((len(F),len(eegsignal))) B[:] = np.nan # loop through sampled frequencies for f in range(len(F)): #print(f) t=np.arange(-3.6*st[f],(3.6*st[f])+1/Fsample,1/Fsample) # define Morlet wavelet m=A[f]*np.exp(-t**2/(2*st[f]**2))*np.exp(1j*2*np.pi*F[f]*t) y=np.convolve(eegsignal,m, 'full') y=abs(y)**2 B[f,:]=y[np.arange(int(np.ceil(len(m)/2)), len(y)-int(np.floor(len(m)/2)) + 1, 1)] T=np.arange(1,len(eegsignal)+1,1)/Fsample return B, T, Fdef BOSC_detect(b,powthresh,durthresh,Fsample): """ detected=BOSC_detect(b,powthresh,durthresh,Fsample) This function detects oscillations based on a wavelet power timecourse, b, a power threshold (powthresh) and duration threshold (durthresh) returned from BOSC_thresholds.m. It now returns the detected vector which is already episode-detected. b - the power timecourse (at one frequency of interest) durthresh - duration threshold in required to be deemed oscillatory powthresh - power threshold returns: detected - a binary vector containing the value 1 for times at which oscillations (at the frequency of interest) were detected and 0 where no oscillations were detected. NOTE: Remember to account for edge effects by including "shoulder" data and accounting for it afterwards! To calculate Pepisode: Pepisode=length(find(detected))/(length(detected)); """ import numpy as np # number of time points nT=len(b) #t=np.arange(1,nT+1,1)/Fsample # Step 1: power threshold x=b>powthresh # we have to turn the boolean to numeric x = np.array(list(map(np.int, x))) # show the +1 and -1 edges dx=np.diff(x) if np.size(np.where(dx==1))!=0: pos=np.where(dx==1)[0]+1 #pos = pos[0] else: pos = [] if np.size(np.where(dx==-1))!=0: neg=np.where(dx==-1)[0]+1 #neg = neg[0] else: neg = [] # now do all the special cases to handle the edges detected=np.zeros(b.shape) if not any(pos) and not any(neg): # either all time points are rhythmic or none if all(x==1): H = np.array([[1],[nT]]) elif all(x==0): H = np.array([]) elif not any(pos): # i.e., starts on an episode, then stops H = np.array([[1],neg]) #np.concatenate(([1],neg), axis=0) elif not any(neg): # starts, then ends on an ep. H = np.array([pos,[nT]]) #np.concatenate((pos,[nT]), axis=0) else: # special-case, create the H double-vector if pos[0]>neg[0]: # we start with an episode pos = np.append(1,pos) if neg[-1]<pos[-1]: # we end with an episode neg = np.append(neg,nT) # NOTE: by this time, length(pos)==length(neg), necessarily H = np.array([pos,neg]) #np.concatenate((pos,neg), axis=0) if H.shape[0]>0: # more than one "hole" # find epochs lasting longer than minNcycles*period goodep=H[1,]-H[0,]>=durthresh if not any(goodep): H = [] else: H = H[:,goodep.nonzero()][:,0] # mark detected episode on the detected vector for h in range(H.shape[1]): detected[np.arange(H[0][h], H[1][h],1)]=1 # ensure that outputs are integer detected = np.array(list(map(np.int, detected))) return detected

ebosc/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""eBOSC - extended Better Oscillation Detection"""
2+
3+
from .version import __version__
4+
from .helpers import *
5+
from .BOSC import *
6+
from .eBOSC import *

0 commit comments

Comments
 (0)