300 likes | 327 Views
An Introduction to TerraME. Pedro Ribeiro de Andrade São José dos Campos, 2011 www.terrame.org. Cell Spaces. TerraME: Ambiente Computacional Multi-paradigma para o Desenvolvimento de Modelos Integrados Natureza-Sociedade.
E N D
An Introduction to TerraME Pedro Ribeiro de Andrade São José dos Campos, 2011 www.terrame.org
Cell Spaces TerraME: Ambiente ComputacionalMulti-paradigma para o Desenvolvimento de Modelos Integrados Natureza-Sociedade Hipótese: Nenhuma abordagem sozinha é suficiente para representar a complexidade das interações sociedade-natureza Fonte: (Carneiro, 2006)
Desenvolvimento do TerraME • CCST-INPE • Pedro Andrade, Gilberto Camara, Raian Maretto • TerraLab/UFOP • Tiago Carneiro • DPI/OBT-INPE • Miguel Monteiro, Time TerraLib
Software: Open source GIS Visualization (TerraView) Modelling (TerraME) Spatio-temporal Database (TerraLib) Statistics (R interface) Data Mining(GeoDMA)
1. Get first pair 2. Execute the ACTION 1. 2. 3. Timer =EVENT 3. 1:32:00 1:32:10 1:42:00 1:38:07 Mens.4 Mens. 2 Mens. 1 Mens. 3 4. return value . . . true 4. timeToHappen += period TerraME: Components Temporal structure Spatial structure latency > 6 years Deforesting Newly implanted Year of creation Slowing down Iddle Deforestation = 100% Spatial relations Rules of behaviour Source: [Carneiro, 2006]
TerraME extensions to Lua • Lua classes usingthe constructor mechanism: Cell, CellularSpace, Neighborhood, Timer, Event, Legend • A CellularSpace is a multivalued set of Cells. It consists of a geographical area of interest, divided into regular or irregular objects. • Each Cell has a set of attributes. • CellularSpaces can be stored and retrieved from TerraLib databases if the modeler specify where the data is.
Cellular Space in memory and forEachCell DEAD = 0 ALIVE = 1 cs = CellularSpace { xdim = 30, ydim = 20 } function random (cs) forEachCell (cs, function (cell) v = math.random() -- a value between 0 and 1 if v > 0.5 then cell.state = ALIVE else cell.state = DEAD end end) end random(cs)
Legend and Observer lifeLeg = Legend{ type = TYPES.NUMBER, groupingMode = GROUPING.UNIQUEVALUE, slices = 2, maximum = ALIVE, minimum = DEAD, colorBar1 = { {BLACK, DEAD}, {WHITE, ALIVE} }, } cs:createObserver(OBSERVERS.MAP, {"state"}, {lifeLeg}) cs:notifyObservers()
Synchronizing a CellularSpace • TerraME keeps two copies of a cellular space in memory: one stores the past values of the cells, and another stores the current (present) values of the cells. • The model equations must read the past copy and write the values to the present copy of the cellular space. • At the correct moment, it will be necessary to synchronize the past copy with the current values of the cellular space.
Game of life source code DEAD = 0 ALIVE = 1 TURNS = 400 function random (cs) forEachCell (cs, function (cell) v = math.random() -- a value between 0 and 1 if v > 0.5 then cell.state = ALIVE else cell.state = DEAD end end) end
Cellular Space and neighborhood cs = CellularSpace { xdim = 50 } random(cs) createMooreNeighborhood(cs, "1", false) functioncountAlive(cell) count = 0 forEachNeighbor(cell, function(cell, neigh) ifneigh.past.state == ALIVE then count = count + 1 end end) return count end
Updating the cellular space functionupdateSpace(mycs) forEachCell(mycs, function(cell) n = countAlive(cell) -- cells with one or no neighbors die (loneliness). if n < 2 then cell.state = DEAD -- cells with four or more neighbors die (overpopulation). elseifn > 3 then cell.state = DEAD -- cells with two neighbors survive. elseifn == 2 then cell.state = cell.past.state -- cells with three neighbors become populated. elseifn == 3 then cell.state = ALIVE end end) end
Running and synchronizing lifeLeg = Legend{ type = TYPES.NUMBER, groupingMode = GROUPING.UNIQUEVALUE, slices = 2, maximum = ALIVE, minimum = DEAD, colorBar1 = { {BLACK, ALIVE}, {WHITE, DEAD} } } cs:createObserver(OBSERVERS.MAP, {"state"}, {lifeLeg}) cs:notifyObservers() fori = 1,TURNS do cs:synchronize() updateSpace(cs) cs:notifyObservers() end
Example 3: Runoff rain rain rain Itacolomi do Itambé Peak Lobo’s Range
CellularSpace from database and neighborhood -- input and output data paths TERRAME_PATH = "e:\\Programas\\TerraME\\" INPUT_PATH = TERRAME_PATH.."Database\\" -- retrieve the cell space from the database csQ = CellularSpace{ database = INPUT_PATH.."cabecaDeBoi.mdb", theme = "cells", select = { "height", "soilWater" } } csQ:load() function filter(cell, neigh) ifcell.height >= neigh.heightthen return true end return false end create3x3Neighborhood(csQ, filter)
Observers using two attributes heightLeg = Legend{ type = TYPES.NUMBER, groupingMode = GROUPING.EQUALSTEPS, slices = 50, maximum = 255, minimum = 0, colorBar1 = { {BLACK, 0}, {WHITE, 1} } } soilWaterLeg = Legend{ type = TYPES.NUMBER, groupingMode = GROUPING.EQUALSTEPS, slices = 100, maximum = 200, minimum = 0, colorBar1 = { {WHITE, 0}, {BLUE, 200} } } csQ:createObserver(OBSERVERS.MAP, {"soilWater", "height"}, {soilWaterLeg, heightLeg})
Rain and runoff RAIN = 4 -- rain/t MIN_HEIGHT = 200 function rain(cs) forEachCell(cs, function(cell) if ANYWHERE or (cell.height > MIN_HEIGHT) then cell.soilWater = cell.soilWater + RAIN end end) end function runoff(cs) cs:synchronize("soilWater") forEachCell(cs, function(cell) cell.soilWater = 0 end) forEachCell(cs, function(cell) countNeigh = cell:getNeighborhood():size() ifcountNeigh > 0 then soilWater = cell.past.soilWater / countNeigh forEachNeighbor(cell, function(cell, neigh) neigh.soilWater = neigh.soilWater + soilWater end) else cell.soilWater = cell.soilWater + cell.past.soilWater end end) end
Timer RAINING_TIME = 5 FINAL_TIME = 50 t = Timer{ Event{message = function(event) rain(csQ) if event:getTime() > RAINING_TIME then return false end end}, Event{message = function(event) runoff(csQ) end}, Event{priority = 5, message = function(event) csQ:notifyObservers() end} } t:execute(FINAL_TIME)
Different spatial resolutions 1985 • Small farms environments: • 500 m resolution • Categorical variable: deforested or forest • One neighborhood relation: • connection through roads • Large farm environments: • 2500 m resolution • Continuous variable: • % deforested • Two alternative neighborhood • relations: • connection through roads • farm limits proximity 1997 1997
Models of Computation (von Neumann, 1966) (Minsky, 1967) (Pedrosa et al, 2003) (Aguiar et al, 2004) (Wooldbridge, 1995) (Straatman et al, 2001) (Rosenschein and Kaelbling, 1995) Cellular automata models Agent based models
State machines Settlement/invaded land Diversify use Sustainability path (alternative uses, technology) money surplus Sustainability path (technology) Manage cattle Buy newland Subsistenceagriculture Create pasture/ Deforest bad land management Abandon/Selltheproperty Speculator/large/small Move towardsthe frontier
From a Cell Agent c a b b c Agent Cell To GPM as a graph
Agent-based modelling relations forEachRelative forEachNeighbor forEachCell Agent Cell forEachAgent forEachCell forEachAgent Society CellularSpace Group Trajectory DBMS
Nested environments Prodes/INPE 2000-2001
Escala 1 pai up-scaling down-scaling filho Escala 2 Nested environments
An Introduction to TerraME Pedro Ribeiro de Andrade São José dos Campos, 2011 www.terrame.org