calculates power spectrum of sum signal for all channels

def calc_signal_power(params, fname, transient=200, Df=None, mlab=True, NFFT=1000,
                      noverlap=0, window=plt.mlab.window_hanning):
    '''
    calculates power spectrum of sum signal for all channels

    '''


    if type(fname) is str and os.path.isfile(fname):
        #open file
        f = h5py.File(fname)
        data = f['data'].value
        srate = f['srate'].value 
        tvec = np.arange(data.shape[1]) * 1000. / srate
        f.close()
    elif type(fname) is np.ndarray:
        data = fname
        srate = 1000.
        tvec = np.arange(data.shape[1]) * 1000. / srate
    else:
        raise Exception, '{} not a file or array'.format(fname)
    
    # slice
    slica = (tvec >= transient)
    data = data[:,slica]

    # subtract mean
    dataT = data.T - data.mean(axis=1)
    data = dataT.T
    
    #extract PSD
    PSD=[]
    for i in np.arange(len(params.electrodeParams['z'])):
        if mlab:
            Pxx, freqs=plt.mlab.psd(data[i], NFFT=NFFT,
                                    Fs=srate, noverlap=noverlap, window=window)
        else:
            [freqs, Pxx] = helpers.powerspec([data[i,]], tbin= 1.,
                                        Df=Df, pointProcess=False)
            mask = np.where(freqs >= 0.)
            freqs = freqs[mask]
            Pxx = Pxx.flatten()
            Pxx = Pxx[mask]
            Pxx = Pxx/tvec[tvec >= transient].size**2
        PSD +=[Pxx.flatten()]
        
    PSD=np.array(PSD)

    return freqs, PSD