Hello, it is me (again )
I now want to export my ERPs to csv. I usually use that code to export my TFR-data. The data I load in “grandaverage_CSplus_Remembered”, are the grand averaged data from one condition from the subjects in the participant list. The code shows me the following error when I run the line “data = np.dstack((timeS,alpha))”:
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 1201 and the array at index 1 has size 1
I guess it has something to do with how the imported data are structured. I usually get an excel sheet with 4 rows (-1 to 0 sec, 0 to 1 sec, 1 to 2 sec, 2 to 3 sec) and one column for each subject. In each cell I get the averaged TFR data for e.g. the time window from 0 to 1 sec for participant xy
baseline_CPR = pd.DataFrame()
for subject in participant_list:
# Load data (after ICA)
session = 'ses-Expo'
data_path ='C:\\Users\\Admin\\Desktop\\Projekt_Franziska\Studie 3\\Analyse\\EEG\\Stats\\ERPs'
file_name_CSplusRemembered=data_path + '/' + subject + 'grandaverage_CSplus_Remembered.fif'
data_CSplusRemembered_path = op.join(data_path,file_name_CSplusRemembered)
data_CSplusRemembered= mne.read_evokeds(data_CSplusRemembered_path)
data_CSplusRemembered=data_CSplusRemembered[0]
data_CSplusRemembered.pick_channels(ch_names=['Fz'])
data_alpha_CSplusRemembered=data_CSplusRemembered.crop(tmin=-1, tmax=3, include_tmax=True)
# data_alpha_CSplusRemembered=data_alpha_CSplusRemembered.apply_baseline(baseline=[-0.2,0], verbose=None)
alpha=np.mean(data_alpha_CSplusRemembered.data, axis=1)
alpha=np.mean(alpha.data, axis=0)
timeS=data_alpha_CSplusRemembered.times[0:]
data = np.dstack((timeS,alpha))
data = data.reshape(4001, 2)
index=data_alpha_CSplusRemembered.times[0:]
columns=['time','value']
df_data_CSplusR = pd.DataFrame(data=data , # values
index=index,
columns=columns) # 1st row as the column names
df_data_CSplusR['pptID'] = subject
df_data_CSplusR['condition'] = 'CPR'
df_data_CSplusR['shock'] = 'P'
df_data_CSplusR['memory'] = 'R'
baseline_CPR = baseline_CPR.append(pd.DataFrame(data = df_data_CSplusR), ignore_index=True)
del data_CSplusRemembered, data_alpha_CSplusRemembered, alpha, df_data_CSplusR
#Averages values to 1 value each sec
baseline_CPR=baseline_CPR[baseline_CPR['time']!=0]
baseline_CPR['Sec']= baseline_CPR['time'].apply(np.ceil)
baseline_CPR_summary=pd.pivot_table(baseline_CPR,values='value',index=['pptID'],columns=['Sec'],aggfunc=np.mean)
baseline_CPR_summary.to_csv('C:\\Users\\Admin\\Desktop\\Projekt_Franziska\\Studie 3\\Analyse\\EEG\\Stats\\ERPs\\ERP_CSp_Remembered_Baseline_Front.csv')
Any idea what might be wrong?
Thank you in advance
Best, Franzi