-
Notifications
You must be signed in to change notification settings - Fork 16
Neighbourhood methods
Neighbourhood methods compute for each gridpoint a statistic based on values within a neighbourhood surrounding this gridpoint.
The functions in gridpp look like this:
values = gridpp.neighbourhood(input_2d, radius, statistic)
values = gridpp.neighbourhood_ens(input_3d, radius, statistic)
where the first is used for processing a single 2D field, and the second is for processing an ensemble of 2D fields. Both return 2D fields. radius
is the half-width of the neighbourhood, and statistic
is one of gridpp.Mean
, gridpp.Min
, gridpp.Max
, gridpp.Std
, gridpp.Variance
, or gridpp.Sum
.
To compute the neighbourhood mean on a 15x15 square neighbourhood, use:
radius = 7
ovalues = gridpp.neighbourhood(ivalues, radius, gridpp.Mean)
Neighbourhoods for ensembles add the ensebmle dimension to the neighbourhood. When computing a statistic, the statistic is calculated by pooling all ensemble members together, creating a single field (instead of one field for each ensemble member).
To calculate quantiles, use the neighbourhood_quantile
method:
radius = 7
quantile = 0.9
num_thresholds = 20
ovalues = gridpp.neighbourhood_quantile(ivalues, quantile, radius, num_thresholds)
To calculate ensemble neighbourhoods, use the _ens
functions:
ivalues_ens = np.random.rand([100, 80, 10]) # 10 member ensemble
radius = 7
ovalues = gridpp.neighbourhood_ens(ivalues_ens, radius, gridpp.Mean)