How MHS-CBAU works
Authors: Clément Hardy1
Affiliations: 1Université du Québec en Outaouais (UQO)
What happens during a LANDIS-II timestep with MHS-CBAU¶

At every timestep, your LANDIS-II scenario file will call Magic Harvest.
Magic Harvest will then call the main Python script of MHS-CBAU, which will make the management decisions and produce a management map and a Biomass Harvest parameter files.
Magic Harvest will then feed these two files to Biomass Harvest to re-load the parameters of Biomass Harvest and make it harvest during this timestep the exact pixels decided in the management maps the script has created.
Understanding the python script used by MHS-CBAU during the LANDIS-II simulation¶

MHS-CBAU uses two Python scripts; one “main” script, and one that contains functions. Separating the functions in the second script makes the main script easier to read. I will only be talking about the main script today.
Both scripts are heavily commented, explaining everything step-by-step. So if you need to understand something, you can read the scripts (see here for the main script and here for the scripts with the functions; even if you don’t know Python, you will learn a lot.

A quick word before we start about a Python object that I used a lot throughout the scripts of MHS-CBAU, because I find it very useful and clear to use : The Python dictionary.
Dictionaries such as those used in Python do not exist natively in R. As you might be more used to R, I’m taking the time to quickly explain how they work.
Python dictionaries are simply objects that associate a “Key” to a “value”. There can be many keys in a dictionary (as much as you want !), but always one value per key.
A simple example : a dictionary that associates the name of a country to the name of its capital. So here, we see the keys (Germany, Canada, England) and the values for each key (Berlin, Ottawa and London respectively).
We can then use the dictionary simply : by giving the dictionary and a given key (e.g. Canada), Python will return the value associated to the key. Simple !
Three things to remembers :
Keys and values can be anything : numbers, strings, complex objects, etc. For example, we could use a key that is a string with the name of a country (e.g. Canada); and then, the associated value could be a list of all of the cities in the country ! So we associated a string (key) to a list (value).
Keys are unique : only one object can be associated to one key. But the object itself can contain many object, like a list...or even a dictionary ! This opens the door to nested dictionaries. For example, we could associated a country (Canada) to a dictionary which associate cities (of Canada) to their population (a number).
Finaly, keep in mind that dictionaries are mutable. We can add, modify and remove keys and values on the fly.
In MHS-CBAU, I mostly use dictionaries to stock information about the forest stands. The first key of these dictionaries (which are often nested) is almost always the unique identification number of a forest stand. We can then access its age, the coordinates of its pixels, its neighboring stands, its composition and so on through dictionaries, as we’re going to see.

Now, coming back to the main script of MHS-CBAU. We’re going to see what happens in this script. Keep in mind that I’m going to simplify things a bit in the next slide, and not describe you things in every tiny details or line-by-line of code. Also keep in mind that this script will run at each timestep in your LANDIS-II simulation.
First section : Loading inputs.
There are a lot of different inputs. This is because the MHS-CBAU scripts takes into account many different information to define which stands to cuts; with what prescription; how big should be the cut; and when do we stop cutting stands.
There are two kinds of inputs :
Static inputs, which are files or parameters which you prepare before the simulation, and will not change during the simulation.
Dynamic inputs, which are data generated by LANDIS-II and which we will use. It’s mostly the output of the Output Biomass Community extension, which is needed for MHS-CBAU. The ouputs of the extension are files that contain the entire state of the vegetation of the landscape - in the same format of the inputs of the initial conditions of LANDIS-II, meaning a raster map and a text file or csv file.

So when the script is done reading the inputs, it will know a lot of things :
The tree species used in your simulation.
The composition of the vegetation in the LANDIS-II landscape at the current timestep
The repartition of your forest stands in the landscape (their neighboring stands, if they are in a protected area, their age, etc.) and their type (even-aged, uneven-aged, shade tolerant or intolerant species dominating)
Your harvest targets (wood volumes for commercial prescriptions, areas for non-commercial prescriptions)
The numbers needed to convert the aboveground biomass of LANDIS-II into merchantable volumes (for the commercial prescriptions)
The probabilities to choose the right prescriptions for a given stand type, and the probabilities to choose a cut size for a given prescription (e.g. clearcutting)
The repeated prescriptions (prescriptions to do at this time step on certain stands that have been scheduled at previous timesteps)
The path of the template file for Biomass Harvest to edit once we will have taken the management decisions.

The second section prepares some objects for the decisions : the counters for the wood volume we will harvest, a dictionary to know which stands have been harvested, a data frame containing all stands to select them and rank them later, and the empty management map we are going to fill.
The wood volume targets are pulled from federal data with a methodology that I will describe below.

Repeated commercial prescriptions : We use a file generated by the script at previous timesteps that contains a list of stands that have a repeated prescriptions.
If a repeated prescription is triggered at this timestep, we register a “skip” for selection at the next section (new commercial prescriptions). This is to avoid having too many repeated prescriptions in the landscape.

New commercial prescriptions : These are prescriptions that harvest stands with “commercial” prescriptions, meaning those that harvest a merchantable volume. These prescriptions are the four different types that are used in the Canadian National Forestry Dabatase, to make the methodology unified across Canada (even though provinces might have different classifications of prescriptions with more types).
We work with "rounds“; at each round, we are going to harvest a group of stand, and we stop doing rounds until the harvest targets in volume (remember that there were volume targets for commercial prescriptions, and then area targets for non-commercial prescriptions that we will see afterwards).
The wood volume targets can be customized; but in MHS-CBAU, I kept things simple : its only hardwoods, and softwoods. Hardwoods are deciduous tree species/angiosperms. We call them “hardwoods” in forestry because their wood is more complex, often more dense and harder than softwoods. Softwoods are gymnosperms, with a simpler wood structure that grows fasters, and is often less dense and less hard than hardwoods. But you could do many different targets that are more representative of what is done in your landscape. For example, in Quebec, it’s often 4 categories that are reported : Fir and spruce; other softwoods; poplars; and other hardwoods. But again, in MHS-CBAU, we do it simply with hardwoods and softwoods, as it’s the two categories reported in the Canadian National Forestry Database from which we pull values for these targets, as we’ll see in the next part of this workshop.
So, at each round, we select a stand based on the wood volume targets that remain to fill, prioritizing stands with wood from the targets that are yet unfilled. We choose the right prescription for the stand based on its type (even-aged/uneven-aged, shade tolerant/intolerant) and probabilities for each prescriptions/stand type. We randomly choose a cut size from the cut size distributions we have to replicate the real-life variation in cut size. Then we compute how much merchantable wood volume we will harvest with this prescriptions in this cut, we register it; and we go to the next round. We keep going until we fill all wood targets.

What happens when the composition of the landscape changes so much that it is not possible to fill one or several of the targets ? In that case, the script will adapt and do its best, but will end up harvesting a wood volume equal to the sum of all targets in the end.
For example : if you need to harvest 5000 m3 of hardwoods and 5000 m3 of softwoods, but then hardwoods mostly disappear from your landscape because of climate change or other disturbances, then the script will harvest 10 000 m3 of wood no matter what (sum of the targets), but will then mostly harvest softwoods (as it is all that remains in your landscape).

Non-commercial prescriptions : in the case of MHS-CBAU, it’s thinning. Thinning is a prescription where we cut trees in order to help the other ones have more light and space to grow. While some thinning is done commercially (meaning the wood we harvest from the cut trees can be sold), it is very marginal.
Therefore, to simplify things in MHS-CBAU, we consider that all forms of thinning don’t participate to the wood volume harvested. Instead, their implementation is done with “area” targets derived from the inputs, meaning that we will affect a certain number of hectares with thinning instead of trying to harvest a certain volume of wood. This logic can be applied to other types of non-commercial prescriptions you might want to implement in MHS-CBAU (education treatments, etc.).
Here in MHS-CBAU, thinning has the effect of harvesting a lot of biomass of young cohorts; and less and less biomass as we go towards older cohorts. This removes younger trees and lets older trees grow better.
So once we start the loop to harvest forest stand until we have reached the area targets for the thinning prescriptions, we are going to choose stands according to the criterias for thinning, and we harvest them until we reach the area target. It’s pretty similar to commercial prescriptions.

Finally, we write the ouputs : especially the management map and the Biomass Harvest parameter files, which will be given to Biomass Harvest to control the pixels that Biomass Harvest will harvest for the time step (see previous section for more information).