Presentation is loading. Please wait.

Presentation is loading. Please wait.

Modelagem Dinâmica com TerraME: Aula 3 Interface entre TerraME e LUA Gilberto Câmara (INPE) Tiago Garcia de Senna Carneiro (UFOP)

Similar presentations


Presentation on theme: "Modelagem Dinâmica com TerraME: Aula 3 Interface entre TerraME e LUA Gilberto Câmara (INPE) Tiago Garcia de Senna Carneiro (UFOP)"— Presentation transcript:

1 Modelagem Dinâmica com TerraME: Aula 3 Interface entre TerraME e LUA Gilberto Câmara (INPE) Tiago Garcia de Senna Carneiro (UFOP)

2 What is TerraME? TerraME is a development environment for spatial dynamical modelling Uses a spatial database for data storage and retrieval

3 Which Cellular Automata? For realistic geographical models  the basic CA principles too constrained to be useful Extending the basic CA paradigm  From binary (active/inactive) values to a set of inhomogeneous local states  From discrete to continuous values (30% cultivated land, 40% grassland and 30% forest)  Transition rules: diverse combinations  Neighborhood definitions from a stationary 8-cell to generalized neighbourhood  From system closure to external events to external output during transitions

4 Spatial dynamic modeling Locations change due to external forces Realistic representation of landscape Elements of dynamic models Geographical space is inhomogeneous Different types of models  discretization of space in cells  generalization of CA  discrete and continous processes  Flexible neighborhood definitions  Extensibility to include user- defined models DemandsRequirements

5 TerraLib TerraLib Enviromental Modeling Framework C++ Signal Processing librarys C++ Mathematical librarys C++ Statistical librarys TerraME Virtual Machine TerraME architecture & applications TerraME Compiler TerraME Language RondôniaModel DinamicaModel TROLLModelCLUEModel fonte: Carneiro (2006)

6 TerraME functionality fonte: Carneiro (2006)

7 TerraME Runtime Environment

8 Cell Spaces

9 2500 m2.500 m e 500 m Cellular Data Base Resolution

10 Computational Modelling with Cell Spaces Cell Spaces Components  Cell Spaces  Generalizes Proximity Matriz – GPM  Hybrid Automata model  Nested enviroment fonte: Carneiro (2006)

11 TerraME extensions to Lua To build spatial dynamic models, TerraME includes new value types in LUA using the constructor mechanism. These values are: CellularSpace, Cell, Neighbourhood

12 Cellular Space A CellularSpace is a multivalued set of Cells. It consists of a geographical area of interest, divided into a regular grid. Each cell in the grid has one or more attributes. CellularSpaces are stored and retrieved from a TerraLib database, so the modeller should specify the properties of the CellularSpace

13 Constructors in Lua LUA has a powerful syntactical tool, called constructor. When the modeller writes name{…}, the LUA interpreter replaces it by name({… }), passing the table {…} as a parameter to the function name( ). This function typically initializes, checks properties values and adds auxiliary data structure or methods.

14 Cellular Space Usa o construtor de LUA csCabecaDeBoi = CellularSpace { dbType = "MySQL", host = "localhost", database = "CabecaDeBoi ", user = "", password = "", layer = "cells90x90", theme = "cells", select = { "altitude", "infCap" } where = "mask <> ‘noData’"; }

15 Loading Data -- Loads the TerraLib cellular space csCabecaDeBoi = CellularSpace { dbType = "ADO", host = "amazonas", database = "c:\\cabecaDeBoi.mdb", user = "", password = "", layer = "cellsSerraDoLobo90x90", theme = "cells", select = { "altimetria", “soilWater", “infCap" } } csCabecaDeBoi:load(); csCabecaDeBoi:loadMooreNeighbourhood; GIS

16 Cell Spaces Cellular Space

