@log_start_end<EOL>@doc_sub(metric_params, metric_return, cols_note, splits_note, division_note,<EOL>start_emp_example)<EOL>def sar(patch, cols, splits, divs, ear=False):
def sar_y_func(spatial_table, all_spp):<EOL><INDENT>return np.mean(spatial_table['<STR_LIT>'])<EOL><DEDENT>def ear_y_func(spatial_table, all_spp):<EOL><INDENT>endemic_counter = <NUM_LIT:0><EOL>for spp in all_spp:<EOL><INDENT>spp_in_cell = [spp in x for x in spatial_table['<STR_LIT>']]<EOL>spp_n_cells = np.sum(spp_in_cell)<EOL>if spp_n_cells == <NUM_LIT:1>:  <EOL><INDENT>endemic_counter += <NUM_LIT:1><EOL><DEDENT><DEDENT>n_cells = len(spatial_table)<EOL>return endemic_counter / n_cells <EOL><DEDENT>if ear:<EOL><INDENT>y_func = ear_y_func<EOL><DEDENT>else:<EOL><INDENT>y_func = sar_y_func<EOL><DEDENT>return _sar_ear_inner(patch, cols, splits, divs, y_func)<EOL>
Calculates an empirical species area or endemics area relationship

Parameters
----------
{0}
divs : str
    Description of how to divide x_col and y_col. See notes.
ear : bool
    If True, calculates an endemics area relationship

Returns
-------
{1} Result has 5 columns; div, x, and y; that give the ID for the
division given as an argument, fractional area, and the mean species
richness at that division.

Notes
-----
{2}

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

{3}

{4}

Examples
--------

{5}

>>> # Get the SAR at the full area (1,1), 1 x 2 division,
>>> # 2 x 1 division, 2 x 2 division, 2 x 4 division, 4 x 2 division, and
>>> # 4 x 4 division
>>> sar = meco.empirical.sar(pat,
            cols='spp_col:spp; count_col:count; x_col:row; y_col:column',
            splits="",
            divs="1,1; 1,2; 2,1; 2,2; 2,4; 4,2; 4,4")

>>> sar[0][1]
   div  n_individs    n_spp   x        y
0  1,1   2445.0000  24.0000  16  24.0000
1  1,2   1222.5000  18.5000   8  18.5000
2  2,1   1222.5000  17.0000   8  17.0000
3  2,2    611.2500  13.5000   4  13.5000
4  2,4    305.6250  10.1250   2  10.1250
5  4,2    305.6250  10.5000   2  10.5000
6  4,4    152.8125   7.5625   1   7.5625

The column div gives the divisions specified in the function call. The
column n_individs specifies the average number of individuals across the
cells made from the given division. n_spp gives the average species across
the cells made from the given division. x gives the absolute area of a
cell for the given division. y gives the same information as n_spp and is
included for easy plotting.

See http://www.macroeco.org/tutorial_macroeco.html for additional
examples and explanation