Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
ego_script [2012/09/24 02:04] hermann |
ego_script [2015/09/14 02:31] admin [Overview] |
||
---|---|---|---|
Line 11: | Line 11: | ||
A simple EGO script model can be seen below: | A simple EGO script model can be seen below: | ||
- | <file cpp ego1.ego> | + | <file java ego1.ego> |
Script {{ | Script {{ | ||
// Loads a GeoTiff map. | // Loads a GeoTiff map. | ||
Line 32: | Line 32: | ||
Here is a slightly more complex example: | Here is a slightly more complex example: | ||
- | <file cpp ego2.ego> | + | <file java ego2.ego> |
Script {{ | Script {{ | ||
landscape := LoadCategoricalMap "c:/landscape.tif"; | landscape := LoadCategoricalMap "c:/landscape.tif"; | ||
- | cells hects m2s := CalcAreas landscape; | + | areas := CalcAreas landscape; |
- | SaveLookupTable hects "c:/area_in_hectares.csv"; | + | SaveTable areas "c:/areas.csv"; |
}}; | }}; | ||
</file> | </file> | ||
- | Note that functor [[Calc Areas]] produces three lookup tables, representing the calculated area in cells, hectares and square meters. | + | Note that functor [[Calc Areas]] produces a table, representing the calculated area in cells, hectares and square meters. |
It is possible to omit variables representing outputs or ignore them using the variable ''_'' (underline). So the previous example can be re-written as shown below: | It is possible to omit variables representing outputs or ignore them using the variable ''_'' (underline). So the previous example can be re-written as shown below: | ||
- | <file cpp ego3.ego> | + | <file java ego3.ego> |
Script {{ | Script {{ | ||
landscape := LoadCategoricalMap "c:/landscape.tif"; | landscape := LoadCategoricalMap "c:/landscape.tif"; | ||
Line 64: | Line 64: | ||
It is also possible to use the input and output names to bind variables and parameters. The previous example can be rewritten as | It is also possible to use the input and output names to bind variables and parameters. The previous example can be rewritten as | ||
- | <file cpp ego4.ego> | + | <file java ego4.ego> |
Script {{ | Script {{ | ||
{ landscape=map } := LoadCategoricalMap { filename="c:/landscape.tif" }; | { landscape=map } := LoadCategoricalMap { filename="c:/landscape.tif" }; | ||
Line 78: | Line 78: | ||
It is possible to freely mix both styles. So you can write the previous input as | It is possible to freely mix both styles. So you can write the previous input as | ||
- | <file cpp ego4.ego> | + | <file java ego4.ego> |
Script {{ | Script {{ | ||
landscape := LoadCategoricalMap { filename="c:/landscape.tif" }; | landscape := LoadCategoricalMap { filename="c:/landscape.tif" }; | ||
Line 88: | Line 88: | ||
It is also possible to inline a definition of functor pretty much like nesting function calls in other programming languages: | It is also possible to inline a definition of functor pretty much like nesting function calls in other programming languages: | ||
- | <file cpp ego5.ego> | + | <file java ego5.ego> |
Script {{ | Script {{ | ||
{ hects=cellAreaInHectares } := CalcAreas (LoadCategoricalMap { filename="c:/landscape.tif" }); | { hects=cellAreaInHectares } := CalcAreas (LoadCategoricalMap { filename="c:/landscape.tif" }); | ||
Line 103: | Line 103: | ||
You can define a single line comment preceding the text with a '%%//%%'. | You can define a single line comment preceding the text with a '%%//%%'. | ||
- | <code cpp> | + | <code java> |
// This is a single line comment. | // This is a single line comment. | ||
</code> | </code> | ||
Line 109: | Line 109: | ||
Multi-line comments can be defined surrounding the text with '%%/*%%' and '%%*/%%'. | Multi-line comments can be defined surrounding the text with '%%/*%%' and '%%*/%%'. | ||
- | <code cpp> | + | <code java> |
/* This is a multi-line | /* This is a multi-line | ||
comment */ | comment */ | ||
Line 116: | Line 116: | ||
It is worth noting that there is a very important difference between both comment styles: multi-line comment style are not preserved if the model is opened using the graphical interface. Usually this is not a problem since multi-line comment can be defined using the '%%//%%' style. Ex: | It is worth noting that there is a very important difference between both comment styles: multi-line comment style are not preserved if the model is opened using the graphical interface. Usually this is not a problem since multi-line comment can be defined using the '%%//%%' style. Ex: | ||
- | <code cpp> | + | <code java> |
// This is a multi-line | // This is a multi-line | ||
// comment | // comment | ||
Line 125: | Line 125: | ||
The sequence ''==='' is used to separate the brief and extended comments of a functor. | The sequence ''==='' is used to separate the brief and extended comments of a functor. | ||
- | <code cpp> | + | <code java> |
// Generate the initial 'seed' | // Generate the initial 'seed' | ||
// | // | ||
Line 165: | Line 165: | ||
The first syntax represents properties using comments. | The first syntax represents properties using comments. | ||
- | <code cpp> | + | <code java> |
/** name = value */ | /** name = value */ | ||
</code> | </code> | ||
Line 171: | Line 171: | ||
The other syntax uses the special symbol @. | The other syntax uses the special symbol @. | ||
- | <code cpp> | + | <code java> |
@name = value | @name = value | ||
</code> | </code> | ||
Line 179: | Line 179: | ||
Examples of properties can be seen below: | Examples of properties can be seen below: | ||
- | <code cpp> | + | <code java> |
/** | /** | ||
dff.date = Wed Oct 21 18:19:21 2009 | dff.date = Wed Oct 21 18:19:21 2009 | ||
Line 195: | Line 195: | ||
</code> | </code> | ||
- | <code cpp> | + | <code java> |
@alias = Largest Patch Area | @alias = Largest Patch Area | ||
@collapsed = yes | @collapsed = yes | ||
Line 232: | Line 232: | ||
The syntax | The syntax | ||
- | <code cpp> | + | <code java> |
// The input map. | // The input map. | ||
// | // | ||
Line 240: | Line 240: | ||
and | and | ||
- | <code cpp> | + | <code java> |
@comment = "The input map. | @comment = "The input map. | ||
Line 255: | Line 255: | ||
Since Dinamica EGO version 2.0, expressions in EGO Script can be represented using an additional special syntax. The example below illustrates: | Since Dinamica EGO version 2.0, expressions in EGO Script can be represented using an additional special syntax. The example below illustrates: | ||
- | <code cpp> | + | <code java> |
if #random <= ($mean - $min) / ($max - $min) then | if #random <= ($mean - $min) / ($max - $min) then | ||
$min + sqrt(#random * ($max - $min) * ($mean - $min)) | $min + sqrt(#random * ($max - $min) * ($mean - $min)) | ||
Line 265: | Line 265: | ||
The use of sigils has some advantages including making easy to determine the data type represented by the variables. They also prevent clashes between special names like "rand", "line" and "column" and the user defined ones. ((Using sigils the expression "rand + #rand" is the sum of a random value with a the value of map named "rand")) | The use of sigils has some advantages including making easy to determine the data type represented by the variables. They also prevent clashes between special names like "rand", "line" and "column" and the user defined ones. ((Using sigils the expression "rand + #rand" is the sum of a random value with a the value of map named "rand")) | ||
- | |||
- | //However, keep in mind that this syntax is not fully compatible with the graphical interface and you may end up having an invalid model if you edit a model created using this syntax in the graphical interface.// | ||
=== Examples === | === Examples === | ||
Line 272: | Line 270: | ||
The example below represents a fragment of a real model using the original syntax: | The example below represents a fragment of a real model using the original syntax: | ||
- | <code cpp> | + | <code java> |
patches := LoadCategoricalMap "../originals/landscape.ers" .no .no 0 0 .none; | patches := LoadCategoricalMap "../originals/landscape.ers" .no .no 0 0 .none; | ||
// ... | // ... | ||
Line 291: | Line 289: | ||
The model modified to use the special expression calculation syntax can be seen below: | The model modified to use the special expression calculation syntax can be seen below: | ||
- | <code cpp> | + | <code java> |
patches := LoadCategoricalMap "../originals/landscape.ers" .no .no 0 0 .none; | patches := LoadCategoricalMap "../originals/landscape.ers" .no .no 0 0 .none; | ||
// ... | // ... | ||
Line 298: | Line 296: | ||
// Isolate the patches of a single category. | // Isolate the patches of a single category. | ||
@collapsed = yes | @collapsed = yes | ||
- | singleCategoryPatches := #[ if #patches = $currenteCategoryId then 1 else null ]; | + | singleCategoryPatches := #[ if #patches = $currenteCategoryId then 1 else null ] .uint8 0 .no; |
</code> | </code> | ||
===== Complex Example ===== | ===== Complex Example ===== | ||
- | <code cpp> | + | <code java> |
@title = Calc Patch Sizes, Mean Patch Sizes and Patch Size Standard Deviations | @title = Calc Patch Sizes, Mean Patch Sizes and Patch Size Standard Deviations | ||
@author = Dinamica Team | @author = Dinamica Team | ||
Line 342: | Line 340: | ||
// Isolate the patches of a single category. | // Isolate the patches of a single category. | ||
@collapsed = yes | @collapsed = yes | ||
- | singleCategoryIndividualizedPatches := CalculateMap [ | + | singleCategoryIndividualizedPatches := # [ |
- | if i1 = v1 then | + | if #patches = $currentCategory then |
- | i1 | + | #patches |
else | else | ||
null | null | ||
- | ] .int32 .default .no .none {{ | + | ] .int32 .default .no .none; |
- | NumberMap patches 1; | + | |
- | + | ||
- | NumberValue currentCategory 1; | + | |
- | }}; | + | |
// Calculate the patch size, the mean patch size and patch size standard | // Calculate the patch size, the mean patch size and patch size standard | ||
Line 375: | Line 369: | ||
// The calculation uses the total patch size and the number of individual patches. | // The calculation uses the total patch size and the number of individual patches. | ||
@collapsed = yes | @collapsed = yes | ||
- | mean := CalculateValue [ | + | mean := $ [ |
- | (t1["cellArea"] * t1["nonNullCells"] / t1["uniqueCells"]) ? 0 | + | (%attributes["cellArea"] * %attributes["nonNullCells"] / %attributes["uniqueCells"]) ? 0 |
- | ] .no 0 {{ | + | ] .no 0; |
- | NumberTable attributes 1; | + | |
- | }}; | + | |
// Calculate the patch sizes. | // Calculate the patch sizes. | ||
Line 404: | Line 396: | ||
// patch size. | // patch size. | ||
@collapsed = yes | @collapsed = yes | ||
- | updatedAccumulatedValue := CalculateValue [ | + | updatedAccumulatedValue := $ [ |
- | v1 + ((t1[v2] - v3) ^ 2) | + | $currentAccumulatedValue + ((%patchSizesInHectares[$currentPatchId] - $mean) ^ 2) |
- | ] .no 0 {{ | + | ] .no 0; |
- | NumberValue mean 3; | + | |
- | + | ||
- | NumberValue currentAccumulatedValue 1; | + | |
- | + | ||
- | NumberValue currentPatchId 2; | + | |
- | + | ||
- | NumberTable patchSizesInHectares 1; | + | |
- | }}; | + | |
}}; | }}; | ||
}}; | }}; | ||
Line 424: | Line 408: | ||
// Calculate the standard deviation using the SUM(Xi - MEAN)^2. | // Calculate the standard deviation using the SUM(Xi - MEAN)^2. | ||
@collapsed = yes | @collapsed = yes | ||
- | standardDeviation := CalculateValue [ | + | standardDeviation := $ [ |
- | sqrt(v1 / t1["uniqueCells"]) ? 0 | + | sqrt($accumulatedValue / %attributes["uniqueCells"]) ? 0 |
- | ] .no 0 {{ | + | ] .no 0; |
- | NumberValue accumulatedValue 1; | + | |
- | + | ||
- | NumberTable attributes 1; | + | |
- | }}; | + | |
}}; | }}; | ||