Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'dev' into new-modifs
Browse files Browse the repository at this point in the history
new modifs.
  • Loading branch information
AxelGiottonini committed May 18, 2022
2 parents fc2434d + f110519 commit 3070e77
Show file tree
Hide file tree
Showing 37 changed files with 10,971 additions and 332 deletions.
72 changes: 72 additions & 0 deletions EEGToolkit.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
Metadata-Version: 2.1
Name: EEGToolkit
Version: 2.0.0
Summary: A package for EEG data analysis of reaction time-delay experiments.
Home-page: https://github.com/AxelGiottonini/AP-EEG.git
Author: Axel Giottonini, Noah Kleinschmidt, Kalvin Dobler
Author-email: [email protected], [email protected], [email protected]
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Scientific/Engineering :: Visualization
Requires-Python: >=3.6
Description-Content-Type: text/markdown

# AP-EEG

## Project description
> ## EEG data analysis
> Students who choose this task ill be provided with the raw EEG recording of one channel, sampled at $500 [Hz]$ which was recorded from a participant presented with auditory stimuli. The students will also receive an events file describing when during the recording one out of two possible sounds were presented to the subject.
> ### Task 1
> Extract the time-period from $0.1 [sec]$ before to $1 [sec]$ after each event for the EEG signal. Store these time-periods in two arrays, one for each of the two event-/sound-types.
> ### Task 2
> Plot the average response for each type of event, with shading for the standard error. On the plot, also indicate $t=0$, the amplitude of the signal in microvolts (Y-axis), and the time relative to sound onset in $[ms]$ (X-axis).
> ### Task 3
> For each sound type, for each time-point after sound onset, test wheter it is significantly different across trials from the baseline. Also test at what time-points after sound onset the EEG signals for the two sound-types are different from each other. Produce one plot containing the average EEG signal of each sound type, along with lines indicating the significant time-periods.

## Milestones
> - **Part 1: Project management and first deliverable** (*Deadline: April 28*)
> - **Part 2: GitHub and second deliverable** (*Deadline: May 5*)
> - **Part 3: Classes and refactoring** (*Deadline: May 12*)
> - **Part 4: Unit tests and issues** (*Deadline: May 19*)
> - **Part 5: Third deliverable, presentation and virtual environment** (*Deadline: June 2*)

## Project roadmap

### Main Objective
The goal is to develop a small package with CLI to evaluate EEG data for reaction delays given different auditory stimuli.
While the outset data is given as a binary stimulus experiment, extending to an arbitrary number of different stimuli would be
a desirable extention.


### Implementation

#### General TODOs
- [x] proper **Docstrings** and comments in general ...
- [x] re-factoring for private methods ...
- [x] requirements.txt
- [x] setup.py
- [ ] (optional but kinda cool) adding EEGData to PYTHONPATH to allow direct CLI calling...
- [ ] `testpypi` distribution
- [x] HTML documentation

#### CLI TODOs:
- [x] Core is pretty much finished already...
- [x] Change the `argparse` settings to allow defaults for parameters like x_scale to allow easier usage

#### Task TODOs:
##### Task 1:
- [x] Event extraction is pretty much finished already
> Possible additions: <br>
> - [x] split reading the files and extracting data, thereby allowing different filetypes to be processed. In case this is done, we might add support for `txt` / `tsv` / `csv` files for more general applicability of the software.


##### Task 2:
- [x] plotting is pretty much finished already...
- [ ] Add units to the figure axes labels
- [x] (optional) adjust color scheme ...

