def load_eeg_dataset(path, filename, attrib, TR, eliminated_vols=None, **kwargs): """ **kwargs: - type: * 'psd': Power Spectrum Density using matplotlib.specgram additional parameters to be included NFFT and noverlap * 'fft': Power Spectrum and Phase using scipy.fft * 'time': EEG timecourse in every TR. """ type = "time" for arg in kwargs: if arg == "type": type = kwargs[arg] print "type = " + type # load eeg data [data, eeg_info] = load_eeg_data(path, filename, TR, eliminatedVols=eliminated_vols) channel_ids = eeg_info["channel_ids"] dt = eeg_info["dt"] kwargs["dt"] = dt if (type == "psd") or (type == "fft"): [samples, freq] = spectrum_eeg(data, **kwargs) data = samples.reshape(samples.shape[0], samples.shape[1], -1) # mvpa analysis: attributes and dataset attr = SampleAttributes(attrib) print "Building dataset..." ds = Dataset.from_channeltimeseries(data, channelids=channel_ids, targets=attr.targets, chunks=attr.chunks) if (type == "psd") or (type == "fft"): ds.a["frequiencies"] = freq ds.a["shape"] = samples.shape ds.a["timepoints"] = np.arange(0, TR, dt) del data if "samples" in locals(): del samples return ds
for j in channelSelected: start = markers[i][1] + (onSet / dt) stop = start + (nSamples / dt) nVec = np.array(data.T[j][start:stop]) if nVec.shape[0] != (nSamples / dt): nVec.resize(nSamples / dt) print "yes" dataRes[j][i] = nVec # Select data based on channels Selected dataResSel = np.take(dataRes, channelSelected, axis=0) ch_infoSel = np.take(ch_info, channelSelected) # reshape data to feed Dataset dataResSel = np.reshape(dataResSel, (nTrials, -1, nSamples / dt)) # Eliminate first n. runs volToEliminate = 5 dataResSel = dataResSel[: nTrials - volToEliminate] # mvpa analysis: attributes and dataset attr = SampleAttributes("/home/robbis/fmri_datasets/monks/monks_attrib_pymvpa.txt") ds = Dataset.from_channeltimeseries( dataResSel, t0=0, dt=dt, channelids=ch_infoSel, targets=attr.targets, chunks=attr.chunks ) del dataRes, dataResSel