-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
549 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# **_<div class=\"alert alert-success\"><font color='darkred'> Tutorials: Machine Learning</font></div>_**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### **_<div class=\"alert alert-success\"><font color='darkblue'> @Yonatan Tarazona Coronel</font></div>_**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 1.0. Neural Network (NN)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"El valor es uno de los elementos fundamentales (como por ejemplo una letra o un número) que manipula un programa. Los valores que hemos visto hasta el momento son 2 (el resultado de sumar 1 + 1) y Hola, mundo.\n", | ||
"\n", | ||
"Estos valores son de distintos **tipos**: 2 es un entero y Hola, mundo es una cadena, llamada así porque contiene una \"cadena\" de letras. Usted (y el intérprete) puede identificar las cadenas porque están encerradas entre comillas.\n", | ||
"La sentencia print también funciona con enteros:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mla import *" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"How to run Neural Network with Python and the EOpy package." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import matplotlib.pyplot as plt\n", | ||
"from dbfread import DBF\n", | ||
"import rasterio\n", | ||
"\n", | ||
"path_raster = r\"G:\\4_RS_Python\\Leccion4\\Datos\\232066\\LC08_SUBSET_232066_20190727_STACK.tif\"\n", | ||
"img = rasterio.open(path_raster)\n", | ||
"\n", | ||
"path_endmembers = r\"G:\\4_RS_Python\\Leccion4\\shp\\signaturas2018.dbf\"\n", | ||
"endmembers = DBF(path_endmembers)\n", | ||
"\n", | ||
"clas = mla(image = img, endm = endmembers)\n", | ||
"classi = clas.NN(max_iter = 400, training_split = 0.5)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# kmeans\n", | ||
"plt.figure(figsize=(7,7))\n", | ||
"plt.imshow(classi.get('Classification_Map'), cmap = 'jet')\n", | ||
"plt.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import writeRaster as wr\n", | ||
"import os\n", | ||
"wr.writeRaster(arr = classi.get('Classification_Map'), \n", | ||
" image = classi.get('Image'),\n", | ||
" filename = 'img2')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 2.0. K-means" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import matplotlib.pyplot as plt\n", | ||
"from dbfread import DBF\n", | ||
"import rasterio\n", | ||
"\n", | ||
"path_raster = r\"G:\\4_RS_Python\\Leccion4\\Datos\\232066\\LC08_SUBSET_232066_20190727_STACK.tif\"\n", | ||
"img = rasterio.open(path_raster)\n", | ||
"\n", | ||
"img.read().shape\n", | ||
"clas = rkmeans(image = img, n_clusters = 4)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# kmeans\n", | ||
"plt.figure(figsize=(7,7))\n", | ||
"plt.imshow(clas, cmap = 'jet')\n", | ||
"plt.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import writeRaster as wr\n", | ||
"import os\n", | ||
"wr.writeRaster(arr = classi.get('Classification_Map'), \n", | ||
" image = classi.get('Image'),\n", | ||
" filename = 'img2')" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.8" | ||
}, | ||
"toc": { | ||
"base_numbering": 1, | ||
"nav_menu": {}, | ||
"number_sections": false, | ||
"sideBar": true, | ||
"skip_h1_title": false, | ||
"title_cell": "Table of Contents", | ||
"title_sidebar": "Contents", | ||
"toc_cell": false, | ||
"toc_position": {}, | ||
"toc_section_display": true, | ||
"toc_window_display": false | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# **_<div class=\"alert alert-success\"><font color='darkred'> Tutorials: Machine Learning</font></div>_**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### **_<div class=\"alert alert-success\"><font color='darkblue'> @Yonatan Tarazona Coronel</font></div>_**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 1.0. Spectral Mixture Analysis (SMA)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"El valor es uno de los elementos fundamentales (como por ejemplo una letra o un número) que manipula un programa. Los valores que hemos visto hasta el momento son 2 (el resultado de sumar 1 + 1) y Hola, mundo.\n", | ||
"\n", | ||
"Estos valores son de distintos **tipos**: 2 es un entero y Hola, mundo es una cadena, llamada así porque contiene una \"cadena\" de letras. Usted (y el intérprete) puede identificar las cadenas porque están encerradas entre comillas.\n", | ||
"La sentencia print también funciona con enteros:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mla import *" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"How to run Neural Network with Python and the EOpy package." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# La ruta de la imagen\n", | ||
"path_img = \"G:/4_RS_Python/Leccion5/Datos/232066/LC08_SUBSET_232066_20190727_STACK.tif\"\n", | ||
"# Luego procedemos a leerla con la funcion gdal.Open()\n", | ||
"img = rasterio.open(path_img)\n", | ||
"\n", | ||
"# Firmas espectrales puras\n", | ||
"M =np.array([[8980,8508,8704,13636,16579,11420], # suelo\n", | ||
" [8207,7545,6548,16463,9725,6673], # bosque\n", | ||
" [9276,9570,10089,6743,5220,5143], # agua\n", | ||
" ])\n", | ||
"#sma = sma(image = img, endmembers = M)\n", | ||
"img.shape" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import matplotlib.pyplot as plt\n", | ||
"plt.figure(figsize=(10,10))\n", | ||
"plt.imshow(sma) # magma, gray, etc.\n", | ||
"plt.colorbar()\n", | ||
"plt.title(\"Spectral Mixture Analysis - LC8\") # Titulo\n", | ||
"plt.xlabel('Columnas X') # Nombre del eje X\n", | ||
"plt.ylabel('Filas Y') # Nombre del eje Y\n", | ||
"plt.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import writeRaster as wr\n", | ||
"import os\n", | ||
"wr.writeRaster(arr = classi.get('Classification_Map'), \n", | ||
" image = classi.get('Image'),\n", | ||
" filename = 'img2')" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.8" | ||
}, | ||
"toc": { | ||
"base_numbering": 1, | ||
"nav_menu": {}, | ||
"number_sections": false, | ||
"sideBar": true, | ||
"skip_h1_title": false, | ||
"title_cell": "Table of Contents", | ||
"title_sidebar": "Contents", | ||
"toc_cell": false, | ||
"toc_position": {}, | ||
"toc_section_display": true, | ||
"toc_window_display": false | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.