Try PoPS in Jupyter Notebook

r.pops.spread is a model for stochastic landscape spread of the pest and pathogens. It uses PoPS (Pest or Pathogen Spread) library. In this tutorial we will use it specifically to model the spread of Sudden Oak Death tree disease in the Rouge River-Siskiyou National Forest region of western Oregon. This tutorial uses sample dataset with

  • tanoak host layer (LEMMA data)
  • digital elevation model (NED)
  • orthophoto (NAIP)
  • roads, streams (USGS)
  • mapset containing weather coefficients

Intro to Jupyter Notebook

This is a quick introduction into Jupyter Notebook. Use Shift+Enter to execute cells.

In [1]:
a = 6
b = 7
c = a * b
print("Answer is", c)
Answer is 42

Setting up GRASS GIS session

In [2]:
from IPython.display import Image
from helper import initialize_GRASS_notebook

initialize_GRASS_notebook(binary="grass",
                          grassdata="data/grassdata", location="PoPS_SOD_tutorial",
                          mapset="tutorial")

import grass.script as gs
from helper import show_interactively, show

Simulation

Study area and preparation

First, we will set computational region of our analyses to predefined study area:

In [3]:
gs.run_command('g.region', region='small_study_area', flags='p')

We use already prepared weather coefficients, represented by raster layers per each week of a simulation. With that, we need to prepare a text file. List and write the maps in a file using g.list:

In [4]:
gs.run_command('g.list', type='raster', pattern="average_weather_*", mapset='weather', output='weather.txt')

Let's look at initial infected tanoak trees in 2019.

In [5]:
show('eu_infection_2019')
Out[5]:
In [6]:
show_interactively('eu_infection_2019')
Out[6]:

Single stochastic run

Run the model using the text file created and setting the required parameters. For this analysis we used wind in NE direction and are looking at the first 5 years of spread from the initial 2019 infection discovery.

We export a result from a single stochastic simulation (with specified random seed).

In [7]:
gs.run_command('r.pops.spread', host='host', total_plants='max_host', infected='eu_infection_2019',
               start_date='2019-01-01', end_date='2023-12-31', step_unit='week', 
               reproductive_rate=1.6, weather_coefficient_file='weather.txt',
               natural_direction='NE', natural_dispersal_kernel='exponential',
               natural_distance=242, natural_direction_strength=3,
               single_series='spread_sod', output_frequency='yearly', runs=1, random_seed=1)

We list newly created output layers representing infected trees in yeach year of the simulation and we set a custom color ramp.

In [8]:
series = gs.list_strings(type='raster', pattern="spread_sod*")
gs.run_command('r.colors', map=series, rules='color_infected.txt')
series
Out[8]:
['spread_sod_2019_12_31@tutorial',
 'spread_sod_2020_12_31@tutorial',
 'spread_sod_2021_12_31@tutorial',
 'spread_sod_2022_12_31@tutorial',
 'spread_sod_2023_12_31@tutorial']

By changing the index from 0 to 4 you can display the steps of the simulation. Notice the NE direction of spread.

In [9]:
show(series[2])
Out[9]: