Skip to content

Commit

Permalink
Merge branch 'develop' into dev/update-wxpython
Browse files Browse the repository at this point in the history
  • Loading branch information
oreHGA authored Mar 4, 2023
2 parents adf5e28 + d0715cf commit c9b6671
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 41 deletions.
21 changes: 9 additions & 12 deletions eegnb/analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import logging
from collections import OrderedDict
from glob import glob
from typing import Union, List, Dict
from collections import Iterable
from typing import Union, List#, Dict
# from collections import Iterable
from time import sleep, time
from numpy.core.fromnumeric import std
# from numpy.core.fromnumeric import std
import keyboard
import os

Expand Down Expand Up @@ -277,14 +277,16 @@ def plot_conditions(

for ch in range(channel_count):
for cond, color in zip(conditions.values(), palette):
sns.tsplot(
X[y.isin(cond), ch],
time=times,
sns.lineplot(
data=pd.DataFrame(X[y.isin(cond), ch].T, index=times),
x=times,
y=ch,
color=color,
n_boot=n_boot,
ci=ci,
ax=axes[ch],
errorbar=('ci',ci)
)
axes[ch].set(xlabel='Time (s)', ylabel='Amplitude (uV)', title=epochs.ch_names[channel_order[ch]])

if diff_waveform:
diff = np.nanmean(X[y == diff_waveform[1], ch], axis=0) - np.nanmean(
Expand All @@ -298,11 +300,6 @@ def plot_conditions(
x=0, ymin=ylim[0], ymax=ylim[1], color="k", lw=1, label="_nolegend_"
)

axes[0].set_xlabel("Time (s)")
axes[0].set_ylabel("Amplitude (uV)")
axes[-1].set_xlabel("Time (s)")
axes[1].set_ylabel("Amplitude (uV)")

if diff_waveform:
legend = ["{} - {}".format(diff_waveform[1], diff_waveform[0])] + list(
conditions.keys()
Expand Down
9 changes: 6 additions & 3 deletions eegnb/experiments/Experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def setup(self, instructions=True):
# Generating a random int for the filename
random_id = random.randint(1000,10000)
# Generating save function
self.save_fn = generate_save_fn(self.eeg.device_name, "visual_n170", random_id, random_id, "unnamed")
experiment_directory = self.name.replace(' ', '_')
self.save_fn = generate_save_fn(self.eeg.device_name, experiment_directory, random_id, random_id, "unnamed")
print(
f"No path for a save file was passed to the experiment. Saving data to {self.save_fn}"
)
Expand Down Expand Up @@ -164,5 +165,7 @@ def run(self, instructions=True):
# Closing the window
self.window.close()



@property
def name(self) -> str:
""" This experiment's name """
return self.exp_name
10 changes: 5 additions & 5 deletions examples/visual_cueing/01r__cueing_singlesub_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
#

# Some standard pythonic imports
import os,sys,glob,numpy as np,pandas as pd
import os,numpy as np#,sys,glob,pandas as pd
from collections import OrderedDict
import warnings
warnings.filterwarnings('ignore')
from matplotlib import pyplot as plt
import matplotlib.patches as patches

# MNE functions
from mne import Epochs,find_events, concatenate_raws
from mne import Epochs,find_events#, concatenate_raws
from mne.time_frequency import tfr_morlet

# EEG-Notebooks functions
Expand Down Expand Up @@ -73,7 +73,7 @@
# One way to analyze the SSVEP is to plot the power spectral density, or PSD. SSVEPs should appear as peaks in power for certain frequencies. We expect clear peaks in the spectral domain at the stimulation frequencies of 30 and 20 Hz.
#

raw.plot_psd();
raw.compute_psd().plot();

# Should see the electrical noise at 60 Hz, and maybe a peak at the red and blue channels between 7-14 Hz (Alpha)

Expand All @@ -84,8 +84,8 @@
# Most ERP components are composed of lower frequency fluctuations in the EEG signal. Thus, we can filter out all frequencies between 1 and 30 hz in order to increase our ability to detect them.
#

raw.filter(1,30, method='iir')
raw.plot_psd(fmin=1, fmax=30);
raw.filter(1,30, method='iir');
raw.compute_psd(fmin=1, fmax=30).plot();

###################################################################################################
# Epoching
Expand Down
36 changes: 18 additions & 18 deletions examples/visual_n170/00x__n170_run_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@
# ---------------------
#
# Imports
import os
from eegnb import generate_save_fn
from eegnb.devices.eeg import EEG
from eegnb.experiments.visual_n170 import n170
from eegnb.experiments import VisualN170

# Define some variables
board_name = "muse"
experiment = "visual_n170"

# Experiment type
experiment = VisualN170()

# EEG device
experiment.eeg = EEG(device="cyton") # "muse")

# Test subject id
subject_id = 0
session_nb = 0
record_duration = 120

###################################################################################################
# Initiate EEG device
# ---------------------
#
# Start EEG device
eeg_device = EEG(device=board_name)
# Session number
session_nb = 0

# Create save file name
save_fn = generate_save_fn(board_name, experiment, subject_id, session_nb)
print(save_fn)
# Experiment recording duration
experiment.duration = 120

###################################################################################################
# Run experiment
# ---------------------
#
n170.present(duration=record_duration, eeg=eeg_device, save_fn=save_fn)
#
experiment.run()

# Saved csv location
print(experiment.save_fn)
12 changes: 9 additions & 3 deletions examples/visual_ssvep/01r__ssvep_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# MNE functions
from mne import Epochs,find_events
from mne.time_frequency import psd_welch,tfr_morlet
from mne.time_frequency import tfr_morlet

# EEG-Notebooks functions
from eegnb.analysis.utils import load_data,plot_conditions
Expand Down Expand Up @@ -88,8 +88,14 @@
# Next, we can compare the PSD of epochs specifically during 20hz and 30hz stimulus presentation

f, axs = plt.subplots(2, 1, figsize=(10, 10))
psd1, freq1 = psd_welch(epochs['30 Hz'], n_fft=1028, n_per_seg=256 * 3, picks='all')
psd2, freq2 = psd_welch(epochs['20 Hz'], n_fft=1028, n_per_seg=256 * 3, picks='all')

welch_params=dict(method='welch',
n_fft=1028,
n_per_seg=256 * 3,
picks='all')

psd1, freq1 = epochs['30 Hz'].compute_psd(**welch_params).get_data(return_freqs=True)
psd2, freq2 = epochs['20 Hz'].compute_psd(**welch_params).get_data(return_freqs=True)
psd1 = 10 * np.log10(psd1)
psd2 = 10 * np.log10(psd2)

Expand Down

0 comments on commit c9b6671

Please sign in to comment.