Community Class

class ecolopy_dev.community.Community(data, j_tot=None)[source]

Main community class.

Parameters:
  • data

    containing species count, can be given in one of:

    • python list, each element being a species count
    • text file containing one species count per line
    • pickle file containing community object
  • j_tot (None) – is the size of the metacommunity, if not defined j_tot = J * 3
Returns:

an Community object

Examples:

# python list
abd = Community([1, 1, 2, 3, 4, 8, 12])
# text file
abd = Community("bci.txt", j_tot=256987)
# finally a saved Community object
abd = Community("abundance_bci_first_try.pik")
draw_rsa(outfile=None, filetype=None, size=(15, 15))[source]

Draw Relative Species Abundances curve.

Parameters:
  • outfile (None) – path were image will be saved, if none, plot will be shown using matplotlib GUI
  • filetype (None) – pdf or png
  • size ((15,15)) – size in inches of the drawing
dump_community(outfile, force=False)[source]

save params and kda with pickle force option is for writing pickle with no consideration if existing

Parameters:
  • outfile – path of the outfile
  • force (False) – overwrite existing outfile
fit_model(name='ewens', **kwargs)[source]

Fit Community to model. Extra arguments can be pssed depending on the model to fit. See doc of its corresponding optimize function.

Parameters:name (Ewens) – name of the model, between Etienne, Ewens or Log-normal
Returns:model
generate_random_neutral_distribution(model=None, J=None)[source]

return distribution of abundance, according to a given model and a given community size. if none of them are given, values of current Community are used.

Parameters:
  • model (None) – model name (default current model)
  • J (None) – size of wanted community (default size of the community of current abundance)
Returns:

random neutral distribution of abundances

get_current_model_name()[source]
Returns:current model name
get_model(name)[source]
Parameters:name – name of a computed model
Returns:a EcologicalModel object corresponding to one of the computed models
iter_models()[source]

iterate over pre computed models

Returns:model object
load_community(infile)[source]

load params and kda with pickle from infile WARNING: do not overwrite values of params.

Parameters:infile – path of the outfile
lrt(model_1, model_2, dgf=1)[source]

likelihood-ratio-test between two neutral models

Parameters:
  • model_1 – string representing simplest model, usually Ewens
  • model_2 – string representing most complex model, usually Etienne
  • dgf (1) – number of degrees of freedom (1 when comparing Etienne and Ewens)
Returns:

p-value of rejection of alternative model

eg: usually ewens, etienne. And if pval < 0.05 than use etienne

rsa_ascii(width=100, height=50, pch='o')[source]

Draw Relative Species Abundances curve (ASCII format).

Parameters:
  • width (100) – width in term of characters
  • height (100) – height in term of characters
  • pch (o) – dot character
Returns:

string corresponding to plot

set_current_model(name)[source]

set on model as default/current model.

Parameters:name – model name of precomputed model
set_model(model)[source]

add one model computed externally to the computed models of current Community object

Parameters:model – model object
test_neutrality(model='ewens', gens=100, full=False, fix_s=False, tries=1000, method='shannon', verbose=False, n_cpus=1)[source]

test for neutrality comparing Shannon entropy if (Hobs > Hrand_neut) then evenness of observed data is higher then neutral

Parameters:
  • model (ewens) – model name otherwise, current model is used
  • gens (100) – number of random neutral distributions to generate
  • full (False) – also return list of compared values (H or lnL) for simulated abundances
  • fix_s (False) – decide whether to fix or not the number of species for the generation of random neutral communities
  • tries (False) – in case S is fixed, determines the number of tries in order to obtain the exact same number of species as original community. In case The number of tries is exceeded, an ERROR message is displayed, and p-value returned is 1.0.
  • method (shannon) – can be either ‘Shannon’ for comparing Shannon’s entropies or ‘loglike’ for comparing log-likelihood values (Etienne 2007). Last method is much more computationally expensive, as likelihood of neutral distribution must be calculated.
  • n_cpus (1) – number of CPUs to use
Returns:

p_value if full=True also returns Shannon entropy (or likelihoods if method=’loglike’) of all random neutral abundances generated