Commit a38c5512 authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

use MCMC config file variable instead of filenames

parent d2c71630
......@@ -303,10 +303,10 @@ class Scenario :
indicators = self.mcmc_config['indicators_config']
dict_indices = {}
dict_indices["proximite"] = self.indice_proximite()
dict_indices["resilience"] = self.indice_resilience(indicators['resilience'])
dict_indices["productivite"] = self.indice_productivitee(indicators['productivity'])
dict_indices["biodiversite"] = self.indice_biodiversite(indicators['biodiversity'])
dict_indices["social"] = self.indice_social(indicators['bdv'], indicators['exploitant'])
dict_indices["resilience"] = self.indice_resilience()
dict_indices["productivite"] = self.indice_productivitee()
dict_indices["biodiversite"] = self.indice_biodiversite()
dict_indices["social"] = self.indice_social()
with gzip.GzipFile('./initial_scenario_indices.gz','w') as fid_gz:
......@@ -321,34 +321,26 @@ class Scenario :
#print "Résultats de l'indice de proximité : " + str(indice_prox)
return indice_prox
def indice_resilience(self, grille):
'''
:param grille: Grid divising the PAT in 5km*5km square
'''
indice_resi = resilience(grille, self.resultat_final, False)
def indice_resilience(self):
indice_resi = resilience(self.mcmc_config['indicators_config']['resilience'], self.resultat_final, False)
#print "Résultats de l'indice de résilience : " + str(indice_resi)
return indice_resi
def indice_productivitee(self, valeurs_cadastrales):
'''
:param valeurs_cadastrales: ShapeFile containing the PAT patches with an attribute corresponding to the cadastral value
'''
indice_prod = indice_productivite(self.resultat_final, valeurs_cadastrales, False)
def indice_productivitee(self):
indice_prod = indice_productivite(self.resultat_final, self.mcmc_config['indicators_config']['productivity'], False)
#print "Résultats de l'indice de productivite : " + str(indice_prod)
return indice_prod
def indice_biodiversite(self, matrice):
'''
:param matrice: Matrix containing all the data about biodiversity. Created with Numpy and the formula of Equivalent Connected Area (Saura et al., 2011)
'''
def indice_biodiversite(self):
#Matrix containing all the data about biodiversity. Created with Numpy and the formula of Equivalent Connected Area (Saura et al., 2011)
matrice = self.mcmc_config['indicators_config']['biodiversity']
indice_bio = biodiversity(self.resultat_final, matrice)
#print "Résultats de l'indice de biodiversite : " + str(indice_bio)
return indice_bio
def indice_social(self, bdv, shape_exploitant):
'''
:param shape_exploitant: ShapeFile containing the PAT patches with an attribute corresponding to the ID of the exploitant
'''
def indice_social(self):
bdv = self.mcmc_config['indicators_config']['bdv']
shape_exploitant = self.mcmc_config['indicators_config']['exploitant']
indice_social = social(shape_exploitant, self.resultat_final, bdv)
#print "Résultats de l'indice de sociabilité : " + str(indice_social)
return indice_social
......@@ -384,9 +376,9 @@ def x_all_indices(scenarInitial, x, nbr_parcelles_a_modifier, cereales, cultures
for i in range(x) :
s = Scenario(scenar, nbr_parcelles_a_modifier, cereales, culturesI, fourrages, fruits_legumes, oleagineux, prairies, proteagineux, liste)
s.indice_proximite()
s.indice_resilience('../Parcelle_PAT/Grille_resilience.shp')
s.indice_productivitee("../Parcelle_PAT/Parcelle_PAT_valCad.shp")
s.indice_biodiversite('./matrix_biodiversity.npz')
s.indice_resilience()
s.indice_productivitee()
s.indice_biodiversite()
scenar = s.get_resultat_final()
liste = True
......@@ -430,7 +422,7 @@ def x_resilience(scenarInitial, x, nbr_parcelles_a_modifier, cereales, culturesI
nbr_parcelles_a_modifier = nbr
s = Scenario(scenar, nbr, cereales, culturesI, fourrages, fruits_legumes, oleagineux, prairies, proteagineux, liste)
#print "Scenario " + str(i) + " : "
ind = s.indice_resilience('../Parcelle_PAT/Grille_resilience.shp')
ind = s.indice_resilience()
#scenar = s.get_resultat_final()
#liste = True
if nbr != 10000:
......@@ -454,7 +446,7 @@ def x_productivite(scenarInitial, x, nbr_parcelles_a_modifier, cereales, culture
for nbr in list :
s = Scenario(scenar, nbr, cereales, culturesI, fourrages, fruits_legumes, oleagineux, prairies, proteagineux, liste)
#print "Scenario " + str(i) + " : "
ind = s.indice_productivitee("../Parcelle_PAT/Parcelle_PAT_valCad.shp")
ind = s.indice_productivitee()
#scenar = s.get_resultat_final()
#liste = True
......@@ -480,7 +472,7 @@ def x_biodiversite(scenarInitial, x, nbr_parcelles_a_modifier, cereales, culture
for nbr in list :
s = Scenario(scenar, nbr, cereales, culturesI, fourrages, fruits_legumes, oleagineux, prairies, proteagineux, liste)
#print "Scenario " + str(i) + " : "
ind = s.indice_biodiversite('./matrix_biodiversity.npz')
ind = s.indice_biodiversite()
#scenar = s.get_resultat_final()
#liste = True
if nbr != 10000:
......@@ -503,7 +495,7 @@ def x_social(scenarInitial, x, nbr_parcelles_a_modifier, cereales, culturesI, fo
for nbr in list :
s = Scenario(scenar, nbr, cereales, culturesI, fourrages, fruits_legumes, oleagineux, prairies, proteagineux, liste)
#print "Scenario " + str(i) + " : "
ind = s1.indice_social('./Bassin_de_vie_Pat.shp', './Parcelle_PAT_exploitant.shp')
ind = s1.indice_social()
#scenar = s.get_resultat_final()
#liste = True
if nbr != 10000:
......@@ -527,19 +519,19 @@ def comparer_2_scenarios(scenar1, scenar2) :
s2_proximite = scenar2.indice_proximite()
dico[1]["proximite"] = s2_proximite
s1_resilience = scenar1.indice_resilience('../Parcelle_PAT/Grille_resilience.shp')
s1_resilience = scenar1.indice_resilience()
dico[0]["resilience"] = s1_resilience
s2_resilience = scenar2.indice_resilience('../Parcelle_PAT/Grille_resilience.shp')
s2_resilience = scenar2.indice_resilience()
dico[1]["resilience"] = s2_resilience
s1_productivite = scenar1.indice_productivitee("../Parcelle_PAT/Parcelle_PAT_valCad.shp")
s1_productivite = scenar1.indice_productivitee()
dico[0]["productivite"] = s1_productivite
s2_productivite = scenar2.indice_productivitee("../Parcelle_PAT/Parcelle_PAT_valCad.shp")
s2_productivite = scenar2.indice_productivitee()
dico[1]["productivite"] = s2_productivite
s1_biodiversite = scenar1.indice_biodiversite('./matrix_biodiversity.npz')
s1_biodiversite = scenar1.indice_biodiversite()
dico[0]["biodiversite"] = s1_biodiversite
s2_biodiversite = scenar2.indice_biodiversite('./matrix_biodiversity.npz')
s2_biodiversite = scenar2.indice_biodiversite()
dico[1]["biodiversite"] = s2_biodiversite
dico[0]["social"] = 0
......@@ -703,10 +695,10 @@ def MCMC(scenarInitial, nbr_loop, nbr_scenario, nbr_scenario_to_stock, nbr_parce
si = Scenario(scenario, 0, cereales, culturesI, fourrages, fruits_legumes, oleagineux, prairies, proteagineux, True, rng)
si_indices = {}
si_indices['proximite'] = si.indice_proximite()
si_indices['resilience'] = si.indice_resilience('../Parcelle_PAT/Grille_resilience.shp')
si_indices['productivite'] = si.indice_productivitee("../Parcelle_PAT/Parcelle_PAT_valCad.shp")
si_indices['biodiversite'] = si.indice_biodiversite('./matrix_biodiversity.npz')
si_indices['social'] = si.indice_social('./Bassin_de_vie_Pat.shp', './Parcelle_PAT_exploitant.shp')
si_indices['resilience'] = si.indice_resilience()
si_indices['productivite'] = si.indice_productivitee()
si_indices['biodiversite'] = si.indice_biodiversite()
si_indices['social'] = si.indice_social()
s_new_indices_avg = {}
s_new_indices_avg['proximite'] = 0
......@@ -720,10 +712,10 @@ def MCMC(scenarInitial, nbr_loop, nbr_scenario, nbr_scenario_to_stock, nbr_parce
dict_scenario[nbr_scenar] = {}
dict_scenario[nbr_scenar]['scenario'] = s.get_scenario()
dict_scenario[nbr_scenar]['proximite'] = s.indice_proximite()
dict_scenario[nbr_scenar]['resilience'] = s.indice_resilience('../Parcelle_PAT/Grille_resilience.shp')
dict_scenario[nbr_scenar]['productivite'] = s.indice_productivitee("../Parcelle_PAT/Parcelle_PAT_valCad.shp")
dict_scenario[nbr_scenar]['biodiversite'] = s.indice_biodiversite('./matrix_biodiversity.npz')
dict_scenario[nbr_scenar]['social'] = s.indice_social('./Bassin_de_vie_Pat.shp', './Parcelle_PAT_exploitant.shp')
dict_scenario[nbr_scenar]['resilience'] = s.indice_resilience()
dict_scenario[nbr_scenar]['productivite'] = s.indice_productivitee()
dict_scenario[nbr_scenar]['biodiversite'] = s.indice_biodiversite()
dict_scenario[nbr_scenar]['social'] = s.indice_social()
s_new_indices_avg['proximite'] += dict_scenario[nbr_scenar]['proximite']
......@@ -786,10 +778,10 @@ def MCMC(scenarInitial, nbr_loop, nbr_scenario, nbr_scenario_to_stock, nbr_parce
s = Scenario(dict_scenario[nbr_scenar%(nbr_scenario_to_stock * 5)]['scenario'].get_resultat_final(), nbr_parcelles_a_modifier, cereales, culturesI, fourrages, fruits_legumes, oleagineux, prairies, proteagineux, liste, rng)
dict_scenario[nbr_scenar]['scenario'] = s.get_scenario()
dict_scenario[nbr_scenar]['proximite'] = s.indice_proximite()
dict_scenario[nbr_scenar]['resilience'] = s.indice_resilience('../Parcelle_PAT/Grille_resilience.shp')
dict_scenario[nbr_scenar]['productivite'] = s.indice_productivitee("../Parcelle_PAT/Parcelle_PAT_valCad.shp")
dict_scenario[nbr_scenar]['biodiversite'] = s.indice_biodiversite('./matrix_biodiversity.npz')
dict_scenario[nbr_scenar]['social'] = s.indice_social('./Bassin_de_vie_Pat.shp', './Parcelle_PAT_exploitant.shp')
dict_scenario[nbr_scenar]['resilience'] = s.indice_resilience()
dict_scenario[nbr_scenar]['productivite'] = s.indice_productivitee()
dict_scenario[nbr_scenar]['biodiversite'] = s.indice_biodiversite()
dict_scenario[nbr_scenar]['social'] = s.indice_social()
old_best_scenario = best_scenario
best_scenario = get_best_scenario(dict_scenario, nbr_scenario_to_stock)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment