uxarray.grid.neighbors.Neighborhood

uxarray.grid.neighbors.Neighborhood#

class uxarray.grid.neighbors.Neighborhood(grid, r=1.0, on='face centers')#

The set of grid elements within a radius r of every element of one grid location, ready to be reduced over.

Building this queries a BallTree once, which is by far the dominant cost of a neighborhood reduction — typically far more than the reduction itself. Holding onto the result lets several reductions, or several variables, share that one query instead of repeating it.

Each reduction is a method: mean(), std(), percentile() and so on run a compiled kernel, and reduce() takes an arbitrary callable for anything without one. Every one takes the data to reduce as its first argument, so several variables can share one query.

Parameters:
  • grid (Grid) – Grid whose elements define the neighborhood.

  • r (float, default=1.) – Radius of the neighborhood, in degrees of great-circle distance.

  • on (str, default="face centers") – Grid location the neighborhood is built around: “nodes”, “edge centers”, or “face centers”.

Examples

>>> import uxarray as ux
>>> uxds = ux.tutorial.open_dataset("outCSne30-vortex")  
>>> nb = uxds.uxgrid.neighborhood(r=5.0)  
>>> smooth = nb.mean(uxds["psi"])  
>>> spread = nb.std(uxds["psi"], ddof=1)  

See also

UxDataArray.neighborhood

Neighborhood around a single variable’s elements.

UxDataset.neighborhood

Neighborhood around every variable in a dataset.

__init__(grid, r=1.0, on='face centers')#

Methods

__init__(grid[, r, on])

max(uxda)

Largest value in each neighborhood.

mean(uxda)

Mean of each neighborhood.

median(uxda)

Median of each neighborhood.

min(uxda)

Smallest value in each neighborhood.

percentile(uxda, q)

Percentile q (between 0 and 100) of each neighborhood.

ptp(uxda)

Peak-to-peak spread (max - min) of each neighborhood.

quantile(uxda, q)

Quantile q (between 0 and 1) of each neighborhood.

reduce(uxda, func)

Reduces each neighborhood with an arbitrary callable.

std(uxda[, ddof])

Standard deviation of each neighborhood, with ddof delta degrees of freedom.

sum(uxda)

Sum of each neighborhood.

var(uxda[, ddof])

Variance of each neighborhood, with ddof delta degrees of freedom.

Attributes

grid

Grid the neighborhood was built from.

grid_dim

Name of the grid dimension this reduces over.

n_neighbors

Number of elements in each neighborhood, itself a grid-mapped field.

on

Grid location the neighborhood is centered on.

r

Neighborhood radius, in degrees.