for i in range(numSims):
    # loop through variable
    for var in ['Non-breeding','Breeding','Total']:
        
        # Time-series
        series=df_traj.loc[i+1][var]
        
        # Find time value at which population goes extinct
        tExt=series[series<=0].index[0]
        
        ews_dic = ewstools.ews_compute(df_traj.loc[i+1][var], 
                          roll_window = rw,
                          smooth='Lowess',
                          span=span,
                          lag_times = lags, 
                          ews = ews,
                          ham_length = ham_length,
                          ham_offset = ham_offset,
                          pspec_roll_offset = pspec_roll_offset,
                          upto=tExt-5,
                          sweep=False)
        
        # The DataFrame of EWS
        df_ews_temp = ews_dic['EWS metrics']
        # The DataFrame of power spectra
        df_pspec_temp = ews_dic['Power spectrum']
        # The DataFrame of kendall tau values
        df_ktau_temp = ews_dic['Kendall tau']
        
        # Compute cross-correlation
        df_cross_corr = cross_corr(df_traj_filt.loc[i+1][['Non-breeding','Breeding']],
print('Compute EWS')

#--------------------------------
# Compute EWS without bootstrapping
#-------------------------------------

# Time-series data as a pandas Series
series = df_traj['x']

# Put into ews_compute
ews_dic = ewstools.ews_compute(series,
                               smooth='Lowess',
                               span=span,
                               roll_window=rw,
                               upto=tcrit,
                               ews=ews,
                               lag_times=lags,
                               sweep=sweep,
                               ham_length=ham_length,
                               ham_offset=ham_offset)

# DataFrame of EWS
df_ews = ews_dic['EWS metrics']

# DataFrame of Power spectra
df_pspec = ews_dic['Power spectrum']

print('Do bootstrapping')

#-------------------------------------
# Compute EWS using bootstrapping
Exemple #3
0
appended_pspec = []


# loop through realisation number
print('\nBegin EWS computation\n')
for r in rVals:       
         
    
    # If time-series goes extinct at any point, do not compute EWS
    if any(df_traj.loc[r]['State variable'] == 0):
        continue
    ews_dic = ewstools.ews_compute(df_traj.loc[r]['State variable'], 
                      roll_window = rw,
                      smooth = 'Lowess',
                      span = span,
                      lag_times = lags, 
                      ews = ews,
                      ham_length = ham_length,
                      ham_offset = ham_offset,
                      sweep = False
                      )
    
    # The DataFrame of EWS
    df_ews_temp = ews_dic['EWS metrics']
    # The DataFrame of power spectra
    df_pspec_temp = ews_dic['Power spectrum']
    
    # Include a column in the DataFrames for r value and variable
    df_ews_temp['r'] = r    
    df_pspec_temp['r'] = r

    # Add DataFrames to list
# Filter time-series to have time-spacing dt2
df_traj_filt = df_traj.loc[::int(dt2 / dt)]

# set up a list to store output dataframes from ews_compute- we will concatenate them at the end
appended_ews = []
appended_ktau = []

# loop through realisation number
print('\nBegin EWS computation\n')
for i in range(numSims):
    # loop through variable
    for var in ['x']:

        ews_dic = ewstools.ews_compute(df_traj_filt.loc[i + 1][var],
                                       roll_window=rw,
                                       span=span,
                                       lag_times=lags,
                                       ews=ews,
                                       upto=tcrit)

        # The DataFrame of EWS
        df_ews_temp = ews_dic['EWS metrics']

        # The DataFrame of ktau values
        df_ktau_temp = ews_dic['Kendall tau']

        # Include a column in the DataFrames for realisation number and variable
        df_ews_temp['Realisation number'] = i + 1
        df_ews_temp['Variable'] = var

        df_ktau_temp['Realisation number'] = i + 1
        df_ktau_temp['Variable'] = var