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 16f9e927 authored by Feliks Kiszkurno's avatar Feliks Kiszkurno
Browse files

Added normalization, normalized classes, AdaBoost, KNN.

parent c62bd5c2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 26.03.2021
@author: Feliks Kiszkurno
"""
import numpy as np
def def_classes(class_num):
class_spacing = 1 / class_num
ids = np.linspace(0, class_num - 1, class_num)
class_start = np.linspace(0, 1 - class_spacing, class_num)
class_end = np.linspace(class_spacing, 1, class_num)
classes_def = np.vstack((ids, class_start, class_end))
return classes_def.T
\ No newline at end of file
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 15.03.2021
@author: Feliks Kiszkurno
"""
import numpy as np
def normalize(array):
array_max = 0
array = np.array(array)
if array.ndim == 1:
array_max = np.max(array)
elif array.ndim == 2:
array_max = np.amax(array)
else:
print('ERROR: incorrect dimensionality of the input array')
exit()
array_norm = array / array_max
return array_norm
......@@ -78,8 +78,8 @@ def plot_and_save(test_name, test_result, plot_title, rho_max, rho_min):
fig.tight_layout()
fig.savefig(Path('results/figures/eps/{}_in_inv_diff.eps'.format(test_name)), bbox_inches="tight")
fig.savefig(Path('results/figures/png/{}_in_inv_diff.png'.format(test_name)), bbox_inches="tight")
fig.savefig(Path('results/figures/pdf/{}_in_inv_diff.pdf'.format(test_name)), bbox_inches="tight")
#fig.savefig(Path('results/figures/png/{}_in_inv_diff.png'.format(test_name)), bbox_inches="tight")
#fig.savefig(Path('results/figures/pdf/{}_in_inv_diff.pdf'.format(test_name)), bbox_inches="tight")
# Plot coverage
cb_cov = []
......@@ -97,7 +97,7 @@ def plot_and_save(test_name, test_result, plot_title, rho_max, rho_min):
fig_cov.tight_layout()
fig_cov.savefig(Path('results/figures/eps/{}_cov.eps'.format(test_name)), bbox_inches="tight")
fig_cov.savefig(Path('results/figures/png/{}_cov.png'.format(test_name)), bbox_inches="tight")
fig_cov.savefig(Path('results/figures/pdf/{}_cov.pdf'.format(test_name)), bbox_inches="tight")
#fig_cov.savefig(Path('results/figures/png/{}_cov.png'.format(test_name)), bbox_inches="tight")
#fig_cov.savefig(Path('results/figures/pdf/{}_cov.pdf'.format(test_name)), bbox_inches="tight")
return
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 25.03.2021
@author: Feliks Kiszkurno
"""
def save_plot(figure_handler, test_name, figure_name):
figure_handler.savefig('results/figures/png/' + test_name + '_1_geometry'+'.png', bbox_inches="tight")
# fig_geometry.savefig('results/figures/pdf/' + test_name + '_1_geometry.pdf', bbox_inches="tight")
# fig_geometry.savefig('results/figures/eps/' + test_name + '_1_geometry.eps', bbox_inches="tight")
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -18,8 +18,10 @@ import slopestabilitytools
def create_data(test_name, test_config, max_depth):
world_boundary_v = [-20 * max_depth, 0] # [NW edge] relatively to the middle
world_boundary_h = [20 * max_depth, -5 * max_depth] # [SE edge]
from main import settings
world_boundary_v = [-9 * max_depth, 0] # [NW edge] relatively to the middle
world_boundary_h = [9 * max_depth, -9 * max_depth] # [SE edge]
# world_boundary_v = [-500, 0] # [right, left border] relatively to the middle
# world_boundary_h = [500, -100] # [top, bottom border]
......@@ -38,11 +40,12 @@ def create_data(test_name, test_config, max_depth):
ax_geometry = slopestabilitytools.set_labels(ax_geometry)
ax_geometry.set_title('1 Geometry of the model')
fig_geometry.tight_layout()
fig_geometry.savefig('results/figures/png/'+test_name+'_1_geometry.png', bbox_inches="tight")
fig_geometry.savefig('results/figures/pdf/' + test_name + '_1_geometry.pdf', bbox_inches="tight")
fig_geometry.savefig('results/figures/eps/' + test_name + '_1_geometry.eps', bbox_inches="tight")
fig_geometry.savefig('results/figures/png/' + test_name + '_1_geometry.png', bbox_inches="tight")
#fig_geometry.savefig('results/figures/pdf/' + test_name + '_1_geometry.pdf', bbox_inches="tight")
#fig_geometry.savefig('results/figures/eps/' + test_name + '_1_geometry.eps', bbox_inches="tight")
measurement_scheme = ert.createERTData(elecs=np.linspace(start=-8*max_depth, stop=8*max_depth, num=8*max_depth+1),
measurement_scheme = ert.createERTData(
elecs=np.linspace(start=-8 * max_depth, stop=8 * max_depth, num=8 * max_depth + 1),
schemeName='dd')
for electrode in measurement_scheme.sensors():
......@@ -59,8 +62,8 @@ def create_data(test_name, test_config, max_depth):
ax_model.set_title('2 Mesh and resistivity distribution')
fig_model.tight_layout()
fig_model.savefig('results/figures/png/' + test_name + '_2_meshdist.png', bbox_inches="tight")
fig_model.savefig('results/figures/pdf/' + test_name + '_2_meshdist.pdf', bbox_inches="tight")
fig_model.savefig('results/figures/eps/' + test_name + '_2_meshdist.eps', bbox_inches="tight")
#fig_model.savefig('results/figures/pdf/' + test_name + '_2_meshdist.pdf', bbox_inches="tight")
#fig_model.savefig('results/figures/eps/' + test_name + '_2_meshdist.eps', bbox_inches="tight")
input_model = pg.solver.parseMapToCellArray(resistivity_map, mesh) # rename to input_mesh
......@@ -75,16 +78,17 @@ 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=2, paraDepth=2*max_depth,
model_inverted = ert_manager.invert(data=data, lam=20, paraDX=0.25, paraMaxCellSize=2, paraDepth=2 * max_depth,
quality=34, zPower=0.4)
result_full = ert_manager.inv.model
#result_array = pg.utils.interperc(result_full, 5)
#result_lim = result_full.array()
#result_lim[np.where(result_array > max(resistivity_map[1]))] = float("NaN")
#result_lim[np.where(result_array < min(resistivity_map[1]))] = float("NaN") # min(resistivity_map[1])
#result_array = result_lim
# result_array = pg.utils.interperc(result_full, 5)
# result_lim = result_full.array()
# result_lim[np.where(result_array > max(resistivity_map[1]))] = float("NaN")
# result_lim[np.where(result_array < min(resistivity_map[1]))] = float("NaN") # min(resistivity_map[1])
# result_array = result_lim
result_array = result_full.array()
result_array_norm = slopestabilitytools.normalize(result_array)
fig_result, ax_result = plt.subplots(1)
pg.show(ert_manager.paraDomain, result_full, label=pg.unit('res'), showMesh=True, ax=ax_result)
......@@ -92,12 +96,13 @@ def create_data(test_name, test_config, max_depth):
ax_result.set_title('3 Result')
fig_result.tight_layout()
fig_result.savefig('results/figures/png/' + test_name + '_3_result.png', bbox_inches="tight")
fig_result.savefig('results/figures/pdf/' + test_name + '_3_result.pdf', bbox_inches="tight")
fig_result.savefig('results/figures/eps/' + test_name + '_3_result.eps', bbox_inches="tight")
#fig_result.savefig('results/figures/pdf/' + test_name + '_3_result.pdf', bbox_inches="tight")
#fig_result.savefig('results/figures/eps/' + test_name + '_3_result.eps', bbox_inches="tight")
input_model2 = pg.interpolate(srcMesh=mesh, inVec=input_model, destPos=ert_manager.paraDomain.cellCenters())
input_model2_array = input_model2.array()
input_model2_array_norm = slopestabilitytools.normalize(input_model2_array)
fig_input, ax_input = plt.subplots(1)
pg.show(ert_manager.paraDomain, input_model2, label=pg.unit('res'), showMesh=True, ax=ax_input)
......@@ -105,8 +110,10 @@ def create_data(test_name, test_config, max_depth):
ax_input.set_title('4 Model on inv mesh')
fig_input.tight_layout()
fig_input.savefig('results/figures/png/' + test_name + '_4_modelinv.png', bbox_inches="tight")
fig_input.savefig('results/figures/pdf/' + test_name + '_4_modelinv.pdf', bbox_inches="tight")
fig_input.savefig('results/figures/eps/' + test_name + '_4_modelinv.eps', bbox_inches="tight")
#fig_input.savefig('results/figures/pdf/' + test_name + '_4_modelinv.pdf', bbox_inches="tight")
#fig_input.savefig('results/figures/eps/' + test_name + '_4_modelinv.eps', bbox_inches="tight")
#if not settings['norm_class']:
# Create classes labels
classes = []
......@@ -115,6 +122,7 @@ def create_data(test_name, test_config, max_depth):
resistivity_values.append(pair[1])
# print(resistivity_values)
# TODO: This has to be rewritten for more complicated cases
for value in input_model2:
# print(value)
res_diff = np.abs(value * np.ones_like(resistivity_values) - resistivity_values)
......@@ -123,13 +131,17 @@ def create_data(test_name, test_config, max_depth):
# print(res_index)
classes.append(res_index)
#elif settings['norm_class']:
classesn = slopestabilitytools.assign_classes(input_model2_array_norm)
# 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")
# pg.show(ert_manager.paraDomain, cov, label="Logarithm of cumulative sensitivity")
rho_arr = []
for entry in resistivity_map:
......@@ -138,16 +150,22 @@ def create_data(test_name, test_config, max_depth):
rho_max = np.max(rho_arr)
rho_min = np.min(rho_arr)
# TODO: this assumes only two resistivities, extend it to consider more
result_array[np.where(result_array < rho_min)] = rho_min
result_array[np.where(result_array > rho_max)] = rho_max
result_array_norm = slopestabilitytools.normalize(result_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,
'INMN': input_model2_array_norm,
'RES': result_array,
'RESN': result_array_norm,
'SEN': cov,
'CLASS': classes})
'CLASS': classes,
'CLASSN': classesn})
# experiment_results.to_csv('results/results/'+test_name+'.csv')
......@@ -155,6 +173,4 @@ def create_data(test_name, test_config, max_depth):
experiment_results.to_csv('results/results/' + test_name + '.csv')
return experiment_results, rho_max, rho_min
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File added
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