So far we have been using top down models, that modeled the whole population, but not individual lives. Today, in the last day of the module, you will explore bottom up stochastic spatial models. Spatial models assume that individuals have their locations. In out case we will model forest on a grid. Each grid cell will be our modelling unit. The forest in the cell growths every iteration (let’s say a year, but it could also be a month). If the fire comes close to the forest (and it is not just burned at a previous iteration) then it might ignite with some probability, proportional to the number of burning cells around. Having this probability of an event, makes this model stochastic - we cannot tell before hand how the system will behave, and every time one reruns the simulations the results will change.

The general idea of our simulation is to try maximizing amount of carbon, stored in the forest. As soon as forest burns - carbon gets released into atmosphere.

1. Forest simulation

Generate a sample forest of 0 age

n <- 100
m <- 100

Age<-matrix(0, ncol=n, nrow=m)
nYears<-1000

color.set<-colorRampPalette(c('#f7fcb9', '#31a354')) # creates a function that will generate colors
forest.colors<-c('red', color.set(200))
image(Age, col=forest.colors )

We want to measure how much carbon forest accumulates. So while forest growth we will estimate total carbon, that is proportional to the sum of age of forest in the grid. Each year each grid cell (of 50 by 50 meters) accumulates 500 kg of carbon per year.

nYears<-1000
Total_carbon<-rep(NA, nYears)

Now we can make a loop, that will make forest grow:

for (i in 1:nYears) {
  Age <- Age+1
  Total_carbon[i]<- sum(Age)*500
}

plot(Total_carbon, type='l')

This is what would happen with the forest if no fires happened. Now we will introduce some fires. When a grid cell burns the age of the cell becomes 0. To know whether the current cell is going to burn we need to know, how many zeroes are in the neighborhood. For this task we will we will need a function neighbours() from simecol package. This function requires a matrix that defines how to weight the neighboring cells.

# install.packages(simecol)
library(simecol)
## Loading required package: deSolve
wdist_fire<-matrix(c(0,0,0.5,0,0,
                    0,0.5, 1, 0.5, 0,
                    0.5, 1, 0, 1, 0.5,
                    0,0.5, 1, 0.5, 0,
                    0,0,0.5,0,0), ncol=5, byrow=TRUE)
wdist_fire
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  0.0  0.0  0.5  0.0  0.0
## [2,]  0.0  0.5  1.0  0.5  0.0
## [3,]  0.5  1.0  0.0  1.0  0.5
## [4,]  0.0  0.5  1.0  0.5  0.0
## [5,]  0.0  0.0  0.5  0.0  0.0

Look at the current matrix we generated for the function - it has

Q1. Please explain why this formula works.

Based on the impact of N nearby cells, the likelihood of a cell catching fire is calculated using the formula \(P_i = 1 - (1 - \text{prob_fire})^N\). The independent probability concept underlies its operation. \(\text{prob_fire}\) refers to the probability of an ignition from a single neighbor. The formula initially computes \((1 - \text{prob_fire})^N\), the probability that a given cell will not catch fire from any of its N neighbors, in the case of multiple cells. The possibility that the cell will catch fire from at least one of its N neighbors is represented by the ultimate ignition probability, which is the complement of this. According to this method, every neighbor has an equal and independent risk of setting off an ignition. Only adjacent cells in the cardinal direction are taken into consideration in the calculation, which represents the combined action of nearby cells.

Now when we know what should be a probability of igniting we need to generate a random number from Bernoulli distribution with a probability \(P_i\). This is done with the function rbinom(). Luckily this function can take take a matrix of \(P_i\) and generate newly developed fires for the whole grid. The Developed_fires variable in the script below generates these spreading fires.

Fires can also come into a system as a result of e.g. lightning or human activity. In the following loop we generate those in a variable New_fires.

Cur_fires variable in the script becomes 1 for a grid cell it was one in the Developed_fires or in the New_fires.

Now you should be ready to read the cellular automation loop.

In order to see how the automation works, please copy and paste this script directly into Console!!!

dev.new(width = 15,   # Create new plot window
        height = 15,
        noRStudioGD = TRUE)

Total_carbon<-rep(NA, nYears)


Age<-matrix(0, ncol=n, nrow=m)
nYears<-100
prob_fire=0.14

