xoa.filter.decimate
- xoa.filter.decimate(obj, radius, method='average', stack_dim='npts', sphere_radius=6371000.0, smooth_factor=1.0)[source]
Decimate a data array or dataset by removing too close points
It typical use is for undersampling a huge dataset before a geostatistical interpolation.
A loop is made on all points: a point that is at a distance less that radius from a previously selected point is not selected. In the case of the “average” method, an average is made at selected points within a radius of radius*smooth_factor.
Warning
X and Y dimensions are stacked during this process if not already stacked.
- Parameters:
obj (xarray.DataArray, xarray.Dataset) – Array or dataset to decimate with lon and lat coordinates
radius (float) – Radius in meters
method (str, int) – Decimation method:
1|"average"
,0|"pick"|"kill"
. pick operates with crude undersampling, while average performs an average with a radius of size radius*smooth_factor.smooth_factor (float) – Factor applied to radius for the average process, not for the selection process. A smooth_factor of zero is equivalent to method set to “pick”. A smooth_factor which is equal to the infinite returns a spatial average over the domain at all selected points.
stack_dim (str) – When lon and lat coordinates have several or uncommon dimensions, they are stacked onto a single dimension whose name is stack_dim, with function
geo_stack()
.sphere_radius (float) – Radius of the sphere in meters
Example
# Create the sample In [1]: npts = 1000 In [2]: x = np.random.uniform(-20, -10, npts) In [3]: y = np.random.uniform(40, 50, npts) In [4]: ds = xr.Dataset( ...: {"temp": ("npts", 20+5*np.exp(-(x+15)**2/3**2-(y-45)**2/3**2))}, ...: coords={"lon": ("npts", x), "lat": ("npts", y)}) ...: # Decimate it with a radius of 150 km In [5]: dsc = decimate(ds, radius=150e3) # Plot In [6]: fig, axs = plt.subplots(ncols=2, sharex=True, sharey=True) In [7]: axs[0].scatter(ds.lon, ds.lat, c=ds.temp, cmap='cmo.thermal') Out[7]: <matplotlib.collections.PathCollection at 0x7f37c174f810> In [8]: axs[0].set_title("Complete") Out[8]: Text(0.5, 1.0, 'Complete') In [9]: axs[1].scatter(dsc.lon, dsc.lat, c=dsc.temp, cmap='cmo.thermal') Out[9]: <matplotlib.collections.PathCollection at 0x7f37c1759010> In [10]: axs[1].set_title("Decimated") Out[10]: Text(0.5, 1.0, 'Decimated')
See also