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 335fa749 authored by felikskiszkurno's avatar felikskiszkurno
Browse files

Changed output mesh to grid. Started work on classification with svc. Many...

Changed output mesh to grid. Started work on classification with svc. Many changes to support functions.
parent 0d9cd837
......@@ -19,46 +19,35 @@ import pygimli as pg
import pygimli.meshtools as mt
import pygimli.physics.ert as ert
# Prepare folder structure for output
is_success = slopestabilitytools.folder_structure.create_folder_structure()
number_of_tests = 10
# Settings
number_of_tests = 2
rho_spread_factor = 1.5
rho_max = 150
layers_min = 1
layers_max = 3
layers_max = 5
min_depth = 1
max_depth = 10
max_depth = 25
# Generate parameters for tests
tests_horizontal = slopestabilitytools.model_params(number_of_tests,
rho_spread_factor, rho_max,
layers_min, layers_max,
min_depth, max_depth)
for test_name in tests_horizontal.keys():
test_result_curr = slostabcreatedata.create_data(test_name, tests_horizontal[test_name])
world_boundary_v = [-200, 0] # [right, left border] relatively to the middle
world_boundary_h = [200, -100] # [top, bottom border]
# Create models and invert them
test_results = {}
fig, ax = plt.subplots(3)
fig.suptitle(test_name)
pg.show(ert_manager.paraDomain, input_model2, ax=ax[0])
ax[0].set_title("Model on the output mesh")
pg.show(ert_manager.paraDomain, result, ax=ax[1])
ax[1].set_title("Inverted")
for test_name in tests_horizontal.keys():
pg.show(ert_manager.paraDomain, result - input_model2, ax=ax[2])
ax[2].set_title("Diff")
test_result_curr = slostabcreatedata.create_data(test_name, tests_horizontal[test_name], max_depth)
test_results.update({test_name: test_result_curr})
del test_result_curr
fig.savefig('results/figs/hor_{}_results.eps'.format(test_name))
fig.savefig('results/figs/hor_{}_results.png'.format(test_name))
# Plot and save figures
slopestabilitytools.plot_and_save(test_name, test_results[test_name], 'Test: '+test_name)
fig_input, ax_input = plt.subplots(1)
pg.show(mesh, input_model, ax=ax_input)
ax_input.set_title('1 Geometry of the model')
fig_input.savefig('results/figs/hor_{}_input.eps'.format(test_name))
fig_input.savefig('results/figs/hor_{}_input.png'.format(test_name))
slopestabilityML.svm_run(test_results)
This diff is collapsed.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on
Created on 16.01.2021
@author:
@author: Feliks Kiszkurno
"""
from .svm_run import svm_run
\ No newline at end of file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 16.01.2021
@author: Feliks Kiszkurno
"""
from sklearn import svm
import slopestabilitytools
import random
import math
def svm_run(test_results):
# https://stackabuse.com/implementing-svm-and-kernel-svm-with-pythons-scikit-learn/
test_number = len(test_results.keys())
test_prediction = random.choice(list(test_results.keys()),
k=math.ceil(test_number*0.1))
test_training = slopestabilitytools.set_diff(list(test_results.keys()), set(test_prediction))
# Create classifier
clf = svm.SVC(gamma=0.001, C=100)
# Train classifier
for test_name in test_training:
# Prepare data
data_set = test_results[test_name]
X = data_set.drop('Z', '')
# Predict with classfier
# Plot
return
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on
Created on 16.01.2021
@author:
@author: Feliks Kiszkurno
"""
from .combine_results import combine_results
from .plot_results import plot_results
from .run_all_tests import run_all_tests
from .SVM.svm_run import svm_run
......@@ -3,5 +3,10 @@
"""
Created on
@author:
@author: Feliks Kiszkurno
"""
def combine_results():
return
......@@ -3,5 +3,10 @@
"""
Created on
@author:
@author: Feliks Kiszkurno
"""
def plot_results():
return
......@@ -3,5 +3,9 @@
"""
Created on
@author:
@author: Feliks Kiszkurno
"""
def run_all_tests():
return
......@@ -14,6 +14,8 @@ directory_structure: create directory structure to contain figures and other fil
from .model_params import model_params
from .plot_and_save import plot_and_save
from .set_labels import set_labels
from .set_diff import set_diff
from .folder_structure.create_folder_structure import create_folder_structure
from .folder_structure.create_folder_for_test import create_folder_for_test
......
......@@ -19,6 +19,12 @@ def create_folder_structure():
is_success = check_create_folder(folder_path)
folder_path = os.getcwd() + '/results/figures/'
is_success = check_create_folder(folder_path)
folder_path = os.getcwd() + '/results/figures/pdf'
is_success = check_create_folder(folder_path)
folder_path = os.getcwd() + '/results/figures/eps'
is_success = check_create_folder(folder_path)
folder_path = os.getcwd() + '/results/figures/png'
is_success = check_create_folder(folder_path)
# Folder for results
folder_path = os.getcwd()+'/results/'
......
......@@ -69,7 +69,11 @@ def model_params(n_of_tests, rho_spread, rho_max, layers_n_min, layers_n_max, de
while layer < test_n_layers[test_names[test_id]] + 1:
new_rho = int(random.rand(1)[0] * rho_max)
new_rho = 0
while new_rho == 0:
new_rho = int(random.rand(1)[0] * rho_max)
if len(rho_temp) == 0:
......
......@@ -6,6 +6,37 @@ Created on 15.01.2021
@author: Feliks Kiszkurno
"""
def plot_and_save():
import pandas as pd
import matplotlib.pyplot as plt
import slopestabilitytools
def plot_and_save(test_name, test_result, plot_title):
x = test_result['X']
print(x)
y = test_result['Y']
inm = test_result['INM']
res = test_result['RES']
fig, ax = plt.subplots(3)
fig.suptitle(plot_title)
ax[0].scatter(x, y, inm)
ax[0].set_title('Input model')
ax[0] = slopestabilitytools.set_labels(ax[0])
ax[1].scatter(x, y, res)
ax[1].set_title('Result')
ax[1] = slopestabilitytools.set_labels(ax[0])
ax[2].scatter(x, y, inm-res)
ax[2].set_title('Difference')
ax[2] = slopestabilitytools.set_labels(ax[0])
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))
return
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 16.01.2021
@author: Feliks Kiszkurno
"""
def set_diff(input_list, input_set):
diff_list = []
for element in input_list:
if element not in input_set:
diff_list.append(element)
return list(diff_list)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 16.01.2021
@author: Feliks Kiszkurno
"""
import matplotlib.pyplot as plt
def set_labels(axis_obj):
axis_obj.set_xlabel('X [m]')
axis_obj.set_xlabel('Depth [m]')
return axis_obj
......@@ -7,4 +7,5 @@ Created on 15.01.2021
"""
from .create_data import create_data
\ No newline at end of file
from .create_data import create_data
from .test_parameters import test_parameters
......@@ -15,19 +15,11 @@ import pygimli.meshtools as mt
import pygimli.physics.ert as ert
def create_data(test_name, test_config):
world_boundary_v = [-200, 0] # [right, left border] relatively to the middle
world_boundary_h = [200, -100] # [top, bottom border]
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]
test_results = {}
test_results_grid = {}
test_input = {}
#test_name = 'hor_1'
# tests_horizontal['layers_pos'][test_name] = [-5]
# INPUT MODEL - SUBSURFACE START #
world = mt.createWorld(start=world_boundary_v, end=world_boundary_h,
......@@ -45,15 +37,12 @@ def create_data(test_name, test_config):
mesh = mt.createMesh(geometry, quality=34) # , area=2)#
resistivity_map = test_config['rho_values'] # [0]
# resistivity_map[0] = [1, 50.0]
# resistivity_map[1] = [2, 150.0]
input_model = pg.solver.parseMapToCellArray(resistivity_map, mesh) # rename to input_mesh
# INPUT MODEL - SUBSURFACE MODEL END ###
# SIMULATE ERT MEASUREMENT - START ###
mesh_pd = [] # add new mesh
data = ert.simulate(mesh, scheme=measurement_scheme, res=resistivity_map, noiseLevel=1, noiseAbs=1e-6, seed=1337)
data.remove(data['rhoa'] < 0)
# SIMULATE ERT MEASUREMENT - END ###
......@@ -62,7 +51,8 @@ def create_data(test_name, test_config):
# RUN INVERSION #
k0 = pg.physics.ert.createGeometricFactors(data)
model_inverted = ert_manager.invert(data=data, lam=20, paraDX=0.25, paraMaxCellSize=5, paraDepth=10, quality=34,
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()
......@@ -75,8 +65,32 @@ def create_data(test_name, test_config):
'Y': ert_manager.paraDomain.cellCenters().array()[:, 1],
'Z': ert_manager.paraDomain.cellCenters().array()[:, 2],
'INM': input_model2_array,
'RES': result_array})
test_results[test_name] = experiment_results
return test_results
\ No newline at end of file
'RES': result_array,
'INPUT_MODEL': input_model2,
'RESULT': result})
# 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.asarray(result_grid)
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(),
'INPUT_MODEL': input_model3,
'RESULT': result_grid,
'CLASS': })
experiment_results_grid.to_csv('results/results/' + test_name + '.csv')
return experiment_results_grid
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 16.01.2021
@author: Feliks Kiszkurno
"""
'''
Automatically test many combinations of parameters and select one with lowest error
'''
def test_parameters():
return
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