Spatial Dynamical Modeling with TerraME - PowerPoint PPT Presentation

About This Presentation
Title:

Spatial Dynamical Modeling with TerraME

Description:

The model equations must read (the ... Using Generalized Proximity Matrices ... ( – PowerPoint PPT presentation

Number of Views:231
Avg rating:3.0/5.0
Slides: 88
Provided by: tcar8
Category:

less

Transcript and Presenter's Notes

Title: Spatial Dynamical Modeling with TerraME


1
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/
2
Modelling human-environment interactions
What models are needed to describe human actions?
3
Clocks, clouds or ants?
Clouds statistical distributions
Clocks deterministic equations
Ants emerging behaviour
4
Dynamic Spatial Models
f (It)
f (It1)
f (It2)
f ( Itn )
F
F
. .
A dynamical spatial model is a computational
representation of a real-world process where a
location on the earths surface changes in
response to variations on external and internal
dynamics on the landscape (Peter Burrough)
5
Nature-society modelling with TerraME
Nature Physical equations Describe processes
Society Decisions on how to Use Earths
resources
6
Nature-society modelling with TerraME
Nature Cellular space
Society Agents
Nature Physical equations Describe processes
Society Decisions on how to Use Earths
resources
7
Modelling collective spatial actions
Space
Agent
Agent Space
Benenson and Torrens, Geographic Automata
Systems, IJGIS, 2005 (but many questions
remain...)
8
Computational Modelling with Cell Spaces
9
TerraME - overview
Model data in cell spaces
Read/write data from a database
10
Cellular Data Base Resolution
11
Spatial structure
Large farmer (25 cells)
Small farmer (2 cells)
500 m (all)
12
Behavior is non-homogeneous in space and time
13
Statistics and agents
ya0 a1x1 a2x2 ... aixi E
Multi-scale modelling
14
Tools for observing simulations
15
TerraME functionality
16
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)
17
TerraME Software Architecture
Model 1
Model 2
Model 3
Model 4
TerraML Language
TerraMLCompiler
TerraML Virtual Machine
TerraLib
18
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

TerraME Programming Language Extension of Lua
Lua is the language of choice for computer games
Ierusalimschy et al, 1996
source the Lua team
19
Lua
  • Roberto Ierusalimschy
  • PUC-Rio, Brazil

20
What is Lua?
  • Yet Another Scripting Language
  • an extension language
  • implemented as a library in ANSI C

21
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

22
How is Lua?
function fat (n) if n 0 then return 1
else return nfat(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

23
Variables and Values
  • Case sensitive
  • semicolon may optionally follow any statement
  • a 1
  • b a2
  • print(a)
  • print(b)

24
Comments
  • double hyphen (--) until the end of the line.
  • block comments start with -- and run until
  • print("hello") -- my comment
  • -- print("hello)
  • --
  • print(10) -- no action (comment)
  • --

25
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 - Kq
  • end
  • print(q "..q)

26
Types
27
Type nil
  • Different from everything else
  • Default variable type
  • Also acts as false (boolean)

28
Type boolean
  • Comparison value
  • if (rain true) then ....

29
boolean
  • false/true
  • nil and false are false, everything else is true
  • zero and the empty string are true
  • operators and, or, and not
  • print(true and false)
  • print(true and (false or true))
  • print(false or (true and false) or (true and
    true))

30
number
  • the only type for numeric values
  • double-precision floating-point number
  • arithmetic operators , , , /
  • exponent () and modulus ()
  • boolean operators (lt, gt, lt, gt, , and )
  • A 6 2.2 4e3
  • a A 2
  • b A 7
  • print(a gt b)
  • print(b 2)

31
Parentheses
  • Always optional (except in the case of function
    call)
  • When in doubt, use parentheses
  • a-i lt b/21 lt--gt (a (-i)) lt ((b/2)1)
  • 5x28 lt--gt 5 ( (x2)8 )
  • a lt y and y lt z lt--gt (a lt y) and (y lt z)
  • xyz lt--gt (x(yz))

32
Type string
  • Immutable
  • No size limit (read large files as strings)
  • No termination value (\0)
  • Powerful Pattern-matching in standard library
  • myname Werner Kuhn

33
if statement
  • An if statement tests condition and executes its
    then-part or its else-part (optional) accordingly
  • a 6 b 5
  • if a lt b then
  • print("a lt b")
  • elseif a lt b 5 then
  • print("b lt a lt b5")
  • else
  • print("a gt b5")
  • end

34
for statement
  • for var exp1, exp2, exp3 do
  • something
  • end
  • Execute something for each value of var from exp1
    to exp2, using exp3 as the step to increment var.
    This third expression is optional (default is 1).
  • for i 1, 10 do
  • print(i)
  • end
  • for i 1, 10, 2 do
  • print(i)
  • end

35
Tables
  • Implement associative arrays
  • any value (including functions and other tables)
    can be used both for indices and values

t -- creates an empty table t1
"hello" t.x print -- t.x is sugar for
tx t.x(t1) -- prints hello t.next
t -- circular list
36
table
  • Tables can be indexed not only with numbers, but
    also with strings or any other value of the
    language, except nil
  • loc
  • cover "forest",
  • distRoad 0.3,
  • distUrban 2
  • print(loc"cover")
  • print(loc.cover)
  • loc.distRoad loc.distRoad2
  • loc.distTotal loc.distRoad loc.distUrban
  • loc.deforestationPot 1/loc.distTotal

37
Tables within tables
  • loc cover "forest",
  • dist road 0.3, urban 2
  • print(loc.dist.road)
  • loc.dist.total loc.dist.road loc.dist.urban
  • print(loc.dist.total)

38
Constructors Create and init tables
  • Record style
  • pointx10,y20
  • print(point.y) --gt 20
  • List style
  • days"Sun","Mon","Tue","Wed, Sat"
  • print(days3) --gt Tue
  • Mixed style
  • pointsx0,y0, point, n2
  • print(pointspoints.n.y) --gt 20

39
Constructors
calls function article
article author"F.P.Brooks", title"The
Mythical Man-Month", year1975,
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",
40
function
  • A function can carry out a specific task
    (commonly called procedure) or compute and return
    values.
  • A function is a first-class value in Lua.
  • Functions can be stored in variables and in
    tables, can be passed as arguments, and can be
    returned by other functions, giving great
    flexibility to the language.
  • myprint print
  • print nil
  • myprint(2)
  • print myprint

41
Functions in Lua
  • function fat (n)
  • if n 0 then
  • return 1
  • else
  • return nfat(n-1)
  • end
  • end

42
Higher-order Functions
  • Functions can also be parameters to other
    functions. This kind of function is what we call
    a higher-order function.
  • ??function foreach(tab, func)
  • for position, value in pairs(tab) do
  • func(value, position)
  • end
  • end
  • x 7, 3, 2, 6, 4
  • foreach(x, function(element)
  • print(element)
  • end)
  • foreach(x, function(value, position)
  • print(position, value)
  • end)

43
Functions in Lua
  • First class values
  • Example cloning a table t

clone foreach(t, function (i,e)
cloneie end)
44
Functions and Tables
w redraw function () ... end, pick
function (x,y) ... end,
if w.pick(x,y) then w.redraw() end
45
Tables with functions
  • Tables may have their own functions.
  • loc
  • cover "forest",
  • distRoad 0.3,
  • distUrban 2,
  • deforestPot function(myloc)
  • return 1/(myloc.distRoad myloc.distUrban)
  • end
  • print(loc.deforestPot(loc))
  • print(locdeforestPot())

46
Tables with functions
  • We can declare a class in Lua by creating a
    function that takes a table constructor as
    argument.
  • function MyLocation(locdata)
  • locdata.covertype "forest"
  • locdata.deforPot function(self)
  • return 1/(self.distRoad self.distUrban)
  • end
  • return locdata
  • end
  • loc MyLocation(distRoad 0.3, distUrban 2)
  • loc MyLocationdistRoad 0.3, distUrban 2
  • print(loc.covertype)
  • print(locdeforPot())

47
Tables x Objects
  • Tables are dynamically created objects.

list
old list ...
48
Objects
  • First-class functions tables almost OO
  • Tables can have functions as fields
  • Sugar for method definition and call
  • Implicit parameter self

49
My second Lua program
  • C 2 -- rain/t
  • K 0.4 -- flow coefficient
  • q 0 --
  • function rain (t)
  • if (t lt 10) then
  • return 4 4math.cos(math.pit/10)
  • else
  • return 4 4math.cos(math.pi(t-10)/10)
  • end
  • end
  • --
  • for time 0, 20, 1 do
  • -- soil water
  • q q rain(time) - Kq
  • end
  • -- report
  • print(q "..q)

50
Standard libraries
  • Basic
  • String
  • Table
  • Math
  • IO
  • OS
  • Debug
  • Coroutine

51
TerraME Vision
  • Nature represented by a cellular space
  • Society represented by agents
  • Several interacting entities share the same
    spatiotemporal structure.

52
rain
rain
rain
Itacolomi do Itambé Peak
Lobos Range
My third Lua program Define a two-dimensional
grid Make it rain on the grid Let water flow
downwards
N
53
TerraME Runtime Environment
54
TerraME allows nested scales
55
Nested scales are necessary for human-environment
models
Diverse space partitions can have different
scales
56
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

57
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"
  • csCabecaDeBoiload()
  • csCabecaDeBoiloadMooreNeighbourhood

58
Creating temporary cellular spaces
  • game CellularSpace
  • xdim N,
  • ydim N

59
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.cells7.infCap)

60
Database management
  • -- loads a cellular space
  • csAmazoniaload()
  • csAmazonialoadNeighbourhood("Moore")
  • -- save (time, themeName, attrTableName) --
  • for time 1, 10,1 do
  • csAmazoniasave(time, sim", "water")
  • end

61
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 "abandon" and cell.latency gt
    10) then cell.cover "secFor"
  • end
  • cell.water cell.past.water 2

62
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
  • )

63
Isotropic neighbourhoods in cell spaces
Von Neumann Neighborhood
Moore Neighborhood
64
Traversing a Neighbourhood
  • csqloadNeighbourhood(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

65
Synchronizing a cell space
rule
count 0
for i, cell ipairs( csValeDoAnary ) do end
if ( cell.past.sim_cover 1 ) then
cell.sim_cover 0 count count 1
end cell.synchronize( )
?
print(Number of deforested cells .. count)
66
Synchronizing a cell space
rule
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
67
Synchronization
  • Always read from the past
  • Always write to the present
  • .
  • csQsyncronize()

68
Trajectories spatial patterns of change
  • modeller defined functions which map indexes
    (atributtes) to geo-objects (cells).

it Trajectory myCellSpace,
function(cell) return cell.cover
"forest end, function( c1, c2
) return c1.dist_roads lt c2.dist_roads
end
69
Which objects are nearest to each other?
70
Using Generalized Proximity Matrices (GPM)
Consolidated area
Emergent area
71
TerraME neighborhoods are graphs
Euclidean space
Open network
Closed network
Aguiar et al., 2003
72
Create or load neighborhoods
  • -- Create a Moore neighborhood
  • createMooreNeighborhood( myCellSpace, neighName
    )
  • -- Create a 3x3 neighborhood
  • create3x3Neighborhood(myCellSpace, filterF() ,
    weightF(), name )
  • -- Create a MxN neighborhood
  • createMxNNeighborhood( M, N, myCellSpace,filterF()
    , weightF(), name )
  • -- Load neighborhood from TerraLib database
  • myCellSpace loadTerraLibGPM(myGPM")
  • -- Load neighborhood from TerraLib GAL files
  • myCellSpaceloadGALNeighborhood("c\\myNeigh.gal")

73
Building neighborhoods between cell spaces
  • spatialCoupling( M, N, cs1,cs2, filterF, weightF,
    name )
  • filterF(cell, neigh) ? Boolean
  • wheighF(cell, neigh) ? Real

74
Example neighborhood to simulate rain
  • -- Creates a 3x3 Neighborhood based on the cell
    "slope"
  • -- only lower neighbors are considered
  • create3x3Neighborhood(
  • csQ,
  • function(cell,neigh)
  • return neigh.altimetry lt cell.altimetry
  • end,
  • function(cell, neigh)
  • return (cell.altimetry - neigh.altimetry)/
  • (cell.altimetry neigh.altimetry)
  • end,
  • "slope"
  • )

75
TerraME integration with GIS (TerraView)
76
Conversion from GIS data to cell spaces
Real world
Vector geospatial data
Cell space
77
The mixed pixel problem
How can you transform from vectors to cell
attributes?
78
Fill the attributes of the cell spaces
For each data type to be transformed, there are
appropriate operations
79
Using FillCell plugin to build Cell Spaces
  • 1. Install the FillCell plugin Copy the file
    "celulas.dll" to the directory
  • "C \ Program Files \ TerraView3.2.0
    \ plugins".
  • 2. Build the cell space with the desired
    resolution

80
Filling Cells from vector data
Numerical areas (polygons, cells) Categorical areas (polygons, cells) Lines and points
Min, max, average, sum, standard dev ?
Majority class (by number or by area) ?
Percentage of each class, Percentage of majority class, area of majority class ?
Average/Sum intersection-weighted ?
Presence, minimum distance, count ?
81
rain
rain
rain
Itacolomi do Itambé Peak
Lobos Range
N
82
Picture direction
Itacolomido Itambé Peak
Lobos Range
83
Demo Rain Drainage Model
  • Database c\\TerraME\\Database\\CabecadeBoi.mdb
  • Model c\\TerraME\\Modelos\\demo4_chuva_geoBD.lua
  • Model c\\TerraME\\Modelos\\demo7_chuva_geoBD.lua

84
Simulation Result (36 min.)
85
Demo Fire propagation
  • Database c\\TerraME\\Database\\db_emas.mdb
  • Model c\\TerraME\\Modelos\\demo6_FireSpreadModel
    .lua

CA 1 CA 2 CA 3 CA 4 CA 5
CA 1 0.100 0.250 0.261 0.273 0.285
CA 2 0.113 0.253 0.264 0.276 0.288
CA 3 0.116 0.256 0.267 0.279 0.291
CA 4 0.119 0.259 0.270 0.282 0.294
CA 5 0.122 0.262 0.273 0.285 0.297
86
Demo Amazon deforestation
  • Database c\\TerraME\\Database\\amazonia.mdb
  • Model c\\TerraME\\Modelos\\demo3_desflorestament
    o_save.lua

87
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 (2nd
    edition). Rio de Janeiro, Lua.Org.
Write a Comment
User Comments (0)
About PowerShow.com