760 likes | 785 Views
Spatial Dynamical Modeling with TerraME. Tiago Carneiro Gilberto Câmara Pedro Andrade. Licence : Creative Commons ̶̶̶̶ By Attribution ̶̶̶̶ Non Commercial ̶̶̶̶ Share Alike http://creativecommons.org/licenses/by-nc-sa/2.5/. Dynamic Spatial Models. f (I t ). f (I t+1 ).
E N D
Spatial Dynamical Modeling with TerraME Tiago Carneiro Gilberto Câmara Pedro Andrade Licence: CreativeCommons ̶̶̶̶ ByAttribution ̶̶̶̶ NonCommercial ̶̶̶̶ ShareAlike http://creativecommons.org/licenses/by-nc-sa/2.5/
Dynamic Spatial Models f (It) f (It+1) f (It+2) f ( It+n ) F F . . “A dynamical spatial model is a computational representation of a real-world process where a location on the earth’s surface changes in response to variations on external and internal dynamics on the landscape” (Peter Burrough)
CellSpaces • GeneralizedProximityMatriz – GPM • Hybrid Automata model • Nested scales • Agents in space Computational Modelling with Cell Spaces
TerraME - overview Model data in cellspaces Read/write data from a database
2500 m 2.500 m e 500 m Cellular Data Base Resolution
TerraME C++ Framework C++ Signal Processing librarys C++ Mathematicallibrarys C++ Statisticallibrarys TerraME: Software Architecture Model 1 Model 2 Model 3 Model 4 TerraML Language TerraMLCompiler TerraML Virtual Machine TerraLib
TerraLib: spatio-temporal database as a basis for innovation G. Câmara et al.“TerraLib: An open-source GIS library for large-scale environmental and socio-economic applications”. In: B. Hall, M. Leahy (eds.), “Open Source Approaches to Spatial Data Handling”. Berlin, Springer, 2008. Modelling (TerraME) Visualization (TerraView) Spatio-temporal Database (TerraLib) Data Mining(GeoDMA) Statistics (aRT)
TerraLib Database TerraME integration with GIS (TerraView) “GPM” Plugin TerraView 3.2.0 “FillCell” Plugin TerraView 3.2.0
Conversion from GIS data to cell spaces Real world Vector geospatial data Cell space
The mixed pixel problem How can you transform from vectors to cell attributes?
Using “FillCell” plugin to build Cell Spaces 1. Install the FillCellplugin: Copy the file "celulas.dll" to the directory "C: \ Program Files \ TerraView3.2.0 \ plugins". 2. Build thecellspacewiththedesiredresolution
Fill the attributes of the cell spaces For each data type to be transformed, there are appropriate operations
Lua Roberto Ierusalimschy PUC-Rio, Brazil
-- a Lua script color = RED b = button { label = ‘OK’, x = 10, y = 20} Host Program Lua Interpreter What is Lua? • Yet Another Scripting Language • an “extension” language • implemented as a library in ANSI C
Why Lua? • Simple and flexible • “Simple things simple, complex things possible” • Small, Efficient, Portable • Whole library written in ANSI C, compiles the same source code in all platforms • Typical uses: MS-DOS, Windows (3.1, 95, NT), Unix (Linux, Solaris, IRIX, AIX, ULTRIX), Next, OS/2, Mac
Where is Lua? • Inside Brazil • Petrobras, the Brazilian Oil Company • Embratel (the main telecommunication company in Brazil) • many other companies • Outside Brazil • Lua is used in hundreds of projects, both commercial and academic • CGILua still in restricted use • until recently all documentation was in Portuguese
How is Lua? function fat (n) if n == 0 then return 1 else return n*fat(n-1) end end • Pascal-like Syntax. • Interpreter executes sequence of statements. • function definitions are also statements (see later) • Six types: numbers, tables, functions, strings, userdata, nil
My first Lua program C = 2; -- rain/t K = 0.4; -- flow coefficient q = 0; -- RULES for time = 0, 20, 1 do -- soil water q = q + C - K*q; end print(“q = "..q);
Type nil • Different from everything else • Default variable type • Also acts as false (boolean)
Type boolean • Comparison value • if (rain == true) then ....
Type number • Unique native type for numbers • double (by default) a = 3 b = 3.5 c = 4.5e-8
Type string • Immutable • No size limit (read large files as strings) • No termination value (‘\0’) • Powerful Pattern-matching in standard library • myname = “Werner Kuhn”;
Tables • Implement associative arrays: • any value (including functions and other tables) can be used both for indices and values t = {} -- creates an empty table t[1] = "hello" t.x = print -- t.x is sugar for t[‘x’] t.x(t[1]) -- prints ‘hello’ t.next = t -- circular list
Table loc = { cover = "forest", distRoad = 0.3, distUrban = 2 }; loc.cover = “cerrado”; loc[“cover”] = “soja”; if (loc.distUrban > 1.5) then
Tables in Lua loc = { cover = "forest", distRoad = 0.3, distUrban = 2 }; loc.desfPot = loc.distRoad + loc.distUrban;
Constructors: Create and init tables • Record style • point={x=10,y=20} • print(point.y) --> 20 • List style • days={"Sun","Mon","Tue","Wed”, Sat"} • print(days[3]) --> Tue • Mixed style • points={{x=0,y=0}, point, n=2} • print(points[points.n].y) --> 20
Constructors calls function “article” article{ author="F.P.Brooks", title="The Mythical Man-Month", year=1975, } news = { {text = "New version 2.0", date = "21/05/1997"}, {text = "New example", date = "21/05/1997"}, {text = "New version: 2.1",date = "17/06/1997"}, } Lua and the Web
Functions in Lua functionfat (n) if n == 0 then return 1 else return n*fat(n-1) end end
function inc (x) return x+1 end inc = function (x) return x+1 end sugar Functions in Lua • First class values • Example: cloning a table t clone = {} foreach(t, function (i,e) clone[i]=e end) Lua and the Web
Functions and Tables w = { redraw = function () ... end, pick = function (x,y) ... end, } if w.pick(x,y) then w.redraw() end
list = {value=v, next=list} value - v next - Tables x Objects • Tables are dynamically created objects. list old list ...
function a:foo (x) ... end a.foo = function (self,x) ... end sugar sugar a:foo(x) a.foo(a,x) Objects • First-class functions+ tables = almost OO • Tables can have functions as fields • Sugar for method definition and call • Implicit parameter self
My second Lua program C = 2; -- rain/t K = 0.4; -- flow coefficient q = 0; -- function rain (t) if (t < 10) then return 4 – 4*math.cos(math.pi*t/10); else return 4 – 4*math.cos(math.pi*(t-10)/10); end end -- for time = 0, 20, 1 do -- soil water q = q + rain(time) - K*q; end -- report print(“q = "..q);
Standard libraries Basic String Table Math IO OS Debug Coroutine
Basic Basic functions print type setmetatable pairs
String String manipulation pattern matching string.find string.gsub
Table • Function for table manipulation • table.insert • table.remove • table.sort
rain rain rain Itacolomi do Itambé Peak Lobo’s Range My third Lua program Define a two-dimensional grid Make it rain on the grid Let water flow downwards N
TerraME: Vision An Earth´s environment can be represented as a synthetic environment where analytical entities (rules) change the space properties in time. Several interacting entities share the same spatiotemporal structure.
TerraLib EnviromentalModeling Framework C++ Signal Processing librarys C++ Mathematicallibrarys C++ Statisticallibrarys TerraME architecture & applications RondôniaModel DinamicaModel TROLLModel CLUEModel TerraME Language TerraME Compiler TerraME Virtual Machine TerraLib
The Scale Concept in TerraME Scale is a generic concept that includes the spatial, temporal, or analytical dimensions used to measure any phenomenon. Extent refers to the magnitude of measurement. Resolution refers to the granularity used in the measures. (Gibson et al. 2000)
Nested scales are necessary for human-environment models Diverse space partitions can have different scales
TerraME extensions to Lua To build spatial dynamic models,TerraME includes new value types in LUA usingthe constructor mechanism. These values are: CellularSpace, Cell, Neighbourhood
Cellular Space A geographical area of interest, divided into a grid. Each cell in the grid has one or more attributes. Stored and retrieved from a TerraLib database
GIS Loading Data -- Loads the TerraLib cellular space csCabecaDeBoi = CellularSpace { dbType = "ADO", host = “localhost", database = "c:\\cabecaDeBoi.mdb", user = "", password = "", layer = "cellsLobo90x90", theme = "cells", select = { “height", “soilWater", “capInf" } } csCabecaDeBoi:load(); csCabecaDeBoi:loadMooreNeighbourhood;