@log_start_end<EOL>@doc_sub(metric_params, metric_return, cols_note, splits_note)<EOL>def comm_grid(patch, cols, splits, divs, metric='<STR_LIT>'):
(spp_col, count_col, x_col, y_col), patch =_get_cols(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'], cols, patch)<EOL>result_list = []<EOL>for substring, subpatch in _yield_subpatches(patch, splits):<EOL><INDENT>spatial_table = _yield_spatial_table(subpatch, divs, spp_col,<EOL>count_col, x_col, y_col)<EOL>spp_set = spatial_table['<STR_LIT>']<EOL>cell_loc = spatial_table['<STR_LIT>']<EOL>n_spp = spatial_table['<STR_LIT>']<EOL>pair_list = []<EOL>dist_list = []<EOL>comm_list = []<EOL>for i in range(len(spatial_table)):<EOL><INDENT>for j in range(i+<NUM_LIT:1>, len(spatial_table)):<EOL><INDENT>iloc = np.round(cell_loc[i], <NUM_LIT:6>)<EOL>jloc = np.round(cell_loc[j], <NUM_LIT:6>)<EOL>pair_list.append('<STR_LIT:(>'+str(iloc[<NUM_LIT:0>])+'<STR_LIT:U+0020>'+str(iloc[<NUM_LIT:1>])+'<STR_LIT>'+<EOL>'<STR_LIT:(>'+str(jloc[<NUM_LIT:0>])+'<STR_LIT:U+0020>'+str(jloc[<NUM_LIT:1>])+'<STR_LIT:)>')<EOL>dist_list.append(_distance(cell_loc[i], cell_loc[j]))<EOL>ij_intersect = spp_set[i] & spp_set[j]<EOL>if metric.lower() == '<STR_LIT>':<EOL><INDENT>comm = <NUM_LIT:2>*len(ij_intersect) / (n_spp[i] + n_spp[j])<EOL><DEDENT>elif metric.lower() == '<STR_LIT>':<EOL><INDENT>comm = len(ij_intersect) / len(spp_set[i] | spp_set[j])<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>comm_list.append(comm)<EOL><DEDENT><DEDENT>subresult = pd.DataFrame({'<STR_LIT>': pair_list, '<STR_LIT:x>': dist_list,<EOL>'<STR_LIT:y>': comm_list})<EOL>result_list.append((substring, subresult))<EOL><DEDENT>return result_list<EOL>
Calculates commonality as a function of distance for a gridded patch

Parameters
----------
{0}
divs : str
    Description of how to divide x_col and y_col. Unlike SAR and EAR, only
    one division can be given at a time. See notes.
metric : str
    One of Sorensen or Jaccard, giving the metric to use for commonality
    calculation

Returns
-------
{1} Result has three columns, pair, x, and y, that give the locations of
the pair of patches for which commonality is calculated, the distance
between those cells, and the Sorensen or Jaccard result.

Notes
-----
{2}

For gridded commonality, cols must also contain x_col and y_col, giving the
x and y dimensions along which to grid the patch.

{3}