<jupyter_start><jupyter_text>South America<jupyter_code>#RZS_TC = pd.read_pickle('/home/chandra/data/Stable_unstable_paper/Dataframe_updated_SA-29.03.2021.pkl')
RZS_TC = pd.read_pickle('/Input_data/Dataframe_updated_SA-29.03.2021.pkl')

len(RZS_TC) 

for classes in [11,14,20,30,190,200,210,220]:
    RZS_TC = RZS_TC[RZS_TC.Landuse != int(classes)]
RZS_TC['Mean_TC'] = RZS_TC['Mean_Treecover']

RZS_TC[['Sr','MAP','Mean_Treecover','TC_f-i']].columns.values

RZS_TC.loc[RZS_TC['Mean_Treecover'] <= 50, 'Mean_Treecover' ] = 0
RZS_TC.loc[RZS_TC['Mean_Treecover'] > 50, 'Mean_Treecover' ] = 1

RZS_TC['TC_f-i_mod'] = RZS_TC['TC_f-i'].abs()

RZS_TC.rename(columns = {'TC_f-i_mod' : 'delTCmod'}, inplace = True)

print(RZS_TC['Sr'].where(RZS_TC['Mean_TC'] > 50).dropna().quantile(0.99))

RZS_TC['Sr_expendable'] = RZS_TC['Sr']

print('Sr_max_99th-percentile')
RZS_TC.loc[RZS_TC['Mean_TC'] < 30, 'Sr_expendable' ] = RZS_TC['Sr'].where(RZS_TC['Mean_TC'] > 50).dropna().quantile(0.99)<jupyter_output>717.9348059082033
Sr_max_99th-percentile<jupyter_text>Only $\overline{P}$ Resilience<jupyter_code>from statsmodels.formula.api import mnlogit
import statsmodels.api as sm
model = mnlogit("Mean_Treecover ~ MAP", RZS_TC).fit()
print(model.summary2())
prediction_1 = model.predict(sm.add_constant(RZS_TC[['MAP']]))[1]

RZS_TC = pd.concat([RZS_TC,prediction_1], axis = 1)

RZS_TC = RZS_TC.rename(columns={1: "Pred_P"})<jupyter_output>/usr/lib/python3/dist-packages/numpy/core/fromnumeric.py:2495: FutureWarning: Method .ptp is deprecated and will be removed in a future version. Use numpy.ptp instead.
  return ptp(axis=axis, out=out, **kwargs)<jupyter_text>Only $S_r$<jupyter_code>from statsmodels.formula.api import mnlogit
import statsmodels.api as sm
model = mnlogit("Mean_Treecover ~ Sr_expendable", RZS_TC).fit()
print(model.summary2())<jupyter_output>Optimization terminated successfully.
         Current function value: 0.409939
         Iterations 6
                          Results: MNLogit
====================================================================
Model:                MNLogit          Pseudo R-squared: 0.408      
Dependent Variable:   Mean_Treecover   AIC:              582170.4374
Date:                 2021-08-15 17:11 BIC:              582193.3837
No. Observations:     710064           Log-Likelihood:   -2.9108e+05
Df Model:             1                LL-Null:          -4.9210e+05
Df Residuals:         710062           LLR p-value:      0.0000     
Converged:            1.0000           Scale:            1.0000     
No. Iterations:       6.0000                                        
--------------------------------------------------------------------
Mean_Treecover = 0  Coef.  Std.Err.     t     P>|t|   [0.025  0.975]
--------------------------------------------------------------------
         Intercept  4.5135 [...]<jupyter_text>$\overline{P} + S_r$<jupyter_code>from statsmodels.formula.api import mnlogit
