#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 15 13:23:24 2017
    
@author: daisy
"""

#%% 
import matplotlib.pyplot as plt
import numpy as np
import mne



subject = 'lanmengying'
con='normal'
subjects_dir ='/Applications/freesurfer/subjects'
data_path='/Users/daisy/Desktop/MEG_data/s28'


# Load stc
fname_stc=data_path+'/run2_mooney_normal/'+ subject+'_'+ con+'_maxpower'
stc = mne.read_source_estimate(fname_stc)


# Load src
spacing='ico5'
fname_src = subjects_dir +'/'+subject+'/bem/'+subject+'-'+spacing[0:3]+'-'+ spacing[3]+'-src.fif'
src = mne.read_source_spaces(fname_src)

#%% extract Max value within each label.
label_name=['lofa-lh','rofa-rh','lpffa-lh','rpffa-rh']
results={}
results['time']=stc.times 
for index in range(len(label_name)):  
                 
    fname_label=data_path + '/roi/' + label_name[index] + '.label'
    anat_label=mne.read_label(fname_label)   
    results[label_name[index]]=stc.extract_label_time_course(anat_label, src, mode='max')
    
    
    
    
                                   
    
   
    
    
    
        
    
    
    
    
    


