In [1]:
import mne
import sqlite3
%pylab inline

mne.set_log_level('WARNING')


Populating the interactive namespace from numpy and matplotlib
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/ipykernel/pylab/config.py:66: DeprecationWarning: metadata {'config': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')
  inline backend."""
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/ipykernel/pylab/config.py:71: DeprecationWarning: metadata {'config': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')
  'retina', 'jpeg', 'svg', 'pdf'.""")
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/ipykernel/pylab/config.py:85: DeprecationWarning: metadata {'config': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')
  use `figure_formats` instead)""")
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/ipykernel/pylab/config.py:95: DeprecationWarning: metadata {'config': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')
  """
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/ipykernel/pylab/config.py:114: DeprecationWarning: metadata {'config': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')
  """)
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/ipykernel/pylab/config.py:44: DeprecationWarning: InlineBackend._config_changed is deprecated: use @observe and @unobserve instead.
  def _config_changed(self, name, old, new):
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/traitlets/traitlets.py:770: DeprecationWarning: A parent of InlineBackend._config_changed has adopted the new @observe(change) API
  clsname, change_or_name), DeprecationWarning)
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/IPython/core/formatters.py:98: DeprecationWarning: DisplayFormatter._formatters_default is deprecated: use @default decorator instead.
  def _formatters_default(self):
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/IPython/core/formatters.py:677: DeprecationWarning: PlainTextFormatter._deferred_printers_default is deprecated: use @default decorator instead.
  def _deferred_printers_default(self):
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/IPython/core/formatters.py:669: DeprecationWarning: PlainTextFormatter._singleton_printers_default is deprecated: use @default decorator instead.
  def _singleton_printers_default(self):
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/IPython/core/formatters.py:672: DeprecationWarning: PlainTextFormatter._type_printers_default is deprecated: use @default decorator instead.
  def _type_printers_default(self):
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/IPython/core/formatters.py:672: DeprecationWarning: PlainTextFormatter._type_printers_default is deprecated: use @default decorator instead.
  def _type_printers_default(self):
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/IPython/core/formatters.py:677: DeprecationWarning: PlainTextFormatter._deferred_printers_default is deprecated: use @default decorator instead.
  def _deferred_printers_default(self):

In [2]:
#raw = mne.io.read_raw_brainvision('/Volumes/Store/Avner/POUYAN-BRAIN/pouyan.vhdr')
#raw = mne.io.read_raw_brainvision('/home/avnerus/Code/eegtest/EEG/test2.vhdr')
#raw = mne.io.read_raw_eeglab('/home/avnerus/Code/eegtest/MATTI/matti_rs_cl_fl.set')
#raw = mne.io.read_raw_brainvision('/Volumes/Store/Avner/MATTI-BRAIN/matti.vhdr')
raw = mne.io.read_raw_eeglab('/Volumes/Store/Avner/MATTI-BRAIN/matti_rs_cl_fl.set')

print(raw.info)


<Info | 16 non-empty fields
    bads : list | 0 items
    buffer_size_sec : float | 1.0
    ch_names : list | Fp1, Fp2, F7, F3, Fz, F4, F8, FC5, FC1, FC2
    chs : list | 32 items (EEG: 32)
    comps : list | 0 items
    custom_ref_applied : bool | False
    dev_head_t : 'mne.transforms.Transform | 3 items
    events : list | 0 items
    highpass : float | 0.0 Hz
    hpi_meas : list | 0 items
    hpi_results : list | 0 items
    lowpass : float | 250.0 Hz
    meas_date : numpy.ndarray | 1970-01-01 02:00:00
    nchan : int | 32
    projs : list | 0 items
    sfreq : float | 500.0 Hz
    acq_pars : NoneType
    acq_stim : NoneType
    ctf_head_t : NoneType
    description : NoneType
    dev_ctf_t : NoneType
    dig : NoneType
    experimenter : NoneType
    file_id : NoneType
    filename : NoneType
    hpi_subsystem : NoneType
    line_freq : NoneType
    meas_id : NoneType
    proj_id : NoneType
    proj_name : NoneType
    subject_info : NoneType
>
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/scipy/special/__init__.py:627: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility
  from ._ufuncs import *
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/scipy/special/__init__.py:627: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from ._ufuncs import *
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/scipy/special/_ellip_harm.py:7: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility
  from ._ellip_harm_2 import _ellipsoid, _ellipsoid_norm
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/scipy/special/_ellip_harm.py:7: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from ._ellip_harm_2 import _ellipsoid, _ellipsoid_norm
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/scipy/io/matlab/mio4.py:18: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility
  from .mio_utils import squeeze_element, chars_to_strings
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/scipy/io/matlab/mio4.py:18: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from .mio_utils import squeeze_element, chars_to_strings
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/scipy/io/matlab/mio5.py:98: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility
  from .mio5_utils import VarReader5
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/scipy/io/matlab/mio5.py:98: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from .mio5_utils import VarReader5

In [3]:
print((raw.ch_names))


[u'Fp1', u'Fp2', u'F7', u'F3', u'Fz', u'F4', u'F8', u'FC5', u'FC1', u'FC2', u'FC6', u'T7', u'C3', u'Cz', u'C4', u'T8', u'TP9', u'CP5', u'CP1', u'CP2', u'CP6', u'TP10', u'P7', u'P3', u'Pz', u'P4', u'P8', u'PO9', u'O1', u'Oz', u'O2', u'PO10']

In [5]:
events = mne.find_events(raw)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-aa5ca818a2dc> in <module>()
----> 1 events = mne.find_events(raw)

/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/mne/event.pyc in find_events(raw, stim_channel, verbose, output, consecutive, min_duration, shortest_event, mask)

/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/mne/utils.pyc in verbose(function, *args, **kwargs)
    549         finally:
    550             set_log_level(old_level)
--> 551     return function(*args, **kwargs)
    552 
    553 

/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/mne/event.pyc in find_events(raw, stim_channel, verbose, output, consecutive, min_duration, shortest_event, mask)
    591 
    592     # pull stim channel from config if necessary
--> 593     stim_channel = _get_stim_channel(stim_channel, raw.info)
    594 
    595     pick = pick_channels(raw.info['ch_names'], include=stim_channel)

/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/mne/utils.pyc in _get_stim_channel(stim_channel, info)
   1562         return stim_channel
   1563 
-> 1564     raise ValueError("No stim channels found. Consider specifying them "
   1565                      "manually using the 'stim_channel' parameter.")
   1566 

ValueError: No stim channels found. Consider specifying them manually using the 'stim_channel' parameter.

In [4]:
print (events)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-f2cb0f1d19b0> in <module>()
----> 1 print (events)

NameError: name 'events' is not defined

In [4]:
# Pick the centro-parietal channels
raw.preload = True
centro_parietal_channels = ['C3','Cz','C4','CP1','CP2','CP5','CP6','P3','Pz','P4']
specific_chans = raw.pick_channels(centro_parietal_channels, copy=True)
print(specific_chans)


<RawEEGLAB  |  n_channels x n_times : 10 x 1651660>

In [5]:
first_event_sec = specific_chans.times[36118]
last_event_sec = specific_chans.times[1613461]
print("Experiment times %f --> %f" % (first_event_sec, last_event_sec))


Experiment times 72.236000 --> 3226.922000

In [6]:
start, stop = specific_chans.time_as_index([first_event_sec,last_event_sec]) 

print(start,stop)


(36118, 1613461)

In [12]:
#last_event_sec = specific_chans.times[1490754]

#FIRST INDEX WORK AROUND
#pouyan_sec = 48 * 60 + 30.16

#first_event_sec = last_event_sec - pouyan_sec

#print("Total Pouyan time: %f" % (pouyan_sec))
#pouyan_start = indexes[0] - pouyanMs

#first_event_sec = 72.235800
#last_event_sec = 3226.920800


#start, stop = specific_chans.time_as_index([first_event_sec,last_event_sec]) 

start = events[0][0]
stop = events[1][0]
print(start,stop)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-12-7942e3fd475a> in <module>()
     15 #start, stop = specific_chans.time_as_index([first_event_sec,last_event_sec])
     16 
---> 17 start = events[0][0]
     18 stop = events[1][0]
     19 print(start,stop)

NameError: name 'events' is not defined

In [7]:
specific_chans = specific_chans.load_data()
specific_chans.preload = False
data, times = specific_chans[:, start:stop]
print(specific_chans)


<RawEEGLAB  |  n_channels x n_times : 10 x 1651660>

In [8]:
print(len(data[0]))


1577343

In [9]:
def get_lpp(index):    
    first_index = int(index + raw.info['sfreq'] * 0.4)
    last_index = int(index + raw.info['sfreq'] * 0.7)
    if last_index < len(data[0]):
        #print("Will get maximum value between index %d and %d" % (first_index, last_index))       
        
        max_amplitude = data[:,first_index:last_index + 1].sum(axis=0).max()
        present_value = data[:,index].sum()
        
        lpp  = max_amplitude - present_value
        return lpp
    else:
        return 0
        
lpp_values = []
for i in range(len(data[0])):
    lpp_values.append(get_lpp(i))

In [10]:
plt.rcParams["figure.figsize"] = [20.0,8.0]
#%pylab qt
a = hist(lpp_values, bins=500)


/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/IPython/core/formatters.py:92: DeprecationWarning: DisplayFormatter._ipython_display_formatter_default is deprecated: use @default decorator instead.
  def _ipython_display_formatter_default(self):
/Volumes/Store/Avner/Projects/socialbonds/venv/lib/python2.7/site-packages/IPython/core/formatters.py:669: DeprecationWarning: PlainTextFormatter._singleton_printers_default is deprecated: use @default decorator instead.
  def _singleton_printers_default(self):

In [1]:
print(a[1][174])


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-2945cb6bc638> in <module>()
----> 1 print(a[1][174])

NameError: name 'a' is not defined

In [12]:
conn = sqlite3.connect('matti_eeg.db')
c = conn.cursor()

In [13]:
# Create table
c.execute('''CREATE TABLE data
             (
             id INTEGER PRIMARY KEY ASC,
             channel0 real, 
             channel1 real, 
             channel2 real, 
             channel3 real, 
             channel4 real, 
             channel5 real, 
             channel6 real, 
             channel7 real, 
             channel8 real, 
             channel9 real, 
             lpp real)''')


Out[13]:
<sqlite3.Cursor at 0x10e655a40>

In [14]:
channels = []
for value_index in range(len(data[0])):
    all_channels = []
    all_channels.append(value_index)
    for channel_index in range(10):
        all_channels.append(data[channel_index][value_index])
    all_channels.append(lpp_values[value_index])
        
    channels.append(tuple(all_channels))      
    
    
#channel0 = map(lambda x: (0,x), data[0])

In [15]:
#print(data[1][1])

In [16]:
c.executemany('INSERT INTO data VALUES (?,?,?,?,?,?,?,?,?,?,?,?)', channels)


Out[16]:
<sqlite3.Cursor at 0x10e655a40>

In [17]:
conn.commit()
conn.close()

In [ ]: