Computes unbiased estimates of the variance of a variable's given dimension(s) at all other dimensions and retains metadata.
Available in version 5.1.1 and later.
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" function dim_variance_n_Wrap ( x : numeric, dims [*] : integer ) return_val : float or double
A variable of numeric type and any dimensionality.dims
The dimension(s) of x on which to calculate the variance. Must be consecutive and monotonically increasing.
The output will be double if x is double, and float otherwise.
The output dimensionality will be the same as all but the dims's dimensions of the input variable. The dimension rank of the input variable will be reduced by the rank of dims.
The dim_variance_n_Wrap function computes the sample variance of all elements of the dimensions indicated by dims for each index of the remaining dimensions and retains metadata. A wrapper function. Missing values are ignored.
Technically, this function calculates an estimate of the sample variance. This means that it divides by [1/(N-1)] where N is the total number of non-missing values.
Create a variable q of size (3,5,10) array. Then calculate the sample variance of the rightmost dimension.
q = random_uniform(-20,100,(/3,5,10/)) qVar= dim_variance(q) ;==> qVar(3,5)Example 2
Let x be of size (ntim,nlat,mlon) and with named dimensions "time", "lat" and "lon", respectively. Then, for each time and latitude, the variance is:
xVarLon= dim_variance( x ) ; ==> xVarLon(ntim,nlat)Generally, users prefer that the returned variable have metadata associated with it. This can be accomplished via the dim_variance_Wrap function:
xVarLon = dim_variance_Wrap( x ) ; ==> xVarLon(time,lat)Example 3
Let x be defined as in Example 2: x(time,lat,lon). Compute the temporal variance at each latitude/longitude grid point. Use NCL's Named Subscripting to reorder the input array such that "time" is the rightmost dimension.
xVarTime = dim_variance( x(lat|:, lon|:, time|:) ) ; ==> xVarTime(nlat,nlon) xVarTime = dim_variance_n( x, 0 ) ; no reordering neededIf metadata is desired use
xVarTime = dim_variance_Wrap( x(lat|:, lon|:, time|:) ) ; ==> xVarTime(lat,lon) xVarTime = dim_variance_n_Wrap( x, 0 ) ; no reordering needed