import statsmodels.api as sm
model = mnlogit("Mean_Treecover ~ MAP+ Sr_expendable", RZS_TC).fit()
print(model.summary2())
prediction = model.predict(sm.add_constant(RZS_TC[['MAP','Sr_expendable']]))[1]
RZS_TC = pd.concat([RZS_TC,prediction], axis = 1)
RZS_TC = RZS_TC.rename(columns={1: "Pred"})<jupyter_output><empty_output><jupyter_text>RZS_TC = RZS_TC.sort_values(by = 'delTCmod')<jupyter_code>RZS_TC<jupyter_output><empty_output><jupyter_text>Supplementary Fi. 6a<jupyter_code>fig = plt.figure(figsize=(7,14))
ax = [plt.subplot(211), plt.subplot(212)]
fig.subplots_adjust(wspace=0.0)
fig.subplots_adjust(hspace=0.0)


a = RZS_TC[['Pred','TC_f-i','Pred_P']].where((RZS_TC['Mean_TC'] >30) & (RZS_TC['TC_f-i'] >= 0)).dropna()
pixel_4 = round(len(a['Pred'].sort_values())/20)

Res_bins = []
Res_bins.append(0)
for i in range(20):
    if i < 19:
        Res_bins.append((a['Pred'].sort_values()[pixel_4*i:pixel_4*(i+1)]).max())
    else:
        Res_bins.append((a['Pred'].sort_values()[pixel_4*i:].max()))

Res_bins[20] = 1
res = []
res_25 = []
res_75 = []
n = []
Res_bins_cen = []
for i in range(np.array(Res_bins).shape[0]-1):
    Res_bins_cen.append((Res_bins[i]+Res_bins[i+1])/2)
for i in range(np.array(Res_bins).shape[0]-1):
    b = a.where((a['Pred'] >= Res_bins[i]) & (a['Pred'] < Res_bins[i+1])).dropna()
    res.append(b['TC_f-i'].median())
    n.append(b['TC_f-i'].size)
    res_25.append(b['TC_f-i'].quantile(0.25))
    res_75.append(b['TC_f-i'].quantile(0.75))
