{ "cells": [ { "cell_type": "markdown", "id": "5f5d6166-1c49-4927-aebb-f50e24baba16", "metadata": { "tags": [] }, "source": [ "# Hemalatha Velappan: Classification of different tree species plantations using deep learning\n", "\n", "[Video recording](https://youtu.be/1OAzeb71lwU)\n", "\n", "### The goal of this work is to develop a model to identify planted forests and the tree species growing there. The model is developed using the \n", "#### (1) known locations of planted forests based on literature and personal communications, \n", "#### (2) image analysis and feature extraction of planted trees\n", "#### (3) spectral signatures unique to each species" ] }, { "cell_type": "code", "execution_count": 1, "id": "81424f42-e772-47f6-b18e-a7fbae518e62", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import torch\n", "import torch.nn as nn\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import scipy\n", "from osgeo import ogr\n", "from sklearn.metrics import r2_score\n", "from sklearn.model_selection import train_test_split" ] }, { "cell_type": "code", "execution_count": 52, "id": "b99b7457-d19e-4642-a0c6-1e3267afe73b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/media/sf_LVM_shared/my_SE_data/Plantation_datasets/Peru_Plantation_Shapefile-Updated\n" ] } ], "source": [ "#Loading plantation shapefile location\n", "\n", "%cd /media/sf_LVM_shared/my_SE_data/Plantation_datasets/Peru_Plantation_Shapefile-Updated" ] }, { "cell_type": "code", "execution_count": 9, "id": "063acc5f-873d-4514-b1fc-476e6250f163", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Driver: GTiff/GeoTIFF\n", "Files: SentinelMap.tif\n", "Size is 898, 770\n", "Coordinate System is:\n", "GEOGCRS[\"WGS 84\",\n", " DATUM[\"World Geodetic System 1984\",\n", " ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n", " LENGTHUNIT[\"metre\",1]]],\n", " PRIMEM[\"Greenwich\",0,\n", " ANGLEUNIT[\"degree\",0.0174532925199433]],\n", " CS[ellipsoidal,2],\n", " AXIS[\"geodetic latitude (Lat)\",north,\n", " ORDER[1],\n", " ANGLEUNIT[\"degree\",0.0174532925199433]],\n", " AXIS[\"geodetic longitude (Lon)\",east,\n", " ORDER[2],\n", " ANGLEUNIT[\"degree\",0.0174532925199433]],\n", " ID[\"EPSG\",4326]]\n", "Data axis to CRS axis mapping: 2,1\n", "Origin = (-76.889769608227439,-7.186342609899349)\n", "Pixel Size = (0.000269494585236,-0.000269494585236)\n", "Metadata:\n", " AREA_OR_POINT=Area\n", "Image Structure Metadata:\n", " COMPRESSION=LZW\n", " INTERLEAVE=PIXEL\n", "Corner Coordinates:\n", "Upper Left ( -76.8897696, -7.1863426) ( 76d53'23.17\"W, 7d11'10.83\"S)\n", "Lower Left ( -76.8897696, -7.3938534) ( 76d53'23.17\"W, 7d23'37.87\"S)\n", "Upper Right ( -76.6477635, -7.1863426) ( 76d38'51.95\"W, 7d11'10.83\"S)\n", "Lower Right ( -76.6477635, -7.3938534) ( 76d38'51.95\"W, 7d23'37.87\"S)\n", "Center ( -76.7687665, -7.2900980) ( 76d46' 7.56\"W, 7d17'24.35\"S)\n", "Band 1 Block=256x256 Type=UInt16, ColorInterp=Gray\n", " Description = B1\n", " Computed Min/Max=1005.000,8417.000\n", "Band 2 Block=256x256 Type=UInt16, ColorInterp=Undefined\n", " Description = B2\n", " Computed Min/Max=696.000,9929.000\n", "Band 3 Block=256x256 Type=UInt16, ColorInterp=Undefined\n", " Description = B3\n", " Computed Min/Max=471.000,10214.000\n", "Band 4 Block=256x256 Type=UInt16, ColorInterp=Undefined\n", " Description = B4\n", " Computed Min/Max=269.000,11283.000\n", "Band 5 Block=256x256 Type=UInt16, ColorInterp=Undefined\n", " Description = B5\n", " Computed Min/Max=269.000,10690.000\n", "Band 6 Block=256x256 Type=UInt16, ColorInterp=Undefined\n", " Description = B6\n", " Computed Min/Max=419.000,11095.000\n", "Band 7 Block=256x256 Type=UInt16, ColorInterp=Undefined\n", " Description = B7\n", " Computed Min/Max=437.000,11857.000\n", "Band 8 Block=256x256 Type=UInt16, ColorInterp=Undefined\n", " Description = B8\n", " Computed Min/Max=390.000,11342.000\n", "Band 9 Block=256x256 Type=UInt16, ColorInterp=Undefined\n", " Description = B8A\n", " Computed Min/Max=355.000,12318.000\n", "Band 10 Block=256x256 Type=UInt16, ColorInterp=Undefined\n", " Description = B9\n", " Computed Min/Max=56.000,2030.000\n", "Band 11 Block=256x256 Type=UInt16, ColorInterp=Undefined\n", " Description = B10\n", " Computed Min/Max=3.000,31.000\n", "Band 12 Block=256x256 Type=UInt16, ColorInterp=Undefined\n", " Description = B11\n", " Computed Min/Max=78.000,13317.000\n", "Band 13 Block=256x256 Type=UInt16, ColorInterp=Undefined\n", " Description = B12\n", " Computed Min/Max=24.000,16040.000\n" ] } ], "source": [ "!gdalinfo -mm SentinelMap.tif" ] }, { "cell_type": "markdown", "id": "f3382d76-5c85-40d5-aa39-bb08d62203eb", "metadata": {}, "source": [ "## Performing zonal statistics on the polygon shapefile wrt the sentinel satellite image" ] }, { "cell_type": "code", "execution_count": 3, "id": "f5897df2-7050-4db4-bf0e-adf4dcf9144a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "processing layer Peru_with_XY\n", "0...10...20...30...40...50...60...70...80...90...100 - done.\n" ] } ], "source": [ "!pkextractogr -f CSV -i SentinelMap.tif -s Peru_XY/Peru_with_XY.shp -r allpoints -r mean -r stdev -o extracted2.csv" ] }, { "cell_type": "code", "execution_count": 3, "id": "40d7ca48-33b5-4f4f-a1f5-a8c11e6f9729", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | OBJECTID | \n", "FUENTE/SOU | \n", "DOCREG | \n", "FECREG | \n", "OBSERV | \n", "ZONUTM | \n", "ORIGEN | \n", "TIPCOM | \n", "NUMREG | \n", "NOMTIT/Tit | \n", "... | \n", "b4 | \n", "b5 | \n", "b6 | \n", "b7 | \n", "b8 | \n", "b9 | \n", "b10 | \n", "b11 | \n", "b12 | \n", "Classification | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "99039 | \n", "GORE San Martín | \n", "APP-RNPF | \n", "27:59.0 | \n", "ara autorizar el aprovechamiento la U.O.G.F. ... | \n", "18 | \n", "1 | \n", "1 | \n", "22-SAM/REG-PLT-2019-050 | \n", "CARBAJAL VIGO, SEBASTIAN | \n", "... | \n", "798 | \n", "1965 | \n", "2724 | \n", "2588 | \n", "2981 | \n", "475 | \n", "11 | \n", "1301 | \n", "493 | \n", "10 | \n", "
1 | \n", "99039 | \n", "GORE San Martín | \n", "APP-RNPF | \n", "27:59.0 | \n", "ara autorizar el aprovechamiento la U.O.G.F. ... | \n", "18 | \n", "1 | \n", "1 | \n", "22-SAM/REG-PLT-2019-050 | \n", "CARBAJAL VIGO, SEBASTIAN | \n", "... | \n", "796 | \n", "2069 | \n", "2740 | \n", "2661 | \n", "3053 | \n", "475 | \n", "11 | \n", "1269 | \n", "460 | \n", "10 | \n", "
2 | \n", "99039 | \n", "GORE San Martín | \n", "APP-RNPF | \n", "27:59.0 | \n", "ara autorizar el aprovechamiento la U.O.G.F. ... | \n", "18 | \n", "1 | \n", "1 | \n", "22-SAM/REG-PLT-2019-050 | \n", "CARBAJAL VIGO, SEBASTIAN | \n", "... | \n", "805 | \n", "2114 | \n", "2717 | \n", "2656 | \n", "3130 | \n", "447 | \n", "10 | \n", "1309 | \n", "485 | \n", "10 | \n", "
3 | \n", "99039 | \n", "GORE San Martín | \n", "APP-RNPF | \n", "27:59.0 | \n", "ara autorizar el aprovechamiento la U.O.G.F. ... | \n", "18 | \n", "1 | \n", "1 | \n", "22-SAM/REG-PLT-2019-050 | \n", "CARBAJAL VIGO, SEBASTIAN | \n", "... | \n", "741 | \n", "1731 | \n", "2253 | \n", "2031 | \n", "2501 | \n", "447 | \n", "10 | \n", "1197 | \n", "440 | \n", "10 | \n", "
4 | \n", "99039 | \n", "GORE San Martín | \n", "APP-RNPF | \n", "27:59.0 | \n", "ara autorizar el aprovechamiento la U.O.G.F. ... | \n", "18 | \n", "1 | \n", "1 | \n", "22-SAM/REG-PLT-2019-050 | \n", "CARBAJAL VIGO, SEBASTIAN | \n", "... | \n", "854 | \n", "2127 | \n", "2660 | \n", "2651 | \n", "3144 | \n", "461 | \n", "9 | \n", "1496 | \n", "580 | \n", "10 | \n", "
5 | \n", "99039 | \n", "GORE San Martín | \n", "APP-RNPF | \n", "27:59.0 | \n", "ara autorizar el aprovechamiento la U.O.G.F. ... | \n", "18 | \n", "1 | \n", "1 | \n", "22-SAM/REG-PLT-2019-050 | \n", "CARBAJAL VIGO, SEBASTIAN | \n", "... | \n", "756 | \n", "1901 | \n", "2482 | \n", "2427 | \n", "2841 | \n", "461 | \n", "9 | \n", "1302 | \n", "492 | \n", "10 | \n", "
6 | \n", "99039 | \n", "GORE San Martín | \n", "APP-RNPF | \n", "27:59.0 | \n", "ara autorizar el aprovechamiento la U.O.G.F. ... | \n", "18 | \n", "1 | \n", "1 | \n", "22-SAM/REG-PLT-2019-050 | \n", "CARBAJAL VIGO, SEBASTIAN | \n", "... | \n", "739 | \n", "1792 | \n", "2374 | \n", "2293 | \n", "2648 | \n", "438 | \n", "9 | \n", "1283 | \n", "518 | \n", "10 | \n", "
7 | \n", "99039 | \n", "GORE San Martín | \n", "APP-RNPF | \n", "27:59.0 | \n", "ara autorizar el aprovechamiento la U.O.G.F. ... | \n", "18 | \n", "1 | \n", "1 | \n", "22-SAM/REG-PLT-2019-050 | \n", "CARBAJAL VIGO, SEBASTIAN | \n", "... | \n", "797 | \n", "2108 | \n", "2745 | \n", "2731 | \n", "3185 | \n", "488 | \n", "10 | \n", "1364 | \n", "502 | \n", "10 | \n", "
8 | \n", "99039 | \n", "GORE San Martín | \n", "APP-RNPF | \n", "27:59.0 | \n", "ara autorizar el aprovechamiento la U.O.G.F. ... | \n", "18 | \n", "1 | \n", "1 | \n", "22-SAM/REG-PLT-2019-050 | \n", "CARBAJAL VIGO, SEBASTIAN | \n", "... | \n", "738 | \n", "1755 | \n", "2448 | \n", "2214 | \n", "2763 | \n", "472 | \n", "9 | \n", "1178 | \n", "439 | \n", "10 | \n", "
9 | \n", "99039 | \n", "GORE San Martín | \n", "APP-RNPF | \n", "27:59.0 | \n", "ara autorizar el aprovechamiento la U.O.G.F. ... | \n", "18 | \n", "1 | \n", "1 | \n", "22-SAM/REG-PLT-2019-050 | \n", "CARBAJAL VIGO, SEBASTIAN | \n", "... | \n", "817 | \n", "1925 | \n", "2571 | \n", "2396 | \n", "2900 | \n", "472 | \n", "9 | \n", "1404 | \n", "533 | \n", "10 | \n", "
10 rows × 56 columns
\n", "\n", " | X | \n", "Y | \n", "b0 | \n", "b1 | \n", "b2 | \n", "b3 | \n", "b4 | \n", "b5 | \n", "b6 | \n", "b7 | \n", "b8 | \n", "b9 | \n", "b10 | \n", "b11 | \n", "b12 | \n", "Classification | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "-76.75757 | \n", "-7.1862 | \n", "1230 | \n", "932 | \n", "792 | \n", "507 | \n", "798 | \n", "1965 | \n", "2724 | \n", "2588 | \n", "2981 | \n", "475 | \n", "11 | \n", "1301 | \n", "493 | \n", "10 | \n", "
1 | \n", "-76.75757 | \n", "-7.1862 | \n", "1230 | \n", "922 | \n", "787 | \n", "479 | \n", "796 | \n", "2069 | \n", "2740 | \n", "2661 | \n", "3053 | \n", "475 | \n", "11 | \n", "1269 | \n", "460 | \n", "10 | \n", "
2 | \n", "-76.75757 | \n", "-7.1862 | \n", "1227 | \n", "930 | \n", "806 | \n", "495 | \n", "805 | \n", "2114 | \n", "2717 | \n", "2656 | \n", "3130 | \n", "447 | \n", "10 | \n", "1309 | \n", "485 | \n", "10 | \n", "
3 | \n", "-76.75757 | \n", "-7.1862 | \n", "1227 | \n", "916 | \n", "761 | \n", "476 | \n", "741 | \n", "1731 | \n", "2253 | \n", "2031 | \n", "2501 | \n", "447 | \n", "10 | \n", "1197 | \n", "440 | \n", "10 | \n", "
4 | \n", "-76.75757 | \n", "-7.1862 | \n", "1232 | \n", "943 | \n", "823 | \n", "535 | \n", "854 | \n", "2127 | \n", "2660 | \n", "2651 | \n", "3144 | \n", "461 | \n", "9 | \n", "1496 | \n", "580 | \n", "10 | \n", "