World Module

class world.Tree_World(topology, AET=1300)[source]

Provide observer methods and control the schedule and execution of simulations.

Args:
topologyTree_Grid instance

Grid object on which agents will live.

AETint

Actual evapotranspiration in the previous year in mm. Assumed to be constant every year.

Attributes:
Smortfloat

Carbon of all trees that died in one year [tC].

Sdead :float)

Dead wood carbon stock [tC].

tsdeadfloat

Anual decomposition rate.

tsdead_Afloat

Proportion of decomposed dead wood that is released to the atmosphere.

Sslowfloat

Slow decomposition portion of soil stock [tC].

tsdead_Sslow :float

Proportion of decomposed dead wood that is tranferred to the slow decomposition Soil stock.

tsslow_Afloat

Proportion of slow decomposition soil stock that is released to the atmosphere.

Sfastfloat

Fast decomposition portion of soil stock [tC].

tsfast_Afloat

Proportion of fast decomposition soil stock that is released to the atmosphere.

tsdead_Sfastfloat

Proportion of decomposed dead wood that is tranferred to the fast decomposition Soil stock.

Cgppfloat

Carbon captured in the gross primary productivity of the living forest.

Crfloat

Carbon released by the total respiration of the living forest (i.e. for maintenance and growth)

Usage:
>>> grid01=Tree_Grid(x_max=5,y_max=5,delta_h=0.5,patch_area=400,I0=860,lday=12,phi_act=360,k=0.7)
>>> world01=Tree_World(topology=grid01)
>>> print(world01)
World object
NEE_data_to_db(nee)[source]

Writes the net ecosystem exchange data to the database.

Adds one row corresponding to the current time step to the NEE table at /sim_#/trees/sys_lvl/NEE.

The following collumns are filled:

dead_wood:

Amount of carbom emissions resulting from dead_wood decomposition.

soil_slow:

Amount of carbom emissions resulting from slow decompositions soil.

soil_fast:

Amount of carbom emissions resulting from fast decompositions soil.

gpp:

Gross primary production. Amount of carbon absorbed by all trees.

living_trees:

Amount of carbom emissions resulting from the respiration of living trees.

smort:

Amount of carbon contained in the trees that died during the past time step.

t_deadwood_sslow:

Amount of carbom tranferred from dead wood to the slow decomposition soil stock.

t_sslow_sfast:

Amount of carbom tranferred from dead wood to the fast decomposition soil stock.

Args:
neefloat

The resulting net ecosystem exchange for the current time step.

Returns: None

calculate_NEE()[source]

Return the Net Ecosystem Exchange (NEE) for the previous timestep.

This is all the carbon that was absorbed by living trees (Cgpp) minus what was emitted to the atmosphere by the living trees (Cr) and the decomposition of the dead wood and soil stocks (tsdead_A+tsslow_A+tsfast_A).

Returns : None

calculate_Sdead()[source]

Calculate the amount of carbon (tC) in the dead wood stock based on the trees that died in the previous year (Smort).

Returns : None

calculate_Sfast()[source]

Calculate the amount of carbon (tC) in the fast decomposition soil stock.

Calculation is based on decomposition rates for the dead wood (tsdead_Sfast) and the rate with which carbon is transferred from this stock to the atmosphere (tsfast_A).

Returns : None

calculate_Sslow()[source]

Calculate the amount of carbon (tC) in the slow decomposition soil stock.

Calculation is based on decomposition rates for the dead wood (tsdead_Sslow) and the rate with which carbon is transferred from this stock to the atmosphere (tsslow_A).

Returns : None

clear_seedbank()[source]

Destroys all the seeds currently in the seedbank

create_HDF_database(database_name)[source]

Create an HDF database to store simulation data.

Structure:

  • root/sim_# : group created using self.simulation number.

  • root/sim_x/sys_lvl: group that holds system level tables.
    • root/sim_x/sys_lvl/NEE: table that holds net ecosystem exchange data.

    • root/sim_x/sys_lvl/Stocks: table that holds carbon stocks data.

    • root/sim_x/sys_lvl/Pop: table that holds population data.

  • root/sim_x/ind_lvl: group that holds system individual level tables.
    • root/sim_x/ind_lvl/Ind: table that holds individual trees data.

Args:
database_name: str

File name (including ‘.h5’ extension) for the database.

Returns: None

create_agents(FT, n, pos=None, ids=None, DBHs=None, ages=None, **kwargs)[source]
Creates ‘n’ trees of type ‘FT’. A list of positions, ids and DBHs

can be provided (Useful to recreate trees from a previous model run, for example).

Note: overwrites methods create_agents from class Agent.

Args:
agent_typeclass

The type (class) of agents to be created

nint

Number of agents to be created

poslist :None

A list of ‘n’ tuples ‘(x,y)’ with the coordinates in which agents will be created. If set to None, agents are created in random positions.

idslist

A list of ‘n’ ints to be used as tree ids.

DBHslist

A list of ‘n’ floats to be used as tree DBHs.

**kwargs

The arguments to be passed to the ‘agent_type’ class. All agents will be created with this same set of arguments.

Returns : None

define_seedbank(Nseed)[source]

Randomly determines how many seed each patch will receive.

Args:
Nseed :int

The total number of seed to be distributed among all patches.

Returnsdict

A dictionary in which keys are patches (‘(x,y)’) and values are the number of seeds.

external_seed_rain()[source]

Creates a seedbank by randomly distibuting seeds across the whole landscape.

Creates ‘Nseed’ seeds for each Functional Type.

Returns: dict

Seedbank as a dictionary with keys as Functional Types and values as a list of seed positions (as in [(x,y),(x,y),…,(x,y)])

