fig.tight_layout() fig.savefig("plots/size_of_dynamical_volume_" + save_name + ".pdf") #plt.show() plt.close() critical_alpha0 = np.transpose(critical_alpha0) connectance = np.real(largest_eigenvalue_region[0, 0][:, 3]) nestedness = np.real(largest_eigenvalue_region[0, 0][:, 2]) for k in range(len(largest_eigenvalue_region)): # plot critical alpha0 fig = plt.figure() ax = fig.add_subplot(111) for nest in all_nestedness: indices = [ int(i) for i in range(len(nestedness)) if cf.closest_element_in_list( nestedness[i], all_nestedness) == nest ] sorted_indices = np.array( [indices[a] for a in np.argsort(connectance[indices])]) connectance_to_plot = [connectance[i] for i in sorted_indices] critical_alpha0_to_plot = [ critical_alpha0[k][i] for i in sorted_indices ] ax.plot(connectance_to_plot, critical_alpha0_to_plot, label=r'$\eta_G\approx' + str(nest) + '$', markersize=10, linewidth=2.5, markeredgewidth=3) ax.set_xlabel(r'Connectance $\kappa_G$') ax.set_ylabel(r'$\alpha_0^D(G,A)$')
local_dynamical_stability_region=cf.load_data_region(alpha_mode,alpha0, filename_lds,optimal_LRI_folder) feasibility_region=cf.load_data_region(alpha_mode, alpha0, filename_feasib, optimal_LRI_folder) alpha0=np.array(alpha0) Nmatrices=len(local_dynamical_stability_region[0,0]) print(Nmatrices) for i in range(Nmatrices): fig = plt.figure() ax = fig.add_subplot(111) NR = local_dynamical_stability_region[0,0,0,0] NS = local_dynamical_stability_region[0,0,0,1] nest = local_dynamical_stability_region[0,0,i, 2] conn = local_dynamical_stability_region[0,0,i, 3] title = r'$\eta_G='+str(cf.closest_element_in_list(nest, all_nestedness))+', \kappa_G='+str(cf.closest_element_in_list(conn, all_connectance))+'$' for k in range(len(alpha_mode)): to_plot=[cf.vol_dyna_if_feas(feasibility_region, local_dynamical_stability_region, k, j, i) for j in range(len(alpha0))] ax.plot(alpha0, to_plot, label=label[k]) ax.set_xlabel(r'$\alpha_0$') ax.set_ylabel(r'Prob$\left(\mathcal{D}_L | \mathcal{F}\right)\left(G, A, \alpha_0\right)$') ax.set_title(title) ax.legend() fig.tight_layout() fig.savefig('plots/prob_dyn_stab_if_feas_NR'+str(NR)+'_NS'+str(NS)+'_Nest'+str(nest)+'_Conn'+str(conn)+'.pdf') plt.close() ##### OLD VERSION BELOW ####### # import numpy as np
data = np.loadtxt(file, usecols=tuple([ i for i in range( 1, 2 * (len(alpha_mode) * (len(syntrophy_mode) - 1) + 1) + 1) ])) #### DATA LOADING ###### # str_stab dictionary is organized this way # str_stab[Nest][Conn][syntrophy mode][alpha mode] nest = [] conn = [] for i in range(len(mat_name)): a = mat_name[i].split("_", 7) actual_nest = float(a[5][4:]) round_nest = cf.closest_element_in_list(actual_nest, all_nestedness) actual_conn = float(a[6][4:-4]) round_conn = cf.closest_element_in_list(actual_conn, all_connectance) nest.append(round_nest) conn.append(round_conn) str_stab = {} # build structural stability dictionary for n in all_nestedness: dnest = {} for c in all_connectance: dconn = {} index = 0 for syn in syntrophy_mode: dsyn = {} for al in alpha_mode: dalpha = {}
suptitle = r'FC' save_name = 'plots/energy_FC' file = 'energy_optimal_RS_matrices' suptitle = r'RS' save_name = 'plots/energy_RS' data = (np.loadtxt(folder + '/' + file + '.out')) connG = data[:, 0] nestG = data[:, 1] connA = data[:, 2] nestA = data[:, 3] energy = data[:, 4] for i in range(len(connG)): connG[i] = cr.closest_element_in_list(connG[i], cr.all_connectance) for i in range(len(nestG)): nestG[i] = cr.closest_element_in_list(nestG[i], cr.all_nestedness) fig = plt.figure() ax = fig.add_subplot(111) for j in range(len(cr.all_nestedness)): nest = cr.all_nestedness[j] points = [i for i in range(len(connG)) if nestG[i] == nest] points = [points[i] for i in np.argsort(connG[points])] ax.plot(connG[points], energy[points], color=cr.nest_colours[j], label=r'$\eta_G=' + str(nest) + '$') ax.legend(bbox_to_anchor=(1., 1.))
feasability[mat_index], cmap=cmap, levels=[0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.00001]) #ax1.plot(fit_g0, fit_S0, color='black', marker='None',linestyle='-.', linewidth=2) ax1.plot(fit_g0, expected_S0, color='black', marker='None', linestyle='--', linewidth=2) ax1.set_xlim(0., 1.) ax1.set_ylim(0., 1.) ax1.set_xlabel(r'$\gamma_0$') ax1.set_ylabel(r'$S_0$') title_axis = r'$\eta_G=' + str( closest_element_in_list(nestedness[mat_index], all_nestedness)) title_axis += r', \kappa_G=' + str( closest_element_in_list(connectance[mat_index], all_connectance)) + '$' ax1.set_title(title_axis) ax12 = fig1.add_subplot(122, aspect='equal') im = ax12.tricontourf( gamma0[mat_index], S0[mat_index_2], feasability[mat_index_2], cmap=cmap, levels=[0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.00001]) #ax12.plot(fit_g0_2, fit_S0_2, color='black', marker='None',linestyle='-.', linewidth=2) ax12.plot(fit_g0_2, expected_S0_2, color='black',
fig.savefig('plots/local_dynamical_stability_region_' + save_name + '.pdf') plt.close() decline = [] critical_alpha0 = [] err_decline = [] for j in range(len(local_dynamical_stability_region[0][0])): fig, ax = plt.subplots(1, 1) local_critical_alpha0 = [] local_decline = [] for i in range(len(local_dynamical_stability_region)): data = local_dynamical_stability_region[i, :, j] NR = data[0, 0] NS = data[0, 1] nestedness = cf.closest_element_in_list(data[0, 2], all_nestedness) connectance = cf.closest_element_in_list(data[0, 3], all_connectance) lds_volume = cf.shrink_volume_for_one_matrix(data) fit_function = cf.exponential_function take_zero_points = False fitted_alpha0, fitted_dyn_volume, estimated_alpha_crit, estimated_vol_zero_syntrophy, ( est_decay_rate, err_decay_rate) = cf.fit_shrinkage_curve(alpha0, lds_volume, fit_function, take_zero_points) print(err_decay_rate) ax.plot(fitted_alpha0, fitted_dyn_volume, color=alpha_mode_colours[i], marker='None', linestyle='solid')
# data is organized this way: decay_rate[NR][alpha_mode][nest][conn] decay_rate = {} dNR25 = {} dNR50 = {} for i in range(len(alpha_mode)): dNR25_almode = {} dNR50_almode = {} data_50 = df_50[i] data_25 = df_25[i] # we first take all NR=50 points and match them to a NR=25 point NR = data_25[:, 0] NS = data_25[:, 1] nestedness_25 = [ cf.closest_element_in_list(n, all_nestedness) for n in data_25[:, 2] ] connectance_25 = [ cf.closest_element_in_list(k, all_connectance) for k in data_25[:, 3] ] decay_rate_25 = data_25[:, 4] nestedness_50 = [ cf.closest_element_in_list(n, all_nestedness) for n in data_50[:, 2] ] connectance_50 = [ cf.closest_element_in_list(k, all_connectance) for k in data_50[:, 3] ] decay_rate_50 = data_50[:, 4] # first for NR=25