NCL Home > Documentation > Functions > General applied math, Statistics

dim_standardize

Calculates standardized anomalies of the rightmost dimension at all other dimensions.

Prototype

	function dim_standardize (
		x    : numeric,  
		opt  : integer   
	)

	return_val [dimsizes(x)] :  float or double

Arguments

x

A variable of numeric type and any dimensionality.

opt

Setting opt=1 means to use the population standard deviation (i.e., divide by the number of non-missing value [N]). Otherwise, the sample standard deviation is used for normalization (i.e., divide by [N-1]).

Return value

The output is of type double if the input is double, and float otherwise.

The dimensionality is the same as the input dimensionality.

Description

The dim_standardize function calculates and removes the mean from all elements of the n-1th (rightmost) dimension. It then standardizes the rightmost dimension by dividing the resulting deviations from the mean by the standard deviation of the rightmost dimension. These values are often called standardized anomalies. This is repeated for each index of the dimensions 0...n-2. Missing values are ignored.

Use dim_standardize_n if you want to specify which dimension(s) to do the calculation on.

Use the dim_standardize_Wrap function if metadata retention is desired. The interface is identical.

See Also

dim_standardize_n, dim_standardize_Wrap, dim_standardize_n_Wrap, dim_median, dim_stddev, dim_num, dim_product, dim_rmsd, dim_rmvmean, dim_rmvmed, dim_stat4, dim_stddev, dim_sum, dim_variance

Examples

Example 1: Let x be a 1-dimensional array: (a) Create a new variable, xNew, that contains standardized values; (b) replace the variable x with the standardized values. Use the population standard deviation.

  xNew = dim_standardize(x, 1)    ; new variable
  x    = dim_standardize(x, 1)    ; Or, overwrite with deviations

  ; Use dim_standardize_Wrap if metadata retention is desired
  ; xNew = dim_standardize_Wrap(x, 1)    ; new variable
  ; x    = dim_standardize_Wrap(x, 1)    ; Or, overwrite with deviations
Example 2: Let x be a 3-dimensional array with dimension sizes (ntim, nlat, nlon). Standardize values of the the rightmost (here, "nlon") dimension. Use the sample standard deviation.

   xLon = dim_standardize (x,0)         ; new variable
   x       = dim_standardize (x,0)      ; overwrite with deviations

   ; Use dim_standardize_Wrap if metadata retention is desired
   ; xLon =  dim_standardize_Wrap(x,0)         ; new variable
   ; x       = dim_standardize_Wrap (x,0)      ; overwrite with deviations
Example 3: Let x be a 3-dimensional array with named dimensions (time, lat, lon) and dimension sizes (ntim, nlat, nlon). Standardize the values of the time dimension at all lat/lon indices, use NCL's named subscripting to reorder the input array such that "time" is the rightmost dimension.

   xTime = dim_standardize(x(lat|:, lon|:, time|:), 0)
   ; Use dim_standardize_Wrap if metadata retention is desired
   ; xTime = dim_standardize_Wrap(x(lat|:, lon|:, time|:), 0)

Important note: reordering arrays can be an expensive operation, especially if your variable is large or you are repeatedly reordering arrays in your script. Use the dim_standardize_n or dim_standardize_n_Wrap functions to avoid reordering:

   xTime = dim_standardize_n(x, 0, 0)         ; no reordering needed

   ; Use dim_standardize_n_Wrap if metadata retention is desired
   ; xTime = dim_standardize_n_Wrap(x, 0, 0)    ; no reordering needed
Example 4: Let x be as in Example 3 and let x contain monthly means for (say) 10 years of data (ntim=120). Standardized monthly anomalies for each month could be calculated using array subscripting and named subscripting to reorder the input array such that "time" is the rightmost dimension. (opt=0 or 1)

   xJan  = dim_standardize(x(lat|:, lon|:, time|0:ntim-1:12), opt)
   xJuly = dim_standardize(x(lat|:, lon|:, time|6:ntim-1:12), opt)

   ; Use dim_standardize_Wrap if metadata retention is desired
   ; xJan  = dim_standardize_Wrap(x(lat|:, lon|:, time|0:ntim-1:12), opt)
   ; xJuly = dim_standardize_Wrap(x(lat|:, lon|:, time|6:ntim-1:12), opt)
Use the dim_standardize_n or dim_standardize_n_Wrap functions to avoid reordering and retain metadata:

   xJan  = dim_standardize_n(x(0:ntim-1:12,:,:), opt, 0)
   xJuly = dim_standardize_n(x(6:ntim-1:12,:,:), opt, 0)

   ; Use dim_standardize_n_Wrap if metadata retention is desired
   ; xJan  = dim_standardize_n_Wrap(x(0:ntim-1:12,:,:), opt, 0)
   ; xJuly = dim_standardize_n_Wrap(x(6:ntim-1:12,:,:), opt, 0)