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

dim_rmvmean

Calculates and removes the mean of the (rightmost) dimension at all other dimensions.

Prototype

	function dim_rmvmean (
		x  : numeric   
	)

	return_val [dimsizes(x)] :  float or double

Arguments

x

A variable of numeric type and any dimensionality.

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_rmvmean function calculates and removes the mean from all elements of the n-1th (rightmost) dimension for each index of the dimensions 0...n-2. Missing values are ignored.

Use dim_rmvmean_n if you want to specify which dimension(s) to remove the mean from.

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

See Also

dim_rmvmean_n, dim_rmvmed, dim_rmvmean_Wrap, dim_rmvmed_Wrap, dim_rmvmean_n_Wrap, dim_rmvmed_n_Wrap

Examples

Example 1: Let x be a 1-dimensional array: (a) Create a new variable, xNew, that contains just the deviations from the mean; (b) replace the variable x with the deviations.

  xNew = dim_rmvmean(x)      ; new variable
  x    = dim_rmvmean(x)      ; overwrite with deviations

  ; Use dim_rmvmean_Wrap if metadata retention is desired
  ; xNew = dim_rmvmean_Wrap(x)      ; new variable
  ; x    = dim_rmvmean_Wrap(x)      ; overwrite with deviations
Example 2: Let x be a 3-dimensional array with dimension sizes (ntim, nlat, nlon). To remove the means of the "nlon" dimension:

   xRmvLon = dim_rmvmean (x)         ; new variable containing deviations (no metadata)
   x       = dim_rmvmean (x)         ; overwrite with deviations

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

   xRmvTime = dim_rmvmean(x(lat|:, lon|:, time|:))

   ; Use dim_rmvmean_Wrap if metadata retention is desired
   ; xRmvTime = dim_rmvmean_Wrap(x(lat|:, lon|:, time|:))
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_rmsd_n or dim_rmsd_n_Wrap functions to avoid reordering:

   xRmvTime = dim_rmvmean_n(x,0)      ; no reordering needed

   
   ; Use dim_rmvmean_n_Wrap if metadata retention is desired
   ; xRmvTime = dim_rmvmean_n_Wrap(x,0)
Example 4: Let x be as in Example 3 and let x contain monthly means for (say) 10 years of data (ntim=120). 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.

   xRmvJan  = dim_rmvmean(x(lat|:, lon|:, time|0:ntim-1:12))
   xRmvJuly = dim_rmvmean(x(lat|:, lon|:, time|6:ntim-1:12))

   ; Use dim_rmvmean_Wrap if metadata retention is desired
   ; xRmvJan  = dim_rmvmean_Wrap(x(lat|:, lon|:, time|0:ntim-1:12))
   ; xRmvJuly = dim_rmvmean_Wrap(x(lat|:, lon|:, time|6:ntim-1:12))

The following code does not require reordering:

   xRmvJan  = dim_rmvmean_n(x(0:ntim-1:12,:,:), 0)   ; no reordering needed
   xRmvJuly = dim_rmvmean_n(x(6:ntim-1:12,:,:), 0)        

   ; Use dim_rmvmean_n_Wrap if metadata retention is desired
   ; xRmvJan  = dim_rmvmean_n_Wrap(x(0:ntim-1:12,:,:),0)      ; no reordering needed
   ; xRmvJuly = dim_rmvmean_n_Wrap(x(6:ntim-1:12,:,:),0)