Question: Python -> Forest Grid Represent the forest as a 2D grid of cells with N R rows and N C columns. At any moment in

Python -> Forest Grid

  • Represent the forest as a 2D grid of cells with N R rows and N C columns.
  • At any moment in time, each cell can be in one of three states: "empty" to represent bare ground or meadow, "live" to represent a living tree (or a group of living trees), or "burning" to represent a tree (or group of trees) on fire.
  • All boundary cells remain permanently "empty", representing a non-flammable forest boundary such as water, infertile ground, highway, or urban area.
  • Implement the forest grid as a 2D numpy array whose data type (dtype) is numpy.uint8: An unsigned 8-bit integer, in order to minimize the array's memory footprint.
  • Use cell values of 0 to represent "empty" cells, 1 to represent "live" cells, and 2 to represent "burning" cells.
  • Create 1D numpy arrays to store the counts of "empty", "live" and "burning" cells at each time-step, and pre-allocate them to the length necessary to store results for the entire simulation duration (rather than growing them every time-step). Store the appropriate counts for the initial grid in their first element.
  • For each time-step of the forest dynamics:
    1. Create a copy of the current forest grid, as a snapshot of all cell states at the start of that time-step.
    2. With a double-loop, iterate over all non-boundary rows and over all non-boundary cells within each row.
      • If the cell is "empty", randomly determine whether to change it to "live" according to the probability p G.
      • If the cell is "live":
        • If any of its neighbors were "burning" at the start of the time-step, change it to "burning";
        • If not, randomly determine whether to change it to "burning" according to the probability p F.
      • If the cell is "burning", change it to "empty".
      • Do not apply more than one of these things to a cell in succession during one time-step!
    3. Count the number of "empty", "live", and "burning" cells (and anything else you wish to keep track of).
  • Maintain an integer variable that counts time-steps (of the burn-in or of the data collection), beginning with zero to represent the initial condition.
  • Iterate over the grid-update dynamics for the desired number of time-steps, recording the counts after each step to the data storage arrays.
  • Convert cell counts to fractions, do any other desired post-processing, report out results, and construct desired plots.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!