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

writing modified patches of each selected scenario at the end of the iteration

parent 96f78df6
......@@ -56,6 +56,7 @@ class Scenario:
newCult = newCult.sample(frac=1, random_state=rng)[:len(samples)].reset_index(drop=True) # shuffle and cut extra elements
# Doing the reallocation
self.patches.loc[samples.index.values,'cultgeopat'] = newCult.values
self.patches.loc[samples.index.values,'cultmodified'] = True
class CulturalIndicator(Indicator):
@overrides
......@@ -127,6 +128,7 @@ class MCMC:
yaml.dump(config_data, outfile, default_flow_style=False)
# finishing init
self.patches = load_pat_patches(self.mcmc_config['patches'])
self.patches['cultmodified'] = False
self.target = pd.read_csv(self.mcmc_config['target'], sep=';',index_col=0)
targetRatio = (self.target['2050']-self.target['2016'])/self.target['2016']
self.targetPAT = self.patches.groupby('cultgeopat')['SURF_PARC'].sum()*(1+targetRatio)
......@@ -206,7 +208,15 @@ class MCMC:
# when data doesn't vary enough on a dimension, it is impossible to generate the pareto density
# and an error is triggered. Here, we ignore this error.
pass
return [scenarios[pareto_mask], scores[pareto_mask]]
scenarios = scenarios[pareto_mask]
scores = scores[pareto_mask]
# Writing shapefiles
shp_dir = self.outputdir + '/patches_iter_{}'.format(iter_nb)
os.makedirs(shp_dir)
for index,scenario in scenarios.iterrows():
scenario = scenario[0]
scenario[scenario['cultmodified']].drop('cultmodified', axis=1).to_file(shp_dir+'/{}_{}'.format(iter_nb,index), encoding='utf-8')
return [scenarios, scores]
def run(self, nb_processes=mp.cpu_count()):
self.pool = mp.Pool(processes=nb_processes)
......
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