2.9. Beyond the Model classΒΆ

Thus far we only used predefined Model class for control flow in the script. Of course you can use all Python constructs inside and outside this Model class. You may need this either to better structure your model, or to calculate things that cannot be done with using the time iteration provided by the Model class.

For instance, it is often wise to rewrite blocks of code as functions. Go to the subdirectory morePython and open functions.py. It is the fire model you programmed earlier. At the top of the dynamic are a number of lines finally calculating potentialNewFire. To make this script better readable, rewrite the program such that this upper block is encapsulated in a function calculatePotentialNewFire. Define this function at the top of the program (just below from pcraster.framework import * and call it in the dynamic. Be sure to test the program!

Question:Give another example of how Python constructs can be used in modelling.
  • Functions
  • Conditional execution