Skip to content

Commit

Permalink
deploy: 1257c3a
Browse files Browse the repository at this point in the history
  • Loading branch information
oreHGA committed Mar 7, 2024
1 parent 460c004 commit 5e3ea09
Show file tree
Hide file tree
Showing 237 changed files with 6,775 additions and 16,540 deletions.
2 changes: 1 addition & 1 deletion .buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 75670e2e8c59814fc976e9ef5fbe74ea
config: 0b0845f06aa0ea4305158e51e2e10944
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from mne.time_frequency import tfr_morlet

# EEG-Noteooks functions
from eegnb.analysis.utils import load_data,plot_conditions
from eegnb.analysis.utils import load_data
from eegnb.datasets import fetch_dataset

# sphinx_gallery_thumbnail_number = 1
Expand Down Expand Up @@ -136,14 +136,14 @@
# Left Cue
tfr, itc = tfr_morlet(epochs['LeftCue'], freqs=frequencies,
n_cycles=wave_cycles, return_itc=True)
tfr = tfr.apply_baseline([-1,-.5],mode='mean')
tfr = tfr.apply_baseline((-1,-.5),mode='mean')
power_Ipsi_TP9 = tfr.data[0,:,:]
power_Contra_TP10 = tfr.data[1,:,:]

# Right Cue
tfr, itc = tfr_morlet(epochs['RightCue'], freqs=frequencies,
n_cycles=wave_cycles, return_itc=True)
tfr = tfr.apply_baseline([-1,-.5],mode='mean')
tfr = tfr.apply_baseline((-1,-.5),mode='mean')
power_Contra_TP9 = tfr.data[0,:,:]
power_Ipsi_TP10 = tfr.data[1,:,:]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -80,7 +69,7 @@
},
"outputs": [],
"source": [
"subs = [101, 102, 103, 104, 105, 106, 108, 109, 110, 111, 112,\n 202, 203, 204, 205, 207, 208, 209, 210, 211, \n 301, 302, 303, 304, 305, 306, 307, 308, 309]\n\ndiff_out = []\nIpsi_out = []\nContra_out = []\nIpsi_spectra_out = []\nContra_spectra_out = []\ndiff_spectra_out = []\nERSP_diff_out = []\nERSP_Ipsi_out = []\nERSP_Contra_out = []\n\nfrequencies = np.linspace(6, 30, 100, endpoint=True)\nwave_cycles = 6\n\n# time frequency window for analysis\nf_low = 7 # Hz\nf_high = 10\nf_diff = f_high-f_low\n \nt_low = 0 # s\nt_high = 1\nt_diff = t_high-t_low\n\nbad_subs= [6, 7, 13, 26]\nreally_bad_subs = [11, 12, 19]\nsub_count = 0 \n \n \n \nfor sub in subs:\n print(sub)\n \n sub_count += 1\n\n \n if (sub_count in really_bad_subs):\n rej_thresh_uV = 90\n elif (sub_count in bad_subs):\n rej_thresh_uV = 90\n else:\n rej_thresh_uV = 90\n\n rej_thresh = rej_thresh_uV*1e-6\n \n \n # Load both sessions\n raw = load_data(sub,1, # subject, session\n experiment='visual-cueing',site='kylemathlab_dev',device_name='muse2016',\n data_dir = eegnb_data_path)\n \n raw.append(\n load_data(sub,2, # subject, session\n experiment='visual-cueing', site='kylemathlab_dev', device_name='muse2016',\n data_dir = eegnb_data_path))\n \n\n # Filter Raw Data\n raw.filter(1,30, method='iir')\n\n #Select Events\n events = find_events(raw)\n event_id = {'LeftCue': 1, 'RightCue': 2}\n epochs = Epochs(raw, events=events, event_id=event_id, \n tmin=-1, tmax=2, baseline=(-1, 0), \n reject={'eeg':rej_thresh}, preload=True,\n verbose=False, picks=[0, 3])\n print('Trials Remaining: ' + str(len(epochs.events)) + '.')\n\n # Compute morlet wavelet\n\n # Left Cue\n tfr, itc = tfr_morlet(epochs['LeftCue'], freqs=frequencies, \n n_cycles=wave_cycles, return_itc=True)\n tfr = tfr.apply_baseline([-1,-.5],mode='mean')\n #tfr.plot(picks=[0], mode='logratio', \n # title='TP9 - Ipsi');\n #tfr.plot(picks=[3], mode='logratio', \n # title='TP10 - Contra');\n power_Ipsi_TP9 = tfr.data[0,:,:]\n power_Contra_TP10 = tfr.data[1,:,:]\n\n # Right Cue\n tfr, itc = tfr_morlet(epochs['RightCue'], freqs=frequencies, \n n_cycles=wave_cycles, return_itc=True)\n tfr = tfr.apply_baseline([-1,-.5],mode='mean')\n #tfr.plot(picks=[0], mode='logratio', \n # title='TP9 - Contra');\n #tfr.plot(picks=[3], mode='logratio', \n # title='TP10 - Ipsi');\n power_Contra_TP9 = tfr.data[0,:,:]\n power_Ipsi_TP10 = tfr.data[1,:,:]\n\n # Plot Differences\n #%matplotlib inline\n times = epochs.times\n power_Avg_Ipsi = (power_Ipsi_TP9+power_Ipsi_TP10)/2;\n power_Avg_Contra = (power_Contra_TP9+power_Contra_TP10)/2;\n power_Avg_Diff = power_Avg_Ipsi-power_Avg_Contra;\n\n\n #find max to make color range\n plot_max = np.max([np.max(np.abs(power_Avg_Ipsi)), np.max(np.abs(power_Avg_Contra))])\n plot_diff_max = np.max(np.abs(power_Avg_Diff))\n\n \n \n #Ipsi\n fig, ax = plt.subplots(1)\n im = plt.imshow(power_Avg_Ipsi,\n extent=[times[0], times[-1], frequencies[0], frequencies[-1]],\n aspect='auto', origin='lower', cmap='coolwarm', vmin=-plot_max, vmax=plot_max)\n plt.xlabel('Time (sec)')\n plt.ylabel('Frequency (Hz)')\n plt.title('Power Average Ipsilateral to Cue')\n cb = fig.colorbar(im)\n cb.set_label('Power')\n # Create a Rectangle patch\n rect = patches.Rectangle((t_low,f_low),t_diff,f_diff,linewidth=1,edgecolor='k',facecolor='none')\n # Add the patch to the Axes\n ax.add_patch(rect)\n\n #TP10\n fig, ax = plt.subplots(1)\n im = plt.imshow(power_Avg_Contra,\n extent=[times[0], times[-1], frequencies[0], frequencies[-1]],\n aspect='auto', origin='lower', cmap='coolwarm', vmin=-plot_max, vmax=plot_max)\n plt.xlabel('Time (sec)')\n plt.ylabel('Frequency (Hz)')\n plt.title(str(sub) + ' - Power Average Contra to Cue')\n cb = fig.colorbar(im)\n cb.set_label('Power')\n # Create a Rectangle patch\n rect = patches.Rectangle((t_low,f_low),t_diff,f_diff,linewidth=1,edgecolor='k',facecolor='none')\n # Add the patch to the Axes\n ax.add_patch(rect)\n\n #difference between conditions\n fig, ax = plt.subplots(1)\n im = plt.imshow(power_Avg_Diff,\n extent=[times[0], times[-1], frequencies[0], frequencies[-1]],\n aspect='auto', origin='lower', cmap='coolwarm', vmin=-plot_diff_max, vmax=plot_diff_max)\n plt.xlabel('Time (sec)')\n plt.ylabel('Frequency (Hz)')\n plt.title('Power Difference Ipsi-Contra')\n cb = fig.colorbar(im)\n cb.set_label('Ipsi-Contra Power')\n # Create a Rectangle patch\n rect = patches.Rectangle((t_low,f_low),t_diff,f_diff,linewidth=1,edgecolor='k',facecolor='none')\n # Add the patch to the Axes\n ax.add_patch(rect)\n \n \n \n \n #output data into array\n Ipsi_out.append(np.mean(power_Avg_Ipsi[np.argmax(frequencies>f_low):\n np.argmax(frequencies>f_high)-1,\n np.argmax(times>t_low):np.argmax(times>t_high)-1 ]\n )\n ) \n Ipsi_spectra_out.append(np.mean(power_Avg_Ipsi[:,np.argmax(times>t_low):\n np.argmax(times>t_high)-1 ],1\n )\n )\n \n Contra_out.append(np.mean(power_Avg_Contra[np.argmax(frequencies>f_low):\n np.argmax(frequencies>f_high)-1,\n np.argmax(times>t_low):np.argmax(times>t_high)-1 ]\n )\n )\n \n Contra_spectra_out.append(np.mean(power_Avg_Contra[:,np.argmax(times>t_low):\n np.argmax(times>t_high)-1 ],1))\n \n \n diff_out.append(np.mean(power_Avg_Diff[np.argmax(frequencies>f_low):\n np.argmax(frequencies>f_high)-1,\n np.argmax(times>t_low):np.argmax(times>t_high)-1 ]\n )\n )\n diff_spectra_out.append(np.mean(power_Avg_Diff[:,np.argmax(times>t_low):\n np.argmax(times>t_high)-1 ],1\n )\n )\n \n \n ERSP_diff_out.append(power_Avg_Diff)\n ERSP_Ipsi_out.append(power_Avg_Ipsi)\n ERSP_Contra_out.append(power_Avg_Contra)\n\n\n \nprint(np.shape(ERSP_diff_out))\nprint(np.shape(Contra_spectra_out))\n\nprint(diff_out)"
"subs = [101, 102, 103, 104, 105, 106, 108, 109, 110, 111, 112,\n 202, 203, 204, 205, 207, 208, 209, 210, 211, \n 301, 302, 303, 304, 305, 306, 307, 308, 309]\n\ndiff_out = []\nIpsi_out = []\nContra_out = []\nIpsi_spectra_out = []\nContra_spectra_out = []\ndiff_spectra_out = []\nERSP_diff_out = []\nERSP_Ipsi_out = []\nERSP_Contra_out = []\n\nfrequencies = np.linspace(6, 30, 100, endpoint=True)\nwave_cycles = 6\n\n# time frequency window for analysis\nf_low = 7 # Hz\nf_high = 10\nf_diff = f_high-f_low\n \nt_low = 0 # s\nt_high = 1\nt_diff = t_high-t_low\n\nbad_subs= [6, 7, 13, 26]\nreally_bad_subs = [11, 12, 19]\nsub_count = 0 \n \n \n \nfor sub in subs:\n print(sub)\n \n sub_count += 1\n\n \n if (sub_count in really_bad_subs):\n rej_thresh_uV = 90\n elif (sub_count in bad_subs):\n rej_thresh_uV = 90\n else:\n rej_thresh_uV = 90\n\n rej_thresh = rej_thresh_uV*1e-6\n \n \n # Load both sessions\n raw = load_data(sub,1, # subject, session\n experiment='visual-cueing',site='kylemathlab_dev',device_name='muse2016',\n data_dir = eegnb_data_path)\n \n raw.append(\n load_data(sub,2, # subject, session\n experiment='visual-cueing', site='kylemathlab_dev', device_name='muse2016',\n data_dir = eegnb_data_path))\n \n\n # Filter Raw Data\n raw.filter(1,30, method='iir')\n\n #Select Events\n events = find_events(raw)\n event_id = {'LeftCue': 1, 'RightCue': 2}\n epochs = Epochs(raw, events=events, event_id=event_id, \n tmin=-1, tmax=2, baseline=(-1, 0), \n reject={'eeg':rej_thresh}, preload=True,\n verbose=False, picks=[0, 3])\n print('Trials Remaining: ' + str(len(epochs.events)) + '.')\n\n # Compute morlet wavelet\n\n # Left Cue\n tfr, itc = tfr_morlet(epochs['LeftCue'], freqs=frequencies, \n n_cycles=wave_cycles, return_itc=True)\n tfr = tfr.apply_baseline((-1,-.5),mode='mean')\n #tfr.plot(picks=[0], mode='logratio', \n # title='TP9 - Ipsi');\n #tfr.plot(picks=[3], mode='logratio', \n # title='TP10 - Contra');\n power_Ipsi_TP9 = tfr.data[0,:,:]\n power_Contra_TP10 = tfr.data[1,:,:]\n\n # Right Cue\n tfr, itc = tfr_morlet(epochs['RightCue'], freqs=frequencies, \n n_cycles=wave_cycles, return_itc=True)\n tfr = tfr.apply_baseline((-1,-.5),mode='mean')\n #tfr.plot(picks=[0], mode='logratio', \n # title='TP9 - Contra');\n #tfr.plot(picks=[3], mode='logratio', \n # title='TP10 - Ipsi');\n power_Contra_TP9 = tfr.data[0,:,:]\n power_Ipsi_TP10 = tfr.data[1,:,:]\n\n # Plot Differences\n #%matplotlib inline\n times = epochs.times\n power_Avg_Ipsi = (power_Ipsi_TP9+power_Ipsi_TP10)/2;\n power_Avg_Contra = (power_Contra_TP9+power_Contra_TP10)/2;\n power_Avg_Diff = power_Avg_Ipsi-power_Avg_Contra;\n\n\n #find max to make color range\n plot_max = np.max([np.max(np.abs(power_Avg_Ipsi)), np.max(np.abs(power_Avg_Contra))])\n plot_diff_max = np.max(np.abs(power_Avg_Diff))\n\n \n \n #Ipsi\n fig, ax = plt.subplots(1)\n im = plt.imshow(power_Avg_Ipsi,\n extent=[times[0], times[-1], frequencies[0], frequencies[-1]],\n aspect='auto', origin='lower', cmap='coolwarm', vmin=-plot_max, vmax=plot_max)\n plt.xlabel('Time (sec)')\n plt.ylabel('Frequency (Hz)')\n plt.title('Power Average Ipsilateral to Cue')\n cb = fig.colorbar(im)\n cb.set_label('Power')\n # Create a Rectangle patch\n rect = patches.Rectangle((t_low,f_low),t_diff,f_diff,linewidth=1,edgecolor='k',facecolor='none')\n # Add the patch to the Axes\n ax.add_patch(rect)\n\n #TP10\n fig, ax = plt.subplots(1)\n im = plt.imshow(power_Avg_Contra,\n extent=[times[0], times[-1], frequencies[0], frequencies[-1]],\n aspect='auto', origin='lower', cmap='coolwarm', vmin=-plot_max, vmax=plot_max)\n plt.xlabel('Time (sec)')\n plt.ylabel('Frequency (Hz)')\n plt.title(str(sub) + ' - Power Average Contra to Cue')\n cb = fig.colorbar(im)\n cb.set_label('Power')\n # Create a Rectangle patch\n rect = patches.Rectangle((t_low,f_low),t_diff,f_diff,linewidth=1,edgecolor='k',facecolor='none')\n # Add the patch to the Axes\n ax.add_patch(rect)\n\n #difference between conditions\n fig, ax = plt.subplots(1)\n im = plt.imshow(power_Avg_Diff,\n extent=[times[0], times[-1], frequencies[0], frequencies[-1]],\n aspect='auto', origin='lower', cmap='coolwarm', vmin=-plot_diff_max, vmax=plot_diff_max)\n plt.xlabel('Time (sec)')\n plt.ylabel('Frequency (Hz)')\n plt.title('Power Difference Ipsi-Contra')\n cb = fig.colorbar(im)\n cb.set_label('Ipsi-Contra Power')\n # Create a Rectangle patch\n rect = patches.Rectangle((t_low,f_low),t_diff,f_diff,linewidth=1,edgecolor='k',facecolor='none')\n # Add the patch to the Axes\n ax.add_patch(rect)\n \n \n \n \n #output data into array\n Ipsi_out.append(np.mean(power_Avg_Ipsi[np.argmax(frequencies>f_low):\n np.argmax(frequencies>f_high)-1,\n np.argmax(times>t_low):np.argmax(times>t_high)-1 ]\n )\n ) \n Ipsi_spectra_out.append(np.mean(power_Avg_Ipsi[:,np.argmax(times>t_low):\n np.argmax(times>t_high)-1 ],1\n )\n )\n \n Contra_out.append(np.mean(power_Avg_Contra[np.argmax(frequencies>f_low):\n np.argmax(frequencies>f_high)-1,\n np.argmax(times>t_low):np.argmax(times>t_high)-1 ]\n )\n )\n \n Contra_spectra_out.append(np.mean(power_Avg_Contra[:,np.argmax(times>t_low):\n np.argmax(times>t_high)-1 ],1))\n \n \n diff_out.append(np.mean(power_Avg_Diff[np.argmax(frequencies>f_low):\n np.argmax(frequencies>f_high)-1,\n np.argmax(times>t_low):np.argmax(times>t_high)-1 ]\n )\n )\n diff_spectra_out.append(np.mean(power_Avg_Diff[:,np.argmax(times>t_low):\n np.argmax(times>t_high)-1 ],1\n )\n )\n \n \n ERSP_diff_out.append(power_Avg_Diff)\n ERSP_Ipsi_out.append(power_Avg_Ipsi)\n ERSP_Contra_out.append(power_Avg_Contra)\n\n\n \nprint(np.shape(ERSP_diff_out))\nprint(np.shape(Contra_spectra_out))\n\nprint(diff_out)"
]
},
{
Expand Down Expand Up @@ -172,7 +161,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.12"
"version": "3.8.18"
}
},
"nbformat": 4,
Expand Down
Binary file modified _downloads/2cbf7eec12f4415419df2cf85cbe5c5b/visual_p300_python.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -33,25 +22,7 @@
},
"outputs": [],
"source": [
"import os\nfrom eegnb import generate_save_fn\nfrom eegnb.devices.eeg import EEG\nfrom eegnb.experiments.visual_n170 import n170\n\n# Define some variables\nboard_name = \"muse\"\nexperiment = \"visual_n170\"\nsubject_id = 0\nsession_nb = 0\nrecord_duration = 120"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initiate EEG device\n\nStart EEG device\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"eeg_device = EEG(device=board_name)\n\n# Create save file name\nsave_fn = generate_save_fn(board_name, experiment, subject_id, session_nb)\nprint(save_fn)"
"from eegnb import generate_save_fn\nfrom eegnb.devices.eeg import EEG\nfrom eegnb.experiments import VisualN170\n\n# Define some variables\nboard_name = \"muse2\" # board name\nexperiment_name = \"visual_n170\" # experiment name\nsubject_id = 0 # test subject id\nsession_nb = 0 # session number\nrecord_duration = 120 # recording duration\n\n# generate save path\nsave_fn = generate_save_fn(board_name, experiment_name, subject_id, session_nb)\n\n# create device object\neeg_device = EEG(device=board_name)\n\n# Experiment type\nexperiment = VisualN170(duration=record_duration, eeg=eeg_device, save_fn=save_fn)"
]
},
{
Expand All @@ -69,7 +40,7 @@
},
"outputs": [],
"source": [
"n170.present(duration=record_duration, eeg=eeg_device, save_fn=save_fn)"
"experiment.run()\n\n# Saved csv location\nprint(\"Recording saved in\", experiment.save_fn)"
]
}
],
Expand All @@ -89,7 +60,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.12"
"version": "3.8.18"
}
},
"nbformat": 4,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import os
from eegnb import generate_save_fn
from eegnb.devices.eeg import EEG
from eegnb.experiments.visual_ssvep import ssvep
from eegnb.experiments import VisualSSVEP

# Define some variables
board_name = "muse"
board_name = "muse2"
experiment = "visual_ssvep"
subject_id = 0
session_nb = 0
Expand All @@ -39,4 +39,5 @@
# Run experiment
# ---------------------
#
ssvep.present(duration=record_duration, eeg=eeg_device, save_fn=save_fn)
ssvep = VisualSSVEP(duration=record_duration, eeg=eeg_device, save_fn=save_fn)
ssvep.run()
Loading

0 comments on commit 5e3ea09

Please sign in to comment.