In [1]:
# Import Necessary Libraries
import numpy as np
import scipy.io

import matplotlib
from matplotlib import *
from matplotlib import pyplot as plt
import itertools
from mpl_toolkits.axes_grid1 import make_axes_locatable

from sklearn.decomposition import PCA
import scipy.stats as stats
from scipy.spatial import distance as Distance

# pretty charting
import seaborn as sns
sns.set_palette('muted')
sns.set_style('darkgrid')

%matplotlib inline

In [11]:
#### Extract wordpairs data into a dictionary for a subject/session/block
#### dictionary{wordpair:{channels}}
def extractSubjVocalizedData(subj, word):
    # file directory for a subj/session/block
    filedir = '../../condensed_data_' + subj + '/summary_vocalization/' + word
    
    # initialize data dictionary with meta data
    data_dict = {}
    data_dict['meta'] = {'subject': subj,
                         'word': word}
    
    all_channel_mats = os.listdir(filedir)
    for channel in all_channel_mats: # loop thru all channels
        chan_file = filedir + '/' + channel

        ## 00: load in data
        data = scipy.io.loadmat(chan_file)
        data = data['data']

        ## 01: get the time point for probeword on
        timeZero = data['timeZero'][0][0][0]

        ## 02: get the time point of vocalization
        vocalization = data['vocalization'][0][0][0]

        ## 03: Get Power Matrix
        power_matrix = data['powerMatZ'][0][0]

        chan = channel.split('_')[0]

        # convert channel data into a json dict
        data_dict[chan] = {'timeZero': timeZero,
                                      'timeVocalization':vocalization,
                                      'powerMat': power_matrix}
    return data_dict

In [12]:
######## Get list of files (.mat) we want to work with ########
subj = 'NIH034' # change the directories if you want
filedir = '../../condensed_data_' + subj + '/summary_vocalization/'
targetWords = os.listdir(filedir)

print targetWords

for word in targetWords:
    wordDir = filedir + word
    
    ## 01: Extract the data of every channel for this subject and targetWord
    wordData = extractSubjVocalizedData(subj, word)
    
    print wordData.keys()
    break


['BRICK', 'CLOCK', 'GLASS', 'JUICE', 'PANTS']
['24', '25', '26', '27', '20', '21', '22', '23', '28', '29', '4', '8', '59', '58', '55', '54', '57', '56', '51', '50', '53', '52', '88', 'meta', '82', '83', '80', '81', '86', '87', '84', '85', '3', '7', '39', '38', '33', '32', '31', '30', '37', '36', '35', '34', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '2', '6', '91', '90', '93', '92', '95', '94', '96', '11', '10', '13', '12', '15', '14', '17', '16', '19', '18', '89', '48', '49', '46', '47', '44', '45', '42', '43', '40', '41', '1', '5', '9', '77', '76', '75', '74', '73', '72', '71', '70', '79', '78']

In [ ]: