venn2_intersection
Returns the unique element intersection (ie., common values) 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_intersection ( a : numeric, string, character, b : numeric, string, character ) return_val [*] : same type as a
Arguments
aAn array of any shape 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 intersection of the input arrays. The result is independent of the input order.
Description
The INTERSECTION of two sets (here, a and b) is the set of elements which are in both sets. For example: let A = (1,2,3) and B = (3,4,5). The INTERSECTION of A and B, written A intersection B = (3).
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_union, venn2_difference, get_unique_values, count_unique_values
Examples
Example 1
Return the intersection of two arrays. Note that the result is independent of the input order.
A = (/"a", "e", "i", "o", "u", "y" /) B = (/"a", "b", "c", "d", "e", "f", "g", "h" /) ABi = venn2_intersection(A, B) ; ABi = (/"a", "e"/) BAi = venn2_intersection(B, A) ; BAi = (/"a", "e"/)
Example 2: Return the unique intersection 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"/) ACBi = venn2_intersection(AC,B) ; ACBi= (/"a","b","e" /)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_intersection(date1, date2) print(DATE)The output would be
Variable: DATE Type: string Total Size: 32 bytes 4 values Number of Dimensions: 1 Dimensions and sizes: [4] Coordinates: Number Of Attributes: 2 _FillValue : missing tag : NCL: venn2_intersection has created the result (0) 1979-01-01-00000 (1) 1979-01-06-00000 (2) 1981-01-02-00000 (3) 1988-05-06-00000
Example 4: The venn2_intersection 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] yxi = venn2_intersection(y3, x) ; yxi = (/1.5, 1.6, 2.8, 3.1/)
Example 5: Use all three Venn based venn2_* functions.
Example 6: 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.