germinate_suitable_seeds(seedbank)[source]

Creates new trees from seedbank.external_seedbank

Args:
seedbank: dict

dictionary with keys as Functional Types and values as a list of seed positions (as in [(x,y),(x,y),…,(x,y)])

Returns: None

incorporate_new_seedbank(new_seedbank, clear=True)[source]

Adds new seedbank data to the topology’s seedbank.

Args:
new_seedbank: dict

dictionary with keys as Functional Types and values as a list of seed positions (as in [(x,y),(x,y),…,(x,y)])

clear: bool

True if the current seedbank is to be cleared before the addition. False if the new_seedbank is to be appended to the current one.

Returns: None.

ind_data_to_db(step)[source]

Writes the individual level tree data to the database.

Adds one row for each tree that was alive during the last time step to the NEE table at /sim_#/trees/ind_lvl/Ind.

The following collumns are filled:

step:

Time step.

ind_id:

Numerical identification.

pos_x:

The x coordinate.

pos_y:

The y coordinate.

age:

Age

dbh:

Stem dimater at Breast Height.

agb:

Aboveground biomass.

height:

Height.

crown_area:

Crown area.

FT:

Plant Functional Type name

Returns: None

initial_update()[source]

Updates the topology and tree attributes. To be executed after the first trees are created.

Returns: None

log_trees(suitable_trees, total_vol)[source]

Randomly log ‘suitable_trees’ until the ‘total_vol’ is reached.

Args:
suitable_treesdict

A dictionary with patches as keys ((x,y)) and lists of suitable tree ids as values (resulting from suitable_trees())

total_vol: float

The total vol of timber to be logged

Returns : None

model_status_from_file(input_file)[source]

Recreates a model landscape at a saved stage.

Args:
input_file: str

.json file cataining model data. Usually generated by the model_status_to_file method.

Returns: None

model_status_to_file(output_file)[source]

Writes seedbank to .json file.

If the output file already exists it will be overwritten. The format is {Functional type : {tree id, tree position, tree diameter, tree age}}

Args:
output_file: str

.json file data will contain the data.

Returns: None

pop_data_to_db()[source]

Writes the population data for each Plant Functional Type to the database .

Adds one row corresponding to the current time step to the NEE table at /sim_#/trees/sys_lvl/Pop. Each column corresponds to one PFT.

Returns: None

run_schedule(step, n, h5_database=None)[source]

Schedule of actions to be run in every time step

Args:
stepint

The current step. Received from run_simulation().

h5_databasestr

Path to the HDF5 file in which model outputs will be saved.

Returns:

(float) the Net Ecosystem Exchange (as calculated by ‘calculate_NEE’) for thar step.

run_simulation(n, logging_settings=None, dispersal_settings={'clear': True, 'mode': 'external'}, produce_fruits=True, increment_time=True, h5file=None, plot_func=None, **kwargs)[source]

Run the code in ‘run_schedule’ ‘n’ times.

Args:
nint

Number of simulations to be run.

logging_yearsrange

The years in which selective logging occurs.

min_dbhfloat

Minimum dbh for a tree to be considered suitable for logging.

max_dbhfloat

Maximum dbh for a tree to be considered suitable for logging.

volfloat

Total volume of timber to be extracted by logging event.

h5filestr

Path to the HDF5 file in which model outputs will be saved

plot_funcfunction

A function that will be run every step. Usually a plotting function that saves a image file to the disk.Must accept a ‘step’ argument,which will receive the step number and can be used to generate the file name.

**kwargs

List of keyword arguments to be passed to plot_func in addition to ‘step’.

Returns : None

seedbank_from_file(input_file)[source]

Loads seedbank from json file into the topology’s seedbank attribute..

Args:
input_file: str

.json file cataining seedbank data. Usually generated by the seedbank_to_file method.

Returns: None

seedbank_to_file(output_file)[source]

Writes seedbank to .json file.

If the output file already exists it will be overwritten. The format is {patch number:{Functional type : number of seeds}}

Args:
output_file: str

.json file data will contain the data.

Returns: None

seeds_pos(est_seeds)[source]

Set a random position within the patch for each seed in est_seeds.

Args:
est_seeddict

A dictionary with patches as keys (‘(x,y)’) and the number of established seeds as values.

Returnslist

A list of seed positions within patches.

stablish_new_trees(clear=True)[source]

Create new tree individuals. Uses ‘define_seedbank()’, ‘topology.seed_establishment’ and ‘seeds_pos’.

Note: This method can be substitued by an equivalent in order to incorporate more realistic representations of seed dispersal.

Returns : None

stocks_data_to_db()[source]

Writes the stock data to the database.

Adds one row corresponding to the current time step to the NEE table at /sim_#/trees/sys_lvl/Stocks.

The following collumns are filled:

agb:

Above ground biomass (the biomass of all trees alive durint the past time step.)

dead_wood:

Amount of carbom stored in the dead wood.

soil_slow:

Amount of carbom stored in the slow-decomposition soil.

soil_fast:

Amount of carbom stored in the fast-decomposition soil.

Returns: None

suitable_trees(patches, min_dbh, max_dbh)[source]

Search for suitable trees for logging in the given patches.

Args:
patcheslist

A list of patches (tuples in the format (x,y)).

min_dbhfloat

Minimum dbh (Diameter at Breast Height) for a tree to be considered suitable for logging.

max_dbh :float

Maximum dbh (Diameter at Breast Height) for a tree to be considered suitable for logging.

Returnsdict

A dictionary with patches as keys ((x,y)) and lists of suitable tree ids as values.