
ismissing
Returns True for every element of the input that contains a missing value (_FillValue).
Prototype
function ismissing ( data ) return_val [dimsizes(data)] : logical
Arguments
dataA variable of any type and dimensionality.
Return value
Returns a logical value (True or False) for each data value.
Description
For each element in data, ismissing returns True if the element is a missing value, and False otherwise.
ismissing is the only way to check for missing values (_FillValue). Conventional direct if checks:
if (data(32).eq.data@_FillValue) if (any(data.eq.data@_FillValue)) if (all(data.eq.data@_FillValue))will not work. This behavior is analogous to checking for NaN in many languages. A direct check [eg: x.eq.NaN ] will not work. A function must be used.
This is useful for filtering missing values.
See Also
set_default_fillvalue, default_fillvalue, ind
Examples
Example 1
If your data can contain all missing values, you may want to check this before doing a calculation on it or trying to plot it:
if(all(ismissing(data))) then print("Your data is all missing. Cannot create plot.") else plot = gsn_csm_contour(wks,data,res) end if
Example 2
If you want to print a warning message if your data contains some missing values:
if(any(ismissing(data))) then print("Your data contains some missing values. Beware.") end if
Example 3
Assume you want to calculate the standard deviation of your data, and you also want to know how many data points were used to calculate this quantity:
x = stddev(data) N = num(.not.ismissing(data))
Example 4
The ismissing function is often used in conjunction with the ind function. The code snippet below shows how to take all elements of lon_values longitude array, and create a new array that has the longitude values followed by a "E" or "W" (for "East" or "West"), or "Eq" for the equator:
lon_labels = new(dimsizes(lon_values),string) lonW_index = ind(-180.lt.lon_values.and.lon_values.lt. 0) lonE_index = ind( 0.lt.lon_values.and.lon_values.lt.180) if(.not.all(ismissing(lonW_index))) lon_labels(lonW_index) = fabs(lon(lonW_index)) + "W" ; west end if if(.not.all(ismissing(lonE_index))) lon_labels(lonE_index) = lon_values(lonE_index) + "E" ; east end if ; Clean up (not necessary) delete(lonW_index) delete(lonE_index) delete(lon0_index)
Example 5: Consider x[*] with _FillValue attribute: (a) count the number of _FillValue (missing values); (b) extract only the non-missing values.
nmsg = num(ismissing(x)) ; count number of missing igood = ind(.not.ismissing(x)) xgood = x(igood) print(xgood)