Lab 10: cellular modeling
Introduction
This lab introduces the concept of cellular modeling. Cellular
modeling is a modeling construct where the value of any once cell is
a function of the surrounding cells.
Cellular Automata and Conway's Game of Life
The game of life is one of the more well-studied CA models. It's
particularly interesting due to its simple rules and the amazingly
complex structures that are generated by them.
The rules are:
- if exactly three neighbors are turned on and cell is off, cell
should turn on.
- if cell is on and two or three cells are on, stay on.
- if cell is on and less than two or more than three cells are on, turn off.
In netscape, open up the page
http://www.mindspring.org/~alanh/life. This will run a java
applet that runs conways game of life. The applet is started by a
button that has the title enjoy life.
When the applet is started, try drawing a straight vertical line.
Hit go.. what is the resulting shape? What happens if there
is a longer line? Or a shorter line? You can clear the slate
between tries by hitting the clear button.
Next, try to create an oval by starting with a shorter line. If
you can make one, try clicking a single cell on one corner. If you
do it right, you can make 4 ovals. If you get the four oval pattern,
then click one corner again. Occasionally, you will produce what's
known as a glider, which is an emergent pattern that seems to
be like a bird flying off in a diagonal direction. After some
practice, you should be able to produce several.
There is a library of stable, oscilating, or emergent patterns
available for experimentation with this program. They can be loaded
by hitting the open button. Try the glider guns, spaceships,
puffers, and billiard balls. They are all emergent patterns
resulting from the same simple rules.
Cellular modeling and GIS data
Next, we will experiment with some software, where we will try and
implement rules at the cellular level, and watch as the process
replicates itself across the landscape.
- create a new lab directory for lab 10. Open up a new arcview
project, and set your working directory accordingly. Turn on Spatial
Analyst.
- Open a grid file: /home/sanduku/classes/5930/lab10/veggy.
Export this file as an ascii export file to your directory:
- File-> Export Data Source
- ASCII Raster: hit OK
- Grid name should be veggy
- call output veggy.asc
- For this next part, we will need to set some environment variables
- open up a terminal window
- change directory to your lab10 directory
- set some environment variables. At the prompt, type:
~sanduku/bin/swarmshell
- you should now see a prompt with a dollar sign in it
- At this point, you should copy in the source code for the CA program.
- cp -R /home/sanduku/classes/5930/lab10/plants .
- change directory in to plants. In this directory, you
should be able to run the sample cellular modeling simulation
plant. We can run the simulation to show the progress of the
invasive plant over time.
- At the unix prompt:
- type plant
- when the window comes up, find the
ProcCtrl window, and hit the Next button.
- in the
Invasive Plant window, right-click your mouse somewhere in the window
- on the blue letters Cell, right-click again.
- touch
the button createPlant
- in the ProcCtrl window, hit
the Next button again. Your selected cell should now turn
green.
- Hit the Start button: the plant should now start
spreading to its neighbors.
- You should now be able to open up emacs (a text editor),
and edit the required files.
- emacs is a text editor that is ideally suited for editing
computer code. You can start it by typing at the command line:
- The command will start the emacs text editor, the dot (.) will
open up the ``present directory'' in it, and the ampersand (&) will
run the process in the background. If you are in your lab directory,
you should see a number of files, including .libs, Cell.h,
Cell.m, etc. The contents of the window are a listing of what's
in your present directory (if you go to the terminal window, and type
ls -l, you will see a similar output.).
- At this point, there is a setting to change, which will make your
life easier. At the menu button at top of the emacs window, choose
the option:
- Help -> Options -> Global Font Lock
- At this point, all the files ending in ~ and .o should turn cyan
color.
- All of the files that are visible in the window can now be viewed
and edited at will. To open a file:
- move the cursor (using the arrow keys) on top of the file name
- prest the letter e (for edit)
- the file will open
- to close the file
- type Ctrl-x k (where Ctrl is the control key)
- type enter
- if you get a message saying that the file has been modified and ``do you really wish to exit'', pres yes (type out the letters y-e-s).
- to save your edits
- you can either hit Files -> Save Buffer
- or you can type Ctrl-x Ctrl-s
- Open up the file Cell.m. This file has all the
instructions that a Cell does at each time step. In this case, a
cell is given two messages: step and update. The
step method reads as such:
- if (plant != nil) [plant grow];
- That statement reads ``if there is a plant, tell it to grow''
- The next message, update in English, reads ``if there
is a future plant flagged, if there is no plant here and the
vegetation type is not 0, tell me (self) to create a
plant''. This whole block can be thought of as the ability of the
cell, with its land type, to be colonized by the plant.
- Here, make a modification to the code to disallow the plant to
grow in vegetation type 3. This is equivalent to saying that
vegetation type 3 is not suitable habitat for the plant.
- change the line to if (plant == nil && vegType != 3) {
- save the file
- at the terminal window, type make
- run plant again.
- Now, open up the file Plant.m. This file has the
instructions for everything that a plant does in this simulation.
In case, the most important methods are the instructions for growing
and colonizing neighbors. Let's examine the growth function first:
- scroll down to the function -grow. This is the method
which describes the growth functions. The first line reads
-
quantity *= 1.1;
- this line takes the size of the plant
(quantity) and multiplies it by 1.1 This in effect makes the plant's
biomass increase by 10% every time step.
- if you wish to alter the plant's growth function, this is the line to modify
- The next line reads age++. This increments the plants
age. The line is the equivalent of age = age + 1
- The next line reads if (quantity > 1.5) [self
colonize];. This line reads "if the quantity is greater than
1.5, I should colonize my neigbhoring cells".
- if you wish to alter the time at which a plant colonizes its neighbors, this is the line to modify
- Next, scroll down to the method that starts with
-colonize. This is the method that defines how a plant
colonizes its neighbors. The translation of this block into English
is as such:
- for (i=1; i<= 8; i++) {
- " for each of my eight neighboring cells"
- if ([myCell getCellAtNeighbor: i] )
- "if there really is a cell there (I'm not on the edge)"
- if ([uniformDblRand getDoubleWithMin: 0.0000 withMax: 1.0000] < .1)
- "Draw a random number where I have a 10% probability of success. If I draw that 1 in 10 chance..."
- [[myCell getCellAtNeighbor: i] orderPlant];
- "schedule a plant to be created at that cell"
- This step describes the methods at which the plant is
colonizing its neighbors. The line with the random number is
defining how likely a neighboring cell will be colonized. If you
were to change the number .1 to .5, you would be changing the
likelyhood of colonization from 10% to 50%.
- if you wish to
alter the aggressivenes of this plant in spreading, this is the line
to modify.
- Let's try making a modification here. Change the number .1 to
some other number (preferably between 0 and 1). Save your changes
(File-> save buffer).
- Return to the terminal window. Type make.
- You will see a bunch of text fly by your window, but eventually
see the phrase created plant. Now you can run the program
plant again. Try the same steps that you tried before
(placing a plant somewhere in the world), and see how the simulation
changes.
- After the file has run, try writing the output to a GIS file.
- find the window DataFileSwarm.
- With the right mouse button, click on the blue letters DataFileSwarm
- In the window that pops up, scroll all the way to the bottom
- click the button writeData
- in your terminal window, you will see some text similar to
Wrote output file "veggy.asc_29_180515" for data layer "veggy.asc"
- rename this file to "veg2.asc" (or anything, as long as it has
the .asc suffix)
- You can now import this file into arcview using
the "import data" option.
Dr. Paul W. Box .