NCL Home > Documentation > Functions > General applied math

# wgt_volrmse

Calculates a weighted volume root-mean-square-difference between two variables.

## Prototype

```	function wgt_volrmse (
q        : numeric,
r        : numeric,
wgtz [*] : numeric,
wgty [*] : numeric,
wgtx [*] : numeric,
opt      : integer
)

return_val  :  float or double
```

## Arguments

q

An array of 3 or more dimensions containing the data to be differenced. The rightmost dimensions should correspond to "level" (lev), "latitude" (lat) and "longitude" (lon) when dealing with quantities on a sphere ([...,],lev,lat,lon), and "z", "y", and "x" otherwise ([...,],z,y,x).

r

An array of 3 or more dimensions containing the data to be differenced. The rightmost dimensions should correspond to "level" (lev), "latitude" (lat) and "longitude" (lon) when dealing with quantities on a sphere ([...,],lev,lat,lon), and "z", "y", and "x" otherwise ([...,],z,y,x).

wgtz

A scalar (typically 1.0) or 1-dimensional array of size "level" (z) containing the weights. A scalar value of 1.0 means no weighting.

wgty

A scalar (typically 1.0) or 1-dimensional array of size "lat" (y) containing the weights. A scalar value of 1.0 means no weighting.

wgtx

A scalar (typically 1.0) or 1-dimensional array of size "lon" (x) containing the weights. A scalar value of 1.0 means no weighting.

opt

If opt = 0, the area average is calculated using available non-missing data. If opt = 1, then if any point in q is missing, the area average is not computed. In this case, it will be set to the missing value, which is indicated by q@_FillValue, or the default missing value if q@_FillValue is not set.

## Return value

Returns an array of the same dimensionality as the leftmost dimensions of q.

The return type is floating point if the input is floating point, and double if the input is of type double.

## Description

This function computes the volume root-mean-square-difference [rmse] between two variables using weights.

Note: for NCL versions 6.4.0 and earlier, this function had a bug that caused the wrong values to be returned due to an internal value being squared twice. This has been fixed in NCL V6.5.0.

## Examples

Example 1

Let q(time, lev, lat, lon) be a global array with dimension sizes ktime = 120, nlev = 28, nlat = 64, mlon = 128; wgtz(klev) be a 1D array containing the log of pressure; wgty(nlat) be a 1D array containing gaussian or cosine weights; assume that no special weighting is applied in the longitude (x) direction. Then:

```  glRmse = wgt_volrmse(q, r, wgtz, wgty, 1.0, 0)   ; glRmse(ktime)
```
will calculate the volume (global) rmse for each time. glRmse will be a 1D array with dimension (ktime = 120). If a missing value is encountered at any of the two rightmost dimensions it is ignored (equivalent to a weight of 0.0) and the rmse is calculated using available non-missing data (opt = 0).

Example 2

```  nhRmse = wgt_volrmse(q(:, :, 33:nlat - 1, :), wgtz, wgty(33:nlat - 1), 1.0, 1)
```
will calculate the volume (northern hemisphere) rmse for each time. Standard subscripting is used to subset the input global array. nhRmse will be a 1D array with dimensions (ktime = 120). If a missing value is encountered at any of the two rightmost dimensions then the result will be set to _FillValue (opt = 1).

Example 3

```  shRmse = wgt_volrmse(q(:, 5:7, {lat | -90:0}, :), wgtz(5:7), wgty({lat | -90:0}), 1.0,0)
```
will calculate the volume (southern hemisphere) rmse for each time using levels 5, 6, 7. Coordinate subscripting and standard subscripting are used to subset the input global array. shRmse will have dimensions (ktime).
{"ft_lang_label":"__label__en","ft_lang_prob":0.7224258,"math_prob":0.9966803,"size":3609,"snap":"2022-05-2022-21","text_gpt3_token_len":1047,"char_repetition_ratio":0.11900139,"word_repetition_ratio":0.24783362,"special_character_ratio":0.2765309,"punctuation_ratio":0.2,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9982207,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-25T16:56:48Z\",\"WARC-Record-ID\":\"<urn:uuid:22aa609f-2849-4fd9-9596-69e8e559b1b1>\",\"Content-Length\":\"19138\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2eb9751f-8e8b-4b64-95b4-593395752fe2>\",\"WARC-Concurrent-To\":\"<urn:uuid:409bd1ed-8bb9-4675-8959-55c5593b3772>\",\"WARC-IP-Address\":\"128.117.225.48\",\"WARC-Target-URI\":\"http://www.ncl.ucar.edu/Document/Functions/Built-in/wgt_volrmse.shtml\",\"WARC-Payload-Digest\":\"sha1:ACSGD6CA5DQQDZG4Q7CW3NESJWWWMLWZ\",\"WARC-Block-Digest\":\"sha1:DUOJBKQS2R4ETZEQHSVR27H54ZOJSPIE\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662588661.65_warc_CC-MAIN-20220525151311-20220525181311-00729.warc.gz\"}"}