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

Added overview plot. Before testing.

parent 87e72b61
%% Cell type:markdown id: tags:
# Slope Stability
### General use notebook
Use it to run the project in Jupyter enviroment
%% Cell type:markdown id: tags:
### Imports
%% Cell type:code id: tags:
``` python
import matplotlib.pyplot as plt
import numpy as np
import scipy
import slopestabilitytools
import slostabcreatedata
import slopestabilityML
import settings
import test_definitions
settings.init()
test_definitions.init()
```
%% Cell type:markdown id: tags:
### Create data
##### Config
%% Cell type:code id: tags:
``` python
create_new_data = False # set to True if you need to reassign the classes
create_new_data_only = False # set to False in order to run ML classifications
reassign_classes = False; class_type = 'norm'
```
%% Cell type:markdown id: tags:
#### Run inversions
%% Cell type:code id: tags:
``` python
tests_horizontal = test_definitions.test_definitions
test_results = {}
for test_name in tests_horizontal.keys():
test_result_curr, test_rho_max, test_rho_min = slostabcreatedata.create_data(test_name,
tests_horizontal[test_name],
max_depth)
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)
```
%% Cell type:markdown id: tags:
### Evaluate existing data with ML classifiers
%% Cell type:code id: tags:
``` python
ml_results = slopestabilityML.run_all_tests(test_results)
```
......@@ -14,6 +14,7 @@ from .run_classi import run_classification
from .preprocess_data import preprocess_data
from .plot_class_res import plot_class_res
from .ask_committee import ask_committee
from .plot_class_overview import plot_class_overview
from .SVM.svm_run import svm_run
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 08.04.2021
@author: Feliks Kiszkurno
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import ticker
import slopestabilitytools
def plot_class_overview(test_results, test_name_pred, class_in, y_pred, clf_name, *, training=False):
x = test_results['X']
y = test_results['Y']
data = {'class_in': class_in, 'class_out': y_pred, 'sen': test_results['sen'], 'depth': y,
'input': test_results['INMN']}
xi, yi, data_gridded = slopestabilitytools.grid_data(x, y, data)
# Create plot
fig, _ax = plt.subplots(nrows = 3, ncols=2)
ax = _ax.flatten
cb = []
fig.suptitle('Classification overview: '+test_name_pred+', '+clf_name)
fig.subplots_adjust(hspace=0.8)
# Plot input classes
im0 = ax[0].contourf(xi, yi, data_gridded['class_in'])
ax[0].set_title('Input classes')
ax[0] = slopestabilitytools.set_labels(ax[0])
cb.append(plt.colorbar(im0, ax=ax[0], label='Class')) # , shrink=0.9)
tick_locator = ticker.MaxNLocator(nbins=4)
cb[0].locator = tick_locator
cb[0].update_ticks()
# Plot prediction
im0 = ax[3].contourf(xi, yi, data_gridded['class_out'])
ax[3].set_title('Predicted classes')
ax[3] = slopestabilitytools.set_labels(ax[3])
cb.append(plt.colorbar(im0, ax=ax[3], label='Class')) # , shrink=0.9)
tick_locator = ticker.MaxNLocator(nbins=4)
cb[3].locator = tick_locator
cb[3].update_ticks()
# Plot input model
im0 = ax[1].contourf(xi, yi, data_gridded['INMN'])
ax[1].set_title('Input model')
ax[1] = slopestabilitytools.set_labels(ax[1])
cb.append(plt.colorbar(im0, ax=ax[1], label='Resistivity log(ohm*m)')) # , shrink=0.9)
tick_locator = ticker.MaxNLocator(nbins=4)
cb[1].locator = tick_locator
cb[1].update_ticks()
# Plot sensitivity
im0 = ax[4].contourf(xi, yi, data_gridded['sen'])
ax[4].set_title('Input classes')
ax[4] = slopestabilitytools.set_labels(ax[4])
cb.append(plt.colorbar(im0, ax=ax[4], label='Sensitivity')) # , shrink=0.9)
tick_locator = ticker.MaxNLocator(nbins=4)
cb[4].locator = tick_locator
cb[4].update_ticks()
# Plot depth
im0 = ax[5].contourf(xi, yi, data_gridded['depth'])
ax[5].set_title('Input classes')
ax[5] = slopestabilitytools.set_labels(ax[5])
cb.append(plt.colorbar(im0, ax=ax[5], label='Depth [m]')) # , shrink=0.9)
tick_locator = ticker.MaxNLocator(nbins=4)
cb[5].locator = tick_locator
cb[5].update_ticks()
fig.tight_layout()
if training is True:
slopestabilitytools.save_plot(fig, clf_name, '{}_ML_{}_class_overview'.format(clf_name, test_name_pred),
subfolder='ML/training')
else:
slopestabilitytools.save_plot(fig, clf_name, '{}_ML_{}_class_overview'.format(clf_name, test_name_pred),
subfolder='ML/prediction')
return
......@@ -84,6 +84,8 @@ def run_classification(test_training, test_prediction, test_results, clf, clf_na
accuracy_result_training.append(score_training * 100)
accuracy_labels_training.append(test_name)
slopestabilityML.plot_class_overview(test_results[test_name], test_name, y_train, y_pred, clf_name, training=True)
result_class = {}
# Predict with classifier
......@@ -111,6 +113,7 @@ def run_classification(test_training, test_prediction, test_results, clf, clf_na
print('I don\'t know which class to use! Exiting...')
exit(0)
slopestabilityML.plot_class_overview(test_results[test_name_pred], test_name_pred, class_in, y_pred, clf_name)
slopestabilityML.plot_class_res(test_results, test_name_pred, class_in, y_pred, clf_name)
# Evaluate result
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 08.04.2021
@author: Feliks Kiszkurno
"""
def init():
global test_definitions
test_definitions = {'hor_01': {'layer_n': 1, 'rho_values': [[1, 5], [2, 15]], 'layers_pos': np.array([-5])},
'hor_02': {'layer_n': 1, 'rho_values': [[1, 5], [2, 50]], 'layers_pos': np.array([-5])},
'hor_03': {'layer_n': 1, 'rho_values': [[1, 15], [2, 20]], 'layers_pos': np.array([-8])},
'hor_04': {'layer_n': 1, 'rho_values': [[1, 5], [2, 10]], 'layers_pos': np.array([-3])},
'hor_05': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-3])},
'hor_06': {'layer_n': 1, 'rho_values': [[1, 2], [2, 10]], 'layers_pos': np.array([-4])},
'hor_07': {'layer_n': 1, 'rho_values': [[1, 10], [2, 20]], 'layers_pos': np.array([-6])},
'hor_08': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-3])},
'hor_09': {'layer_n': 1, 'rho_values': [[1, 3], [2, 25]], 'layers_pos': np.array([-3])},
'hor_10': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-7])},
'hor_11': {'layer_n': 1, 'rho_values': [[1, 10], [2, 12]], 'layers_pos': np.array([-4])},
'hor_12': {'layer_n': 1, 'rho_values': [[1, 15], [2, 50]], 'layers_pos': np.array([-5])},
'hor_13': {'layer_n': 2, 'rho_values': [[1, 3], [2, 5], [3, 15]],
'layers_pos': np.array([-3, -6])},
'hor_14': {'layer_n': 2, 'rho_values': [[1, 2], [2, 4], [3, 8]],
'layers_pos': np.array([-4, -8])},
'hor_15': {'layer_n': 1, 'rho_values': [[1, 4], [2, 15], [3, 25]],
'layers_pos': np.array([-4, -8])},
'hor_16': {'layer_n': 1, 'rho_values': [[1, 5], [2, 20], [3, 50]],
'layers_pos': np.array([-4, -8])}
}
\ No newline at end of file
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