Jump to content

Filter Small: Difference between revisions

From SELESwiki
No edit summary
Line 14: Line 14:
In the following sections we will examine all of the model files for this model. Note that instead of downloading the zip file above, you could just copy the text in the boxes below into a text editor and save it with the appropriate name (Section title). Opening the resulting .scn file in the SELES simulator would run this model.
In the following sections we will examine all of the model files for this model. Note that instead of downloading the zip file above, you could just copy the text in the boxes below into a text editor and save it with the appropriate name (Section title). Opening the resulting .scn file in the SELES simulator would run this model.


===MLM.scn===
===FilterSmall.scn===
 
  SELES Scenario
  SELES Scenario
  $gisData$ = ..\..\CaseStudy_Morice\gisData\cell
  $gisData$ = ..\..\CaseStudy\gisData\cell
  StudyArea = $gisData$\BEC
  PatchLayer = $gisData$\Old_bF
  Model Dimensions: StudyArea
  Model Dimensions: PatchLayer
  Model.sel
  filterSmall.sel
  SimPriority Low Priority
  sizeThreshold = 100
//SimStart 100000 1
 
===Model.sel===


===FilterSmall.sel===
  Seles Model
  Seles Model
  Time Units: Step kiloStep 1000 100000
  Time Units: Step KiloStep 1000 2
  Landscape Events:
  Landscape Events:
ConvexHull.lse
  findSmall.lse
  deleteSmall.lse
  Spatial Constants:
  Spatial Constants:
StudyArea
  PatchLayer
  Spatial Variables:
  Spatial Variables:
ConvexHullPoints[1] <= 0
  FilteredPatchLayer[1] <= 0
ConvexHull[1] <= 0
  Visited[2] <= 0
  Global Variables:
  Global Variables:
  TRLoc = 0
  // Size threshold (in cells)
  sizeThreshold = 100
  numFilteredPatches = 0
  numFilteredCells = 0
  numUnfilteredPatches = 0
  numUnfilteredCells = 0
  PatchType = 1
  Output Frequency: 1
  Output Frequency: 1


===ConvexHull.lse===
===FilterSmall.lse===
 
  // Find small patches out of a layer
  // Sweep-line approach to identifying convex hull using a worker agent
  LSEVENT: FindSmall
  LSAGENT: ConvexHull
  DEFINITIONS
  DEFINITIONS
  LAYER: StudyArea, ConvexHull, ConvexHullPoints
  GLOBAL VARIABLE: PatchType
  GLOBAL VARIABLE: TRLoc
  LAYER: PatchLayer, FilteredPatchLayer, Visited
  LOCAL VARIABLE: EndingPivotLoc
  GLOBAL VARIABLE: sizeThreshold
  AGENT VARIABLE: PivotLocation, EdgeLocation, EdgeRow, EdgeCol
  GLOBAL VARIABLE: numUnfilteredPatches, numUnfilteredCells
 
  CLUSTER VARIABLE: currPatchSize
  LOCAL: cps
  ENDDEF
  ENDDEF
  INITIALSTATE
  INITIALSTATE
  FilteredPatchLayer = IF (PatchLayer EQ PatchType) THEN 1 ELSE 0
   INITIALSTATE = 1
   INITIALSTATE = 1
// Find the top-right-most point
  TRLoc = 0
  OVER REGION WHOLE MAP
      DECISION StudyArea > 0
      TRLoc = MAX(TRLoc, Location)
  ENDFN
ConvexHull = 1 // Initialize convex hull layer to all ones (will erase areas outside hull)
  ENDIS
  ENDIS
  NUMAGENTS = 1 // Only need a single worker
  RETURNTIME = 0
// Start on the first pivot vertex on convex hull
AGENTLOCATION
  REGION LOCATION(TRLoc)
ENDAL
  PROBINIT
  PROBINIT
  PROBINIT = 1
  PROBINIT = (FilteredPatchLayer EQ 1) AND (Visited EQ 0)
// Set up first pivot vertex, and first raster boundary location
 
  PivotLocation = Location
  currPatchSize = 0
  EdgeRow = NUMROWS-1
  numUnfilteredPatches = numUnfilteredPatches + (Visited EQ 0)
  EdgeCol = COL(Location)
  numUnfilteredCells = numUnfilteredCells + 1
  EdgeLocation = LOCATION(EdgeRow, EdgeCol)
  cps = 0
  EndingPivotLoc = -1
  ENDPI
  ENDPI
  TRANSITIONS
  TRANSITIONS
  // Continue until we reach the ending pivot location (which is actually second time we hit the second pivot          vertex,
  TRANSITIONS = (Visited EQ 0) AND (FilteredPatchLayer EQ 1)
  // since the first pivot vertex gets only partially processed on first pass)
  Visited = 1
  TRANSITIONS = (PivotLocation NEQ EndingPivotLoc)
  currPatchSize = currPatchSize + 1
