environmentaltools.spatiotemporal.indicators.neighbourhood_mean
- environmentaltools.spatiotemporal.indicators.neighbourhood_mean(data_cube, size=3)[source]
Calculate neighborhood mean value for each cell.
Applies a spatial moving average filter to compute the mean value within a specified neighborhood around each cell. This is useful for spatial smoothing and analyzing local context.
- Parameters:
data_cube (np.ndarray) – 3D array with shape (time, lat, lon) containing spatiotemporal data.
size (int, optional) – Neighborhood size (e.g., 3 for 3x3 neighborhood). Default is 3.
- Returns:
cube_filtered – 3D array with neighborhood means, same shape as input.
- Return type:
np.ndarray
Notes
The function applies a uniform filter that computes the mean value within a square neighborhood of the specified size around each cell. Edge effects are handled using reflection mode.
Examples
>>> import numpy as np >>> data_cube = np.random.random((10, 20, 20)) >>> smoothed = neighbourhood_mean(data_cube, size=5)