ax[0].plot(np.array(Res_bins_cen),res, '-o', color = 'b')
ax[0].fill_between(np.array(Res_bins_cen),res_25,res_75, alpha = 0.25, color = 'b')
ax[0].set_ylim(0,25)
ax[0].set_xlim(0,1)
ax[0].tick_params(axis='both', which='major', labelsize=14)
ax[0].text(-0.1,-2, r'$\Delta {}$'+'TC (pp)', fontsize = '16', rotation = 90)
ax[0].spines['right'].set_visible(False)
ax[0].spines['top'].set_visible(False)
ax[0].set_xticklabels([' '])
from scipy import stats
cor, p = stats.spearmanr(np.array(Res_bins_cen),res)
if p <= 0.05:
    ax[0].text(0.1,20, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ < 0.05', color = 'b', fontsize = '14')
else:
    ax[0].text(0.1,20, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ = '+str(round(p,2)), color = 'b', fontsize = '14')


pixel_4 = round(len(a['Pred_P'].sort_values())/20)
Res_bins = []
Res_bins.append(0)
for i in range(20):
    if i < 19:
        Res_bins.append((a['Pred_P'].sort_values()[pixel_4*i:pixel_4*(i+1)]).max())
    else:
        Res_bins.append((a['Pred_P'].sort_values()[pixel_4*i:].max()))

Res_bins[20] = 1
res = []
res_25 = []
res_75 = []
n = []
Res_bins_cen = []
for i in range(np.array(Res_bins).shape[0]-1):
    Res_bins_cen.append((Res_bins[i]+Res_bins[i+1])/2)
for i in range(np.array(Res_bins).shape[0]-1):
    b = a.where((a['Pred_P'] >= Res_bins[i]) & (a['Pred_P'] < Res_bins[i+1])).dropna()
    res.append(b['TC_f-i'].median())
    n.append(b['TC_f-i'].size)
    res_25.append(b['TC_f-i'].quantile(0.25))
    res_75.append(b['TC_f-i'].quantile(0.75))
ax[0].plot(np.array(Res_bins_cen),res, '-o', color = 'black')
ax[0].fill_between(np.array(Res_bins_cen),res_25,res_75, alpha = 0.25, color = 'black')
ax[0].set_ylim(0,25)
ax[0].set_xlim(0,1)
ax[0].tick_params(axis='both', which='major', labelsize=14)
ax[0].text(-0.1,-2, r'$\Delta {}$'+'TC (pp)', fontsize = '16', rotation = 90)
ax[0].spines['right'].set_visible(False)
ax[0].spines['top'].set_visible(False)
ax[0].set_xticklabels([' '])
from scipy import stats
cor, p = stats.spearmanr(np.array(Res_bins_cen),res)
if p <= 0.05:
    ax[0].text(0.1,19, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ < 0.05', color = 'black', fontsize = '14')
else:
    ax[0].text(0.1,19, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ = '+str(round(p,2)), color = 'black', fontsize = '14')


a = RZS_TC[['Pred','TC_f-i','Pred_P']].where((RZS_TC['Mean_TC'] >30) & (RZS_TC['TC_f-i'] < 0)).dropna()

pixel_4 = round(len(a['Pred'].sort_values())/20)
Res_bins = []
Res_bins.append(0)
for i in range(20):
    if i < 19:
        Res_bins.append((a['Pred'].sort_values()[pixel_4*i:pixel_4*(i+1)]).max())
    else:
        Res_bins.append((a['Pred'].sort_values()[pixel_4*i:].max()))

Res_bins[20] = 1

res = []
res_25 = []
res_75 = []
n = []
Res_bins_cen = []
for i in range(np.array(Res_bins).shape[0]-1):
    Res_bins_cen.append((Res_bins[i]+Res_bins[i+1])/2)
for i in range(np.array(Res_bins).shape[0]-1):
    b = a.where((a['Pred'] >= Res_bins[i]) & (a['Pred'] < Res_bins[i+1])).dropna()
    res.append(b['TC_f-i'].median())
    n.append(b['TC_f-i'].size)
    res_25.append(b['TC_f-i'].quantile(0.25))
    res_75.append(b['TC_f-i'].quantile(0.75))
ax[1].plot(np.array(Res_bins_cen),res, '-o', color = 'r')
ax[1].fill_between(np.array(Res_bins_cen),res_25,res_75, alpha = 0.25, color = 'r')
ax[1].set_ylim(-25,0)
ax[1].set_xlim(0,1)
ax[1].tick_params(axis='both', which='major', labelsize=14)
ax[1].text(-0.1,-2, r'$\Delta {}$'+'TC (pp)', fontsize = '16', rotation = 90)
ax[1].spines['right'].set_visible(False)
ax[1].spines['bottom'].set_visible(False)
ax[1].set_xticklabels([' '])
from scipy import stats
cor, p = stats.spearmanr(np.array(Res_bins_cen),res)

if p <= 0.05:
    ax[1].text(0.1,-20, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ < 0.05', color = 'r', fontsize = '14')
else:
    ax[1].text(0.1,-20, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ = '+str(round(p,2)), color = 'r', fontsize = '14')

    
pixel_4 = round(len(a['Pred_P'].sort_values())/20)
Res_bins = []
Res_bins.append(0)
for i in range(20):
    if i < 19:
        Res_bins.append((a['Pred_P'].sort_values()[pixel_4*i:pixel_4*(i+1)]).max())
    else:
        Res_bins.append((a['Pred_P'].sort_values()[pixel_4*i:].max()))

Res_bins[20] = 1

res = []
res_25 = []
res_75 = []
n = []
Res_bins_cen = []
for i in range(np.array(Res_bins).shape[0]-1):
    Res_bins_cen.append((Res_bins[i]+Res_bins[i+1])/2)
for i in range(np.array(Res_bins).shape[0]-1):
    b = a.where((a['Pred_P'] >= Res_bins[i]) & (a['Pred_P'] < Res_bins[i+1])).dropna()
    res.append(b['TC_f-i'].median())
    n.append(b['TC_f-i'].size)
    res_25.append(b['TC_f-i'].quantile(0.25))
    res_75.append(b['TC_f-i'].quantile(0.75))
ax[1].plot(np.array(Res_bins_cen),res, '-o', color = 'black')
ax[1].fill_between(np.array(Res_bins_cen),res_25,res_75, alpha = 0.25, color = 'black')
ax[1].set_ylim(-25,0)
ax[1].set_xlim(0,1)
ax[1].tick_params(axis='both', which='major', labelsize=14)
ax[1].text(-0.1,-2, r'$\Delta {}$'+'TC (pp)', fontsize = '16', rotation = 90)
ax[1].spines['right'].set_visible(False)
ax[1].spines['bottom'].set_visible(False)
ax[1].set_xticklabels([' ',0.2,0.4,0.6,0.8,1])
ax[1].set_xlim(0,1)
ax[1].xaxis.tick_top()
ax[1].text(0.4,-2, 'Resilience', fontsize = '16')
from scipy import stats
cor, p = stats.spearmanr(np.array(Res_bins_cen),res)
if p <= 0.05:
    ax[1].text(0.1,-21, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ < 0.05', color = 'black', fontsize = '14')
else:
    ax[1].text(0.1,-21, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ = '+str(round(p,2)), color = 'black', fontsize = '14')<jupyter_output><ipython-input-19-acf448e12f89>:40: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax[0].set_xticklabels([' '])
<ipython-input-19-acf448e12f89>:80: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax[0].set_xticklabels([' '])
<ipython-input-19-acf448e12f89>:123: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax[1].set_xticklabels([' '])
<ipython-input-19-acf448e12f89>:165: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax[1].set_xticklabels([' ',0.2,0.4,0.6,0.8,1])<jupyter_text>----------------------------------------------------------------------------------------------------  For Africa<jupyter_code>#RZS_TC = pd.read_pickle('/home/chandra/data/Stable_unstable_paper/Dataframe_updated_AF-29.03.2021.pkl')
RZS_TC = pd.read_pickle('/Input_data/Dataframe_updated_AF-29.03.2021.pkl')

for classes in [11,14,20,30,190,200,210,220,230]:
    RZS_TC = RZS_TC[RZS_TC.Landuse != int(classes)]
RZS_TC['Mean_TC'] = RZS_TC['Mean_Treecover']

RZS_TC[['Sr','MAP','Mean_Treecover','TC_f-i']].columns.values

RZS_TC.loc[RZS_TC['Mean_Treecover'] <= 50, 'Mean_Treecover' ] = 0
RZS_TC.loc[RZS_TC['Mean_Treecover'] > 50, 'Mean_Treecover' ] = 1

RZS_TC['TC_f-i_mod'] = RZS_TC['TC_f-i'].abs()

RZS_TC.rename(columns = {'TC_f-i_mod' : 'delTCmod'}, inplace = True)

print(RZS_TC['Sr'].where(RZS_TC['Mean_TC'] > 50).dropna().quantile(0.99))

RZS_TC['Sr_expendable'] = RZS_TC['Sr']

print('Sr_max_99th-percentile')
RZS_TC.loc[RZS_TC['Mean_TC'] < 30, 'Sr_expendable' ] = RZS_TC['Sr'].where(RZS_TC['Mean_TC'] > 50).dropna().quantile(0.99)<jupyter_output>566.4888842773433
Sr_max_99th-percentile<jupyter_text>Only $\overline{P}$ Resilience<jupyter_code>from statsmodels.formula.api import mnlogit
import statsmodels.api as sm
model = mnlogit("Mean_Treecover ~ MAP", RZS_TC).fit()
print(model.summary2())
prediction_1 = model.predict(sm.add_constant(RZS_TC[['MAP']]))[1]

RZS_TC = pd.concat([RZS_TC,prediction_1], axis = 1)

RZS_TC = RZS_TC.rename(columns={1: "Pred_P"})<jupyter_output><empty_output><jupyter_text>Only $S_r$<jupyter_code>from statsmodels.formula.api import mnlogit
import statsmodels.api as sm
model = mnlogit("Mean_Treecover ~ Sr_expendable", RZS_TC).fit()
print(model.summary2())<jupyter_output>Optimization terminated successfully.
         Current function value: 0.162125
         Iterations 8
                          Results: MNLogit
====================================================================
Model:                MNLogit          Pseudo R-squared: 0.605      
Dependent Variable:   Mean_Treecover   AIC:              257513.0910
Date:                 2021-08-15 17:19 BIC:              257536.2611
No. Observations:     794170           Log-Likelihood:   -1.2875e+05
Df Model:             1                LL-Null:          -3.2633e+05
Df Residuals:         794168           LLR p-value:      0.0000     
Converged:            1.0000           Scale:            1.0000     
No. Iterations:       8.0000                                        
--------------------------------------------------------------------
Mean_Treecover = 0  Coef.  Std.Err.     t     P>|t|   [0.025  0.975]
--------------------------------------------------------------------
         Intercept  6.5494 [...]<jupyter_text>$\overline{P} + S_r$<jupyter_code>from statsmodels.formula.api import mnlogit
import statsmodels.api as sm
model = mnlogit("Mean_Treecover ~ MAP+ Sr_expendable", RZS_TC).fit()
print(model.summary2())
prediction = model.predict(sm.add_constant(RZS_TC[['MAP','Sr_expendable']]))[1]
RZS_TC = pd.concat([RZS_TC,prediction], axis = 1)
RZS_TC = RZS_TC.rename(columns={1: "Pred"})
RZS_TC<jupyter_output><empty_output><jupyter_text>Supplementary Fi. 6b<jupyter_code>fig = plt.figure(figsize=(7,14))
ax = [plt.subplot(211), plt.subplot(212)]
fig.subplots_adjust(wspace=0.0)
fig.subplots_adjust(hspace=0.0)


a = RZS_TC[['Pred','TC_f-i','Pred_P']].where((RZS_TC['Mean_TC'] >30) & (RZS_TC['TC_f-i'] >= 0)).dropna()
pixel_4 = round(len(a['Pred'].sort_values())/20)

Res_bins = []
Res_bins.append(0)
for i in range(20):
    if i < 19:
        Res_bins.append((a['Pred'].sort_values()[pixel_4*i:pixel_4*(i+1)]).max())
    else:
        Res_bins.append((a['Pred'].sort_values()[pixel_4*i:].max()))

Res_bins[20] = 1
res = []
res_25 = []
res_75 = []
n = []
Res_bins_cen = []
for i in range(np.array(Res_bins).shape[0]-1):
    Res_bins_cen.append((Res_bins[i]+Res_bins[i+1])/2)
for i in range(np.array(Res_bins).shape[0]-1):
    b = a.where((a['Pred'] >= Res_bins[i]) & (a['Pred'] < Res_bins[i+1])).dropna()
    res.append(b['TC_f-i'].median())
    n.append(b['TC_f-i'].size)
    res_25.append(b['TC_f-i'].quantile(0.25))
    res_75.append(b['TC_f-i'].quantile(0.75))
ax[0].plot(np.array(Res_bins_cen),res, '-o', color = 'b')
ax[0].fill_between(np.array(Res_bins_cen),res_25,res_75, alpha = 0.25, color = 'b')
ax[0].set_ylim(0,25)
ax[0].set_xlim(0,1)
ax[0].tick_params(axis='both', which='major', labelsize=14)
ax[0].text(-0.1,-2, r'$\Delta {}$'+'TC (pp)', fontsize = '16', rotation = 90)
ax[0].spines['right'].set_visible(False)
ax[0].spines['top'].set_visible(False)
ax[0].set_xticklabels([' '])
from scipy import stats
cor, p = stats.spearmanr(np.array(Res_bins_cen),res)
if p <= 0.05:
    ax[0].text(0.1,20, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ < 0.05', color = 'b', fontsize = '14')
else:
    ax[0].text(0.1,20, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ = '+str(round(p,2)), color = 'b', fontsize = '14')


pixel_4 = round(len(a['Pred_P'].sort_values())/20)
Res_bins = []
Res_bins.append(0)
for i in range(20):
    if i < 19:
        Res_bins.append((a['Pred_P'].sort_values()[pixel_4*i:pixel_4*(i+1)]).max())
    else:
        Res_bins.append((a['Pred_P'].sort_values()[pixel_4*i:].max()))

Res_bins[20] = 1
res = []
res_25 = []
res_75 = []
n = []
Res_bins_cen = []
for i in range(np.array(Res_bins).shape[0]-1):
    Res_bins_cen.append((Res_bins[i]+Res_bins[i+1])/2)
for i in range(np.array(Res_bins).shape[0]-1):
    b = a.where((a['Pred_P'] >= Res_bins[i]) & (a['Pred_P'] < Res_bins[i+1])).dropna()
    res.append(b['TC_f-i'].median())
    n.append(b['TC_f-i'].size)
    res_25.append(b['TC_f-i'].quantile(0.25))
    res_75.append(b['TC_f-i'].quantile(0.75))
ax[0].plot(np.array(Res_bins_cen),res, '-o', color = 'black')
ax[0].fill_between(np.array(Res_bins_cen),res_25,res_75, alpha = 0.25, color = 'black')
ax[0].set_ylim(0,25)
ax[0].set_xlim(0,1)
ax[0].tick_params(axis='both', which='major', labelsize=14)
ax[0].text(-0.1,-2, r'$\Delta {}$'+'TC (pp)', fontsize = '16', rotation = 90)
ax[0].spines['right'].set_visible(False)
ax[0].spines['top'].set_visible(False)
ax[0].set_xticklabels([' '])
from scipy import stats
cor, p = stats.spearmanr(np.array(Res_bins_cen),res)
if p <= 0.05:
    ax[0].text(0.1,19, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ < 0.05', color = 'black', fontsize = '14')
else:
    ax[0].text(0.1,19, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ = '+str(round(p,2)), color = 'black', fontsize = '14')


a = RZS_TC[['Pred','TC_f-i','Pred_P']].where((RZS_TC['Mean_TC'] >30) & (RZS_TC['TC_f-i'] < 0)).dropna()

pixel_4 = round(len(a['Pred'].sort_values())/20)
Res_bins = []
Res_bins.append(0)
for i in range(20):
    if i < 19:
        Res_bins.append((a['Pred'].sort_values()[pixel_4*i:pixel_4*(i+1)]).max())
    else:
        Res_bins.append((a['Pred'].sort_values()[pixel_4*i:].max()))

Res_bins[20] = 1

res = []
res_25 = []
res_75 = []
n = []
Res_bins_cen = []
for i in range(np.array(Res_bins).shape[0]-1):
    Res_bins_cen.append((Res_bins[i]+Res_bins[i+1])/2)
for i in range(np.array(Res_bins).shape[0]-1):
    b = a.where((a['Pred'] >= Res_bins[i]) & (a['Pred'] < Res_bins[i+1])).dropna()
    res.append(b['TC_f-i'].median())
    n.append(b['TC_f-i'].size)
    res_25.append(b['TC_f-i'].quantile(0.25))
    res_75.append(b['TC_f-i'].quantile(0.75))
ax[1].plot(np.array(Res_bins_cen),res, '-o', color = 'r')
ax[1].fill_between(np.array(Res_bins_cen),res_25,res_75, alpha = 0.25, color = 'r')
ax[1].set_ylim(-25,0)
ax[1].set_xlim(0,1)
ax[1].tick_params(axis='both', which='major', labelsize=14)
ax[1].text(-0.1,-2, r'$\Delta {}$'+'TC (pp)', fontsize = '16', rotation = 90)
ax[1].spines['right'].set_visible(False)
ax[1].spines['bottom'].set_visible(False)
ax[1].set_xticklabels([' '])
from scipy import stats
cor, p = stats.spearmanr(np.array(Res_bins_cen),res)

if p <= 0.05:
    ax[1].text(0.1,-20, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ < 0.05', color = 'r', fontsize = '14')
else:
    ax[1].text(0.1,-20, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ = '+str(round(p,2)), color = 'r', fontsize = '14')

    
pixel_4 = round(len(a['Pred_P'].sort_values())/20)
Res_bins = []
Res_bins.append(0)
for i in range(20):
    if i < 19:
        Res_bins.append((a['Pred_P'].sort_values()[pixel_4*i:pixel_4*(i+1)]).max())
    else:
        Res_bins.append((a['Pred_P'].sort_values()[pixel_4*i:].max()))

Res_bins[20] = 1

res = []
res_25 = []
res_75 = []
n = []
Res_bins_cen = []
for i in range(np.array(Res_bins).shape[0]-1):
    Res_bins_cen.append((Res_bins[i]+Res_bins[i+1])/2)
for i in range(np.array(Res_bins).shape[0]-1):
    b = a.where((a['Pred_P'] >= Res_bins[i]) & (a['Pred_P'] < Res_bins[i+1])).dropna()
    res.append(b['TC_f-i'].median())
    n.append(b['TC_f-i'].size)
    res_25.append(b['TC_f-i'].quantile(0.25))
    res_75.append(b['TC_f-i'].quantile(0.75))
ax[1].plot(np.array(Res_bins_cen),res, '-o', color = 'black')
ax[1].fill_between(np.array(Res_bins_cen),res_25,res_75, alpha = 0.25, color = 'black')
ax[1].set_ylim(-25,0)
ax[1].set_xlim(0,1)
ax[1].tick_params(axis='both', which='major', labelsize=14)
ax[1].text(-0.1,-2, r'$\Delta {}$'+'TC (pp)', fontsize = '16', rotation = 90)
ax[1].spines['right'].set_visible(False)
ax[1].spines['bottom'].set_visible(False)
ax[1].set_xticklabels([' ',0.2,0.4,0.6,0.8,1])
ax[1].set_xlim(0,1)
ax[1].xaxis.tick_top()
ax[1].text(0.4,-2, 'Resilience', fontsize = '16')
from scipy import stats
cor, p = stats.spearmanr(np.array(Res_bins_cen),res)
if p <= 0.05:
    ax[1].text(0.1,-21, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ < 0.05', color = 'black', fontsize = '14')
else:
    ax[1].text(0.1,-21, r'$Sp. corr.$ = '+str(round(cor,2))+ r', $pvalue$ = '+str(round(p,2)), color = 'black', fontsize = '14')<jupyter_output><ipython-input-15-acf448e12f89>:40: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax[0].set_xticklabels([' '])
<ipython-input-15-acf448e12f89>:80: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax[0].set_xticklabels([' '])
<ipython-input-15-acf448e12f89>:123: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax[1].set_xticklabels([' '])
<ipython-input-15-acf448e12f89>:165: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax[1].set_xticklabels([' ',0.2,0.4,0.6,0.8,1])
{'fraction_non_alphanumeric': 0.23995423995423995, 'fraction_numerical': 0.06177606177606178, 'mean_word_length': 4.267386392166708, 'pattern_counts': {'":': 0, '<': 84, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '433467', 'license': 'MIT', 'n_tokens_mistral': 9766, 'n_tokens_neox': 8938, 'n_words': 1256, 'path': '2. Manuscript_resilience analysis.ipynb', 'repo_name': 'chandrakant6492/Ecosystem_stability_and_resilience', 'size': '20979'}