venn2_difference
Returns the unique element symmetric differences between two arrays.
Available in version 6.4.0 and later.
Prototype
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" ; This library is automatically loaded
; from NCL V6.2.0 onward.
; No need for user to explicitly load.
function venn2_difference (
a : numeric, string, character,
b : numeric, string, character
)
return_val [*] : same type as a
Arguments
aAn array of any type and size.
bAn array of the same type as a. It may have a different size and shape.
Return value
A scalar or one-dimensional array containing the elements that form the difference of the input arrays. The result is independent of the input order.
Description
The symmetric DIFFERENCE of two sets (here, a and b) is the set of elements which are in either of the sets and not in their intersection. For example: let A = (1,2,3) and B = (3,4,5). The DIFFERENCE of A and B, written A difference B = (1,2,4,5).
NCL has a limited suite of simple Venn_diagram functions: (i) venn2_difference, (ii) venn2_intersection and (iii) venn2_union. Pictoral depictions are here.
See Also
venn2_intersection, venn2_union, get_unique_values, count_unique_values
Examples
Example 1: Return the unique different elements of two arrays. The result is independent of the input order.
A = (/"a", "e", "i", "o", "u", "y" /) B = (/"a", "b", "c", "d", "e", "f", "g", "h" /) ABd = venn2_difference(A, B) ; ABd= (/"b","c","d","f","g","h","i","o","u","y" /) BAd = venn2_difference(B, A) ; BAd = ABd
Example 2: Return the unique different elements of three arrays. The result is independent of the input order.
A = (/"a", "e", "i", "o", "u", "y" /) B = (/"a", "b", "c", "d", "e", "f", "g", "h" /) C = (/"a","b", "q", "y", "z"/) AC = array_append_record(A, C, 0) ; AC = (/"a","e","i","o","u","y","a", "b", "q", "y", "z"/) ACBd = venn2_difference(AC,B) ; ACBd= (/"c","d","f","g","h","i","o","q","u","y","z" /)
Example 3
date1 = (/"1979-01-01-00000","1979-01-02-00000","1979-01-08-00000","1979-01-06-00000" \
,"1980-12-12-00000","1981-01-02-00000","1988-05-06-00000","1988-05-06-00000" /)
date2 = (/"1979-05-01-00000","1979-01-01-00000","1979-01-06-00000","1981-01-02-00000" \
,"1981-01-02-00000","1987-01-02-00000","1988-05-06-00000"/)
DATE = venn2_difference(date1, date2) ; DATE = (/"1979-01-02-00000", "1979-01-08-00000" \
,"1979-05-01-00000", "1980-12-12-00000" \
,"1987-01-02-00000"/)
Example 4
The venn2_difference function allows arrays of different sizes and shapes.
y = (/ (/1.5, 2.8, 1.6/), (/3.1, 1.5, 9.9/), (/2.8, 2.8, 2.8/) /) ; 3 x 3 x = (/ 1.5, 1.6, 3.1, 2.8, 2.8 /) ; [5] yxd = venn2_difference(y, x) ; yxd = (/ 9.9 /)
Example 5: Use all three Venn based venn2_* functions.
models_rcp26 = (/"CanESM2", "CCSM4", "CESM1-CAM5", "CNRM-CM5", "CSIRO-Mk3-6-0" \
,"FIO-ESM", "GFDL-CM3", "GFDL-ESM2G", "GFDL-ESM2M", "GISS-E2-H" \
,"GISS-E2-R", "HadGEM2-AO", "HadGEM2-ES", "IPSL-CM5A-LR" \
,"IPSL-CM5A-MR", "MIROC5", "MIROC-ESM", "MIROC-ESM-CHEM" \
,"MPI-ESM-LR", "MPI-ESM-MR", "MRI-CGCM3", "NorESM1-M", "NorESM1-ME"/)
models_rcp45 = (/"ACCESS1-0", "ACCESS1-3", "bcc-csm1-1", "bcc-csm1-1-m", "BNU-ESM" \
,"CanCM4", "CanESM2", "CCSM4", "CESM1-BGC", "CESM1-CAM5" \
,"CESM1-CAM5-1-FV2", "CMCC-CM", "CMCC-CMS", "CNRM-CM5", "CSIRO-Mk3-6-0"\
,"CSIRO-Mk3L-1-2", "FIO-ESM", "GFDL-CM2p1", "GFDL-CM3", "GFDL-ESM2G" \
,"GFDL-ESM2M", "GISS-E2-H", "GISS-E2-H-CC", "GISS-E2-R", "GISS-E2-R-CC"\
,"HadCM3", "HadGEM2-AO", "HadGEM2-CC", "HadGEM2-ES", "inmcm4" \
,"IPSL-CM5A-LR", "IPSL-CM5A-MR", "IPSL-CM5B-LR", "MIROC5", "MIROC-ESM" \
,"MIROC-ESM-CHEM", "MPI-ESM-LR", "MPI-ESM-MR", "MRI-CGCM3", "NorESM1-M"\
,"NorESM1-ME"/)
models_rcp85 = (/"ACCESS1-0", "ACCESS1-3", "bcc-csm1-1", "bcc-csm1-1-m", "BNU-ESM" \
,"CanESM2", "CCSM4", "CESM1-BGC", "CESM1-CAM5", "CESM1-CAM5-1-FV2" \
,"CMCC-CESM", "CMCC-CM", "CMCC-CMS", "CNRM-CM5", "CSIRO-Mk3-6-0", "FIO-ESM" \
,"GFDL-CM3", "GFDL-ESM2G", "GFDL-ESM2M", "GISS-E2-H", "GISS-E2-H-CC" \
,"GISS-E2-R", "GISS-E2-R-CC", "HadGEM2-AO", "HadGEM2-CC", "HadGEM2-ES" \
,"inmcm4", "IPSL-CM5A-LR", "IPSL-CM5A-MR", "IPSL-CM5B-LR", "MIROC5" \
,"MIROC-ESM", "MIROC-ESM-CHEM", "MPI-ESM-LR", "MPI-ESM-MR", "MRI-CGCM3"\
,"MRI-ESM1", "NorESM1-M", "NorESM1-ME"/)
printVarSummary(models_rcp26) ; 23
printVarSummary(models_rcp45) ; 41
printVarSummary(models_rcp85) ; 39
; Venn results on two data sets; all three operations
uu_rcp_2645 = venn2_union(models_rcp26, models_rcp45 ) ; union
print(uu_rcp_2645)
ui_rcp_2645 = venn2_intersection(models_rcp26, models_rcp45 ) ; intersection
print(ui_rcp_2645)
ud_rcp_2645 = venn2_difference(models_rcp26, models_rcp45 ) ; difference
print(ud_rcp_2645)
print("==================================")
; Use the above '2645' results with the rcp_85
uu_rcp_2645_85 = venn2_union(uu_rcp_2645, models_rcp85 )
print(uu_rcp_2645_85)
ui_rcp_2645_85 = venn2_intersection(ui_rcp_2645, models_rcp85 )
print(ui_rcp_2645_85)
ud_rcp_2645_85 = venn2_difference(ud_rcp_2645, models_rcp85 )
print(ud_rcp_2645_85)
print("==================================")
The printed output is
here.