Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚸 Walkthrough on rasterizing vector polygons into label masks #31

Merged
merged 18 commits into from
Aug 18, 2022

Conversation

weiji14
Copy link
Owner

@weiji14 weiji14 commented Jul 18, 2022

Tutorial on creating vector label masks for an image segmentation task. Using flood water extent polygons digitized by UNITAR-UNOSAT over Johor, Malaysia on Sentinel-1 imagery taken 15 Dec 2019.

Preview at https://zen3geo--31.org.readthedocs.build/en/31/vector-segmentation-masks.html

Satellite detected waters extents as of 15 December 2019 over Johor, Malaysia

TODO:

  • Setup blank datashader.Canvas from template xarray.DataArray input
  • Rasterize vector polygon labels onto blank canvas
  • Pair the Sentinel-1 and rasterized label inputs into a single datapipe and dataloader

References:

Initial draft tutorial on preparing vector labels for an image segmentation task. Using shapefiles of flood water extent digitized by UNITAR-UNOSAT over Johor, Malaysia on Sentinel-1 imagery taken 15 Dec 2019.
@weiji14 weiji14 added the documentation Improvements or additions to documentation label Jul 18, 2022
@weiji14 weiji14 added this to the 0.2.1 milestone Jul 18, 2022
@weiji14 weiji14 self-assigned this Jul 18, 2022
Fix readthedocs build failure because pyogrio was not installed.
New datashader DataPipe classes to use!
Picking a single Sentinel-1 image from 15 Dec 2019 over Johor, Malaysia corresponding to the mapped flood extent polygons. Perform reprojection from EPSG;4326 to UTM, and transform VV channel from linear to decibel. Did a bit of reorganizing to put the raster section before the vector section, may decide to change it later when the canvas part comes in.
Fix readthedocs `ERROR: Couldn't find cache key for notebook file vector-segmentation-labels.md`.

Signed-off-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
A comprehensive library for creating static, animated, and interactive visualizations in Python!
Debugging why readthedocs build fails when reproducing the same environment and commands locally works.
See if this helps with fixing the KeyboardInterrupt when plotting the Sentinel-1 map using matplotlib, hopefully 5 minutes is more than enough.
Read in the two shapefiles using PyogrioReaderIterDataPipe, and show a quick example of reprojecting and visualizing the vector polygons.
Using template Sentinel-1 xarray.DataArray grid to create blank datashader.Canvas. Show how the metadata information match! Also some small edits to the previous pyogrio section like fixing an incorrectly set projection system.
Show how the painting of vector geopandas.GeoDataFrame polygons onto the datashader.Canvas works! Got some words of caution and where to seek more advice. Also added spatialpandas to the 'docs' extras list of dependencies.
Simple Python interface for Graphviz!
Marie Kondo-ing the section on pre-processing the vector data, because working with two shapefiles was a pain. The merging of two GeoDataFrame objects using BatchMapper was a bad idea as it returned a DataPipe without a length, so DatashaderRasterizer complained. Decided too that focusing on just one vector was enough to teach the concept, and the masters can read the footnotes on more advanced combinatorial pipelines.
Combining two xarray.DataArray objects into a single xarray.Dataset before slicing. Using Zipper to pair the two DataPipes, and then Collator to do the actual combining. Showing the DataPipe graph after the zip stage to give people an overview of the (many) steps done so far. Double checked too that the image and mask looks ok, which led to the discovery of an issue with rounding numbers or something. Had to change the resolution from 80m to 100m because of this, otherwise the rasterized water mask is cut off at the Southern part.
Fixes `ExecutableNotFound: failed to execute PosixPath('dot'), make sure the Graphviz executables are on your systems' PATH`. Decided to use apt instead of conda because it's less hassle.
Just complete the whole vector segmentation tutorial in one go! Really simplified the ending with a minimal xbatcher slicing and conversion to torch.Tensor step only. Gave a shoutout to Edoardo's work at UNOSAT in the end. Decided to rename the file to vector-segmentation-masks. Added more emojis throughout the page, and should be good to go!
@weiji14 weiji14 marked this pull request as ready for review August 18, 2022 22:55
@weiji14 weiji14 merged commit ce0f4da into main Aug 18, 2022
@weiji14 weiji14 deleted the vector-segmentation-labels branch August 18, 2022 23:06
weiji14 added a commit that referenced this pull request Oct 2, 2022
Refactoring the xarray collate functions to use `xr.merge` instead of the dictionary style way of appending data variables to an xarray.Dataset. Solution adapted from 7787f8e in #62 that is more robust to images being cut off due to rounding issues as with 6b18934 in #31. Downside is the need to verbosely rename the xarray.DataArray objects, and handle some conflicting coordinate labels.
weiji14 added a commit that referenced this pull request Oct 2, 2022
* ♻️ Use xarray.merge with join="override" in collate functions

Refactoring the xarray collate functions to use `xr.merge` instead of the dictionary style way of appending data variables to an xarray.Dataset. Solution adapted from 7787f8e in #62 that is more robust to images being cut off due to rounding issues as with 6b18934 in #31. Downside is the need to verbosely rename the xarray.DataArray objects, and handle some conflicting coordinate labels.

* 📝 Minor tweaks to vector segmentation mask walkthrough

A few whitespace fixes and fixing some DataPipe references.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant