-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add neighborhood filter to remap #923
Conversation
Apply a function like np.mean or np.max to neighborhood around all points. It is like inverse distance weighting with power=0 but there is no weighting. All points in neighborhood are treated the same. The neighborhood is at a fixed radius instead of a fixed number of neighbors. Eliminated depreciated destination_obj argument.
default r=1 (degrees) No more destination_obj, only destination_grid Don't think we need to add remapped variable to existing UxDataset or construct a UxDataset from remapped variable and existing variable. Use [var_name] when constructing destination_uxds.
Hi @ahijevyc This is a great contribution. Can you create an issue & link it to this PR (can restate parts from the description). I'll give this a detailed review after this weekend, however a couple initial thoughts: We could have two forms of this function:
This reminds me of our Topological Aggregations, except instead of using the connectivity to determine the "neighborhood", it uses the number of neighbors returned from a nearest neighbor query. Could another name for this type of functionality be referred to as a "Spatial Aggregation"? A sample taking from another discussion:
Noted! I'll take a look into it. |
Thanks. And yes, I will create an issue and link it to this PR.
I like the idea of
- UxDataArray.apply_neighborhood_filter() which applies the filter to
the same Grid
Would we lose any functionality by completely separating the remapping
capability from the neighborhood filter? Instead of using a function
UxDataArray.remap.neighborhood_filter(), one would chain remap after
UxDataArray.apply_neighborhood_filter(), like
UxDataArray.apply_neighborhood_filter().remap.nearest_neighbor() ?
This would require an extensive revision of my pull request, but I don't
mind if it simplifies the code.
By the way, should we use this call structure with the remap accessor
UxDataArray.remap.nearest_neighbor()
or this call structure
UxDataArray.nearest_neighbor_remap()?
UxDataset.nearest_neighbor_remap
<https://uxarray.readthedocs.io/en/latest/user_api/generated/uxarray.UxDataset.nearest_neighbor_remap.html#uxarray.UxDataset.nearest_neighbor_remap>
is
in the User API, but UxDataArray.remap.nearest_neighbor() is in the User
Guide on Remapping.
To your comment about "spatial Aggregation", apply_neighborhood_filter()is
definitely a *spatial* method, with its reliance on radius=r, but it
doesn't *aggregate* in the sense of reducing the number of elements or
dimensions. In other words, the output has the same number of dimensions
and elements as the input.
And finally, you are right; we should probably add the capability to
weight neighborhood elements by inverse distance. I originally just wanted
a "maximum" filter, so it didn't require weighting. But if you want
a "mean" filter, weighting the elements on inverse distance, or better yet,
area, makes sense.
|
"By the way, should we use this call structure with the remap accessor To comment on this, you should use UxDataArray.remap.nearest_neighbor(). You can directly call UxDataArray.nearest_neighbor_remap(), but it will give a deprecation warning, and actually will not work anymore since we added some updates to remap, which weren't added to UxDataArray.nearest_neighbor_remap() as it was supposed to be removed awhile ago. Thanks for bringing this up! The deprecation warning has been there for several months so I think it is safe to delete this code altogether. I will put together a pr for this. |
I am preparing a new pull request #941 with the neighborhood filter on its own. It is not a part of remap. |
Apply a neighborhood filter within a circular radius r (in degrees) to a UxDataset or UxDataArray.
Issue #930
Overview
This neighborhood filter is written under
remap
so it has the ability to remap, but perhaps the neighborhood filter could be moved up to its own function, like UxDataset.neighborhold_filter. One doesn't always need to remap. As a workaround, if you don't need to remap, just supply the same destination UxGrid as the source.This is kind of like
uxarray.UxDataArray.inverse_distance_weighted_remap
, but the neighborhood is defined by distance, not a number of nearest neighbors. This is ideally suited for a variable resolution mesh, in which a constant of neighbors doesn't have a constant sized neighborhood. Another difference is that this neighborhood filter does not weight data by inverse distance.This function shares the same logic as
uxarray.UxDataArray.subset.bounding_circle
to select grid elements in a circular neighborhood, but this function applies it to all elements in grid, not just one center_coordinate.The filter function
func
may be a user-defined function, but usesnp.mean
by default. It could bemin
,max
,np.median
. It can even usenp.percentile
if you supply a single quantile argument withfunctools.partial
(see below)The new function
remap.apply_func.py
usedremap.inverse_distance_weighted.py
andremap.nearest_neighbor.py
as a starting point.inverse_distance_weighted.py
andnearest_neighbor.py
have a lot of the same code but have different documentation style. Their formatting styles should probably be brought back into agreement before this pull request is completed.Expected Usage
PR Checklist
General
Testing
Documentation
_
) and have been added todocs/internal_api/index.rst
docs/user_api/index.rst
Examples
docs/examples/
folderdocs/examples.rst
toctreedocs/gallery.yml
with appropriate thumbnail photo indocs/_static/thumbnails/