def corrSuitabilityMaps(): #### Script to find corelation between suitbility maps for country in case_studies: suitDir = os.path.join(os.getcwd(), 'results', 'figures', 'suitability_maps') workDir = parameters.getWorkDir() resultFolder = os.path.join(workDir, 'results', country, 'metrics') fig_dir = os.path.join(os.getcwd(), 'results', 'figures') pointFile = 'sampPointNr.col' pointDir = os.path.join(os.getcwd(), 'input_data', country, pointFile) file_list = os.listdir(suitDir) file_list = [x for x in file_list if x.startswith(country)] maps = [ os.path.join(os.getcwd(), 'results', 'figures', 'suitability_maps', f) for f in file_list ] maps_pairs = [(file_list[i], file_list[j]) for i in range(len(file_list)) for j in range(i + 1, len(file_list))] maps_pairs = [(x[8:], y[8:]) for x, y in maps_pairs] arrays = [] for a_map in maps: arrays.append(metrics.map2Array(a_map, pointDir)) pairs = [(arrays[i], arrays[j]) for i in range(len(arrays)) for j in range(i + 1, len(arrays))] for i, pair in enumerate(pairs): # Check for NaNs mask = np.isnan(pair[0]) | np.isnan(pair[1]) # Mask, to remove NaNs x = pair[0][~mask] y = pair[1][~mask] print(x.shape, y.shape) print(np.corrcoef(x, y)) # Plot plt.scatter(x, y, s=0.1) a_string = 'correlation coefficient between '+\ maps_pairs[i][0]+' and '+maps_pairs[i][1]+': '+str(np.corrcoef(x,y)[0,1]) plt.title(a_string) plt.xlabel(maps_pairs[i][0]) plt.ylabel(maps_pairs[i][1]) aPath = os.path.join( fig_dir, country + '_' + maps_pairs[i][0] + '_' + maps_pairs[i][1]) plt.savefig(os.path.join(resultFolder, aPath)) plt.close('all') print(country, 'done')
# -*- coding: cp1252 -*- import pickle import os import metrics import numpy as np import parameters import calibrate from pcraster.framework import * #### Script to read in the metrics saved as the result of the LU_urb.py script. #### Metrics are transformed into an array # Work directory: work_dir = parameters.getWorkDir() # Get metrics metricNames = parameters.getSumStats() # Get the number of parameter iterations and number of time step defined in the parameter.py script nrOfTimesteps = parameters.getNrTimesteps() numberOfIterations = parameters.getNumberofIterations() iterations = range(1, numberOfIterations + 1, 1) timeSteps = range(1, nrOfTimesteps + 1, 1) # Get the observed time steps. Time steps relate to the year of the CLC data, where 1990 was time step 0. obsSampleNumbers = [1] #range(1,20+1,1) <- for stochastic model obsTimeSteps = parameters.getObsTimesteps() # Read the reference files refArray = parameters.getColFiles() # Path to the folder with the metrics stored