17 Referencing cells A CellularSpace has a special attribute called cells. It is a one-dimensional table of references for each Cell in the CellularSpace -- c is the seventh cell in the cellular space c = csCabecaDeBoi.cells[ 7 ]; -- Updating the attribute “infcap” from the seventh cell c.infcap = 10; print (csCabecaDeBoi.cells[7].infCap);

18 Database management -- loads a cellular space csAmazonia:load(); csAmazonia:loadNeighbourhood("Moore"); … -- save (time, themeName, attrTableName) -- for time = 1, 10,1 do csAmazonia:save(time, “sim", {"water"}); end

19 The Cell type A Cell value has two special attributes: latency and past. The latency attribute registers the period of time since the last change in a cell attribute value. The past attribute is a copy of all cell attribute values in the instant of the last change. if(cell.cover == "abandoned" and cell.latency >= 10 ) then cell.cover = "secFor"; end cell.water = cell.past.water + 2;

20 Traversing a Cell Space "for...end" statement: "for i, cell in pairs (csQ.cells) do...end”. The i and cell variable in the statement are the index and the value of a cell inside the cells attribute from the cellular space csQ. for i, cell in pairs( csQ.cells ) do cell.water = cell.past.water + 2; end

21 Traversing a Cell Space ForEachCell(cs, function()) Applies the chosen function to each cell of the cellular space. This function enables using different rules in a cellular space. ForEachCell(csQ, function(cell) cell.Water = cell.past.Water + 2; return true; end);

22 Traversing a Cell Space for i, cell in pairs( csQ.cells ) do cell.water = cell.past.water + 2; end -- usar para um percorrimento genérico -- percorrer por um valor ordenado ForEachCell(csQ, function(cell) cell.Water = cell.past.Water + 2; return true; end); -- pode aplicar diferentes funções

23 Von Neumann Neighborhood Moore Neighborhood Isotropic neighbourhoods in cell spaces

24 Traversing a Neighbourhood csq:loadNeighbourhood(“Moore”); ForEachCell(csQ, function(cell) count = 0; ForEachNeighbour(cell, 0, function(cell, neigh) if (neigh.past.value == 1 and neigh ~= cell) then count = count + 1; end end; ); -- for each neighbor

25 Traversing a Neighbourhood csQ:loadNeighbourhood(“Moore”); for i, cell in pairs( csQ.cells ) do count = 0; ForEachNeighbour(cell, 0, function(cell, neigh) if (neigh.past.value == 1) then count = count + 1; end end; ); -- for each neighbor end

26 Synchronizing a cell space TerraME keeps two copies of a cellular space in memory: one stores the past values of the cell attributes, and another stores the current (present) values of the cell attributes. The model equations must read (the right side of the equation rules) the past copy, and must write (the left side of the equation rules) the values to the present copy of the cellular space. At the correct moment, it will be necessary to synchronize the two copies of the cellular space, copying the current attribute values to the past copy of the cellular space.

27 Synchronization Leia sempre do antigo (“past”); Escreva sempre no novo (“present”); …. csQ:syncronize();

28 for i, cell ipairs( csValeDoAnary ) do end count = 0 ; print(“Number of deforested cells: ”.. count); if ( cell.past.cover == “forest” ) then cell.cover = “deforested”; count = count + 1 ; end cell.synchronize( ); Syncronization tntn t n+1 rule ? fonte: Carneiro (2006)

29 References Carneiro, T., 2006. Nested-CA: a foundation for multiscale modeling of land use and land change., in PhD Thesis in Computer Science. National Institute of Space Research: São José dos Campos, Brazil. Carneiro, T.; Câmara, G., 2007. A Gentle Introduction to TerraME. INPE Report, 2007. Ierusalimschy, R. 2006. Programming in Lua (2 nd edition). Rio de Janeiro, Lua.Org.


Download ppt "Modelagem Dinâmica com TerraME: Aula 3 Interface entre TerraME e LUA Gilberto Câmara (INPE) Tiago Garcia de Senna Carneiro (UFOP)"

Similar presentations


Ads by Google