def calc_signal_power(params, fname, transient=<NUM_LIT:200>, Df=None, mlab=True, NFFT=<NUM_LIT:1000>,<EOL>noverlap=<NUM_LIT:0>, window=plt.mlab.window_hanning):
if type(fname) is str and os.path.isfile(fname):<EOL><INDENT>f = h5py.File(fname)<EOL>data = f['<STR_LIT:data>'].value<EOL>srate = f['<STR_LIT>'].value <EOL>tvec = np.arange(data.shape[<NUM_LIT:1>]) * <NUM_LIT> / srate<EOL>f.close()<EOL><DEDENT>elif type(fname) is np.ndarray:<EOL><INDENT>data = fname<EOL>srate = <NUM_LIT><EOL>tvec = np.arange(data.shape[<NUM_LIT:1>]) * <NUM_LIT> / srate<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>'.format(fname))<EOL><DEDENT>slica = (tvec >= transient)<EOL>data = data[:,slica]<EOL>dataT = data.T - data.mean(axis=<NUM_LIT:1>)<EOL>data = dataT.T<EOL>PSD=[]<EOL>for i in np.arange(len(params.electrodeParams['<STR_LIT:z>'])):<EOL><INDENT>if mlab:<EOL><INDENT>Pxx, freqs=plt.mlab.psd(data[i], NFFT=NFFT,<EOL>Fs=srate, noverlap=noverlap, window=window)<EOL><DEDENT>else:<EOL><INDENT>[freqs, Pxx] = helpers.powerspec([data[i,]], tbin= <NUM_LIT:1.>,<EOL>Df=Df, pointProcess=False)<EOL>mask = np.where(freqs >= <NUM_LIT:0.>)<EOL>freqs = freqs[mask]<EOL>Pxx = Pxx.flatten()<EOL>Pxx = Pxx[mask]<EOL>Pxx = Pxx/tvec[tvec >= transient].size**<NUM_LIT:2><EOL><DEDENT>PSD +=[Pxx.flatten()]<EOL><DEDENT>PSD=np.array(PSD)<EOL>return freqs, PSD<EOL>
calculates power spectrum of sum signal for all channels