def deletion_links_effect(k, periodoborr, minputchar_a, minputchar_b, minputchar_a_mask, minputchar_b_mask, ldev_inf): minputchar_a, fil, col = delete_link(minputchar_a) minputchar_b[col][fil] = 0 minpeq_a = minputchar_a * minputchar_a_mask minpeq_b = minputchar_b * minputchar_b_mask sgcom.inform_user(ldev_inf, \ "Day:%d (year %d). Deleted links plant %d <-> pollinator %d"\ % (k, k // sgGL.DAYS_YEAR , int_to_ext_rep(fil), int_to_ext_rep(col))) return minpeq_a, minpeq_b, minputchar_a, minputchar_b,
def init_random_links_removal(eliminarenlaces, periods, ldev_inf, minputchar_a): periodoborr = periods if eliminarenlaces > 0: cuenta = cuentaenlaces(minputchar_a) hayqueborrar = math.trunc(eliminarenlaces * cuenta) sgcom.inform_user(ldev_inf, "Links %d. Will be deleted %d" %\ (cuentaenlaces(minputchar_a), hayqueborrar)) if hayqueborrar > 0: periodoborr = periods // (hayqueborrar) return periodoborr
def deletion_links_effect(k, periodoborr, minputchar_a, minputchar_b, minputchar_a_mask, minputchar_b_mask, ldev_inf): minputchar_a, fil, col = delete_link(minputchar_a) minputchar_b[col][fil] = 0 minpeq_a = minputchar_a * minputchar_a_mask minpeq_b = minputchar_b * minputchar_b_mask sgcom.inform_user(ldev_inf, \ "Day:%d (year %d). Deleted links plant %d <-> pollinator %d"\ % (k, k // sgGL.DAYS_YEAR , int_to_ext_rep(fil), int_to_ext_rep(col))) return minpeq_a, minpeq_b, minputchar_a, minputchar_b,
def init_random_links_removal(eliminarenlaces, periods, ldev_inf, minputchar_a): periodoborr = periods if eliminarenlaces > 0: cuenta = cuentaenlaces(minputchar_a) hayqueborrar = math.trunc(eliminarenlaces * cuenta) sgcom.inform_user(ldev_inf, "Links %d. Will be deleted %d" %\ (cuentaenlaces(minputchar_a), hayqueborrar)) if hayqueborrar > 0: periodoborr = periods // (hayqueborrar) return periodoborr
def init_blossom_pertubation_params(BssDat, numspecies_a, year_periods, ldev_inf): # Blossom variability analysis global pendiente, periodo pBssvar_species = [] pendiente = periodo = 0 hay_bssvar = (BssDat.Bssvar_sd > 0.0) & (len(BssDat.Bssvar_species) > 0) if (hay_bssvar): if (BssDat.Bssvar_modulationtype_list[0] == 'linear'): strvalor = (", Slope %0.2f " % (BssDat.Bssvar_modulationtype_list[1])) else: if (BssDat.Bssvar_modulationtype_list[0] == 'sin'): strvalor = (", Period %0.2f " % (BssDat.Bssvar_modulationtype_list[1])) else: strvalor = '' straff = (". Affected species:%s" % (BssDat.Bssvar_species)) sgcom.inform_user(ldev_inf, "Blossom variability active. Period: %0.2f (%% of year), Initial moment standard dev.: %0.04f (%% of year), Type: %s%s%s "\ % (BssDat.Bssvar_period, BssDat.Bssvar_sd, BssDat.Bssvar_modulationtype_list[0], strvalor, straff)) if (str(BssDat.Bssvar_species[0]).upper() == 'ALL'): listaspecies = list(range(numspecies_a)) else: listaspecies = [i - 1 for i in BssDat.Bssvar_species] bssvar_allones = np.ones((year_periods, ), dtype=float) #for i in range(numspecies_a): for i in range_species_a: if i in listaspecies: if (BssDat.Bssvar_modulationtype_list[0] == 'None'): varspecies = calcbssvarespecie(BssDat.Bssvar_period, BssDat.Bssvar_sd, bss_pert_no_modulation, year_periods) elif (BssDat.Bssvar_modulationtype_list[0] == 'linear'): pendiente = float(BssDat.Bssvar_modulationtype_list[1]) varspecies = calcbssvarespecie(BssDat.Bssvar_period, BssDat.Bssvar_sd, bss_pert_lineal, year_periods) elif (BssDat.Bssvar_modulationtype_list[0] == 'sin'): periodo = int(BssDat.Bssvar_modulationtype_list[1]) varspecies = calcbssvarespecie(BssDat.Bssvar_period, BssDat.Bssvar_sd, bss_pert_sinusoidal, year_periods) pBssvar_species.append(np.array(varspecies)) else: pBssvar_species.append(bssvar_allones) return pBssvar_species, hay_bssvar, pendiente, periodo
def init_blossom_pertubation_params(BssDat, numspecies_a, year_periods, ldev_inf): # Blossom variability analysis global pendiente, periodo pBssvar_species = [] pendiente = periodo = 0 hay_bssvar = (BssDat.Bssvar_sd > 0.0) & (len(BssDat.Bssvar_species) > 0) if (hay_bssvar): if (BssDat.Bssvar_modulationtype_list[0] == 'linear'): strvalor = (", Slope %0.2f " % (BssDat.Bssvar_modulationtype_list[1])) else: if (BssDat.Bssvar_modulationtype_list[0] == 'sin'): strvalor = (", Period %0.2f " % (BssDat.Bssvar_modulationtype_list[1])) else: strvalor = '' straff = (". Affected species:%s" % (BssDat.Bssvar_species)) sgcom.inform_user(ldev_inf, "Blossom variability active. Period: %0.2f (%% of year), Initial moment standard dev.: %0.04f (%% of year), Type: %s%s%s "\ % (BssDat.Bssvar_period, BssDat.Bssvar_sd, BssDat.Bssvar_modulationtype_list[0], strvalor, straff)) if (str(BssDat.Bssvar_species[0]).upper() == 'ALL'): listaspecies = list(range(numspecies_a)) else: listaspecies = [i-1 for i in BssDat.Bssvar_species] bssvar_allones = np.ones((year_periods,), dtype=float) #for i in range(numspecies_a): for i in range_species_a: if i in listaspecies: if (BssDat.Bssvar_modulationtype_list[0] == 'None'): varspecies = calcbssvarespecie(BssDat.Bssvar_period, BssDat.Bssvar_sd, bss_pert_no_modulation, year_periods) elif (BssDat.Bssvar_modulationtype_list[0] == 'linear'): pendiente = float(BssDat.Bssvar_modulationtype_list[1]) varspecies = calcbssvarespecie(BssDat.Bssvar_period, BssDat.Bssvar_sd, bss_pert_lineal, year_periods) elif (BssDat.Bssvar_modulationtype_list[0] == 'sin'): periodo = int(BssDat.Bssvar_modulationtype_list[1]) varspecies = calcbssvarespecie(BssDat.Bssvar_period, BssDat.Bssvar_sd, bss_pert_sinusoidal, year_periods) pBssvar_species.append(np.array(varspecies)) else: pBssvar_species.append(bssvar_allones) return pBssvar_species, hay_bssvar, pendiente, periodo
def predators_population_evolution(hay_foodweb, ldev_inf, numspecies_a, Nindividuals_a, numspecies_b, Nindividuals_b, K_c, Nindividuals_c, r_c, numspecies_c, minputchar_d, j, k): if hay_foodweb: rowNi = [] for n in range(numspecies_c): coef_bij_matrix = c_devorados = r_eqsum = 0 signo = signfunc(r_c[n]) if (Nindividuals_c[k][n] > 0): for j in range_species_a: coef_bij_matrix = Nindividuals_a[k][j] * minputchar_d[j][n] r_eqsum += coef_bij_matrix for j in range_species_b: coef_bij_matrix = Nindividuals_b[k][j] *\ minputchar_d[j + numspecies_a][n] r_eqsum += coef_bij_matrix rperiodequivalente = calc_r_periodo_vh(r_eqsum, invperiod) term_c = round(Nindividuals_c[k][n] *\ (1 - Nindividuals_c[k][n] / K_c[n])) if term_c > 1: incPredatoria = np.random.binomial( term_c, -math.expm1(-rperiodequivalente)) else: incPredatoria = 0 incNmalth = np.random.binomial( Nindividuals_c[k][n], -math.expm1(-calc_r_periodo_vh(abs(r_c[n]), invperiod))) signo = signfunc(r_c[n]) pop_c = Nindividuals_c[k][n] + incPredatoria + signo * incNmalth if (pop_c == 0): sgcom.inform_user(ldev_inf, \ "Predator species %d extinction in day %d" % (n, k)) else: pop_c = 0 rowNi.append(pop_c) Nindividuals_c.append(rowNi)
def predators_population_evolution(hay_foodweb, ldev_inf, numspecies_a, Nindividuals_a, numspecies_b, Nindividuals_b, K_c, Nindividuals_c, r_c, numspecies_c, minputchar_d, j, k): if hay_foodweb: rowNi = [] for n in range(numspecies_c): coef_bij_matrix = c_devorados = r_eqsum = 0 signo = signfunc(r_c[n]) if (Nindividuals_c[k][n] > 0): for j in range_species_a: coef_bij_matrix = Nindividuals_a[k][j] * minputchar_d[j][n] r_eqsum += coef_bij_matrix for j in range_species_b: coef_bij_matrix = Nindividuals_b[k][j] *\ minputchar_d[j + numspecies_a][n] r_eqsum += coef_bij_matrix rperiodequivalente = calc_r_periodo_vh(r_eqsum, invperiod) term_c = round(Nindividuals_c[k][n] *\ (1 - Nindividuals_c[k][n] / K_c[n])) if term_c > 1: incPredatoria = np.random.binomial(term_c, -math.expm1(-rperiodequivalente)) else: incPredatoria = 0 incNmalth = np.random.binomial(Nindividuals_c[k][n], -math.expm1(-calc_r_periodo_vh(abs(r_c[n]), invperiod))) signo = signfunc(r_c[n]) pop_c = Nindividuals_c[k][n] + incPredatoria + signo * incNmalth if (pop_c == 0): sgcom.inform_user(ldev_inf, \ "Predator species %d extinction in day %d" % (n, k)) else: pop_c = 0 rowNi.append(pop_c) Nindividuals_c.append(rowNi)
def init_forced_external_pertubations(pl_ext, pol_ext, yearperiods, hayextplantas, hayextpolin, ldev_inf, lfich_inf): global forced_extinctions_in_course forced_extinctions_in_course = False if hayextplantas: inicioextplantas = pl_ext['start'] * sgGL.DAYS_YEAR nperpl = pl_ext['numperiod'] periodoextpl = pl_ext['period'] spikepl = round(periodoextpl * pl_ext['spike']) species_list_text = sgcom.create_list_species_affected(','.join( [str(i) for i in pl_ext['species']])) sgcom.inform_user(ldev_inf, "Perturbations. Plants species %s, period (years): %0.2f, numperiods: %d, spike (fraction of period): %0.2f, rate: %.03f, start (year): %d"\ % (species_list_text, periodoextpl / sgGL.DAYS_YEAR, nperpl, pl_ext['spike'], float(pl_ext['rate']), pl_ext['start'])) else: inicioextplantas = nperpl = periodoextpl = spikepl = 0 if hayextpolin: inicioextpol = pol_ext['start'] * sgGL.DAYS_YEAR nperpol = pol_ext['numperiod'] periodoextpol = pol_ext['period'] spikepol = round(periodoextpol * pol_ext['spike']) species_list_text = sgcom.create_list_species_affected(','.join( [str(i) for i in pol_ext['species']])) sgcom.inform_user(ldev_inf, "Perturbations. Pollinators species %s, period (years): %d, numperiods: %d, spike (fraction of period): %0.2f, rate: %.03f, start (year): %d"\ % (species_list_text, periodoextpol / sgGL.DAYS_YEAR, nperpol, pol_ext['spike'], float(pol_ext['rate']), pol_ext['start'])) else: inicioextpol = nperpol = periodoextpol = spikepol = 0 perturbation_conditions = sgcom.ExternalPerturbationConditions( nperpl, inicioextplantas, periodoextpl, spikepl, nperpol, inicioextpol, periodoextpol, spikepol) return (perturbation_conditions)
def init_forced_external_pertubations(pl_ext, pol_ext, yearperiods, hayextplantas, hayextpolin, ldev_inf, lfich_inf): global forced_extinctions_in_course forced_extinctions_in_course = False if hayextplantas: inicioextplantas = pl_ext['start'] * sgGL.DAYS_YEAR nperpl = pl_ext['numperiod'] periodoextpl = pl_ext['period'] spikepl = round(periodoextpl * pl_ext['spike']) species_list_text = sgcom.create_list_species_affected(','.join([str(i) for i in pl_ext['species']] )) sgcom.inform_user(ldev_inf, "Perturbations. Plants species %s, period (years): %0.2f, numperiods: %d, spike (fraction of period): %0.2f, rate: %.03f, start (year): %d"\ % (species_list_text, periodoextpl / sgGL.DAYS_YEAR, nperpl, pl_ext['spike'], float(pl_ext['rate']), pl_ext['start'])) else: inicioextplantas = nperpl = periodoextpl = spikepl = 0 if hayextpolin: inicioextpol = pol_ext['start'] * sgGL.DAYS_YEAR nperpol = pol_ext['numperiod'] periodoextpol = pol_ext['period'] spikepol = round(periodoextpol * pol_ext['spike']) species_list_text = sgcom.create_list_species_affected(','.join([str(i) for i in pol_ext['species']] )) sgcom.inform_user(ldev_inf, "Perturbations. Pollinators species %s, period (years): %d, numperiods: %d, spike (fraction of period): %0.2f, rate: %.03f, start (year): %d"\ % (species_list_text, periodoextpol / sgGL.DAYS_YEAR, nperpol, pol_ext['spike'], float(pol_ext['rate']), pol_ext['start'])) else: inicioextpol = nperpol = periodoextpol = spikepol = 0 perturbation_conditions = sgcom.ExternalPerturbationConditions(nperpl, inicioextplantas, periodoextpl, spikepl, nperpol, inicioextpol, periodoextpol, spikepol) return(perturbation_conditions)
def predators_param_init(filename, hay_foodweb, direntrada, ldev_inf, lfich_inf, dt): K_c = [] Nindividuals_c = [] rowNindividuals_c = [] r_c = [] r_cperiod = [] minputchar_c = [] minputchar_d = [] numspecies_c = 0 if hay_foodweb > 0: filename_c = filename + '_c.txt' filename_d = filename + '_d.txt' sgcom.inform_user(lfich_inf, "Predators matrix c: <a href='file:///" +\ dt + "/input/" + filename_c + "' target=_BLANK>" +\ filename_c + "<a>") sgcom.inform_user(lfich_inf, "Predators matrix d: <a href='file:///" +\ dt + "/input/" + filename_d + "' target=_BLANK>" +\ filename_d + "<a>") try: l_minputchar_c = sgcom.dlmreadlike(filename_c, direntrada) minputchar_c = np.array(l_minputchar_c, dtype=float) nrows_c = len(minputchar_c) ncols_c = len(minputchar_c[0]) numspecies_c = ncols_c except: print("INPUT FILE BAD FORMAT") else: sgcom.inform_user(ldev_inf, "Predator species : %d" % numspecies_c) for n in range(numspecies_c): rowNindividuals_c.append(int(minputchar_c[nrows_c - 3][n])) K_c.append(int(minputchar_c[nrows_c - 2][n])) r_c.append(minputchar_c[nrows_c - 1][n]) r_cperiod.append( calc_r_periodo_vh(minputchar_c[nrows_c - 1][n], invperiod)) Nindividuals_c.append(rowNindividuals_c) l_minputchar_d = sgcom.dlmreadlike(filename_d, direntrada) minputchar_d = np.array(l_minputchar_d, dtype=float) nrows_d = len(minputchar_d) ncols_d = len(minputchar_d[0]) numspecies_d = ncols_d return Nindividuals_c, minputchar_c, numspecies_c, K_c, r_c, minputchar_d
def predators_param_init(filename, hay_foodweb, direntrada, ldev_inf, lfich_inf, dt): K_c = [] Nindividuals_c = [] rowNindividuals_c = [] r_c = [] r_cperiod = [] minputchar_c = []; minputchar_d = [] numspecies_c = 0 if hay_foodweb > 0: filename_c = filename + '_c.txt' filename_d = filename + '_d.txt' sgcom.inform_user(lfich_inf, "Predators matrix c: <a href='file:///" +\ dt + "/input/" + filename_c + "' target=_BLANK>" +\ filename_c + "<a>") sgcom.inform_user(lfich_inf, "Predators matrix d: <a href='file:///" +\ dt + "/input/" + filename_d + "' target=_BLANK>" +\ filename_d + "<a>") try: l_minputchar_c = sgcom.dlmreadlike(filename_c, direntrada) minputchar_c = np.array(l_minputchar_c, dtype=float) nrows_c = len(minputchar_c) ncols_c = len(minputchar_c[0]) numspecies_c = ncols_c except: print("INPUT FILE BAD FORMAT") else: sgcom.inform_user(ldev_inf, "Predator species : %d" % numspecies_c) for n in range(numspecies_c): rowNindividuals_c.append(int(minputchar_c[nrows_c - 3][n])) K_c.append(int(minputchar_c[nrows_c - 2][n])) r_c.append(minputchar_c[nrows_c - 1][n]) r_cperiod.append(calc_r_periodo_vh(minputchar_c[nrows_c - 1][n], invperiod)) Nindividuals_c.append(rowNindividuals_c) l_minputchar_d = sgcom.dlmreadlike(filename_d, direntrada) minputchar_d = np.array(l_minputchar_d, dtype=float) nrows_d = len(minputchar_d) ncols_d = len(minputchar_d[0]) numspecies_d = ncols_d return Nindividuals_c, minputchar_c, numspecies_c, K_c, r_c, minputchar_d
def food_render(simulation_params, sig_ret_val, displayinic, periods, verbose=True): global ax sgGL.ldev_inf, sgGL.lfich_inf = sgcom.open_info_channels( verbose, simulation_params.fichreport, 'a') matplotlib.rc('xtick', labelsize=8) matplotlib.rc('ytick', labelsize=8) factorescala = 1.2 numspecies_a = len(sig_ret_val.Nindividuals_a[0]) numspecies_b = len(sig_ret_val.Nindividuals_b[0]) numspecies_c = len(sig_ret_val.Nindividuals_c[0]) plt.figure('Mutualist network simulation. Input file: ' +\ simulation_params.filename, dpi=resolucion, figsize=(ancho, alto)) ax = plt.subplot(3, 1, 1) plt.title('Plants') plt.ylabel('Individuals') # plt.xlabel('Days') plt.grid(True) for i in range(numspecies_a): graf = [] x = [] for k in range(displayinic, periods): graf.append(sig_ret_val.Nindividuals_a[k][i]) x.append(k) plt.plot(x, graf, color=cm.Set1(i / (numspecies_a)), lw=calc_lw_width(numspecies_a)) a = plt.gca() a.set_ylim([0, factorescala * sig_ret_val.maxminval.maxa_individuos]) if numspecies_b < 11: box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.9, box.height]) ax = plt.subplot(3, 1, 2) plt.title('Pollinators') plt.ylabel('Individuals') # plt.xlabel('Days') plt.grid(True) for i in range(numspecies_b): graf = [] x = [] for k in range(displayinic, periods): graf.append(sig_ret_val.Nindividuals_b[k][i]) x.append(k) plt.plot(x, graf, color=cm.Paired(i / (numspecies_b)), lw=calc_lw_width(numspecies_b)) a = plt.gca() a.set_ylim([0, factorescala * sig_ret_val.maxminval.maxb_individuos]) if numspecies_b < 11: box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.9, box.height]) ax = plt.subplot(3, 1, 3) plt.title('Predators') plt.ylabel('Individuals') plt.xlabel('Years') plt.grid(True) lmaxc = max(sig_ret_val.Nindividuals_c) maxc_individuos = max(lmaxc) for i in range(numspecies_c): graf = [] x = [] for k in range(displayinic, periods): graf.append(sig_ret_val.Nindividuals_c[k][i]) x.append(k) plt.plot(x, graf, color=cm.Paired(i / (numspecies_c)), lw=calc_lw_width(numspecies_c)) a = plt.gca() a.set_ylim([0, factorescala * maxc_individuos]) if numspecies_c < 11: box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.9, box.height]) nsal = 'output_pict_foodweb_' + simulation_params.filename + '_' +\ simulation_params.algorithm + '_' + simulation_params.output_suff +\ '_' + str(periods) + '.png' dt = simulation_params.dirtrabajo.replace('\\', '/') plt.savefig(str(dt + '/' + simulation_params.dirsal.replace('\\', '/') + nsal), bbox_inches=0) plt.close() sgcom.inform_user(sgGL.lfich_inf, "<P align=left><br>Foodweb effect picture<br>") sgcom.inform_user(sgGL.lfich_inf,\ "<IMG SRC=file:///%s ALIGN=LEFT width=1200 BORDER=0>" %\ str(dt + '/' + simulation_params.dirsal.replace('\\', '/') + nsal)) sgcom.inform_user(sgGL.lfich_inf, '<p>') sgcom.close_info_channels(sgGL.lfich_inf)
def mutual_render(simulation_params, sig_ret_val, displayinic, periods, verbose=True): global ax # if (len(sig_ret_val.pBssvar_species)): # nrows = 3 # else: # nrows = 2 nrows = 3 matplotlib.rc('xtick', labelsize=8) matplotlib.rc('ytick', labelsize=8) years = periods // sgGL.DAYS_YEAR sgGL.ldev_inf, sgGL.lfich_inf = sgcom.open_info_channels( verbose, simulation_params.fichreport, 'a') factorescala = 1.1 numspecies_a = len(sig_ret_val.Nindividuals_a[0]) numspecies_b = len(sig_ret_val.Nindividuals_b[0]) plt.figure('Mutualist network simulation. Input file: ' +\ simulation_params.filename, dpi=resolucion, figsize=(ancho, alto)) ax = plt.subplot(nrows, 2, 1) pintasubplot(sig_ret_val.Nindividuals_a, 0, sig_ret_val.maxminval.maxa_individuos, displayinic, periods, factorescala, numspecies_a, 'Plants', 'Individuals') ax = plt.subplot(nrows, 2, 3) pintasubplot(sig_ret_val.ra_eff, sig_ret_val.maxminval.min_reff, sig_ret_val.maxminval.max_reff, displayinic, periods, factorescala, numspecies_a, '', 'Efficient growth rate') plt.xlabel('Years') # if (len(sig_ret_val.pBssvar_species)): # for i in range(numspecies_a): # graf = [sig_ret_val.pBssvar_species[i][0]] # x = [0] # for k in range (0, years): # graf.append(sig_ret_val.pBssvar_species[i][k]) # x.append(1 + k) # ax = plt.subplot(nrows, 2, 5) # listacoefs = np.array(sig_ret_val.pBssvar_species) # listacoefs = np.c_[listacoefs[:,0],listacoefs] # listacoefs = list(listacoefs.transpose()) # pintasubplot(listacoefs, 0, 1, displayinic, years, factorescala, # numspecies_a, '', 'Blossom variability coeffs.', # periodsinyears = True) # plt.xlabel('Years') ax = plt.subplot(nrows, 2, 2) pintasubplot(sig_ret_val.Nindividuals_b, 0, sig_ret_val.maxminval.maxb_individuos, displayinic, periods, factorescala, numspecies_b, 'Polllinators', '') ax = plt.subplot(nrows, 2, 4) pintasubplot(sig_ret_val.rb_eff, sig_ret_val.maxminval.min_reff, sig_ret_val.maxminval.max_reff, displayinic, periods, factorescala, numspecies_b, '', '') plt.xlabel('Years') # Network Growth Power ax = plt.subplot(nrows, 2, 5) pintasubplot(sig_ret_val.network_growth_power, min(sig_ret_val.network_growth_power), max(sig_ret_val.network_growth_power), displayinic, periods, factorescala, 1, '', 'Network Growth Power', displaylegend=False) dt = simulation_params.dirtrabajo.replace('\\', '/') nsal = 'output_pict_plantsandpols_' + simulation_params.filename +\ '_' + simulation_params.algorithm + '_' + simulation_params.output_suff +\ '_' + str(years) + '.png' plt.savefig(str(dt + '/' + simulation_params.dirsal.replace('\\', '/') + nsal), bbox_inches=0) sgcom.inform_user(sgGL.lfich_inf, "<p align=left>Populations evolution picture") sgcom.inform_user(sgGL.lfich_inf, \ "<IMG SRC=file:///%s ALIGN=LEFT width=1200 BORDER=0>" %\ str(dt + '/' + simulation_params.dirsal.replace('\\', '/') + nsal)) sgcom.inform_user(sgGL.lfich_inf, '</p><br>') sgcom.close_info_channels(sgGL.lfich_inf) plt.close()
def bino_mutual(sim_cond=''): global cuentaperpl, cuentaperpol global Logistic_abs global model_r_alpha global pendiente, blossomperiod, sd, periodo global count_collapse_years global forced_extinctions_in_course global init_collapse_years global range_species_a, range_species_b sgGL.ldev_inf, sgGL.lfich_inf, periods, systemextinction,\ May, haymut, model_r_alpha, count_collapse_years, init_collapse_years = \ init_simulation_environment(sim_cond.year_periods, sim_cond.fichreport, sim_cond.algorithm, sim_cond.verbose) tinic = time() sgcom.start_report(sgGL.ldev_inf, sim_cond.filename, sim_cond.com, sim_cond.year_periods, sim_cond.algorithm, sim_cond.release, sim_cond.hay_foodweb) numspecies_a, minputchar_a, nrows_a, ncols_a = \ sgcom.read_simulation_matrix(sim_cond.filename, sim_cond.dirtrabajo, sim_cond.direntrada, '_a.txt', 'Plants', sim_cond.N0plants, lfich_inf = sgGL.lfich_inf) rowNindividuals_a, Alpha_a, cAlpha_a, r_a, rd_a, Nindividuals_a,\ ra_eff, ra_equs, r_tot_eqsum_a = init_lists_pop(periods, numspecies_a, minputchar_a) lcompatibplantas = init_blossom_perturbation_lists( sim_cond.plants_blossom_prob, sim_cond.blossom_pert_list, numspecies_a) range_periods = range(periods - 1) range_species_a = range(numspecies_a) numspecies_b, minputchar_b, nrows_b, ncols_b = \ sgcom.read_simulation_matrix(sim_cond.filename, sim_cond.dirtrabajo, sim_cond.direntrada, '_b.txt', 'Pollinators ', sim_cond.N0pols, lfich_inf = sgGL.lfich_inf) rowNindividuals_b, Alpha_b, cAlpha_b, r_b,\ rd_b, Nindividuals_b, rb_eff, rb_equs, r_tot_eqsum_b = init_lists_pop(periods, numspecies_b, minputchar_b) range_species_b = range(numspecies_b) add_report_simulation_conditions(sim_cond.plants_blossom_prob, sim_cond.plants_blossom_sd, sim_cond.plants_blossom_type, sim_cond.blossom_pert_list, sgGL.ldev_inf, numspecies_a, rowNindividuals_a, numspecies_b, rowNindividuals_b) network_growth_power = np.zeros(periods, dtype=float) mut_brake_a = Alpha_a mut_brake_b = Alpha_b # Random links removal periodoborr = init_random_links_removal(sim_cond.eliminarenlaces, periods, sgGL.ldev_inf, minputchar_a) # Extinction analysis. Forced death rate increases # inicioextplantas, inicioextpol, hayextplantas, hayextpolin, j =\ hayextplantas, hayextpolin, inner_pl_ext, inner_pol_ext, j = init_external_perturbation_lists( sim_cond.pl_ext, sim_cond.pol_ext, numspecies_a, numspecies_b) pert_cond = init_forced_external_pertubations( sim_cond.pl_ext, sim_cond.pol_ext, sim_cond.year_periods, hayextplantas, hayextpolin, sgGL.ldev_inf, sgGL.lfich_inf) # Extinction analysis. Blossom pertubations bloss_species, hay_bssvar, pBssvar_species = \ init_blossom_perturbations_conditions(sim_cond.year_periods, sim_cond.blossom_pert_list, sim_cond.Bssvar_data, sgGL.ldev_inf, numspecies_a) Nindividuals_c, minputchar_c, numspecies_c, K_c, r_c, minputchar_d = \ predators_param_init(sim_cond.filename, sim_cond.hay_foodweb, sim_cond.direntrada, sgGL.ldev_inf, sgGL.lfich_inf, sim_cond.dirtrabajo.replace('\\', '/')) for k in range_periods: ''' The compatibilty matrixes masks are created when the year starts ''' if not (k % sgGL.DAYS_YEAR): # Much faster than if ((k%sgGL.DAYS_YEAR)==0) if (not (systemextinction)): systemextinction = check_system_extinction( sim_cond.algorithm, k, lcompatibplantas, sim_cond.plants_blossom_prob, ra_equs, rb_equs, ra_eff, rb_eff) forced_extinctions_in_course = False if systemextinction: sgcom.inform_user(sgGL.ldev_inf,\ "ALARM !!!. System will collapse. Day %d (year %d). NGP %0.3f" %\ (k, k // sgGL.DAYS_YEAR,network_growth_power[k])) if sim_cond.exit_on_extinction: sim_ret_val = sgcom.SimulationReturnValues( Nindividuals_a, Nindividuals_b, Nindividuals_c, ra_eff, rb_eff, ra_equs, rb_equs, [], systemextinction, pBssvar_species, network_growth_power) return (sim_ret_val) minputchar_a_mask, minputchar_b_mask, lcompatibplantas =\ calc_random_blossom_effect(numspecies_a, nrows_a, ncols_a, nrows_b, ncols_b, numspecies_b, sim_cond, blossom_pert_list=bloss_species[:]) minpeq_a, minpeq_b = calc_perturbed_coeffs( k, hay_bssvar, pBssvar_species, minputchar_a, minputchar_a_mask, numspecies_a, minputchar_b, minputchar_b_mask, numspecies_b) # Eliminacion aleatoria de enlaces if (sim_cond.eliminarenlaces > 0) & (k > 0) & (k % periodoborr == 0): minpeq_a, minpeq_b , minputchar_a, minputchar_b = \ deletion_links_effect(k, periodoborr, minputchar_a, minputchar_b, minputchar_a_mask, minputchar_b_mask, sgGL.ldev_inf) if haymut: r_tot_eqsum_a = np.dot(np.transpose(minpeq_a[0:numspecies_b, :]),\ Nindividuals_b[k, :]) r_tot_eqsum_b = np.dot(np.transpose(minpeq_b[0:numspecies_a, :]),\ Nindividuals_a[k, :]) mut_brake_a = Alpha_a + cAlpha_a * r_tot_eqsum_a mut_brake_b = Alpha_b + cAlpha_b * r_tot_eqsum_b brake_a = mut_brake_a * np.transpose(Nindividuals_a[k, ]) brake_b = mut_brake_b * np.transpose(Nindividuals_b[k, ]) # pepars = [PopEvoPars(n, "Plant", # numspecies_a, sim_cond.algorithm, # sim_cond.hay_foodweb, inner_pl_ext, # May, haymut, ra_eff, ra_equs, # minpeq_a, j, cAlpha_a, Alpha_a, r_a, rd_a, # Nindividuals_a, numspecies_b, Nindividuals_b, # Nindividuals_c, minputchar_c, numspecies_c, # pert_cond.inicioextplantas, hayextplantas, # pert_cond.nperpl, pert_cond.periodoextpl, # pert_cond.spikepl, k, model_r_alpha, r_tot_eqsum_a[n], # sgGL.ldev_inf) for n in range_species_a if Nindividuals_a[k,n]>0] # with Pool(3) as p: # (p.map(populations_evolution_parallel, pepars)) # list(map(populations_evolution_parallel, pepars)) #[populations_evolution_parallel(x) for x in pepars] [ populations_evolution( n, numspecies_a, #sim_cond.algorithm, sim_cond.hay_foodweb, inner_pl_ext, #May, haymut, ra_eff, ra_equs, minpeq_a, j, #cAlpha_a, Alpha_a, r_a, rd_a, Nindividuals_a, numspecies_b, Nindividuals_b, Nindividuals_c, minputchar_c, numspecies_c, pert_cond.inicioextplantas, hayextplantas, pert_cond.nperpl, pert_cond.periodoextpl, pert_cond.spikepl, k, model_r_alpha, r_tot_eqsum_a[n], brake_a[n], sgGL.ldev_inf, isplant=True) for n in range_species_a if Nindividuals_a[k, n] > 0 ] [ populations_evolution( n, numspecies_b, #sim_cond.algorithm, sim_cond.hay_foodweb, inner_pol_ext, #May, haymut, rb_eff, rb_equs, minpeq_b, j, #cAlpha_b, Alpha_b, r_b, rd_b, Nindividuals_b, numspecies_a, Nindividuals_a, Nindividuals_c, minputchar_c, numspecies_c, pert_cond.inicioextpol, hayextpolin, pert_cond.nperpol, pert_cond.periodoextpol, pert_cond.spikepol, k, model_r_alpha, r_tot_eqsum_b[n], brake_b[n], sgGL.ldev_inf, isplant=False) for n in range_species_b if Nindividuals_b[k, n] > 0 ] if (np.sum(Nindividuals_a[k, ]) + np.sum(Nindividuals_b[k, ])) > 0: network_growth_power[k+1] = np.average(list(np.extract(Nindividuals_a[k,]>0,ra_equs[k+1,]))+\ list(np.extract(Nindividuals_b[k,]>0,rb_equs[k+1,]))) else: network_growth_power[k + 1:] = network_growth_power[k] if (sim_cond.hay_foodweb): predators_population_evolution(sim_cond.hay_foodweb, sgGL.ldev_inf, numspecies_a, Nindividuals_a, numspecies_b, Nindividuals_b, K_c, Nindividuals_c, r_c, numspecies_c, minputchar_d, j, k) ra_eff[0, ] = ra_eff[1, ] rb_eff[0, ] = rb_eff[1, ] network_growth_power[0] = network_growth_power[1] network_growth_power = np.transpose(network_growth_power) maxminval = sgcom.find_max_values(Nindividuals_a, Nindividuals_b, ra_eff, rb_eff, ra_equs, rb_equs) tfin = time() sgcom.end_report(sgGL.ldev_inf, sgGL.lfich_inf, sim_cond, tfin, tinic, periods, Nindividuals_a, ra_eff, ra_equs, Nindividuals_b, rb_eff, rb_equs, network_growth_power, Nindividuals_c) sim_ret_val = sgcom.SimulationReturnValues(Nindividuals_a, Nindividuals_b, Nindividuals_c, ra_eff, rb_eff, ra_equs, rb_equs, maxminval, systemextinction, pBssvar_species, network_growth_power) return (sim_ret_val)
def add_report_simulation_conditions(plants_blossom_prob, plants_blossom_sd, plants_blossom_type, blossom_pert_list, ldev_inf, numspecies_a, rowNindividuals_a, numspecies_b, rowNindividuals_b): sgcom.inform_user(ldev_inf, "Plant species: %d" % numspecies_a) sgcom.inform_user(ldev_inf, "Plant initial populations %s" %\ rowNindividuals_a) sgcom.inform_user(ldev_inf, "Pollinator species: %d" % numspecies_b) sgcom.inform_user(ldev_inf, "Pollinator initial populations %s" % rowNindividuals_b) if (plants_blossom_type == 'Binary'): sgcom.inform_user(ldev_inf, "Blossom probability %s, type %s. Plant affected species:%s" %\ (plants_blossom_prob, plants_blossom_type, str(blossom_pert_list))) else: sgcom.inform_user(ldev_inf, "Blossom probability, type %s, mean %s, standard dev. %s. Plant affected species:%s" %\ (plants_blossom_type, plants_blossom_prob, plants_blossom_sd, str(blossom_pert_list)))
def populations_evolution(n, numspecies_p, #algorithm, hay_foodweb, p_ext, #May, haymut, rp_eff, rp_eq, minputchar_p, j, #cAlpha_p, Alpha_p, r_p, rd_p, Nindividuals_p, numspecies_q, Nindividuals_q, Nindividuals_c, minputchar_c, numspecies_c, inicioext, hayext, nper, periodoext, spike, k, model_r_a, r_tot_eqsum_n, brake_p_n, ldev_inf, isplant = True): global cuentaperpl, cuentaperpol p_devorados = 0 r_muerte = rd_p[n] # Function is only executed if Nindividuals_p[k, n]>0 if hayext: if (isplant) & (cuentaperpl < nper): r_muerte, cuentaperpl = perturbation(p_ext, n, rd_p[n], cuentaperpl, inicioext, periodoext, spike, k) elif not(isplant) & (cuentaperpol < nper): r_muerte, cuentaperpol = perturbation(p_ext, n, rd_p[n], cuentaperpol, inicioext, periodoext, spike, k) # CODIGO OBSOLETO, May eliminado # # elif (May): # for j in range(numspecies_q): # r_eqsum, term_May, rMay = calc_mutualism_params(minputchar_p, # Alpha_p, Nindividuals_p, Nindividuals_q, # r_eqsum, term_May, rMay, k, j, n, r_p, # r_muerte) rtot_p = r_p[n] + r_tot_eqsum_n - r_muerte # Predators effect if hay_foodweb: p_devorados, j, rceff = predators_effect(p_devorados, j, Nindividuals_p, Nindividuals_c, minputchar_c, numspecies_c, n, k) # New algorithm # ciclo_verhulst Inline code following Vwn Rossum's advice #rcal = rtot_p - ( Alpha_p[n] + cAlpha_p[n] * r_tot_eqsum_n) * Nindividuals_p[k, n] #rcal = rtot_p - mut_brake_p_n* Nindividuals_p[k, n] rcal = rtot_p - brake_p_n #rcal = 0 inc_pop = Nindividuals_p[k, n] absrcal = abs(rcal) rcalpos = (absrcal == rcal) # IF rcal is tiny, what happens when populations are stable return # zero. Approximation to speed up algorithm #if absrcal*Nindividuals_p[k, n]>sgGL.IGNORE_REFF: rspneq = math.pow(1 + absrcal, invperiod ) - 1 incNmalth = np.random.binomial(Nindividuals_p[k, n], -math.expm1(-rspneq)) if rcalpos: inc_pop += incNmalth else: inc_pop -= incNmalth pop_p = inc_pop - p_devorados # Codigo obsoleto que contemplaba los modelos viejos # # elif not (May): # retl = ciclo_new_model(rtot_p, Nindividuals_p[k, n], # 1 / Alpha_p[n], Logistic_abs) # else: # retl = ciclo_May(r_p[n] - r_muerte, rMay, term_May, # Nindividuals_p[k, n], Alpha_p[n]) # Species extinction if not(pop_p): if isplant: strtype = "Plant" else: strtype = "Pollinator" sgcom.inform_user(ldev_inf, "Day %d (year %d). %s species %d extincted" %\ (k, k // sgGL.DAYS_YEAR, strtype, int_to_ext_rep(n))) rp_eff[k + 1:, n], rp_eq[k + 1:, n] = rp_eff[k, n], rp_eq[k, n] return Nindividuals_p[k + 1, n] = pop_p rp_eff[k + 1, n], rp_eq[k + 1, n] = rcal, rtot_p
def add_report_simulation_conditions(plants_blossom_prob, plants_blossom_sd, plants_blossom_type, blossom_pert_list, ldev_inf, numspecies_a, rowNindividuals_a, numspecies_b, rowNindividuals_b): sgcom.inform_user(ldev_inf, "Plant species: %d" % numspecies_a) sgcom.inform_user(ldev_inf, "Plant initial populations %s" %\ rowNindividuals_a) sgcom.inform_user(ldev_inf, "Pollinator species: %d" % numspecies_b) sgcom.inform_user(ldev_inf, "Pollinator initial populations %s" % rowNindividuals_b) if (plants_blossom_type == 'Binary'): sgcom.inform_user(ldev_inf, "Blossom probability %s, type %s. Plant affected species:%s" %\ (plants_blossom_prob, plants_blossom_type, str(blossom_pert_list))) else: sgcom.inform_user(ldev_inf, "Blossom probability, type %s, mean %s, standard dev. %s. Plant affected species:%s" %\ (plants_blossom_type, plants_blossom_prob, plants_blossom_sd, str(blossom_pert_list)))
def populations_evolution( n, numspecies_p, #algorithm, hay_foodweb, p_ext, #May, haymut, rp_eff, rp_eq, minputchar_p, j, #cAlpha_p, Alpha_p, r_p, rd_p, Nindividuals_p, numspecies_q, Nindividuals_q, Nindividuals_c, minputchar_c, numspecies_c, inicioext, hayext, nper, periodoext, spike, k, model_r_a, r_tot_eqsum_n, brake_p_n, ldev_inf, isplant=True): global cuentaperpl, cuentaperpol p_devorados = 0 r_muerte = rd_p[n] # Function is only executed if Nindividuals_p[k, n]>0 if hayext: if (isplant) & (cuentaperpl < nper): r_muerte, cuentaperpl = perturbation(p_ext, n, rd_p[n], cuentaperpl, inicioext, periodoext, spike, k) elif not (isplant) & (cuentaperpol < nper): r_muerte, cuentaperpol = perturbation(p_ext, n, rd_p[n], cuentaperpol, inicioext, periodoext, spike, k) # CODIGO OBSOLETO, May eliminado # # elif (May): # for j in range(numspecies_q): # r_eqsum, term_May, rMay = calc_mutualism_params(minputchar_p, # Alpha_p, Nindividuals_p, Nindividuals_q, # r_eqsum, term_May, rMay, k, j, n, r_p, # r_muerte) rtot_p = r_p[n] + r_tot_eqsum_n - r_muerte # Predators effect if hay_foodweb: p_devorados, j, rceff = predators_effect(p_devorados, j, Nindividuals_p, Nindividuals_c, minputchar_c, numspecies_c, n, k) # New algorithm # ciclo_verhulst Inline code following Vwn Rossum's advice #rcal = rtot_p - ( Alpha_p[n] + cAlpha_p[n] * r_tot_eqsum_n) * Nindividuals_p[k, n] #rcal = rtot_p - mut_brake_p_n* Nindividuals_p[k, n] rcal = rtot_p - brake_p_n #rcal = 0 inc_pop = Nindividuals_p[k, n] absrcal = abs(rcal) rcalpos = (absrcal == rcal) # IF rcal is tiny, what happens when populations are stable return # zero. Approximation to speed up algorithm #if absrcal*Nindividuals_p[k, n]>sgGL.IGNORE_REFF: rspneq = math.pow(1 + absrcal, invperiod) - 1 incNmalth = np.random.binomial(Nindividuals_p[k, n], -math.expm1(-rspneq)) if rcalpos: inc_pop += incNmalth else: inc_pop -= incNmalth pop_p = inc_pop - p_devorados # Codigo obsoleto que contemplaba los modelos viejos # # elif not (May): # retl = ciclo_new_model(rtot_p, Nindividuals_p[k, n], # 1 / Alpha_p[n], Logistic_abs) # else: # retl = ciclo_May(r_p[n] - r_muerte, rMay, term_May, # Nindividuals_p[k, n], Alpha_p[n]) # Species extinction if not (pop_p): if isplant: strtype = "Plant" else: strtype = "Pollinator" sgcom.inform_user(ldev_inf, "Day %d (year %d). %s species %d extincted" %\ (k, k // sgGL.DAYS_YEAR, strtype, int_to_ext_rep(n))) rp_eff[k + 1:, n], rp_eq[k + 1:, n] = rp_eff[k, n], rp_eq[k, n] return Nindividuals_p[k + 1, n] = pop_p rp_eff[k + 1, n], rp_eq[k + 1, n] = rcal, rtot_p
def bino_mutual(sim_cond = ''): global cuentaperpl, cuentaperpol global Logistic_abs global model_r_alpha global pendiente, blossomperiod, sd, periodo global count_collapse_years global forced_extinctions_in_course global init_collapse_years global range_species_a, range_species_b sgGL.ldev_inf, sgGL.lfich_inf, periods, systemextinction,\ May, haymut, model_r_alpha, count_collapse_years, init_collapse_years = \ init_simulation_environment(sim_cond.year_periods, sim_cond.fichreport, sim_cond.algorithm, sim_cond.verbose) tinic = time() sgcom.start_report(sgGL.ldev_inf, sim_cond.filename, sim_cond.com, sim_cond.year_periods, sim_cond.algorithm, sim_cond.release, sim_cond.hay_foodweb) numspecies_a, minputchar_a, nrows_a, ncols_a = \ sgcom.read_simulation_matrix(sim_cond.filename, sim_cond.dirtrabajo, sim_cond.direntrada, '_a.txt', 'Plants', sim_cond.N0plants, lfich_inf = sgGL.lfich_inf) rowNindividuals_a, Alpha_a, cAlpha_a, r_a, rd_a, Nindividuals_a,\ ra_eff, ra_equs, r_tot_eqsum_a = init_lists_pop(periods, numspecies_a, minputchar_a) lcompatibplantas = init_blossom_perturbation_lists(sim_cond.plants_blossom_prob, sim_cond.blossom_pert_list, numspecies_a) range_periods = range(periods-1) range_species_a = range(numspecies_a) numspecies_b, minputchar_b, nrows_b, ncols_b = \ sgcom.read_simulation_matrix(sim_cond.filename, sim_cond.dirtrabajo, sim_cond.direntrada, '_b.txt', 'Pollinators ', sim_cond.N0pols, lfich_inf = sgGL.lfich_inf) rowNindividuals_b, Alpha_b, cAlpha_b, r_b,\ rd_b, Nindividuals_b, rb_eff, rb_equs, r_tot_eqsum_b = init_lists_pop(periods, numspecies_b, minputchar_b) range_species_b = range(numspecies_b) add_report_simulation_conditions(sim_cond.plants_blossom_prob, sim_cond.plants_blossom_sd, sim_cond.plants_blossom_type, sim_cond.blossom_pert_list, sgGL.ldev_inf, numspecies_a, rowNindividuals_a, numspecies_b, rowNindividuals_b) network_growth_power = np.zeros(periods, dtype=float) mut_brake_a = Alpha_a mut_brake_b = Alpha_b # Random links removal periodoborr = init_random_links_removal(sim_cond.eliminarenlaces, periods, sgGL.ldev_inf, minputchar_a) # Extinction analysis. Forced death rate increases # inicioextplantas, inicioextpol, hayextplantas, hayextpolin, j =\ hayextplantas, hayextpolin, inner_pl_ext, inner_pol_ext, j =init_external_perturbation_lists( sim_cond.pl_ext, sim_cond.pol_ext, numspecies_a, numspecies_b) pert_cond = init_forced_external_pertubations(sim_cond.pl_ext, sim_cond.pol_ext, sim_cond.year_periods, hayextplantas, hayextpolin, sgGL.ldev_inf, sgGL.lfich_inf) # Extinction analysis. Blossom pertubations bloss_species, hay_bssvar, pBssvar_species = \ init_blossom_perturbations_conditions(sim_cond.year_periods, sim_cond.blossom_pert_list, sim_cond.Bssvar_data, sgGL.ldev_inf, numspecies_a) Nindividuals_c, minputchar_c, numspecies_c, K_c, r_c, minputchar_d = \ predators_param_init(sim_cond.filename, sim_cond.hay_foodweb, sim_cond.direntrada, sgGL.ldev_inf, sgGL.lfich_inf, sim_cond.dirtrabajo.replace('\\', '/')) for k in range_periods: ''' The compatibilty matrixes masks are created when the year starts ''' if not(k % sgGL.DAYS_YEAR): # Much faster than if ((k%sgGL.DAYS_YEAR)==0) if (not(systemextinction)): systemextinction = check_system_extinction(sim_cond.algorithm, k, lcompatibplantas, sim_cond.plants_blossom_prob, ra_equs, rb_equs, ra_eff, rb_eff) forced_extinctions_in_course = False if systemextinction: sgcom.inform_user(sgGL.ldev_inf,\ "ALARM !!!. System will collapse. Day %d (year %d). NGP %0.3f" %\ (k, k // sgGL.DAYS_YEAR,network_growth_power[k])) if sim_cond.exit_on_extinction: sim_ret_val = sgcom.SimulationReturnValues( Nindividuals_a, Nindividuals_b, Nindividuals_c, ra_eff, rb_eff, ra_equs, rb_equs, [], systemextinction, pBssvar_species, network_growth_power) return(sim_ret_val) minputchar_a_mask, minputchar_b_mask, lcompatibplantas =\ calc_random_blossom_effect(numspecies_a, nrows_a, ncols_a, nrows_b, ncols_b, numspecies_b, sim_cond, blossom_pert_list=bloss_species[:]) minpeq_a, minpeq_b = calc_perturbed_coeffs(k, hay_bssvar, pBssvar_species, minputchar_a, minputchar_a_mask, numspecies_a, minputchar_b, minputchar_b_mask, numspecies_b) # Eliminacion aleatoria de enlaces if (sim_cond.eliminarenlaces > 0) & (k > 0) & (k % periodoborr == 0): minpeq_a, minpeq_b , minputchar_a, minputchar_b = \ deletion_links_effect(k, periodoborr, minputchar_a, minputchar_b, minputchar_a_mask, minputchar_b_mask, sgGL.ldev_inf) if haymut: r_tot_eqsum_a = np.dot(np.transpose(minpeq_a[0:numspecies_b, :]),\ Nindividuals_b[k, :]) r_tot_eqsum_b = np.dot(np.transpose(minpeq_b[0:numspecies_a, :]),\ Nindividuals_a[k, :]) mut_brake_a = Alpha_a + cAlpha_a * r_tot_eqsum_a mut_brake_b = Alpha_b + cAlpha_b * r_tot_eqsum_b brake_a = mut_brake_a * np.transpose(Nindividuals_a[k,]) brake_b = mut_brake_b * np.transpose(Nindividuals_b[k,]) # pepars = [PopEvoPars(n, "Plant", # numspecies_a, sim_cond.algorithm, # sim_cond.hay_foodweb, inner_pl_ext, # May, haymut, ra_eff, ra_equs, # minpeq_a, j, cAlpha_a, Alpha_a, r_a, rd_a, # Nindividuals_a, numspecies_b, Nindividuals_b, # Nindividuals_c, minputchar_c, numspecies_c, # pert_cond.inicioextplantas, hayextplantas, # pert_cond.nperpl, pert_cond.periodoextpl, # pert_cond.spikepl, k, model_r_alpha, r_tot_eqsum_a[n], # sgGL.ldev_inf) for n in range_species_a if Nindividuals_a[k,n]>0] # with Pool(3) as p: # (p.map(populations_evolution_parallel, pepars)) # list(map(populations_evolution_parallel, pepars)) #[populations_evolution_parallel(x) for x in pepars] [populations_evolution(n, numspecies_a, #sim_cond.algorithm, sim_cond.hay_foodweb, inner_pl_ext, #May, haymut, ra_eff, ra_equs, minpeq_a, j, #cAlpha_a, Alpha_a, r_a, rd_a, Nindividuals_a, numspecies_b, Nindividuals_b, Nindividuals_c, minputchar_c, numspecies_c, pert_cond.inicioextplantas, hayextplantas, pert_cond.nperpl, pert_cond.periodoextpl, pert_cond.spikepl, k, model_r_alpha, r_tot_eqsum_a[n], brake_a[n], sgGL.ldev_inf, isplant = True) for n in range_species_a if Nindividuals_a[k,n]>0] [populations_evolution(n, numspecies_b, #sim_cond.algorithm, sim_cond.hay_foodweb, inner_pol_ext, #May, haymut, rb_eff, rb_equs, minpeq_b, j, #cAlpha_b, Alpha_b, r_b, rd_b, Nindividuals_b, numspecies_a, Nindividuals_a, Nindividuals_c, minputchar_c, numspecies_c, pert_cond.inicioextpol, hayextpolin, pert_cond.nperpol, pert_cond.periodoextpol, pert_cond.spikepol, k, model_r_alpha, r_tot_eqsum_b[n], brake_b[n], sgGL.ldev_inf, isplant = False) for n in range_species_b if Nindividuals_b[k,n]>0 ] if ( np.sum(Nindividuals_a[k,]) + np.sum(Nindividuals_b[k,]) ) > 0: network_growth_power[k+1] = np.average(list(np.extract(Nindividuals_a[k,]>0,ra_equs[k+1,]))+\ list(np.extract(Nindividuals_b[k,]>0,rb_equs[k+1,]))) else: network_growth_power[k+1:] = network_growth_power[k] if (sim_cond.hay_foodweb): predators_population_evolution(sim_cond.hay_foodweb, sgGL.ldev_inf, numspecies_a, Nindividuals_a, numspecies_b, Nindividuals_b, K_c, Nindividuals_c, r_c, numspecies_c, minputchar_d, j, k) ra_eff[0, ] = ra_eff[1, ] rb_eff[0, ] = rb_eff[1, ] network_growth_power[0] = network_growth_power[1] network_growth_power = np.transpose(network_growth_power) maxminval = sgcom.find_max_values(Nindividuals_a, Nindividuals_b, ra_eff, rb_eff, ra_equs, rb_equs) tfin = time() sgcom.end_report(sgGL.ldev_inf, sgGL.lfich_inf, sim_cond, tfin, tinic, periods, Nindividuals_a, ra_eff, ra_equs, Nindividuals_b, rb_eff, rb_equs, network_growth_power, Nindividuals_c) sim_ret_val = sgcom.SimulationReturnValues(Nindividuals_a, Nindividuals_b, Nindividuals_c, ra_eff, rb_eff, ra_equs, rb_equs, maxminval, systemextinction, pBssvar_species, network_growth_power) return(sim_ret_val)