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

Apply a neighborhood filter with radius r to all elements of UxDataArray #930

Open
ahijevyc opened this issue Sep 3, 2024 · 0 comments · May be fixed by #941
Open

Apply a neighborhood filter with radius r to all elements of UxDataArray #930

ahijevyc opened this issue Sep 3, 2024 · 0 comments · May be fixed by #941
Assignees
Labels
new feature New feature or request

Comments

@ahijevyc
Copy link
Collaborator

ahijevyc commented Sep 3, 2024

Proposed new feature or change:

Apply a neighborhood filter within a circular radius r (in degrees) to a UxDataset or UxDataArray.

Overview

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.

This function would share the same logic as uxarray.UxDataArray.subset.bounding_circle to select grid elements in a circular neighborhood, but apply it to all elements in grid, not just one center_coordinate.

Ideally, the filter function func would be a user-defined, but at a minimum would be capable of calculating a neighborhood-maximum. Other possibilities are np.mean, min, np.median and np.percentile.

Expected Usage

import numpy as np

import uxarray

grid_path = "/glade/campaign/mmm/wmr/weiwang/cps/irma3/2020/tk707_conus/init.nc"
data_path = "/glade/campaign/mmm/wmr/weiwang/cps/irma3/mp6/tk707/diag.2017-09-07_09.00.00.nc"
uxds = uxarray.open_mfdataset(
grid_path,
data_path
)

Trim domain

lon_bounds = (-74, -64)
lat_bounds = (18, 24)
uxda = uxds["refl10cm_max"].isel(Time=0).subset.bounding_box(lon_bounds, lat_bounds)
uxda

this is how you use this function to get the maximum value within a 0.25-deg neighborhood of each element.

uxda_smoothed_mean = uxda.apply_neighorhood_filter(func=max, r=0.25)

@ahijevyc ahijevyc added the new feature New feature or request label Sep 3, 2024
@philipc2 philipc2 linked a pull request Sep 9, 2024 that will close this issue
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
Status: 🏗 In progress
Development

Successfully merging a pull request may close this issue.

2 participants