Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OTB Guided Tour
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
David Youssefi
OTB Guided Tour
Commits
6f64ad65
Commit
6f64ad65
authored
May 15, 2019
by
Yannick TANGUY
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add step2
parent
a425da5a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
110 additions
and
3 deletions
+110
-3
step2_compute_watermask.ipynb
step2_compute_watermask.ipynb
+110
-3
No files found.
step2_compute_watermask.ipynb
View file @
6f64ad65
...
...
@@ -16,9 +16,48 @@
"\n",
"## Step 2 : \n",
"\n",
"The aim of this second exercise is to com
pute a water mask, from NDWI2 values
\n",
"The aim of this second exercise is to com
bine NDWI2 values to create a water mask
\n",
"- what kind of function do we need to implement ?\n",
"- are all the pixels valid ?"
"- are all the pixels valid ?\n",
"- we want to maximize water extent\n",
"\n",
"We are also going to use OTB pipeline, to avoid writing intermediate file : \n",
"- the first step will be plugged as input of the second step\n",
"- only the final application will launch the pipeline, with ExecuteAndWriteOutput()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import otbApplication\n",
"import rasterio\n",
"\n",
"import display_api\n",
"import utils\n",
"\n",
"# Data directory\n",
"DATA_DIR = \"data\"\n",
"\n",
"# Output directory\n",
"OUTPUT_DIR = \"output\"\n",
"\n",
"# NDWI synthesis\n",
"NDWI_synthesis = os.path.join(OUTPUT_DIR,\"synthesis_NDWI2.tif\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Compute the NDWI2** \n",
"\n",
"Do we need to adapt the formula to deal with invalid pixels ? \n",
"\n",
"What happens with clouds ?"
]
},
{
...
...
@@ -35,16 +74,84 @@
" # BandMath takes a list of images as input,\n",
" # so we have to give a Python list [ image ], or [ image1, image2, .., imageN]\n",
" app.SetParameterStringList(\"il\",[im])\n",
" app.SetParameterString(\"out\",im.replace(\"RVBPIR.tif\",\"_ndwi2.tif\"))\n",
" out = os.path.join(out_dir, os.path.basename(im.replace(\"_RVBPIR.tif\",\"_NDWI2.tif\")))\n",
" app.SetParameterString(\"out\",out)\n",
" app.SetParameterString(\"exp\",\"(im1b2-im1b4)/(im1b2+im1b4)\")\n",
" # Plug the application in the pipeline \n",
" # does NOT launch the pipeline yet !\n",
" app.Execute()\n",
" # we save the application in a list\n",
" if (index == 0):\n",
" tab_App = [app]\n",
" else:\n",
" tab_App.append(app)\n",
" index += 1\n",
" # the list of applications is returned\n",
" return tab_App"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**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",
"- the expression will be use all the images im1b1, im2b1, etc."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def compute_watermask(list_app):\n",
" app = otbApplication.Registry.CreateApplication(\"BandMath\")\n",
" index = 1\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",
" index += 1\n",
"\n",
"\n",
" print(exp)\n",
"\n",
" \n",
" app.SetParameterString(\"out\",NDWI_synthesis)\n",
" app.SetParameterString(\"exp\",exp)\n",
" app.ExecuteAndWriteOutput()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment