return periods_mq1q3, amplitudes_mq1q3, powers_mq1q3, phases_R if __name__ == '__main__': ''' A short demonstration of the provided ensemble measures ''' from pyboat import WAnalyzer, ssg from pyboat.plotting import ensemble_dynamics, power_distribution, Fourier_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 Tstart = 30 # initial period Tend = 50 # period at the end Nt = 500 # number of samples per signal signals = [ ssg.create_noisy_chirp(T1=Tstart, T2=T, Nt=Nt, eps=1) for T in np.linspace(Tstart, Tend, 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
''' A short demonstration of the provided ensemble measures ''' import numpy as np import pandas as pd from pyboat import ensemble_measures as em 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
# data=pd.read_csv(path+file+r'.csv') ## #If we want only the first part of the experiment # thresh=int((max(data['frame'])+1)/2) # select_index_2=data.loc[data['frame']<=thresh]['frame'] # data=data.loc[data['frame'].isin(select_index_2)] power_series = pd.read_csv(path3 + file + r'_powerseries.csv') select_index = power_series.loc[power_series['0'] > 10]['index'] data = data.loc[:, data.columns.isin(select_index)] dt = 0.5 # the sampling interval, 0.5hours lowT = 16 highT = 32 periods = np.linspace(lowT, highT, 200) wAn = WAnalyzer(periods, dt, time_unit_label='hours') time = data.index.values * 0.5 num_signals = len(data.columns) - 1 print(num_signals) norm_signals = pd.DataFrame(columns=data.columns, index=data.index) count = 0 ridge_results = {} ridge_table = pd.DataFrame() for column in data: if count >= 0 and count <= num_signals: #equal to 0 if there is no frame column signal = data[column].dropna() #For circadian signal only
# --- create a synthetic signal --- eps = 0.5 # noise intensity alpha = 0.4 # AR1 parameter Nt = 400 # 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 # set up analyzing instance wAn = WAnalyzer(periods, dt, T_cut_off, time_unit_label = time_unit) # plot signal and trend wAn.plot_signal(signal) wAn.plot_trend(signal) ppl.legend(ncol = 2) # wAn.plot_detrended(signal1) # compute the spectrum without detrending wAn.compute_spectrum(signal, sinc_detrend = False) # compute the spectrum with detrending (sinc_detrend = True is the default) wAn.compute_spectrum(signal) wAn.get_maxRidge(power_thresh = 5) wAn.draw_Ridge()
from pyboat import ensemble_measures as em from pyboat import plotting as pl plt.rcParams.update({'font.size': 20}) name_folder = 'Amplitude_vs_trend/' name_folder2 = 'powerseries/' path = 'C:/Users/nicag/Desktop/William_traces/' path2 = str(path) + str(name_folder) path3 = str(path) + str(name_folder2) dt = 0.5 # the sampling interval, 0.5hours lowT = 16 highT = 32 periods = np.linspace(lowT, highT, 200) wAn = WAnalyzer(periods, dt, time_unit_label='hours') channel1 = 'cell_cycle' channel2 = 'circadian' file_list = ['untreated', '0uM', '5uM', '10uM'] file_list2 = ['low', 'medium', 'high'] #path='C:/Users/nicag/Desktop/TNBC/Single_cell_data_Anna/' #file_list=['25','50','100','DMSO100','5uM100','10uM100'] for i in range(4): nom = file_list[i] file = 'high_density_' + str(nom) + '_' + str(channel2) # file=str(file_list2[i])+'_density_'+str(file_list[0])+'_'+str(channel2) # file='InterpolatedTraces_'+str(nom)
import matplotlib.pyplot as ppl import numpy as np from pyboat import WAnalyzer, ssg ppl.ion() # --- set basic parameters and initialize the Analyzer--- dt = 2 # the sampling interval, 2s periods = np.linspace(6, 90, 150) # period range, 6s to 90s wAn = WAnalyzer(periods, dt, time_unit_label='s') # --- create a synthetic signal --- eps = 0.5 # noise intensity alpha = 0.4 # AR1 parameter, set to 0 for white noise Nt = 220 # number of samples # oscillatory signal which sweeps from 30s to 50s signal1 = ssg.create_noisy_chirp(T1 = 30 / dt, T2 = 50 / dt, Nt = Nt, eps = eps, alpha = alpha) # add slower oscillatory trend with a period of 70s signal2 = ssg.create_chirp(T1 = 70 / dt, T2 = 70 / dt, Nt = Nt) # add exponential decay syn_env = ssg.create_exp_envelope(tau = 0.65 * Nt, Nt = Nt) # linear superposition signal = syn_env * (signal1 + 2. * signal2)
''' This script shows how to estimate an empirical background from an ensemble of 'non-oscillatory' signals, and how to apply this estimated background to the analysis. ''' import numpy as np import pandas as pd from pyboat import WAnalyzer, ssg from pyboat import plotting as pl from pyboat.core import ar1_powerspec import matplotlib.pyplot as ppl # set up analyzing instance periods = np.linspace(5, 80, 100) dt = 1 wAn = WAnalyzer(periods, dt, p_max=20) # create an ensemble of short AR(1) realizations # in a real life scenario this would be the 'non-oscillatory' # test signals alpha = 0.7 signals = [ssg.ar1_sim(alpha, Nt=120) for i in range(100)] # store the individual time averaged Wavelet spectra df_fouriers = pd.DataFrame(index=wAn.periods) # the individual Fourier estimates for i, sig in enumerate(signals): wAn.compute_spectrum(sig, do_plot=False) df_fouriers[i] = wAn.get_averaged_spectrum()