Commit 37718945 authored by David Youssefi's avatar David Youssefi

ENH: island/sea convention + simplify step4

parent 78c76715
......@@ -39,8 +39,6 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from glob import glob\n",
"import ipywidgets\n",
"\n",
"# Data directory\n",
......@@ -70,6 +68,8 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from glob import glob\n",
"import rasterio\n",
"DATE = date_buttons.value\n",
"raster = rasterio.open(glob(os.path.join(DATA_DIR, \"*{}*.tif\".format(DATE)))[0])"
......@@ -116,16 +116,6 @@
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"startx, starty, endx, endy = display_api.get_bounding_box_from_draw(raster, dc)\n",
"print (startx, starty, endx, endy)"
]
},
{
"cell_type": "markdown",
"metadata": {},
......
......@@ -32,8 +32,6 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from glob import glob\n",
"import ipywidgets\n",
"\n",
"# Data directory\n",
......@@ -74,6 +72,8 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from glob import glob\n",
"import otbApplication\n",
"\n",
"# input / output files\n",
......@@ -128,6 +128,8 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from glob import glob\n",
"import otbApplication\n",
"\n",
"# input / output files\n",
......
......@@ -19,33 +19,13 @@
"The aim of this second exercise is to combine NDWI2 values to create a water mask : what kind of function do we need to implement ?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from glob import glob\n",
"import ipywidgets\n",
"\n",
"# Data directory\n",
"DATA_DIR = \"data\"\n",
"\n",
"# Output directory\n",
"OUTPUT_DIR = \"output\"\n",
"\n",
"# Date list\n",
"DATE_LIST = [\"20180711\", \"20180701\", \"20180621\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Compute watermask for each image\n",
"\n",
"We are going to threshold NDWI to compute a watermask (0 for land, 1 for water)"
"We are going to threshold NDWI to compute a watermask (1 for land, 0 for water)"
]
},
{
......@@ -54,6 +34,17 @@
"metadata": {},
"outputs": [],
"source": [
"# Data directory\n",
"DATA_DIR = \"data\"\n",
"\n",
"# Output directory\n",
"OUTPUT_DIR = \"output\"\n",
"\n",
"# Date list\n",
"DATE_LIST = [\"20180711\", \"20180701\", \"20180621\"]\n",
"\n",
"import os\n",
"from glob import glob\n",
"import otbApplication\n",
"\n",
"# input / output files\n",
......@@ -93,11 +84,11 @@
"source": [
"### Threshold ndwi : <b> Fill the <span style=\"color:black;background:yellow\">threshold_ndwi</span> function </b> \n",
"\n",
"**Tips:** The formula to threshold (th=0.3) the NDWI images can be written using\n",
"**Tips:** The formula to threshold the NDWI images can be written using\n",
"- binary operators:\n",
" - ‘+’ addition, ‘-‘ subtraction, ‘*’ multiplication, ‘/’ division\n",
" - ‘^’ raise x to the power of y\n",
" - ‘<’ less than, **‘>’ greater than**, ‘<=’ less or equal, ‘>=’ greater or equal\n",
" - **‘<’ less than**, ‘>’ greater than, ‘<=’ less or equal, ‘>=’ greater or equal\n",
" - ‘==’ equal, ‘!=’ not equal\n",
" - ‘||’ logical or, ‘&&’ logical and\n",
"- functions: exp(), log(), sin(), cos(), min(), **max()**, ...\n",
......@@ -113,6 +104,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Watermask\n",
"watermask = os.path.join(OUTPUT_DIR, \"WATERMASK.tif\")\n",
"def threshold_ndwi(ndwi1, ndwi2, ndwi3):\n",
" # Fill the threshold_ndwi function\n",
......
......@@ -16,23 +16,6 @@
"## Step 3 : Compute Watermask (with OTB pipeline)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from glob import glob\n",
"import ipywidgets\n",
"\n",
"# Data directory\n",
"DATA_DIR = \"data\"\n",
"\n",
"# Output directory\n",
"OUTPUT_DIR = \"output\""
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -48,9 +31,18 @@
"metadata": {},
"outputs": [],
"source": [
"import otbApplication\n",
"# Data directory\n",
"DATA_DIR = \"data\"\n",
"\n",
"# Output directory\n",
"OUTPUT_DIR = \"output\"\n",
"\n",
"import os\n",
"import time\n",
"\n",
"from glob import glob\n",
"import otbApplication\n",
"\n",
"tic = time.clock()\n",
"\n",
"watermask = os.path.join(OUTPUT_DIR, \"WATERMASK.tif\")\n",
......@@ -91,7 +83,7 @@
"thresapp = otbApplication.Registry.CreateApplication(\"BandMath\")\n",
"thresapp.SetParameterStringList(\"il\",[ndwi1, ndwi2, ndwi3])\n",
"thresapp.SetParameterString(\"out\", watermask)\n",
"thresapp.SetParameterString(\"exp\", \"max(im1b1, im2b1, im3b1) > 0.3\")\n",
"thresapp.SetParameterString(\"exp\", \"max(im1b1, im2b1, im3b1) < 0.3\")\n",
"thresapp.ExecuteAndWriteOutput()\n",
"\n",
"toc = time.clock()\n",
......@@ -119,9 +111,18 @@
"metadata": {},
"outputs": [],
"source": [
"import otbApplication\n",
"# Data directory\n",
"DATA_DIR = \"data\"\n",
"\n",
"# Output directory\n",
"OUTPUT_DIR = \"output\"\n",
"\n",
"import os\n",
"import time\n",
"\n",
"from glob import glob\n",
"import otbApplication\n",
"\n",
"tic = time.clock()\n",
"\n",
"watermask = os.path.join(OUTPUT_DIR, \"WATERMASK.tif\")\n",
......@@ -162,7 +163,7 @@
"thresapp = otbApplication.Registry.CreateApplication(\"BandMath\")\n",
"thresapp.SetParameterStringList(\"il\",[ndwi1, ndwi2, ndwi3]) # to be modified\n",
"thresapp.SetParameterString(\"out\", watermask)\n",
"thresapp.SetParameterString(\"exp\", \"max(im1b1, im2b1, im3b1) > 0.3\")\n",
"thresapp.SetParameterString(\"exp\", \"max(im1b1, im2b1, im3b1) < 0.3\")\n",
"thresapp.ExecuteAndWriteOutput()\n",
"\n",
"toc = time.clock()\n",
......@@ -175,9 +176,19 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import rasterio\n",
"import display_api\n",
"\n",
"# Data directory\n",
"DATA_DIR = \"data\"\n",
"\n",
"# Output directory\n",
"OUTPUT_DIR = \"output\"\n",
"\n",
"# Watermask\n",
"watermask = os.path.join(OUTPUT_DIR, \"WATERMASK.tif\")\n",
"\n",
"raster = rasterio.open(watermask)\n",
"m, dc = display_api.rasters_on_map([raster], OUTPUT_DIR, [\"WATERMASK\"])\n",
"m"
......
This diff is collapsed.
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