Skip to content

LabNeuroCogDevel/SteadyState.py

Repository files navigation

SteadyState EEG Task

Port of Presentation

Task settings

Triggers and duration

For each trial, a 20, 30, or 40Hz “click train” sounds is played. The trial starts with a TTL value of 2, 3, or 4 depending on the sound frequency. The trials are presented in blocks of 150 by frequency and last 1.10 seconds.

import mne
import numpy as np
import pandas as pd
from sspipe import p, px
exf = '/Volumes/Hera/Raw/EEG/7TBrainMech/11752_20190409/11752_20190409_SS.bdf'
b = mne.io.read_raw_bdf(exf)
s = b.get_data(['Status'])[0,:]
mins = min(s)
e = mne.find_events(b)
validttl = [int(x)  for x in e[:,2]-mins if x >0 and x < 300 ]
cnt = {}
for ttl in validttl:
  cnt[ttl] = cnt.get(ttl,0) + 1

# quck run length encode
i = np.where(np.diff([0]+validttl+[0])!=0)[0]
l = np.diff(i)
rle = [(validttl[v], l[ii]) for ii,v in enumerate(i[:len(i)-1])]
# print(rle)
# [(4, 150), (2, 150), (3, 150)]

# get even duration for each event type
#  - take the diff of event onsets and div by sample rate 
#  - only works because events are blocked rather than interleaved
meddur =\
  [
    e[e[:,2] == k+mins,0] \
    | p(np.diff) \
    | px/b.info['sfreq'] \
    | p(lambda x: {
	    'ttl': k,
	    'n': cnt[k],
	    'med_dur': np.median(x),
	    'std': np.std(x)})
	      for k in cnt.keys()\
   ] | p(pd.DataFrame)
# send meddur back
meddur

trigger reset to zero

before each trigger there are zeros. after 6 samples

print(np.array([s[e[x,0]-1:e[x,0]+10] for x in [1,2,3]]))
print(6/b.info['sfreq'])

settings

default_background_color = 0,0,0; picture { text { caption = “+”; font_size = 36; font_color = 255,255,255; }; x = 0; y = 0;} default;

trial {duration = 1100 …} …. 128 start time=10 duration=1500 …. 129 end time=1500 duration=20

file“port”
gamma40.sce4
gamma202
gamma303

Psychopy

https://www.psychopy.org/api/sound.html

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published