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

[POC]: Classification notebook #620

Open
adebardo opened this issue Oct 25, 2024 · 2 comments · May be fixed by #644
Open

[POC]: Classification notebook #620

adebardo opened this issue Oct 25, 2024 · 2 comments · May be fixed by #644
Labels
[POC] Conception To review Tickets needs approval about it conception

Comments

@adebardo
Copy link

adebardo commented Oct 25, 2024

Context

The purpose of this ticket is to set up a notebook allowing demcompare users to perform metric measurements, such as mean or NMAD, in specific areas using classification. This notebook can be included in examples and used as a tutorial notebook during the practical session.

Setup

For the tutorial, it would be helpful to use demcompare data along with the associated masks.

Information

  • The masks will be treated as rasters using the GeoUtils tool. mask = gu.Raster('xdem_gironde_mask.tif')
  • The masks are binary masks stacked in different bands --> TODO: Convert the demcompare mask into this format.

Notebook Workflow

  1. Opening the DEM
  2. Opening the mask
  3. Converting the mask into 4 Boolean masks
  4. Adding a function to select one of the 4 masks and apply it to the DEM dem.set_mask(mask_single_band_boolean)
  5. Providing a set of plots (slope, hillshade, etc.) to highlight the use of classification
  6. Providing a set of metrics (NMAD, mean, etc.) to highlight the use of classification

Extras parts

In demcompare, it is possible to measure metrics based on grouped information; it would be useful to demonstrate in the notebook how to do this using the xdem API.

Examples:

  • Calculating the NMAD for different slope intervals (here, consider dividing the slope into masks according to the intervals)
  • Merging a segmentation mask with slope intervals to measure metrics

/estimation 4d

@adebardo adebardo added the [POC] Conception stuck The issue conception is stopped label Oct 25, 2024
@adebardo adebardo changed the title [POC]: Notebook de classif [POC]: Classification notebook Oct 25, 2024
@rhugonnet
Copy link
Contributor

Here's the discussion I was mentioning about scalable classif (with raster-vector) extraction: https://discourse.pangeo.io/t/advice-for-scalable-raster-vector-extraction/4129.
If scalability becomes important, we probably want to either let geocube figure this out and use it in GeoUtils (via Xarray accessor), or use/inspire ourselves from rasterstats.

@adebardo adebardo added [POC] Conception To review Tickets needs approval about it conception and removed [POC] Conception stuck The issue conception is stopped labels Oct 30, 2024
@rhugonnet
Copy link
Contributor

On the edited description: Sounds good!

One remark on the extras:

In demcompare, it is possible to measure metrics based on grouped information; it would be useful to demonstrate in the notebook how to do this using the xdem API.

By "grouped information", you mean performing data binning? (I see the translation is "groupement par classes" in French, I didn't know!)
We do this a lot. We have a helper function that is used both for uncertainty analysis and coregistration: nd_binning (see https://xdem-rhugonnet.readthedocs.io/en/towards_0.1/gen_modules/xdem.spatialstats.nd_binning.html#xdem.spatialstats.nd_binning), mostly a wrapper of https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.binned_statistic_dd.html#scipy.stats.binned_statistic_dd returning the results in a pd.DataFrame with properly defined intervals, and allowing to do this in N-D. We also have plotting for 1D/2D: https://xdem-rhugonnet.readthedocs.io/en/towards_0.1/gen_modules/xdem.spatialstats.plot_1d_binning.html#xdem.spatialstats.plot_1d_binning.

On future improvements:

The limitation right now is that those functions expect arrays, and not raster. For easier use in the future, we were thinking of moving these tools to a geoutils.stats module, and adding a method to Raster for performing nd_binning on a raster, with a list of other variables that could also be rasters (which would be inherited by the DEM class; or Xarray accessor). See #378.

Once we have the Xarray accessors, we could also potentially rely on groupby through flox for computational performance, see: https://xarray.dev/.blog/flox.

@vschaffn vschaffn linked a pull request Nov 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[POC] Conception To review Tickets needs approval about it conception
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants