def fftplt3(x,Mch,pval=0.1,dtrnd=True,demean=True,titlestr='',Dt=0.01): """Differs from fftplt3 solely by plotting the power spectral density in log-form, 10*log10(P).""" fs=1 titl_plc = (1.,1.) if demean: x = x - x.mean() if dtrnd: Pout = plt.psd(x, NFFT=Mch, detrend=pylab.detrend_linear, noverlap=Mch/2, Fs=fs) else: Pout = plt.psd(x, NFFT=Mch, detrend=pylab.detrend_none, noverlap=Mch/2, Fs=fs) xdtrnd = pylab.detrend_linear(x) xauto = mcmath.acorr_mlab(xdtrnd,2) rhoxauto = (xauto[1] + np.sqrt(abs(xauto[2])))/2 R = mcmath.redspec(rhoxauto,np.arange(Mch/2),Mch) P = Pout[0][:R.size] F = Pout[1][:R.size] Psum = P.sum() Rsum = R.sum() PRratio = Psum/Rsum Rcmp = R*PRratio dof = (x.size / (Mch/2.)) * 1.2 Fval = stats.f.isf(pval,dof,dof) tst = P / Rcmp pass1 = np.where(tst > Fval)[0] maxs = mcmath.extrema_find(P,'max',t=F,dt=Dt) max_ind = np.intersect1d(maxs,pass1) Fmaxs = F[max_ind] Fmaxs2 = np.append(Fmaxs,0.1) Fmaxs2.sort() Tmaxs = 1/(Fmaxs2) Tmaxs = np.round(Tmaxs,2) ax = plt.gca() ax.plot(F,10*np.log10(Rcmp)) ax.set_xticks(Fmaxs2) ax.set_xticklabels(Tmaxs) my_fmt_xdate(ax,rot=90,hal='center') multiline(Fmaxs,c='red',ls='--') xtl = ax.get_xticklabels() ytl = ax.get_yticklabels() plt.setp(xtl,'size',10) plt.setp(ytl,'size',9) ppct = int((1 - pval)*100) titl_str = '%s FFT (chunksize: %d) :: peak CL: %d%%' % (titlestr,Mch,ppct) plt.text(titl_plc[0],titl_plc[1],titl_str,ha='right',va='bottom',size=12,transform=ax.transAxes) plt.xlabel('Peak period (yrs)',size=11) return (F,P,Rcmp)
def fftplt3(x, Mch, pval=0.1, dtrnd=True, demean=True, titlestr='', Dt=0.01): """Differs from fftplt3 solely by plotting the power spectral density in log-form, 10*log10(P).""" fs = 1 titl_plc = (1., 1.) if demean: x = x - x.mean() if dtrnd: Pout = plt.psd(x, NFFT=Mch, detrend=pylab.detrend_linear, noverlap=Mch / 2, Fs=fs) else: Pout = plt.psd(x, NFFT=Mch, detrend=pylab.detrend_none, noverlap=Mch / 2, Fs=fs) xdtrnd = pylab.detrend_linear(x) xauto = mcmath.acorr_mlab(xdtrnd, 2) rhoxauto = (xauto[1] + np.sqrt(abs(xauto[2]))) / 2 R = mcmath.redspec(rhoxauto, np.arange(Mch / 2), Mch) P = Pout[0][:R.size] F = Pout[1][:R.size] Psum = P.sum() Rsum = R.sum() PRratio = Psum / Rsum Rcmp = R * PRratio dof = (x.size / (Mch / 2.)) * 1.2 Fval = stats.f.isf(pval, dof, dof) tst = P / Rcmp pass1 = np.where(tst > Fval)[0] maxs = mcmath.extrema_find(P, 'max', t=F, dt=Dt) max_ind = np.intersect1d(maxs, pass1) Fmaxs = F[max_ind] Fmaxs2 = np.append(Fmaxs, 0.1) Fmaxs2.sort() Tmaxs = 1 / (Fmaxs2) Tmaxs = np.round(Tmaxs, 2) ax = plt.gca() ax.plot(F, 10 * np.log10(Rcmp)) ax.set_xticks(Fmaxs2) ax.set_xticklabels(Tmaxs) my_fmt_xdate(ax, rot=90, hal='center') multiline(Fmaxs, c='red', ls='--') xtl = ax.get_xticklabels() ytl = ax.get_yticklabels() plt.setp(xtl, 'size', 10) plt.setp(ytl, 'size', 9) ppct = int((1 - pval) * 100) titl_str = '%s FFT (chunksize: %d) :: peak CL: %d%%' % (titlestr, Mch, ppct) plt.text(titl_plc[0], titl_plc[1], titl_str, ha='right', va='bottom', size=12, transform=ax.transAxes) plt.xlabel('Peak period (yrs)', size=11) return (F, P, Rcmp)
def fftplt2(x,Mch,pval=0.1,dtrnd=True,demean=True,titlestr='',Dt=0.01): """Differs from fftplt1 by returning a plot highlighting sig peaks, with their freq axis tick marks notated by their period. Also allows adjustment of sig level and title string.""" fs=1 titl_plc = (1.,1.) if demean: x = x - x.mean() if dtrnd: Pout = plt.psd(x, NFFT=Mch, detrend=pylab.detrend_linear, noverlap=Mch/2, Fs=fs) else: Pout = plt.psd(x, NFFT=Mch, detrend=pylab.detrend_none, noverlap=Mch/2, Fs=fs) xdtrnd = pylab.detrend_linear(x) xauto = mcmath.acorr_mlab(xdtrnd,2) rhoxauto = (xauto[1] + np.sqrt(abs(xauto[2])))/2 R = mcmath.redspec(rhoxauto,np.arange(Mch/2),Mch) P = Pout[0][:R.size] F = Pout[1][:R.size] Psum = P.sum() Rsum = R.sum() PRratio = Psum/Rsum Rcmp = R*PRratio dof = (x.size / (Mch/2.)) * 1.2 Fval = stats.f.isf(pval,dof,dof) tst = P / Rcmp pass1 = np.where(tst > Fval)[0] maxs = mcmath.extrema_find(P,'max',t=F,dt=Dt) max_ind = np.intersect1d(maxs,pass1) Fmaxs = F[max_ind] Fmaxs2 = np.append(Fmaxs,0.1) Fmaxs2.sort() Tmaxs = 1/(Fmaxs2) Tmaxs = np.round(Tmaxs,2) fig = plt.figure(figsize=(7,5)) ax = fig.add_axes((0.1,0.14,0.88,0.81)) ax.plot(F,P,) ax.plot(F,Rcmp) ax.set_xticks(Fmaxs2) ax.set_xticklabels(Tmaxs) my_fmt_xdate(ax,rot=90,hal='center') multiline(Fmaxs,c='red',ls='--') xtl = ax.get_xticklabels() ytl = ax.get_yticklabels() plt.setp(xtl,'size',10) plt.setp(ytl,'size',9) ppct = int((1 - pval)*100) titl_str = '%s FFT (chunksize: %d) :: peak CL: %d%%' % (titlestr,Mch,ppct) plt.text(titl_plc[0],titl_plc[1],titl_str,ha='right',va='bottom',size=12,transform=ax.transAxes) plt.xlabel('Peak period (yrs)',size=11) return (F,P,Rcmp)
def fftplt2(x, Mch, pval=0.1, dtrnd=True, demean=True, titlestr='', Dt=0.01): """Differs from fftplt1 by returning a plot highlighting sig peaks, with their freq axis tick marks notated by their period. Also allows adjustment of sig level and title string.""" fs = 1 titl_plc = (1., 1.) if demean: x = x - x.mean() if dtrnd: Pout = plt.psd(x, NFFT=Mch, detrend=pylab.detrend_linear, noverlap=Mch / 2, Fs=fs) else: Pout = plt.psd(x, NFFT=Mch, detrend=pylab.detrend_none, noverlap=Mch / 2, Fs=fs) xdtrnd = pylab.detrend_linear(x) xauto = mcmath.acorr_mlab(xdtrnd, 2) rhoxauto = (xauto[1] + np.sqrt(abs(xauto[2]))) / 2 R = mcmath.redspec(rhoxauto, np.arange(Mch / 2), Mch) P = Pout[0][:R.size] F = Pout[1][:R.size] Psum = P.sum() Rsum = R.sum() PRratio = Psum / Rsum Rcmp = R * PRratio dof = (x.size / (Mch / 2.)) * 1.2 Fval = stats.f.isf(pval, dof, dof) tst = P / Rcmp pass1 = np.where(tst > Fval)[0] maxs = mcmath.extrema_find(P, 'max', t=F, dt=Dt) max_ind = np.intersect1d(maxs, pass1) Fmaxs = F[max_ind] Fmaxs2 = np.append(Fmaxs, 0.1) Fmaxs2.sort() Tmaxs = 1 / (Fmaxs2) Tmaxs = np.round(Tmaxs, 2) fig = plt.figure(figsize=(7, 5)) ax = fig.add_axes((0.1, 0.14, 0.88, 0.81)) ax.plot( F, P, ) ax.plot(F, Rcmp) ax.set_xticks(Fmaxs2) ax.set_xticklabels(Tmaxs) my_fmt_xdate(ax, rot=90, hal='center') multiline(Fmaxs, c='red', ls='--') xtl = ax.get_xticklabels() ytl = ax.get_yticklabels() plt.setp(xtl, 'size', 10) plt.setp(ytl, 'size', 9) ppct = int((1 - pval) * 100) titl_str = '%s FFT (chunksize: %d) :: peak CL: %d%%' % (titlestr, Mch, ppct) plt.text(titl_plc[0], titl_plc[1], titl_str, ha='right', va='bottom', size=12, transform=ax.transAxes) plt.xlabel('Peak period (yrs)', size=11) return (F, P, Rcmp)