Commit 7de6e67f authored by Feliks Kiszkurno's avatar Feliks Kiszkurno
Browse files

Added notebooks. Proof of concept for line based interface detection

parent 50f3fab7
......@@ -19,8 +19,8 @@ import test_definitions
settings.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
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'
param_path = os.path.abspath(os.path.join(os.getcwd()) + '/' + 'TestDefinitions/high_contrast_lambda_zweight.csv')
test_definitions.init(path=param_path)
......
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"source": [
"In the text cells I give the best-coverage case number of tests. Each cells has a more reasonable parameters. Number of tests below each cell, is for the feasible approach. However, I am not sure how this will affect the generalization of the classifiers."
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "markdown",
"source": [
"## 1 Interface - 2 layers\n",
"For 1 interface it looks quite simple and doable. All valid combinations of depth and resistivities can be tested with 432 profiles given the parameters defined below"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"execution_count": 4,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of tests: 48\n"
]
}
],
"source": [
"test_def1 = np.array([]).reshape([0,2]) # This is the important thing (left column: resistivity, right column: depth)\n",
"depth_def = np.array([]).reshape([0,1])\n",
"res_def = np.array([]).reshape([0,1])\n",
"start = -4; end = -21; step = -2 # Depth range\n",
"start_res = 1; end_res = 5; step_res = 1 # Resistivity range\n",
"for res_1 in np.arange(start_res, end_res-step_res, step_res):\n",
" for res_2 in np.arange(res_1+step_res, end_res, step_res):\n",
" new_res_set = np.array([res_1, res_2]).reshape([2,1])\n",
" for depth_1 in np.arange(start, end-step, step):\n",
" new_set = np.array([0, depth_1]).reshape([2,1])\n",
" test_def_temp = np.append(new_res_set, new_set, axis=1)\n",
" test_def1 = np.append(test_def1, test_def_temp, axis=0)\n",
"print('Number of tests: {:.0f}'.format(test_def1.shape[0]/2))"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% 1 interface\n"
}
}
},
{
"cell_type": "markdown",
"source": [
"## 2 Interfaces - 3 layers\n",
"Here it already gets harder. To get coverage of the same range of combinations as with 1 interface, 2730 profiles are needed."
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"execution_count": 61,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of tests: 360\n"
]
}
],
"source": [
"test_def2 = np.array([]).reshape([0,2]) # This is the important thing (left column: resistivity, right column: depth)\n",
"depth_def = np.array([]).reshape([0,1])\n",
"res_def = np.array([]).reshape([0,1])\n",
"start = -4; end = -21; step = -2 # Depth range\n",
"start_res = 5; end_res = 100; step_res = 20 # Resistivity range\n",
"for res_1 in np.arange(start_res, end_res-2*step_res, step_res):\n",
" for res_2 in np.arange(res_1+step_res, end_res-step_res, step_res):\n",
" for res_3 in np.arange(res_2+step_res, end_res, step_res):\n",
" new_res_set = np.array([res_1, res_2, res_3]).reshape([3,1])\n",
" for depth_1 in np.arange(start, end-step, step):\n",
" for depth_2 in np.arange(depth_1+step, end, step):\n",
" new_set = np.array([0, depth_1, depth_2]).reshape([3,1])\n",
" test_def_temp = np.append(new_res_set, new_set, axis=1)\n",
" test_def2 = np.append(test_def2, test_def_temp, axis=0)\n",
"print('Number of tests: {:.0f}'.format(test_def2.shape[0]/3))"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% 2 interfaces\n"
}
}
},
{
"cell_type": "markdown",
"source": [
"## 3 interfaces - 4 layers\n",
"Here it gets awful. For the same coverage of combinations 122 694 profiles would be needed. This is not feasible, not even with Sebastians server."
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"execution_count": 62,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of tests: 420\n"
]
}
],
"source": [
"test_def3 = np.array([]).reshape([0,2]) # This is the important thing (left column: resistivity, right column: depth)\n",
"depth_def = np.array([]).reshape([0,1])\n",
"res_def = np.array([]).reshape([0,1])\n",
"start = -4; end = -21; step = -2 # Depth range\n",
"start_res = 10; end_res = 100; step_res = 20 # Resistivity range\n",
"for res_1 in np.arange(start_res, end_res-3*step_res, step_res):\n",
" for res_2 in np.arange(res_1+step_res, end_res-2*step_res, step_res):\n",
" for res_3 in np.arange(res_2+step_res, end_res-step_res, step_res):\n",
" for res_4 in np.arange(res_3+step_res, end_res, step_res):\n",
" new_res_set = np.array([res_1, res_2, res_3, res_4]).reshape([4,1])\n",
" for depth_1 in np.arange(start, end-2*step, step):\n",
" for depth_2 in np.arange(depth_1+step, end-step, step):\n",
" for depth_3 in np.arange(depth_2+step, end, step):\n",
" new_set = np.array([0, depth_1, depth_2, depth_3]).reshape([4,1])\n",
" test_def_temp = np.append(new_res_set, new_set, axis=1)\n",
" test_def3 = np.append(test_def3, test_def_temp, axis=0)\n",
"print('Number of tests: {:.0f}'.format(test_def3.shape[0]/4))\n"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% 3 interfaces\n"
}
}
},
{
"cell_type": "code",
"execution_count": 5,
"outputs": [],
"source": [
"#test_def_all = np.append(test_def1, test_def2, axis=0)\n",
"#test_def_all = np.append(test_def_all, test_def3, axis=0)\n",
"test_def_df = pd.DataFrame(test_def1, columns=['RHO', 'POS'])\n",
"test_def_df.to_csv('temp.csv')"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
\ No newline at end of file
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import slopestabilitytools\n",
"import slopestabilityML\n",
"import settings\n",
"\n",
"import pandas as pd\n",
"\n",
"from sklearn.preprocessing import StandardScaler, OneHotEncoder\n",
"from sklearn.compose import ColumnTransformer\n",
"from sklearn.pipeline import make_pipeline"
]
},
{
"cell_type": "markdown",
"source": [
"### Read and preprocess data"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"execution_count": 2,
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'settings' has no attribute 'settings'",
"output_type": "error",
"traceback": [
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[0;31mAttributeError\u001B[0m Traceback (most recent call last)",
"\u001B[0;32m<ipython-input-2-ba85f918aa07>\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[0;32m----> 1\u001B[0;31m \u001B[0mtest_results\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mslopestabilitytools\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mdatamanagement\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mimport_tests\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 2\u001B[0m \u001B[0mis_success\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mslopestabilitytools\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mfolder_structure\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcreate_folder_structure\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 3\u001B[0m \u001B[0mrandom_seed\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;36m999\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 4\u001B[0m \u001B[0mtest_training\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mtest_prediction\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mslopestabilityML\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0msplit_dataset\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mtest_results\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mkeys\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mrandom_seed\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 5\u001B[0m \u001B[0mnum_feat\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;34m[\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
"\u001B[0;32m~/Documents/Studies/MasterThesis/PythonProjects/SlopeStability/slopestabilitytools/datamanagement/import_tests.py\u001B[0m in \u001B[0;36mimport_tests\u001B[0;34m(abs_path)\u001B[0m\n\u001B[1;32m 15\u001B[0m \u001B[0;32mdef\u001B[0m \u001B[0mimport_tests\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mabs_path\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;34m''\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 16\u001B[0m \u001B[0mtest_results\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;34m{\u001B[0m\u001B[0;34m}\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 17\u001B[0;31m \u001B[0mtest_names\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mslopestabilitytools\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mdatamanagement\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mtest_list\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m'.csv'\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mabs_path\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mabs_path\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 18\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 19\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mtest_name\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mtest_names\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
"\u001B[0;32m~/Documents/Studies/MasterThesis/PythonProjects/SlopeStability/slopestabilitytools/datamanagement/test_list.py\u001B[0m in \u001B[0;36mtest_list\u001B[0;34m(extension, abs_path)\u001B[0m\n\u001B[1;32m 16\u001B[0m \u001B[0;32mdef\u001B[0m \u001B[0mtest_list\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mextension\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m*\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mabs_path\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;34m''\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 17\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 18\u001B[0;31m \u001B[0mpath\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mabs_path\u001B[0m \u001B[0;34m+\u001B[0m \u001B[0msettings\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0msettings\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;34m'data_folder'\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 19\u001B[0m \u001B[0mfile_list\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mos\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mlistdir\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mpath\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 20\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n",
"\u001B[0;31mAttributeError\u001B[0m: module 'settings' has no attribute 'settings'"
]
}
],
"source": [
"test_results = slopestabilitytools.datamanagement.import_tests()\n",
"is_success = slopestabilitytools.folder_structure.create_folder_structure()\n",
"random_seed = 999\n",
"test_training, test_prediction = slopestabilityML.split_dataset(test_results.keys(), random_seed)\n",
"num_feat = []\n",
"if settings.settings['norm'] is True:\n",
" num_feat.append('RESN')\n",
"else:\n",
" num_feat.append('RES')\n",
"\n",
"if settings.settings['sen'] is True:\n",
" num_feat.append('SEN')\n",
"\n",
"if settings.settings['depth'] is True:\n",
" num_feat.append('Y')\n",
"\n",
"num_trans = StandardScaler()\n",
"\n",
"if settings.settings['use_labels'] is True:\n",
" cat_feat = ['LABELS']\n",
" cat_lab = ['Very Low', 'Low', 'Medium', 'High', 'Very High']\n",
" cat_trans = OneHotEncoder(categories=[cat_lab])\n",
" preprocessor = ColumnTransformer(transformers=[('num', num_trans, num_feat)])\n",
" # ('cat', cat_trans, cat_feat)])\n",
"\n",
"else:\n",
" preprocessor = ColumnTransformer(transformers=[('num', num_trans, num_feat)])\n",
"\n",
"\n",
"\n",
"test_results_combined = pd.DataFrame()\n",
"for name in test_training:\n",
" test_results_combined = test_results_combined.append(test_results[name])\n",
"test_results_combined = test_results_combined.reset_index()\n",
"test_results_combined = test_results_combined.drop(['index'], axis='columns')\n",
"x_train, y_train = slopestabilityML.preprocess_data(test_results_combined)\n",
"x_position = test_results_combined['X']"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "markdown",
"source": [
"### SVM"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"from sklearn import svm\n",
"from sklearn.model_selection import GridSearchCV\n",
"svc_parameters = {}\n",
"svc_classifier = svm.SVC()\n",
"svc_pipeline = make_pipeline(preprocessor, svc_classifier)\n",
"clf = GridSearchCV(svc_pipeline, svc_parameters)\n",
"clf.fit(x_train, y_train)\n",
"sorted(clf.cv_results_.keys())"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
\ No newline at end of file
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Interface detector based on max_gradient_classifier\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import slopestabilitytools\n",
"import math\n",
"from scipy import interpolate"
]
},
{
"cell_type": "code",
"execution_count": 2,
"outputs": [],
"source": [
"def mov_avg(array, window_length, *, method='same'):\n",
" array_avg = np.convolve(array, np.ones(window_length), method) / window_length\n",
" return array_avg"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 34,
"outputs": [],
"source": [
"result_grid = np.ones([250, 1000])\n",
"result_grid[0:51, :] = 0\n",
"result_grid[51:101, :] = 1\n",
"result_grid[101:151, :] = 2\n",
"result_grid[151:201, :] = 3\n",
"result_grid[201:250, :] = 4\n",
"depths = np.linspace(0, 200, 250)\n",
"result_grid_rolled = np.roll(result_grid, -1, axis=0)\n",
"result = result_grid - result_grid_rolled\n",
"result[-1, :] = 0"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 36,
"outputs": [],
"source": [
"interface_id = []\n",
"interface_n = []\n",
"for column in result.T:\n",
" indexes = np.where(column != 0)\n",
" interface_n.append(len(indexes[0]))\n",
" interface_id.append(indexes)\n",
"interface_id[0] = [np.array([50, 100, 150])]\n",
"interface_id[5] = [np.array([100, 150])]\n",
"interface_id[-1] = [np.array([50, 200])]\n",
"interface_number = np.bincount(interface_n).argmax()\n",
"#print(result.shape[1])\n",
"interface_depths_ids = np.ones([interface_number, result.shape[1]])*float(\"NaN\")\n",
"interface_depths = np.ones([interface_number, result.shape[1]])*float(\"NaN\")\n",
"incomplete_detections = []\n",
"for col_num in range(len(interface_id)):\n",
" if len(interface_id[col_num][0]) == interface_number:\n",
" interface_depths_ids[:, col_num] = interface_id[col_num][0]\n",
" interface_depths[:, col_num] = depths[interface_id[col_num][0]]\n",
" else:\n",
" incomplete_detections.append(col_num)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 44,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a\n",
"[-59.83935743 -19.67871486 20.48192771 60.64257028]\n",
"19.678714859437747\n",
"[-109.83935743 -69.67871486 -29.51807229 10.64257028]\n",
"10.642570281124506\n"
]
}
],
"source": [
"for col_num_inc in incomplete_detections:\n",
" if col_num_inc is 0:\n",
" new_ids = np.ones([interface_number, 1])*float(\"NaN\")\n",
" for depth_id in interface_id[col_num_inc][0]:\n",
" depth_id_array = np.ones([interface_number, 1])*depth_id\n",
" diff = interface_depths[:, col_num_inc+1].reshape([interface_number, 1]) - depth_id_array\n",
" pos = np.where(abs(diff).reshape([len(diff)]) == np.amin(abs(diff)))\n",
" new_ids[int(pos[0])] = depths[depth_id]\n",
" interface_depths[:,col_num_inc] = new_ids.reshape([interface_number])\n",
" elif col_num_inc == result.shape[1]-1:\n",
" new_ids = np.ones([interface_number, 1])*float(\"NaN\")\n",
" for depth_id in interface_id[col_num_inc][0]:\n",
" depth_id_array = np.ones([interface_number, 1])*depth_id\n",
" diff = interface_depths[:, col_num_inc-1].reshape([interface_number, 1]) - depth_id_array\n",
" pos = np.where(abs(diff).reshape([len(diff)]) == np.amin(abs(diff)))\n",
" new_ids[int(pos[0])] = depths[depth_id]\n",
" interface_depths[:,col_num_inc] = new_ids.reshape([interface_number])\n",
" else:\n",
" print('a')\n",
" new_ids = np.ones([interface_number, 1])*float(\"NaN\")\n",
" for depth_id in interface_id[col_num_inc][0]:\n",
" depth_id_array = np.ones([interface_number, 1])*depth_id\n",
" diff = ((interface_depths[:, col_num_inc-1].reshape([interface_number, 1])+interface_depths[:, col_num_inc-1].reshape([interface_number, 1]))/2) - depth_id_array\n",
" print(diff.reshape([len(diff)]))\n",
" print(np.amin(abs(diff)))\n",
" pos = np.where(abs(diff).reshape([len(diff)]) == np.amin(abs(diff)))\n",
" new_ids[int(pos[0])] = depths[depth_id]\n",
" interface_depths[:,col_num_inc] = new_ids.reshape([interface_number])\n"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 6,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"250\n"
]
}
],
"source": [
"gradient = np.gradient(result_grid, axis=0)\n",
"gradient2 = np.gradient(gradient, axis=0)\n",
"gradient2 = gradient2/np.amax(gradient2)\n",
"ind = gradient2 < 0.15\n",
"gradient2[ind] = 1\n",
"\n",
"inds = np.zeros(gradient2.T.shape[0])\n",
"classes = np.zeros_like(gradient2.T)\n",
"print(gradient2.T.shape[1])\n",
"for num, column in enumerate(gradient2.T):\n",
" #print(num)\n",
" inds[num] = np.argmax(column)\n",
"inds = mov_avg(inds, math.ceil(len(inds)/10))\n",
"for num, column in enumerate(classes):\n",
" column[:int(inds[num])] = 0\n",
"classes = classes.T"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 14,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"300\n",
"[0 0 3 4 5]\n"
]
},
{
"data": {
"text/plain": "<matplotlib.contour.QuadContourSet at 0x7fec13377b10>"
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"text/plain": "<Figure size 432x288 with 1 Axes>",
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAASjklEQVR4nO3df4wc5X3H8fcXjKmVkGKaQo1xjBM5qDYqTmLR1FQJVZqQkErgoiTmD+JWSI4iUEGhoib5o/xj1UXFSRoaS46AgJtCUMkFVBISglJFkdMQgwjYuFecQMA/ZCuFCCohCPa3f+wcrM97t7u3u7ezz71f0ulmn52ZfZ6Z2c/NPvPsXGQmkqSynDDsCkiS+s9wl6QCGe6SVCDDXZIKZLhLUoHmDbsCAPNPWJAL5r1t2NWQpJHy0m8P/zozf7/Vc7UI9wXz3saa0z817GpI0kh5cP9XfjXVc3bLSFKBDHdJKpDhLkkFMtwlqUCGuyQVyHCXpAIZ7pJUIMNdkgpkuEtSgQx3SSqQ4S5JBTLcJalAhrskFchwl6QCGe6SVCDDXZIKZLhLUoEMd0kqkOEuSQUy3CWpQIa7JBXIcJekAhnuklQgw12SCmS4S1KBDHdJKpDhLkkFMtwlqUCGuyQVyHCXpAIZ7pJUoLbhHhFLIuKHEbEnInZHxDVV+Y0RsT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a+NN2sLcpKanct9/eww7342xRk5oHq92FgjEY3y6HqoxnV78PV7KVtj27bua+anlw+UjLzUGYeycyjwNd4s2utmHZHxEk0Au4bmfmtqrj4/d2q3XXd38MO96JvUxARb4mIUyamgY8Au2i0cX0123rgvmr6fmBdRJwcEcuA5TQuvIyqrtpZfZR/OSLeX40e+HTTMiNjIuAqa2nscyik3VUdbwX2ZOaWpqeK3t9Ttbu2+7sGV6AvpnHV+RfAF4Zdnz637Z00rpb/HNg90T7g94CHgaer36c1LfOFaluMU+ORAy3aeheNj6S/pXFmcuVM2gmspvHm+AVwC9W3qOv6M0W7twNPAk/QeIMvKqndwJ/S6EZ4Ani8+rm49P09Tbtrub+9/YAkFWjY3TKSpAEw3CWpQIa7JBXIcJekAhnuklQgw12SCmS4S1KB/h8+U2oObT03OgAAAABJRU5ErkJggg==\n"
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"print(gradient2.T.shape[1])\n",
"temp = np.array([1,2,3,4,5])\n",
"temp[:2] = 0\n",
"print(temp)\n",
"plt.contourf(classes)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 20,
"outputs": [],
"source": [
"classes_interp_f = interpolate.interp2d(xi, yi, classes)\n",
"classes_interp = np.zeros_like(x)\n",
"for cell_id in range(len(x)):\n",
" classes_interp[cell_id] = classes_interp_f(x[cell_id], y[cell_id])"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"