ConvexHullPoints = 1
cps = currPatchSize
// Walk line from boundary to vertex and erase until a new pivot vertex is hit (then move there)
  oldPivot = PivotLocation
  hitPivot = FALSE
  OVER REGION VECTOR(EdgeLocation, PivotLocation)
    DECISION !hitPivot
  IF (StudyArea > 0) // hit new vertex
        hitPivot = TRUE
        IF (EndingPivotLoc EQ -1) AND (Location NEQ PivotLocation)
          EndingPivotLoc = PivotLocation
        ENDFN
        PivotLocation = Location
    ELSE
        ConvexHull = 0 // erase
    ENDFN
  ENDFN
// Move boundary location clockwise around outside edge of raster
  IF (EdgeRow EQ NUMROWS-1) AND (EdgeCol < NUMCOLS-1)
    EdgeCol = EdgeCol + 1
  ELSE IF (EdgeCol EQ NUMCOLS-1) AND (EdgeRow > 0)
    EdgeRow = EdgeRow - 1
  ELSE IF (EdgeRow EQ 0) AND (EdgeCol > 0)
    EdgeCol = EdgeCol - 1
  ELSE
    EdgeRow = EdgeRow + 1
  ENDFN
  EdgeLocation = LOCATION(EdgeRow, EdgeCol)
  ENDTR
  ENDTR
  POPULATIONTIME = 1
  SPREADLOCATION
  // Move to current/new pivot location
  REGION CENTRED(1, 1.5)
  MOVELOCATION
      DECISION (Visited EQ 0) AND (FilteredPatchLayer EQ 1)
  REGION LOCATION(PivotLocation)
ENDSL
  ENDML
  SPREADTIME = -1
  ENDCLUSTER
  IF (0 < cps < sizeThreshold)
      Visited = 2
  ENDFN
 
  ENDCLUSTER = 1
  ENDEC


==Suggested Experiments==
==Suggested Experiments==


To explore this cellular automata model further, try the following:
To explore this cellular automata model further, try the following:

Revision as of 21:59, 8 November 2006

Summary

Screenshot

Download Model

Download the .scn, .sel and .lse files by clicking on the following link: File:FilterSmall.zip

Model Code Exploration

In the following sections we will examine all of the model files for this model. Note that instead of downloading the zip file above, you could just copy the text in the boxes below into a text editor and save it with the appropriate name (Section title). Opening the resulting .scn file in the SELES simulator would run this model.

FilterSmall.scn

SELES Scenario
$gisData$ = ..\..\CaseStudy\gisData\cell
PatchLayer = $gisData$\Old_bF
Model Dimensions: PatchLayer
filterSmall.sel
sizeThreshold = 100

FilterSmall.sel

Seles Model
Time Units: Step KiloStep 1000 2
Landscape Events:
  findSmall.lse
  deleteSmall.lse
Spatial Constants:
  PatchLayer
Spatial Variables:
  FilteredPatchLayer[1] <= 0
  Visited[2] <= 0
Global Variables:
  //  Size threshold (in cells)
  sizeThreshold = 100
  numFilteredPatches = 0
  numFilteredCells = 0
  numUnfilteredPatches = 0
  numUnfilteredCells = 0
  PatchType = 1
Output Frequency: 1

FilterSmall.lse

// Find small patches out of a layer
LSEVENT: FindSmall
DEFINITIONS
  GLOBAL VARIABLE: PatchType
  LAYER: PatchLayer, FilteredPatchLayer, Visited 
  GLOBAL VARIABLE: sizeThreshold
  GLOBAL VARIABLE: numUnfilteredPatches, numUnfilteredCells
  
  CLUSTER VARIABLE: currPatchSize
  LOCAL: cps
ENDDEF
INITIALSTATE
  FilteredPatchLayer = IF (PatchLayer EQ PatchType) THEN 1 ELSE 0
  INITIALSTATE = 1
ENDIS
RETURNTIME = 0
PROBINIT
  PROBINIT = (FilteredPatchLayer EQ 1) AND (Visited EQ 0) 
  currPatchSize = 0
  numUnfilteredPatches = numUnfilteredPatches + (Visited EQ 0)
  numUnfilteredCells = numUnfilteredCells + 1
  cps = 0
ENDPI
TRANSITIONS
  TRANSITIONS = (Visited EQ 0) AND (FilteredPatchLayer EQ 1)
  Visited = 1
  currPatchSize = currPatchSize + 1
cps = currPatchSize
ENDTR
SPREADLOCATION
  REGION CENTRED(1, 1.5)
     DECISION (Visited EQ 0) AND (FilteredPatchLayer EQ 1)
ENDSL
SPREADTIME = -1
ENDCLUSTER
  IF (0 < cps < sizeThreshold)
     Visited = 2
  ENDFN
 ENDCLUSTER = 1
ENDEC

Suggested Experiments

To explore this cellular automata model further, try the following: