To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit d61e55a5 authored by felikskiszkurno's avatar felikskiszkurno
Browse files

Added coverage parameter to results. Changed plot_and_save.py

parent 0b5bd718
......@@ -21,6 +21,7 @@ import pygimli.physics.ert as ert
# Config
create_new_data = False
create_new_data_only = False
# Prepare folder structure for output
is_success = slopestabilitytools.folder_structure.create_folder_structure()
......@@ -34,13 +35,13 @@ else:
# TODO Put this part into a function
# Settings
number_of_tests = 10
number_of_tests = 5
rho_spread_factor = 1.5
rho_max = 150
rho_max = 20
layers_min = 1
layers_max = 5
min_depth = 1
max_depth = 25
layers_max = 3
min_depth = 2
max_depth = 10
# Generate parameters for tests
tests_horizontal = slopestabilitytools.model_params(number_of_tests,
......@@ -59,8 +60,11 @@ else:
# Plot and save figures
slopestabilitytools.plot_and_save(test_name, test_results[test_name], 'Test: ' + test_name)
for test_name in test_results.keys():
slopestabilitytools.plot_and_save(test_name, test_results[test_name], 'Test: ' + test_name)
if not create_new_data_only:
for test_name in test_results.keys():
slopestabilitytools.plot_and_save(test_name, test_results[test_name], 'Test: ' + test_name)
ml_results = slopestabilityML.run_all_tests(test_results)
#svm_accuracy_score, svm_accuracy_labels = slopestabilityML.svm_run(test_results)
ml_results = slopestabilityML.run_all_tests(test_results)
# svm_accuracy_score, svm_accuracy_labels = slopestabilityML.svm_run(test_results)
elif create_new_data_only:
print('Done')
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on
@author:
"""
# https://letsfigureout.com/2020/03/08/nearest-neighbor-algorithm-with-python-and-numpy/
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on
@author:
"""
# https://letsfigureout.com/2020/03/08/nearest-neighbor-algorithm-with-python-and-numpy/
\ No newline at end of file
......@@ -6,10 +6,15 @@ Created on 19.01.2021
@author: Feliks Kiszkurno
"""
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
def preprocess_data(data_set):
x_train = data_set.drop(['Z', 'INM', 'CLASS'], axis='columns')
y_train = data_set['CLASS']
num_feat = []
return x_train, y_train
......@@ -8,6 +8,8 @@ Created on 15.01.2021
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import ticker
from scipy import interpolate
import numpy as np
import slopestabilitytools
......@@ -18,33 +20,68 @@ def plot_and_save(test_name, test_result, plot_title):
y = test_result['Y']
inm = test_result['INM']
res = test_result['RES']
cov = test_result['SEN']
xx, yy = np.meshgrid(x, y)
inm_i = interpolate.griddata((x, y), inm, (xx, yy), method='linear')
res_i = interpolate.griddata((x, y), res, (xx, yy), method='linear')
cov_i = interpolate.griddata((x, y), cov, (xx, yy), method='linear')
x_vec = np.unique(np.array(x))
y_vec = np.unique(np.array(y))
X, Y = np.meshgrid(x_vec, y_vec)
[m, n] = X.shape
inm_plot = np.array(inm).reshape((m, n))
res_plot = np.array(res).reshape((m, n))
print('plot_and_save')
fig, ax = plt.subplots(3)
# Plot data input, inversion result and difference
cb = []
fig, _ax = plt.subplots(nrows=3, ncols=1)
ax = _ax.flatten()
fig.suptitle(plot_title)
fig.subplots_adjust(hspace=0.8)
ax[0].contourf(X, Y, inm_plot)
im0 = ax[0].contourf(xx, yy, inm_i)
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)
tick_locator = ticker.MaxNLocator(nbins=4)
cb[0].locator = tick_locator
cb[0].update_ticks()
ax[1].contourf(X, Y, res_plot)
im1 = ax[1].contourf(xx, yy, res_i)
ax[1].set_title('Result')
ax[1] = slopestabilitytools.set_labels(ax[0])
ax[1] = slopestabilitytools.set_labels(ax[1])
cb.append(plt.colorbar(im1, ax=ax[1], label='Resistivity [om]'))#, shrink=0.9)
tick_locator = ticker.MaxNLocator(nbins=4)
cb[1].locator = tick_locator
cb[1].update_ticks()
ax[2].contourf(X, Y, inm_plot-res_plot)
im2 = ax[2].contourf(xx, yy, inm_i-res_i)
ax[2].set_title('Difference')
ax[2] = slopestabilitytools.set_labels(ax[0])
ax[2] = slopestabilitytools.set_labels(ax[2])
cb.append(plt.colorbar(im2, ax=ax[2], label='Resistivity [om]'))#, shrink=0.9)
tick_locator = ticker.MaxNLocator(nbins=4)
cb[2].locator = tick_locator
cb[2].update_ticks()
fig.savefig('results/figures/eps/{}_in_inv_diff.eps'.format(test_name))
fig.savefig('results/figures/png/{}_in_inv_diff.png'.format(test_name))
fig.savefig('results/figures/pdf/{}_in_inv_diff.pdf'.format(test_name))
# Plot coverage
cb_cov = []
fig_cov, ax_cov = plt.subplots(nrows=1, ncols=1)
fig.suptitle(plot_title+' coverage')
im0 = ax_cov.contourf(xx, yy, 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)
tick_locator = ticker.MaxNLocator(nbins=4)
cb_cov.locator = tick_locator
cb_cov.update_ticks()
fig.savefig('results/figures/eps/hor_{}_input.eps'.format(test_name))
fig.savefig('results/figures/png/hor_{}_input.png'.format(test_name))
fig.savefig('results/figures/pdf/hor_{}_input.pdf'.format(test_name))
fig_cov.savefig('results/figures/eps/{}_cov.eps'.format(test_name))
fig_cov.savefig('results/figures/png/{}_cov.png'.format(test_name))
fig_cov.savefig('results/figures/pdf/{}_cov.pdf'.format(test_name))
return
......@@ -12,6 +12,6 @@ import matplotlib.pyplot as plt
def set_labels(axis_obj):
axis_obj.set_xlabel('X [m]')
axis_obj.set_xlabel('Depth [m]')
axis_obj.set_ylabel('Depth [m]')
return axis_obj
......@@ -16,8 +16,8 @@ import pygimli.physics.ert as ert
def create_data(test_name, test_config, max_depth):
world_boundary_v = [-10 * max_depth, 0] # [right, left border] relatively to the middle
world_boundary_h = [10 * max_depth, -4 * max_depth] # [top, bottom border]
world_boundary_v = [-20 * max_depth, 0] # [right, left border] relatively to the middle
world_boundary_h = [20 * max_depth, -4 * max_depth] # [top, bottom border]
test_results = {}
......@@ -29,7 +29,9 @@ def create_data(test_name, test_config, max_depth):
geometry = world # +block
measurement_scheme = ert.createERTData(elecs=np.linspace(start=-45, stop=45, num=91), schemeName='dd')
measurement_scheme = ert.createERTData(elecs=np.linspace(start=-5*max_depth, stop=5*max_depth, num=6*max_depth+1),
schemeName='dd')
for electrode in measurement_scheme.sensors():
geometry.createNode(electrode)
geometry.createNode(electrode - [0, 0.1]) # What does it do?
......@@ -51,54 +53,51 @@ def create_data(test_name, test_config, max_depth):
# RUN INVERSION #
k0 = pg.physics.ert.createGeometricFactors(data)
model_inverted = ert_manager.invert(data=data, lam=20, paraDX=0.25, paraMaxCellSize=5, paraDepth=max_depth,
quality=34,
zPower=0.4)
#result = ert_manager.inv.model
#result_array = result.array()
#input_model2 = pg.interpolate(srcMesh=mesh, inVec=input_model, destPos=ert_manager.paraDomain.cellCenters())
##input_model2_array = input_model2.array()
# experiment_results = pd.DataFrame(data={'X': ert_manager.paraDomain.cellCenters().array()[:, 0],
# 'Y': ert_manager.paraDomain.cellCenters().array()[:, 1],
# 'Z': ert_manager.paraDomain.cellCenters().array()[:, 2],
# 'INM': input_model2_array,
# 'RES': result_array,
# 'INPUT_MODEL': input_model2,
# 'RESULT': result})
model_inverted = ert_manager.invert(data=data, lam=20, paraDX=0.1, paraMaxCellSize=2, paraDepth=max_depth,
quality=34, zPower=0.4)
result = ert_manager.inv.model
result_array = result.array()
input_model2 = pg.interpolate(srcMesh=mesh, inVec=input_model, destPos=ert_manager.paraDomain.cellCenters())
input_model2_array = input_model2.array()
# Create classes labels
classes = []
resistivity_values = []
for pair in resistivity_map:
resistivity_values.append(pair[1])
# print(resistivity_values)
for value in input_model2:
# print(value)
res_diff = np.abs(value * np.ones_like(resistivity_values) - resistivity_values)
# print(res_diff)
res_index = np.argmin(res_diff)
# print(res_index)
classes.append(res_index)
# Create sensitivity values
jac = ert_manager.fop.jacobian() #
# Normalization only for visualization!
# Coverage = cumulative sensitivity = all measurements
cov = ert_manager.coverage()
#pg.show(ert_manager.paraDomain, cov, label="Logarithm of cumulative sensitivity")
experiment_results = pd.DataFrame(data={'X': ert_manager.paraDomain.cellCenters().array()[:, 0],
'Y': ert_manager.paraDomain.cellCenters().array()[:, 1],
'Z': ert_manager.paraDomain.cellCenters().array()[:, 2],
'INM': input_model2_array,
'RES': result_array,
'SEN': cov,
'CLASS': classes})
# experiment_results.to_csv('results/results/'+test_name+'.csv')
# test_results[test_name] = experiment_results
# Interpolate to grid
grid = pg.createGrid(x=np.linspace(start=-50, stop=50, num=101),
y=-pg.cat([0], pg.utils.grange(0.5, max_depth, n=2 * max_depth + 1)),
marker=2)
input_model3 = pg.interpolate(srcMesh=mesh, inVec=input_model, destPos=grid.cellCenters())
result_grid = ert_manager.invert(data=data, mesh=grid, lam=20, paraDX=0.25, paraMaxCellSize=5, paraDepth=max_depth, quality=34,
zPower=0.4)
class_array = np.ones_like(input_model3) * resistivity_map[-1][0]
layer_id = 1
layer_depth_previous = 0
for depth in test_config['layers_pos']:
class_array[np.where((grid.cellCenters().array()[:, 1] >= depth) & (
grid.cellCenters().array()[:, 1] < layer_depth_previous))] = layer_id
layer_depth_previous = depth
layer_id += 1
experiment_results_grid = pd.DataFrame(data={'X': grid.cellCenters().array()[:, 0],
'Y': grid.cellCenters().array()[:, 1],
'Z': grid.cellCenters().array()[:, 2],
'INM': input_model3.array(),
'RES': result_grid.array(),
'CLASS': class_array})
experiment_results_grid.to_csv('results/results/' + test_name + '.csv')
experiment_results.to_csv('results/results/' + test_name + '.csv')
return experiment_results_grid
return experiment_results
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