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

# Time-series data as a pandas Series
series = df_traj['x']
        
# Put into ews_compute
ews_dic = 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']


# Plot trajectory and smoothing
df_ews[['State variable','Smoothing']].plot()
appended_ews = []

# Print update
print('\nBegin EWS computation\n')

# Loop through noise type
for noise_type in ['add', 'multi', 'k']:
    
    # Loop through h value
    for h in hVals:
        
        ews_dic = ews_compute(df_traj_filt.loc[noise_type].loc[h]['State'], 
                          roll_window = rw, 
                          band_width = bw,
                          lag_times = lags, 
                          ews = ews,
                          ham_length = ham_length,
                          ham_offset = ham_offset,
                          pspec_roll_offset = pspec_roll_offset
                          )
        
        # The DataFrame of EWS
        df_ews_temp = ews_dic['EWS metrics']
        
        # Include a column in the DataFrames for noise type and h value
        df_ews_temp['h'] = h
        df_ews_temp['Noise'] = noise_type

                
        # Add DataFrames to list
        appended_ews.append(df_ews_temp)
# 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 = ews_compute(df_traj_filt.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=tcrit)

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

        # The DataFrame of kendall tau 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
Beispiel #4
0
# set up a list to store output dataframes from ews_compute- we will concatenate them at the end
appended_ews = []
appended_pspec = []

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

        ews_dic = ews_compute(df_traj_filt.loc[i + 1][var],
                              roll_window=rw,
                              band_width=bw,
                              lag_times=lags,
                              ews=ews,
                              ham_length=ham_length,
                              ham_offset=ham_offset,
                              pspec_roll_offset=pspec_roll_offset,
                              upto=tbif)

        # 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 realisation number and variable
        df_ews_temp['Realisation number'] = i + 1
        df_ews_temp['Variable'] = var

        df_pspec_temp['Realisation number'] = i + 1

#--------------------------------
# Compute EWS (moments) without bootstrapping
#-------------------------------------

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

# Time-series data as a pandas Series
series = df_traj_filt['x']
        
# Put into ews_compute
ews_dic = ews_compute(series,
                      smooth = 'Lowess',
                      span = span,
                      roll_window = rw,
                      upto = tcrit,
                      ews = ews)

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

# Plot trajectory and smoothing
df_ews[['State variable','Smoothing']].plot()

# Plot variance
df_ews[['Variance']].plot()



Beispiel #6
0
# Trajectory data stored in a DataFrame indexed by time
data = {'Time': t, 'x': x}
df_traj = pd.DataFrame(data).set_index('Time')

#--------------------------------
# Compute EWS (moments) without bootstrapping
#-------------------------------------

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

# Put into ews_compute
ews_dic = ews_compute(series,
                      smooth='Lowess',
                      span=span,
                      roll_window=0.5,
                      upto=tcrit,
                      ews=ews)

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

# Plot trajectory and smoothing
df_ews[['State variable', 'Smoothing']].plot()

# Plot variance
df_ews[['Variance']].plot()

#-------------------------------------
# Compute EWS using bootstrapping
#–----------------------------------
Beispiel #7
0
dt2 = 1
df_sims_filt = df_sims[np.remainder(df_sims.index,dt2) == 0]

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

# Print update
print('\n   Begin EWS computation \n')

# loop through each trajectory as an input to ews_compute
for i in range(numSims):
    dict_ews = ews_compute(df_sims_filt['Sim '+str(i+1)], 
                      roll_window=0.5, 
                      band_width=0.05,
                      lag_times=[1], 
                      ews=['var','ac','sd','cv','skew','kurt','smax'],
                      ham_length=40,                     
                      upto=tbif*0.9,
                      pspec_roll_offset = 20)
    
    # EWS dataframe
    df_ews_temp = dict_ews['EWS metrics']
    # Include a column in the dataframe for realisation number
    df_ews_temp['Realisation number'] = i+1
    
#    # Power spectra dataframe
#    df_pspec_temp = dict_ews['Power spectrum']
#    df_pspec_temp['Realisation number'] = i+1
    
    # Kendall tau values
    df_ktau_temp = dict_ews['Kendall tau']
sampleVals = np.array(df_samples.index.levels[1])

# Loop through realtimes
for t in tVals:

    # Loop through sample values
    for sample in sampleVals:

        # Compute EWS for near-stationary sample series
        series_temp = df_samples.loc[t].loc[sample]['x']

        ews_dic = ews_compute(series_temp,
                              roll_window=1,
                              band_width=1,
                              lag_times=lags,
                              ews=ews,
                              ham_length=ham_length,
                              ham_offset=ham_offset,
                              pspec_roll_offset=pspec_roll_offset,
                              upto=1,
                              sweep=False)

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

        # Include columns for sample value and realtime
        df_ews_temp['Sample'] = sample
        df_ews_temp['Time'] = t

        # Drop NaN values
        df_ews_temp = df_ews_temp.dropna()