from pyboat import WAnalyzer, ssg from pyboat import plotting as pl # set up analyzing instance periods = np.linspace(5, 60, 100) dt = 1 wAn = WAnalyzer(periods, dt) # create a bunch of chirp signals # with diverging period over time Nsignals = 50 # times 2 Tstart = 30 # initial period Tmax = 50 # slowest signal Nt = 500 # number of samples per signal signals = [ ssg.create_noisy_chirp(T1=Tstart, T2=Tend, Nt=Nt, eps=1) for Tend in np.linspace(Tstart, Tmax, Nsignals) ] # add the same number of pure noise signals noisy_ones = [ssg.ar1_sim(alpha=0.5, Nt=Nt) for i in range(Nsignals)] # signals ids are just column numbers here signals = pd.DataFrame(signals + noisy_ones).T # get the the individual ridge readouts ridge_results = {} # store the individual time averaged Wavelet spectra df_fouriers = pd.DataFrame(index=wAn.periods)
''' from pyboat import WAnalyzer, ssg from pyboat.plotting import plot_ensemble_dynamics, plot_power_distribution # set up analyzing instance periods = np.linspace(5, 60, 100) dt = 1 wAn = WAnalyzer(periods, dt, T_cut_off=None) # create a bunch of chirp signals Nsignals = 50 # times 2 T1 = 30 # initial period Nt = 500 # number of samples per signal signals = [ ssg.create_noisy_chirp(T1=T1, T2=T, Nt=Nt, eps=1) for T in np.linspace(T1, 50, Nsignals) ] # add the same amount of pure noise noisy_ones = [ssg.ar1_sim(alpha=0.5, N=Nt) for i in range(Nsignals)] signals = signals + noisy_ones # get the the individual ridge readouts ridge_results = [] for signal in signals: wAn.compute_spectrum(signal, sinc_detrend=False, do_plot=False) rd = wAn.get_maxRidge(smoothing_wsize=11) ridge_results.append(rd)
ppl.ion() periods = np.linspace(4, 90, 150) dt = 2 T_cut_off = 65 # cut off period time_unit = 's' # --- create a synthetic signal --- eps = 0.5 # noise intensity alpha = 0.4 # AR1 parameter Nt = 500 # number of samples signal1 = ssg.create_noisy_chirp(T1=30 / dt, T2=50 / dt, Nt=Nt, eps=eps, alpha=alpha) # add slower oscillatory trend signal2 = ssg.create_chirp(T1=70 / dt, T2=70 / dt, Nt=Nt) # linear superposition signal = signal1 + 1.5 * signal2 # --- calculate trend --- trend = pyboat.sinc_smooth(signal, T_cut_off, dt) detr_signal = signal - trend # plot the signal/trend
# compare to the theoretical spectrum, # note the finite size effects suppressing the power for higher periods! theo_bg = ar1_powerspec(alpha, wAn.periods, wAn.dt) ppl.plot(wAn.periods, theo_bg, 'k--', label='theoretical') ppl.legend() # now we take the median of the Fourier power # distribution as expected empirical background emp_bg = df_fouriers.median(axis=1) # note that we have have persistent and consistent periods print(len(emp_bg.index) == len(wAn.periods)) # let's create a very noisy signal with the same # background process as noise mixed in test_signal = ssg.create_noisy_chirp(T1=70, T2=40, Nt=500, alpha=alpha, eps=1.) # SNR is 1! # plain wavelet analysis wAn.compute_spectrum(test_signal) # let's draw the confidence intervals from the theoretical spectrum wAn.draw_confidence_from_bg(theo_bg, colors='black') # now let's use the 'empirical' one, taking into # account the finite size effect wAn.draw_confidence_from_bg(emp_bg, colors='orange') # finally let's get the ridge within the CI regions # from the empirical background ridge_data = wAn.get_sign_maxRidge(emp_bg) wAn.draw_Ridge()