Commit a75b6bd1 authored by Feliks Kiszkurno's avatar Feliks Kiszkurno
Browse files

Some bug fixes. plot_and_save.py has been edited to use less ram consuming...

Some bug fixes. plot_and_save.py has been edited to use less ram consuming scatter instead of contourf
parent 92903664
......@@ -11,12 +11,13 @@ import slopestabilitytools
import slopestabilityML
import slostabcreatedata
import os.path
import gc
import numpy as np
import settings
import test_definitions
settings.init()
test_definitions.init()
#test_definitions.init()
# Config
create_new_data = True # set to True if you need to reassign the classes
create_new_data_only = True # set to False in order to run ML classifications
......@@ -51,35 +52,39 @@ else:
max_depth = 8
# Generate parameters for tests
# tests_horizontal = slopestabilitytools.model_params(number_of_tests,
# tests_parameters = slopestabilitytools.model_params(number_of_tests,
# rho_spread_factor, rho_max,
# layers_min, layers_max,
# min_depth, max_depth)
#tests_horizontal = test_definitions.test_definitions
tests_horizontal = slostabcreatedata.read_test_parameters(os.path.abspath(os.path.join(os.getcwd()) + '/' + 'TestDefinitions/hor_1layer_varying_depth.csv'))
#tests_parameters = test_definitions.test_definitions
tests_parameters = slostabcreatedata.read_test_parameters(os.path.abspath(os.path.join(os.getcwd()) + '/' + 'TestDefinitions/hor_1layer_varying_depth.csv'))
test_definitions.init(tests_parameters)
# tests_horizontal = {'hor_11': {'layer_n': 1, 'rho_values': [[1, 10], [2, 12]], 'layers_pos': np.array([-4])}}
# tests_parameters = {'hor_11': {'layer_n': 1, 'rho_values': [[1, 10], [2, 12]], 'layers_pos': np.array([-4])}}
# Create models and invert them
test_results = {}
for test_name in tests_horizontal.keys():
for test_name in tests_parameters.keys():
test_result_curr, test_rho_max, test_rho_min = slostabcreatedata.create_data(test_name,
tests_horizontal[test_name],
abs(tests_horizontal[test_name]['layers_pos'].max()))
tests_parameters[test_name],
abs(tests_parameters[test_name]['layers_pos'].max()))
test_results.update({test_name: test_result_curr})
del test_result_curr
# Plot and save figures
slopestabilitytools.plot_and_save(test_name, test_results[test_name], 'Test: ' + test_name, test_rho_max,
test_rho_min)
gc.collect()
# Evaluate data with ML techniques
if not create_new_data_only:
print('Running ML stuff...')
tests_parameters = slostabcreatedata.read_test_parameters(
os.path.abspath(os.path.join(os.getcwd()) + '/' + 'TestDefinitions/hor_1layer_varying_depth.csv'))
test_definitions.init(tests_parameters)
ml_results = slopestabilityML.run_all_tests(test_results)
# Finish the script if ML classifiaction was not executed
......
......@@ -139,7 +139,7 @@ for electrode in measurement_scheme.sensors():
mesh = mt.createMesh(geometry, quality=34)#, area=2)#
#print(tests_horizontal['rho_values'][test_name])
#print(tests_parameters['rho_values'][test_name])
resistivity_map = tests_horizontal['rho_values'][test_name]#[0]
resistivity_map[0] = [1, 50.0]
resistivity_map[1] = [2, 150.0]
......
......@@ -139,7 +139,7 @@ for electrode in measurement_scheme.sensors():
mesh = mt.createMesh(geometry, quality=34)#, area=2)#
#print(tests_horizontal['rho_values'][test_name])
#print(tests_parameters['rho_values'][test_name])
resistivity_map = tests_horizontal['rho_values'][test_name]#[0]
resistivity_map[0] = [1, 50.0]
resistivity_map[1] = [2, 150.0]
......
......@@ -121,7 +121,7 @@ def model_params(n_of_tests, rho_spread, rho_max, layers_n_min, layers_n_max, de
'rho_values': rho_final,
'layers_pos': test_layers_pos[test_names[test_id]]}})
#tests_horizontal = {'names': test_names,
#tests_parameters = {'names': test_names,
# 'layer_n': test_n_layers,
# 'rho_values': test_rho,
# 'layers_pos': test_layers_pos}
......
......@@ -19,23 +19,32 @@ def plot_and_save(test_name, test_result, plot_title, rho_max, rho_min):
if settings.settings['norm'] is True:
plot_title = plot_title + '_norm'
data = {'INM': test_result['INMN'],
'RES': test_result['RESN'],
'SEN': test_result['SEN']}
inm = test_result['INMN']
res = test_result['RESN']
sen = test_result['SEN']
elif settings.settings['norm'] is False:
data = {'INM': test_result['INM'],
'RES': test_result['RES'],
'SEN': test_result['SEN']}
else:
print('I don\'t know which kind of data to use! Exiting...')
exit(0)
xi, yi, data_gridded = slopestabilitytools.grid_data(x, y, data)
inm_i = data_gridded['INM']
res_i = data_gridded['RES']
cov_i = data_gridded['SEN']
inm = test_result['INM']
res = test_result['RES']
sen = test_result['SEN']
# if settings.settings['norm'] is True:
# plot_title = plot_title + '_norm'
# data = {'INM': test_result['INMN'],
# 'RES': test_result['RESN'],
# 'SEN': test_result['SEN']}
# elif settings.settings['norm'] is False:
# data = {'INM': test_result['INM'],
# 'RES': test_result['RES'],
# 'SEN': test_result['SEN']}
#
# else:
# print('I don\'t know which kind of data to use! Exiting...')
# exit(0)
#
# xi, yi, data_gridded = slopestabilitytools.grid_data(x, y, data)
#
# inm_i = data_gridded['INM']
# res_i = data_gridded['RES']
# cov_i = data_gridded['SEN']
print('Plotting and saving overview figure... ')
......@@ -49,7 +58,8 @@ def plot_and_save(test_name, test_result, plot_title, rho_max, rho_min):
fig.suptitle(plot_title)
fig.subplots_adjust(hspace=0.8)
im0 = ax[0].contourf(xi, yi, inm_i, vmax=rho_max, vmin=rho_min)
im0 = ax[0].scatter(x, y, c=inm)
#im0 = ax[0].contourf(xi, yi, inm_i, vmax=rho_max, vmin=rho_min)
ax[0].set_title('Input model')
ax[0] = slopestabilitytools.set_labels(ax[0])
cb.append(plt.colorbar(im0, ax=ax[0], label='Resistivity [om]'))#, shrink=0.9)
......@@ -57,7 +67,8 @@ def plot_and_save(test_name, test_result, plot_title, rho_max, rho_min):
cb[0].locator = tick_locator
cb[0].update_ticks()
im1 = ax[1].contourf(xi, yi, res_i, vmax=rho_max, vmin=rho_min)
im1 = ax[1].scatter(x, y, c=res)
#im1 = ax[1].contourf(xi, yi, res_i, vmax=rho_max, vmin=rho_min)
ax[1].set_title('Result')
ax[1] = slopestabilitytools.set_labels(ax[1])
cb.append(plt.colorbar(im1, ax=ax[1], label='Resistivity [om]'))#, shrink=0.9)
......@@ -65,7 +76,8 @@ def plot_and_save(test_name, test_result, plot_title, rho_max, rho_min):
cb[1].locator = tick_locator
cb[1].update_ticks()
im2 = ax[2].contourf(xi, yi, inm_i-res_i, cmap='RdBu')
im2 = ax[2].scatter(x, y, c=inm-res, cmap='RdBu')
#im2 = ax[2].contourf(xi, yi, inm_i-res_i, cmap='RdBu')
ax[2].set_title('Difference')
ax[2] = slopestabilitytools.set_labels(ax[2])
cb.append(plt.colorbar(im2, ax=ax[2], label='Resistivity [om]'))#, shrink=0.9)
......@@ -82,7 +94,8 @@ def plot_and_save(test_name, test_result, plot_title, rho_max, rho_min):
fig.suptitle(plot_title+' coverage')
im0 = ax_cov.contourf(xi, yi, cov_i)
im0 = ax_cov.scatter(x, y, c=sen)
#im0 = ax_cov.contourf(xi, yi, cov_i)
ax_cov.set_title(plot_title+' coverage')
ax_cov = slopestabilitytools.set_labels(ax_cov)
cb_cov = plt.colorbar(im0, ax=ax_cov, label='Coverage') # , shrink=0.9)
......
......@@ -30,8 +30,8 @@ def create_data(test_name, test_config, max_depth):
# INPUT MODEL - SUBSURFACE START #
world = mt.createWorld(start=world_boundary_v, end=world_boundary_h,
layers=test_config['layers_pos']) # ,
# marker=np.linspace(1, tests_horizontal['layer_n']['hor_1'],
# tests_horizontal['layer_n']['hor_1']))
# marker=np.linspace(1, tests_parameters['layer_n']['hor_1'],
# tests_parameters['layer_n']['hor_1']))
geometry = world # +block
......
......@@ -11,7 +11,7 @@ import numpy as np
def read_test_parameters(path_to_file):
params = pd.read_csv(path_to_file, header=1)
params = pd.read_csv(path_to_file)
test_definitions = {}
test_names = params['NAME'].unique()
......@@ -24,9 +24,8 @@ def read_test_parameters(path_to_file):
for i, row in params_temp.iterrows():
rho_list.append([layer_id, row['RHO']])
layer_id += 1
if row['POS'] is not 0:
if int(row['POS']) is not 0:
position.append(row['POS'])
print(row['RHO'])
test_definitions[name] = {'layer_n': row['LAYER_N'], 'rho_values': rho_list, 'layers_pos': np.array(position)}
return test_definitions
......@@ -7,70 +7,73 @@ Created on 08.04.2021
"""
import numpy as np
import slostabcreatedata
import os.path
def init(test_def):
def init():
global test_definitions
test_definitions = slostabcreatedata.read_test_parameters(os.path.abspath(os.path.join(os.getcwd()) + '/' + 'TestDefinitions/hor_1layer_varying_depth.csv'))
test_definitions = {'hor1_01': {'layer_n': 1, 'rho_values': [[1, 5], [2, 15]], 'layers_pos': np.array([-5])},
'hor1_02': {'layer_n': 1, 'rho_values': [[1, 5], [2, 50]], 'layers_pos': np.array([-5])},
'hor1_03': {'layer_n': 1, 'rho_values': [[1, 15], [2, 20]], 'layers_pos': np.array([-8])},
'hor1_04': {'layer_n': 1, 'rho_values': [[1, 5], [2, 10]], 'layers_pos': np.array([-3])},
'hor1_05': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-3])},
'hor1_06': {'layer_n': 1, 'rho_values': [[1, 2], [2, 10]], 'layers_pos': np.array([-4])},
'hor1_07': {'layer_n': 1, 'rho_values': [[1, 10], [2, 20]], 'layers_pos': np.array([-6])},
'hor1_08': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-3])},
'hor1_09': {'layer_n': 1, 'rho_values': [[1, 3], [2, 25]], 'layers_pos': np.array([-3])},
'hor1_10': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-7])},
'hor1_11': {'layer_n': 1, 'rho_values': [[1, 10], [2, 12]], 'layers_pos': np.array([-4])},
'hor1_12': {'layer_n': 1, 'rho_values': [[1, 15], [2, 50]], 'layers_pos': np.array([-5])},
'hor1_14': {'layer_n': 1, 'rho_values': [[1, 5], [2, 75]], 'layers_pos': np.array([-5])},
'hor1_15': {'layer_n': 1, 'rho_values': [[1, 15], [2, 50]], 'layers_pos': np.array([-8])},
'hor1_16': {'layer_n': 1, 'rho_values': [[1, 25], [2, 50]], 'layers_pos': np.array([-5])},
'hor1_17': {'layer_n': 1, 'rho_values': [[1, 25], [2, 75]], 'layers_pos': np.array([-5])},
'hor1_18': {'layer_n': 1, 'rho_values': [[1, 5], [2, 75]], 'layers_pos': np.array([-8])},
'hor1_19': {'layer_n': 1, 'rho_values': [[1, 50], [2, 60]], 'layers_pos': np.array([-7])},
# 'hor1_20': {'layer_n': 1, 'rho_values': [[1, 2], [2, 10]], 'layers_pos': np.array([-15])},
# Tests with two layers
# 'hor2_01': {'layer_n': 2, 'rho_values': [[1, 3], [2, 5], [3, 15]],
# 'layers_pos': np.array([-3, -6])},
# 'hor2_02': {'layer_n': 2, 'rho_values': [[1, 2], [2, 4], [3, 8]],
# 'layers_pos': np.array([-4, -8])},
# 'hor2_03': {'layer_n': 2, 'rho_values': [[1, 4], [2, 15], [3, 25]],
# 'layers_pos': np.array([-4, -8])},
# 'hor2_04': {'layer_n': 2, 'rho_values': [[1, 5], [2, 20], [3, 50]],
# 'layers_pos': np.array([-4, -8])},
# 'hor2_05': {'layer_n': 2, 'rho_values': [[1, 5], [2, 35], [3, 50]],
# 'layers_pos': np.array([-4, -8])},
# 'hor2_06': {'layer_n': 2, 'rho_values': [[1, 5], [2, 35], [3, 50]],
# 'layers_pos': np.array([-4, -8])},
# 'hor2_07': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# 'layers_pos': np.array([-4, -8])},
# 'hor2_08': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# 'layers_pos': np.array([-3, -9])},
# 'hor2_09': {'layer_n': 2, 'rho_values': [[1, 3], [2, 40], [3, 70]],
# 'layers_pos': np.array([-4, -8])},
# 'hor2_10': {'layer_n': 2, 'rho_values': [[1, 3], [2, 40], [3, 70]],
# 'layers_pos': np.array([-4, -8])},
# 'hor2_11': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# 'layers_pos': np.array([-3, -15])},
# 'hor2_12': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# 'layers_pos': np.array([-4, -6])},
# 'hor2_13': {'layer_n': 2, 'rho_values': [[1, 5], [2, 35], [3, 50]],
# 'layers_pos': np.array([-5, -20])},
# 'hor2_14': {'layer_n': 2, 'rho_values': [[1, 5], [2, 35], [3, 50]],
# 'layers_pos': np.array([-3, -5])},
# 'hor2_15': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# 'layers_pos': np.array([-5, -15])},
# 'hor2_16': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# 'layers_pos': np.array([-3, -15])},
# 'hor2_17': {'layer_n': 2, 'rho_values': [[1, 2], [2, 4], [3, 8]],
# 'layers_pos': np.array([-4, -15])},
# 'hor2_18': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 15]],
# 'layers_pos': np.array([-3, -15])},
# 'hor2_19': {'layer_n': 2, 'rho_values': [[1, 15], [2, 20], [3, 30]],
# 'layers_pos': np.array([-3, -15])},
# 'hor2_20': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# 'layers_pos': np.array([-3, -10])}
}
# test_definitions = {'hor1_01': {'layer_n': 1, 'rho_values': [[1, 5], [2, 15]], 'layers_pos': np.array([-5])},
# 'hor1_02': {'layer_n': 1, 'rho_values': [[1, 5], [2, 50]], 'layers_pos': np.array([-5])},
# 'hor1_03': {'layer_n': 1, 'rho_values': [[1, 15], [2, 20]], 'layers_pos': np.array([-8])},
# 'hor1_04': {'layer_n': 1, 'rho_values': [[1, 5], [2, 10]], 'layers_pos': np.array([-3])},
# 'hor1_05': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-3])},
# 'hor1_06': {'layer_n': 1, 'rho_values': [[1, 2], [2, 10]], 'layers_pos': np.array([-4])},
# 'hor1_07': {'layer_n': 1, 'rho_values': [[1, 10], [2, 20]], 'layers_pos': np.array([-6])},
# 'hor1_08': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-3])},
# 'hor1_09': {'layer_n': 1, 'rho_values': [[1, 3], [2, 25]], 'layers_pos': np.array([-3])},
# 'hor1_10': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-7])},
# 'hor1_11': {'layer_n': 1, 'rho_values': [[1, 10], [2, 12]], 'layers_pos': np.array([-4])},
# 'hor1_12': {'layer_n': 1, 'rho_values': [[1, 15], [2, 50]], 'layers_pos': np.array([-5])},
# 'hor1_14': {'layer_n': 1, 'rho_values': [[1, 5], [2, 75]], 'layers_pos': np.array([-5])},
# 'hor1_15': {'layer_n': 1, 'rho_values': [[1, 15], [2, 50]], 'layers_pos': np.array([-8])},
# 'hor1_16': {'layer_n': 1, 'rho_values': [[1, 25], [2, 50]], 'layers_pos': np.array([-5])},
# 'hor1_17': {'layer_n': 1, 'rho_values': [[1, 25], [2, 75]], 'layers_pos': np.array([-5])},
# 'hor1_18': {'layer_n': 1, 'rho_values': [[1, 5], [2, 75]], 'layers_pos': np.array([-8])},
# 'hor1_19': {'layer_n': 1, 'rho_values': [[1, 50], [2, 60]], 'layers_pos': np.array([-7])},
# # 'hor1_20': {'layer_n': 1, 'rho_values': [[1, 2], [2, 10]], 'layers_pos': np.array([-15])},
#
# # Tests with two layers
# # 'hor2_01': {'layer_n': 2, 'rho_values': [[1, 3], [2, 5], [3, 15]],
# # 'layers_pos': np.array([-3, -6])},
# # 'hor2_02': {'layer_n': 2, 'rho_values': [[1, 2], [2, 4], [3, 8]],
# # 'layers_pos': np.array([-4, -8])},
# # 'hor2_03': {'layer_n': 2, 'rho_values': [[1, 4], [2, 15], [3, 25]],
# # 'layers_pos': np.array([-4, -8])},
# # 'hor2_04': {'layer_n': 2, 'rho_values': [[1, 5], [2, 20], [3, 50]],
# # 'layers_pos': np.array([-4, -8])},
# # 'hor2_05': {'layer_n': 2, 'rho_values': [[1, 5], [2, 35], [3, 50]],
# # 'layers_pos': np.array([-4, -8])},
# # 'hor2_06': {'layer_n': 2, 'rho_values': [[1, 5], [2, 35], [3, 50]],
# # 'layers_pos': np.array([-4, -8])},
# # 'hor2_07': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# # 'layers_pos': np.array([-4, -8])},
# # 'hor2_08': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# # 'layers_pos': np.array([-3, -9])},
# # 'hor2_09': {'layer_n': 2, 'rho_values': [[1, 3], [2, 40], [3, 70]],
# # 'layers_pos': np.array([-4, -8])},
# # 'hor2_10': {'layer_n': 2, 'rho_values': [[1, 3], [2, 40], [3, 70]],
# # 'layers_pos': np.array([-4, -8])},
# # 'hor2_11': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# # 'layers_pos': np.array([-3, -15])},
# # 'hor2_12': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# # 'layers_pos': np.array([-4, -6])},
# # 'hor2_13': {'layer_n': 2, 'rho_values': [[1, 5], [2, 35], [3, 50]],
# # 'layers_pos': np.array([-5, -20])},
# # 'hor2_14': {'layer_n': 2, 'rho_values': [[1, 5], [2, 35], [3, 50]],
# # 'layers_pos': np.array([-3, -5])},
# # 'hor2_15': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# # 'layers_pos': np.array([-5, -15])},
# # 'hor2_16': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# # 'layers_pos': np.array([-3, -15])},
# # 'hor2_17': {'layer_n': 2, 'rho_values': [[1, 2], [2, 4], [3, 8]],
# # 'layers_pos': np.array([-4, -15])},
# # 'hor2_18': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 15]],
# # 'layers_pos': np.array([-3, -15])},
# # 'hor2_19': {'layer_n': 2, 'rho_values': [[1, 15], [2, 20], [3, 30]],
# # 'layers_pos': np.array([-3, -15])},
# # 'hor2_20': {'layer_n': 2, 'rho_values': [[1, 5], [2, 10], [3, 70]],
# # 'layers_pos': np.array([-3, -10])}
# }
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