def epoched_spectral_proc(ts_file,sfreq,freq_band,con_method,epoch_window_length): import numpy as np from neuropype_ephy.spectral import compute_and_save_spectral_connectivity data = np.load(ts_file) print data.shape print sfreq print freq_band if epoch_window_length == None: conmat_file = compute_and_save_spectral_connectivity(data=data,con_method=con_method,sfreq=sfreq,fmin = freq_band[0],fmax = freq_band[1]) else: print "Shape before splits:" print data.shape print "sfreq:" print sfreq nb_splits = data.shape[1] // (epoch_window_length * sfreq) print "nb_splits:" print nb_splits reste = data.shape[1] % int(epoch_window_length * sfreq) print "reste:" print reste if reste != 0: data = data[:,:-reste] print "shape after reste:" print data.shape print "epoching data with {}s by window, resulting in {} epochs".format(epoch_window_length,nb_splits) list_epoched_data = np.array_split(data,nb_splits,axis = 1) for epo in list_epoched_data: print epo.shape #print "Shape after splits:" #print epoched_data.shape epoched_data = np.array(list_epoched_data) conmat_file = compute_and_save_spectral_connectivity(data=epoched_data, con_method=con_method, sfreq=sfreq, fmin= freq_band[0], fmax=freq_band[1]) return conmat_file
def _run_interface(self, runtime): print 'in SpectralConn' ts_file = self.inputs.ts_file sfreq = self.inputs.sfreq freq_band = self.inputs.freq_band con_method = self.inputs.con_method epoch_window_length = self.inputs.epoch_window_length export_to_matlab = self.inputs.export_to_matlab index = self.inputs.index if epoch_window_length == traits.Undefined: print '*** NO epoch_window_length ***' data = np.load(ts_file) else: raw_data = np.load(ts_file) nb_splits = raw_data.shape[1] // (epoch_window_length * sfreq) reste = raw_data.shape[1] % int(epoch_window_length * sfreq) if reste != 0: raw_data = raw_data[:,:-reste] print "epoching data with {}s by window, resulting in {} epochs (rest = {})".format(epoch_window_length,nb_splits,reste) data = np.array(np.array_split(raw_data,nb_splits,axis = 1)) self.conmat_file = compute_and_save_spectral_connectivity(data = data,con_method = con_method,index = index, sfreq=sfreq, fmin= freq_band[0], fmax=freq_band[1],export_to_matlab = export_to_matlab) return runtime
def spectral_proc_label(ts_file,sfreq,freq_band,con_method,label,mode): import numpy as np #import os from neuropype_ephy.spectral import compute_and_save_spectral_connectivity data = np.load(ts_file) conmat_file = compute_and_save_spectral_connectivity(data = data,con_method = con_method,sfreq=sfreq, fmin= freq_band[0], fmax=freq_band[1],index = label,mode = mode) return conmat_file