Old_fires <-Age
image(Age, col=forest.colors)
for (i in 1:nYears) {
  Age <- Age+1
  # look at the neighbors and ignite with the probability proportional to the number of neighbors we have on fire.
  Developed_fires<- rbinom( m*n , 1, 1-(1-prob_fire)^neighbours(Old_fires, wdist=wdist_fire))
   dim(Developed_fires)<-c(m,n)
  
   New_fires<- rbinom( m*n , 1, 2/10000)
   dim(New_fires)<-c(m,n)
   
 Cur_fires <- sign(Developed_fires + New_fires) # it will be 1 if there was developed or new fire or zero otherwise
   
 Cur_fires[Age < 2]<-0 # recently burned places cannot burn again
 
 Age[Cur_fires==1]<-0 # if there was a new fire in a cell - set age to zero
 
  Total_carbon[i]<- sum(Age)*500
  image(Age, col=forest.colors, add=TRUE)
 Old_fires<-Cur_fires
}

Let’s look at the carbon sequestration now:

plot(Total_carbon, type='l')

Please estimate the average age of the forest after a 500 hundred years.

dev.new(width = 15,   
        height = 15,
        noRStudioGD = TRUE)

Total_carbon <- rep(NA, nYears)


Age <- matrix(0, ncol=n, nrow=m)
nYears <- 500  
prob_fire = 0.14

Old_fires <- Age
image(Age, col=forest.colors)

for (i in 1:nYears) {
    Age <- Age + 1

    Developed_fires <- rbinom(m * n, 1, 1 - (1 - prob_fire)^neighbours(Old_fires, wdist=wdist_fire))
    dim(Developed_fires) <- c(m, n)
  
    New_fires <- rbinom(m * n, 1, 2 / 10000)
    dim(New_fires) <- c(m, n)
   
    Cur_fires <- sign(Developed_fires + New_fires)
   
    Cur_fires[Age < 2] <- 0
 
    Age[Cur_fires == 1] <- 0 
 
    Total_carbon[i] <- sum(Age) * 500
    image(Age, col=forest.colors, add=TRUE)
    Old_fires <- Cur_fires
}

average_age_forest <- mean(Age)
print(average_age_forest)
## [1] 192.6124
plot(Total_carbon, type='l')

2. Add road with higher ignition probability

Imagine now, that we have a road that goes through a center of the forest. Let’s say it goes between grid lines 49 and 50 and increases probability of getting new fire to 0.05.

Q2. Add the follwing line in the loop New_fires[,49:50]<-rbinom( length(New_fires[,49:50]) , 1 , 0.05 ) and explain how this addition affects the results.

The route is represented by the designated grid lines (49 and 50). The probability of new fires beginning in these grid cells is increased by the code to 0.05, which is substantially higher than the initial probability of 2/10000 for the rest of the forest in the original script. This modification reflects the elevated chance of a fire starting in a region next to a road, which may be brought on by human activity or other road-related factors.

3. Add fire lines

Fire lines are very effective in stopping distributing fires. In practice fire line means a line cleaned of forest that is hard to cross for the developing fire. At the same time fire lines consume some forest, so less carbon gets accumulated. In this task you will explore optimal distribution of the fire lines in the example we developed above. The task is to distribute firelines in a way, that would maximize carbon sequestration by the fores.

One fire line can be added in our grid with the following code Age[,40]<-0 for horizontal and Age[40,]<-0 for vertical fire line.