##### Task 3:
- [x] What about the intra-signal baseline-comparison ?
- [x] signal-comparison is finished already...
15 changes: 15 additions & 0 deletions EEGToolkit.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
README.md
setup.py
EEGToolkit/__init__.py
EEGToolkit/main.py
EEGToolkit.egg-info/PKG-INFO
EEGToolkit.egg-info/SOURCES.txt
EEGToolkit.egg-info/dependency_links.txt
EEGToolkit.egg-info/entry_points.txt
EEGToolkit.egg-info/top_level.txt
EEGToolkit/EEGData/EEGData.py
EEGToolkit/EEGData/__init__.py
EEGToolkit/EEGStats/EEGStats.py
EEGToolkit/EEGStats/__init__.py
EEGToolkit/auxiliary/__init__.py
EEGToolkit/auxiliary/auxiliary.py
1 change: 1 addition & 0 deletions EEGToolkit.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions EEGToolkit.egg-info/entry_points.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[console_scripts]
EEGToolkit = EEGToolkit.EEGData:main
1 change: 1 addition & 0 deletions EEGToolkit.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EEGToolkit
95 changes: 72 additions & 23 deletions EEGToolkit/EEGData.py → EEGToolkit/EEGData/EEGData.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@
describing event metadata as a 2D array, describing both the timepoints and the type of event in two columns.
"""
import sys
import os

import os
import subprocess
import inspect
import argparse
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from EEGStats import plot_signal, difference_plot

try:
from EEGToolkit.EEGStats import plot_signal, difference_plot
except ImportError:
abspath = os.path.abspath(__file__)
dname = os.path.dirname(os.path.dirname(abspath))
sys.path.append(dname)

from EEGStats import plot_signal, difference_plot


supported_filetypes = [ "npy", "tsv", "csv", "txt" ]
class EEGData():
Expand Down Expand Up @@ -156,7 +168,8 @@ def read( self, signal_path : str = None , event_path : str = None ) -> None:
def extract(self,
start_sec:float,
stop_sec:float,
event_type : ( int or tuple or list or np.ndarray ) = None) -> np.ndarray:
event_type : ( int or tuple or list or np.ndarray ) = None,
**kwargs ) -> np.ndarray:
"""
Extracts data for a specific (set of) event(s) from the loaded data.
And returns the data as numpy ndarrays (or a list thereof, in case of
Expand Down Expand Up @@ -420,7 +433,8 @@ def summary(self,
n = len(data)

# generate a new figure
fig, ax = plt.subplots(n,n)
figsize = kwargs.pop( "figsize", ( 3*n,2*n ) )
fig, ax = plt.subplots(n,n, figsize = figsize )

# setup a baseline reference, either with the computed
# baselines or None ...
Expand All @@ -439,6 +453,7 @@ def summary(self,
x_scale, y_scale,
baseline = baseline[i],
make_legend = make_legend,
significance_level = significance_level,
ax = ax[i,i] )

ax[i,i].set_title(f"Signal {signals[i]}")
Expand Down Expand Up @@ -647,12 +662,12 @@ def main():
formatter_class=argparse.RawDescriptionHelpFormatter,description = descr1, epilog = descr2 )
parser.add_argument(
"--eeg_path", "--eeg",
type=str, required=True,
type=str,
help = f"A file containing EEG signal data. Supported filetypes are {supported_filetypes}"
)
parser.add_argument(
"--event_path", "--event",
type=str, required=True,
type=str,
help = f"A file containing event metadata for the signal file. Supported filetypes are {supported_filetypes}"
)
parser.add_argument(
Expand All @@ -662,7 +677,7 @@ def main():
)
parser.add_argument(
"--sampling_frequency", "--freq", "-f",
type=float, required=True,
type=float,
help = "The frequency at which the EEG signal data was recorded (in Hertz)."
)
parser.add_argument(
Expand All @@ -672,12 +687,12 @@ def main():
)
parser.add_argument(
"--start_sec", "--start", "-s",
type=float, required=True,
type=float,
help = "The upstream time-padding for event extraction (in seconds)."
)
parser.add_argument(
"--stop_sec", "--stop", "-e",
type=float, required=True,
type=float,
help = "The downstream time-padding for event extraction (in seconds)."
)

Expand All @@ -696,23 +711,57 @@ def main():
type=float, default = 1000,
help = "A scaling factor for the signal-scale (y-values) from volts to some other unit. Default is 1000 (= millivolts)."
)

parser.add_argument(
"--viewer", "-i",
action="store_true",
default = False,
help = "Open the EEGToolKit Viewer GUI in a web browser."
)

args = parser.parse_args()

# the main program (reading datafiles, extracting, and summarizing)
data = EEGData(args.eeg_path, args.event_path, args.sampling_frequency)
data.extract( args.start_sec, args.stop_sec )
if args.baseline:
data.baseline()
data.summary(
significance_level = args.p_value,
x_scale = args.x_scale,
y_scale = args.y_scale,
output = args.output
)

if args.output is not None:
print( f"Output saved successfully to: '{args.output}'" )
# if the viewer is being called then we want to just open the
# viewer and nothing else
if args.viewer:
# first we need to get the relative location of the main.
# py file within the package.
directory = os.path.dirname(
inspect.getfile( plot_signal )
)
directory = os.path.dirname( directory )
main_file = f"{directory}/main.py"

# then we call the web interface
print( "Starting the \033[94mEEGToolKit \033[96mViewer" )
subprocess.run( f"streamlit run {main_file}", shell = True )

else:

# the main program (reading datafiles, extracting, and summarizing)
try:
data = EEGData(args.eeg_path, args.event_path, args.sampling_frequency)
data.extract( args.start_sec, args.stop_sec )
if args.baseline:
data.baseline()
data.summary(
significance_level = args.p_value,
x_scale = args.x_scale,
y_scale = args.y_scale,
output = args.output
)

if args.output is not None:
print( f"Output saved successfully to: '{args.output}'" )
except FileNotFoundError as e:
print(e)
return
except TypeError as e:
print(e)
return
except ValueError as e:
print(e)
return

if __name__ == "__main__":

Expand Down
1 change: 1 addition & 0 deletions EEGToolkit/EEGData/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .EEGData import *
Loading

0 comments on commit 3070e77

Please sign in to comment.