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

dim_rmsd

Computes the root-mean-square-difference between two variables' rightmost dimension at all other dimensions.

Prototype

	function dim_rmsd (
		x  : numeric,  
		y  : numeric   
	)

	return_val  :  float or double

Arguments

x

A variable of numeric type and any dimensionality.

y

A variable of numeric type and same dimensionality as x.

Return value

The output will be double if x is double, and float otherwise.

The output dimensionality is the same as the first n-1 dimensions of the input variable. That is, the dimension rank of the input variable will be reduced by one.

Description

The dim_rmsd function computes the root-mean-square-difference of all elements of the n-1 dimension for each index of the dimensions 0...n-2. Missing values are ignored.

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

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

See Also

dim_rmsd_Wrap, dim_rmsd_n, dim_rmsd_n_Wrap, dim_avg, dim_median, dim_num, dim_product, dim_rmsd_n, dim_rmvmean, dim_rmvmed, dim_standardize, dim_stat4, dim_sum

Examples

Example 1

Create two variables q nd r of size (3,5,10) array. Then calculate the root-mean-square-difference of the rightmost dimension.

    q   = random_uniform(-20,100,(/3,5,10/))
    r   = random_uniform(-50, 99,(/3,5,10/))
    rmsd= dim_rmsd(q,r)   ;==>  rmsd(3,5)

    ; Use dim_rmsd_Wrap if metadata retention is desired
    ; rmsd= dim_rmsd_Wrap(q,r)   ;==>  rmsd(3,5)
Example 2

Let x and y be of size (ntim,nlat,mlon) and with named dimensions "time", "lat" and "lon", respectively. Then, for each time and latitude, the root-mean-square-difference is:

    rmsdLon= dim_rmsd( x,y )    ; ==> rmsdLon(ntim,nlat)

    ; Use dim_rmsd_Wrap if metadata retention is desired
    ; rmsdLon= dim_rmsd_Wrap( x,y )    ; ==> rmsdLon(ntim,nlat)
Example 3

Let x be defined as in Example 2: x(time,lat,lon). Compute the temporal root-mean-square-difference at each latitude/longitude grid point. Use named subscripting to reorder the input array such that "time" is the rightmost dimension.

    rmsdTime = dim_rmsd( x(lat|:,lon|:,time|:), \ 
    y(lat|:,lon|:,time|:) )    
    ; ==> rmsdTime(nlat,nlon)

    ; Use dim_rmsd_Wrap if metadata retention is desired
    ; rmsdTime = dim_rmsd_Wrap( x(lat|:,lon|:,time|:), \
    ; y(lat|:,lon|:,time|:) )    
    ; ==> rmsdTime(nlat,nlon)

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:

    rmsdTime = dim_rmsd_n( x, y, 0 )                                       
    ; ==> no reordering needed

    ; Use dim_rmsd_n_Wrap if metadata retention is desired
    ; rmsdTime = dim_rmsd_n_Wrap( x, y, 0 )