-
Notifications
You must be signed in to change notification settings - Fork 27
Add grouped_stats for categorical or continuous binning
#815
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,7 @@ import numpy as np | |
|
|
||
| # Instantiate a raster from a filename on disk | ||
| filename_rast = gu.examples.get_path("exploradores_aster_dem") | ||
| rast = gu.Raster(filename_rast) | ||
| rast = gu.Raster(filename_rast, force_nodata=-9999) | ||
| rast | ||
| ``` | ||
|
|
||
|
|
@@ -93,6 +93,56 @@ inlier_mask = rast > 1500 | |
| rast.get_stats(inlier_mask=inlier_mask) | ||
| ``` | ||
|
|
||
| ## Grouped statistics | ||
|
|
||
| GeoUtils provides support for grouped statistics, allowing statistics to be computed independently over subsets of data | ||
| defined by one or more grouping bins. This is particularly useful when analyzing how statistical properties vary | ||
| across classes, bins, or segmentation derived from the data itself. | ||
|
|
||
|
|
||
| ### Example with altitude intervals | ||
| In this example, we will create different altitude classes from a chosen interval [400, 1000, 2000, 3000, >3000]. | ||
| Once these bins are created, we reapply them and compute the mean, minimum, and maximum values of the same raster | ||
| for each sub-interval. It is also possible to use a reference other than the raster itself for the group_by. | ||
|
|
||
| A dictionary containing the masks that have been created during the computation will also be returned by the function. | ||
| Using GeoUtils functions makes it very easy to visualise them. | ||
|
|
||
| ```{code-cell} ipython3 | ||
| group_by = {"raster": rast.data} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why there is no file linked to rast ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we cover only NDArrayNum here, do you want to be more inclusive ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is in case the user wants to reproduce the example. It is not possible with this example.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure to understand the problem, but if you look at the beginning of stats.md file you'll see a file attached to raster |
||
| bins = [[1000, 2000, 3000]] | ||
| statistics = ["mean", "min", "max"] | ||
|
|
||
| df = rast.grouped_stats(group_by, bins, statistics) | ||
| df | ||
| ``` | ||
|
|
||
| ### Example with vector outlines masks | ||
|
|
||
| In this example, we will create a mask such as altitude is more than 2000 meters. | ||
|
adebardo marked this conversation as resolved.
|
||
| Once these masks are created as a raster, we reapply them and compute the mean, minimum, and maximum values of the same raster | ||
| for masks = True. It is also possible to use a reference other than the raster itself for the group_by. | ||
|
|
||
| ```{code-cell} ipython3 | ||
| import matplotlib.pyplot as plt | ||
|
|
||
| filename_rast = gu.examples.get_path("everest_landsat_b4") | ||
| filename_vect = gu.examples.get_path("everest_rgi_outlines") | ||
| rast = gu.Raster(filename_rast) | ||
|
adebardo marked this conversation as resolved.
Outdated
|
||
| vect = gu.Vector(filename_vect) | ||
| vect_rasterized = vect.create_mask(rast) | ||
|
|
||
| vect_rasterized.plot() | ||
| plt.show() | ||
|
|
||
| group_by = {"elevation": rast.data} | ||
| bins = [vect_rasterized.data] | ||
| statistics = ["mean", "min", "max"] | ||
|
|
||
| df = rast.grouped_stats(group_by, bins, statistics) | ||
| df | ||
| ``` | ||
|
|
||
| ## Subsampling | ||
|
|
||
| The {func}`~geoutils.Raster.subsample` method allows to efficiently extract a valid random subsample from a raster or a point cloud. It can conveniently | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.