Note that in order to make loop running faster, you can comment out the image() function within the loop (#image()), as it takes most of the time simulation time. Also note, that because we run stochastic models, the results get a bit different over time.

dev.new(width = 15,   
        height = 15,
        noRStudioGD = TRUE)


Age <- matrix(0, ncol=n, nrow=m)  
nYears <- 500  
prob_fire = 0.14
Old_fires <- Age
Total_carbon <- rep(NA, nYears)

for (i in 1:nYears) {
    Age <- Age + 1

    Age[,40] <- 0  
    Age[40,] <- 0  

    Developed_fires <- rbinom(m * n, 1, 1 - (1 - prob_fire)^neighbours(Old_fires, wdist=wdist_fire))
    dim(Developed_fires) <- c(m, n)
  
    New_fires <- rbinom(m * n, 1, 2 / 10000)
    dim(New_fires) <- c(m, n)
   
    Cur_fires <- sign(Developed_fires + New_fires)
   
    Cur_fires[Age < 2] <- 0
 
    Age[Cur_fires == 1] <- 0 
 
    Total_carbon[i] <- sum(Age) * 500

    Old_fires <- Cur_fires
}


average_age_forest <- mean(Age)
total_carbon_sequestration <- sum(Total_carbon)
print(paste("Average age of forest:", average_age_forest))
## [1] "Average age of forest: 169.3215"
print(paste("Total carbon sequestration:", total_carbon_sequestration))
## [1] "Total carbon sequestration: 280778309500"

4. Fire lines cut on schedule.

Imagine now, that you can cut the fire lines not annually but biannually. Evaluate how much less effective this strategy could be. To get odd and even numbers you can use follwoing R construct:

dev.new(width = 15,  
        height = 15,
        noRStudioGD = TRUE)


Age <- matrix(0, ncol=n, nrow=m) 
nYears <- 500  
prob_fire = 0.14
Old_fires <- Age
Total_carbon <- rep(NA, nYears)


for (i in 1:nYears) {
    Age <- Age + 1

   
    if (i %% 2 == 0) {
       
        Age[,40] <- 0
    } else {
        
        Age[40,] <- 0
    }

    
    Developed_fires <- rbinom(m * n, 1, 1 - (1 - prob_fire)^neighbours(Old_fires, wdist=wdist_fire))
    dim(Developed_fires) <- c(m, n)
  
    
    New_fires <- rbinom(m * n, 1, 2 / 10000)
    dim(New_fires) <- c(m, n)
   
  
    Cur_fires <- sign(Developed_fires + New_fires)
   
    Cur_fires[Age < 2] <- 0
 
    Age[Cur_fires == 1] <- 0 
 
    
    Total_carbon[i] <- sum(Age) * 500

    
    Old_fires <- Cur_fires
}


average_age_forest <- mean(Age)
total_carbon_sequestration <- sum(Total_carbon)
print(paste("Average age of forest:", average_age_forest))
## [1] "Average age of forest: 183.3152"
print(paste("Total carbon sequestration:", total_carbon_sequestration))
## [1] "Total carbon sequestration: 309836542500"
dev.new(width = 15,   
        height = 15,
        noRStudioGD = TRUE)


Age <- matrix(0, ncol=n, nrow=m)  
nYears <- 500  
prob_fire = 0.14
Old_fires <- Age
Total_carbon <- rep(NA, nYears)


schedule <- function(year, Age) {
    
     Age[,40] <- 0
     Age[40,] <- 0

     if (year %% 2 == 0) {
         Age[,40] <- 0
     } else {
         Age[40,] <- 0
     }

     if (year %% 3 == 0) {
         Age[,40] <- 0
         Age[40,] <- 0
     }

    return(Age)
}


for (i in 1:nYears) {
    Age <- Age + 1

    
    Age <- schedule(i, Age)

    
    Developed_fires <- rbinom(m * n, 1, 1 - (1 - prob_fire)^neighbours(Old_fires, wdist=wdist_fire))
    dim(Developed_fires) <- c(m, n)
  
    
    New_fires <- rbinom(m * n, 1, 2 / 10000)
    dim(New_fires) <- c(m, n)
   
    
    Cur_fires <- sign(Developed_fires + New_fires)
   
    
    Cur_fires[Age < 2] <- 0
 
    
    Age[Cur_fires == 1] <- 0 
 
    
    Total_carbon[i] <- sum(Age) * 500

    Old_fires <- Cur_fires
}


average_age_forest <- mean(Age)
total_carbon_sequestration <- sum(Total_carbon)
print(paste("Average age of forest:", average_age_forest))
## [1] "Average age of forest: 184.4239"
print(paste("Total carbon sequestration:", total_carbon_sequestration))
## [1] "Total carbon sequestration: 312416585000"

Q3. Please provide you conclusion here.

A mature forest with an average age of 179.58 years and significant carbon sequestration of almost 318.96 billion units is depicted in the simulation, which spans 500 years and illustrates successful fire line management. This maturity and carbon absorption point to a beneficial effect on mitigating climate change. It’s crucial to remember that this is a simplified model and that practical implementations should take into account a variety of ecological aspects. The findings demonstrate that, in general, effective management of fire lines can significantly enhance forest health and carbon sequestration, supporting ecological sustainability and climate goals.

This was it, I hope it was not too heavy…