Commit 0c1e01b3 authored by David Youssefi's avatar David Youssefi

ENH: steps 1,2 completed

parent 6f64ad65
......@@ -136,7 +136,7 @@
"# Compute radiometric indices (NDVI & NDWI2) on a stack of images\n",
"ndwi_filenames_list = compute_ndwi(utils.list_images(DATA_DIR,\"_RVBPIR.tif\"), OUTPUT_DIR)\n",
"if ndwi_filenames_list is not None:\n",
" print (ndwi_filenames_list)\n",
" print (ndwi_filenames_list)http://localhost:8888/notebooks/step1_compute_radiometric_indices.ipynb#\n",
"else:\n",
" print (\"TODO: fill the compute_ndwi_function\")"
]
......@@ -147,14 +147,18 @@
"metadata": {},
"outputs": [],
"source": [
"if ndwi_filenames_list is not None:\n",
" # Display on a map\n",
" rasters = list(map(rasterio.open, ndwi_filenames_list))\n",
" overnames = list(map(os.path.basename, ndwi_filenames_list))\n",
" m, dc = display_api.rasters_on_map(rasters, OUTPUT_DIR, overnames)\n",
" m\n",
"else:\n",
" print (\"TODO: fill the compute_ndwi_function\")"
"# Display on a map\n",
"rasters = list(map(rasterio.open, ndwi_filenames_list))\n",
"overnames = list(map(os.path.basename, ndwi_filenames_list))\n",
"m, dc = display_api.rasters_on_map(rasters, OUTPUT_DIR, overnames)\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Go to the [Step 2](./step2_compute_watermask.ipynb)"
]
}
],
......
......@@ -14,7 +14,7 @@
"<b> Press <span style=\"color:black;background:yellow\">SHIFT+ENTER</span> to execute the notebook interactively cell by cell </b></div>\n",
"\n",
"\n",
"## Step 2 : \n",
"## Step 2 : Compute Watermask\n",
"\n",
"The aim of this second exercise is to combine NDWI2 values to create a water mask\n",
"- what kind of function do we need to implement ?\n",
......@@ -53,7 +53,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Compute the NDWI2** \n",
"### Compute the NDWI2\n",
"\n",
"Do we need to adapt the formula to deal with invalid pixels ? \n",
"\n",
......@@ -66,7 +66,7 @@
"metadata": {},
"outputs": [],
"source": [
"def app_radiometricindices(images):\n",
"def app_radiometricindices(images, out_dir):\n",
" index = 0\n",
" for im in images:\n",
" # Here we create an application\n",
......@@ -94,7 +94,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Compute watermask from a list of NDWI2 images**\n",
"### Compute watermask from a list of NDWI2 images\n",
"\n",
"We are going to use a list of images to compute a watermask (0 for land, 1 for water) : \n",
"- the inputs must be set in a list with app.AddImageToParameterInputImageList\n",
......@@ -107,25 +107,38 @@
"metadata": {},
"outputs": [],
"source": [
"def compute_watermask(list_app):\n",
" if index==1:\n",
" exp = exp+\"im\"+str(index)+\"b1\"\n",
" else:\n",
" exp = exp+\", \"+\"im\"+str(index)+\"b1\"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def compute_watermask(list_app,outputfilename):\n",
" app = otbApplication.Registry.CreateApplication(\"BandMath\")\n",
"\n",
" index = 1\n",
" input_list = []\n",
" exp = \"?????\"\n",
" for appli in list_app:\n",
" app.AddImageToParameterInputImageList(\"il\",appli.GetParameterOutputImage(\"out\"))\n",
" if index==1:\n",
" exp = exp # + \"some function that involves im1b1\"\n",
" else:\n",
" exp = exp # +\", \"+\"im\"+str(index)+\"b1\"\n",
" exp = exp # +\", \"+\"im\"+str(index)+\"b1\"def compute_watermask(list_app,outputfilename):\n",
" index += 1\n",
"\n",
"\n",
" print(exp)\n",
"\n",
" \n",
" app.SetParameterString(\"out\",NDWI_synthesis)\n",
" app.SetParameterString(\"out\",outputfilename)\n",
" app.SetParameterString(\"exp\",exp)\n",
" app.ExecuteAndWriteOutput()\n"
" app.ExecuteAndWriteOutput()"
]
},
{
......@@ -136,7 +149,7 @@
"source": [
"# Compute radiometric indices (NDVI & NDWI2) on a stack of images\n",
"list_app = app_radiometricindices(utils.list_images(DATA_DIR,\"_RVBPIR.tif\"), OUTPUT_DIR)\n",
"compute_watermask(os.path.join(OUTPUT_DIR, NDWI_synthesis), list_app)\n"
"compute_watermask(list_app, NDWI_synthesis)"
]
},
{
......@@ -144,14 +157,23 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"import rasterio\n",
"import display_api\n",
"\n",
"raster = rasterio.open(NDWI_synthesis)\n",
"m, dc = display_api.rasters_on_map([raster], OUTPUT_DIR, [\"NDWI synthesis\"])\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"### Go to the [Step 3](./step3_segment_watermask_threshold_NDWI.ipynb)"
]
}
],
"metadata": {
......
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