[Xulu-commits] r63 - in trunk: dist src/edu/bonn/xulu/plugin/model/sleuth
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Oct 26 16:05:42 CET 2009
Author: rgoetzke
Date: 2009-10-26 16:05:38 +0100 (Mon, 26 Oct 2009)
New Revision: 63
Added:
trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel_MC.java
trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel_MC_ContentManager.java
Modified:
trunk/dist/xulu-doc.zip
trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel.java
trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelContentManager.java
Log:
Modified: trunk/dist/xulu-doc.zip
===================================================================
(Binary files differ)
Modified: trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel.java
===================================================================
--- trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel.java 2009-10-21 08:43:39 UTC (rev 62)
+++ trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel.java 2009-10-26 15:05:38 UTC (rev 63)
@@ -23,9 +23,10 @@
* in the code have been untouched and are the same as in the original UGM.<br>
* This is the basic UGM code, a plain Cellular Automaton. Additional functions are implemented in other models, like:<br>
* <ul>
- * <li><b>UGM Calibration ({@link UrbanGrowthModelCalibration})</b>: The same model algorithm like this, but in order to calibrate the model by finding the correct parameter values with the method of Multiple Resolution Comparison (@link MultipleResolutionValidation)</li>
- * <li><b>UGM SelfModifying({@link UrbanGrowthModelSelfModifying})</b>: The same model algorithm like this, but with the possibility of self-modification of the parameter values.</li>
- * <li><b>UGM CalibrationSelfModifying({@link UrbanGrowthModelCalibrationSelfModification})</b>: The same model algorithm like this, but in order to calibrate the model by finding the correct parameter values with the method of Multiple Resolution Comparison (@link MultipleResolutionValidation)
+ * <li><b>UGM MonteCarlo ({@link UrbanGrowthModel_MC UrbanGrowthModel_MC})</b>: The same model algorithm like this, but with Monte Carlo Iterations. The resulting map shows the probabilities for new urbanization (@link MultipleResolutionValidation MultipleResolutionValidation)</li>
+ * <li><b>UGM Calibration ({@link UrbanGrowthModelCalibration UrbanGrowthModelCalibration})</b>: The same model algorithm like this, but in order to calibrate the model by finding the correct parameter values with the method of Multiple Resolution Comparison (@link MultipleResolutionValidation)</li>
+ * <li><b>UGM SelfModifying({@link UrbanGrowthModelSelfModifying UrbanGrowthModelSelfModifying})</b>: The same model algorithm like this, but with the possibility of self-modification of the parameter values.</li>
+ * <li><b>UGM CalibrationSelfModifying({@link UrbanGrowthModelCalibrationSelfModification UrbanGrowthModelCalibrationSelfModification})</b>: The same model algorithm like this, but in order to calibrate the model by finding the correct parameter values with the method of Multiple Resolution Comparison (@link MultipleResolutionValidation)
* While calibrating the model modifies the parameter values.</li>
* </ul>
* <br>
@@ -73,43 +74,43 @@
*
* @see UrbanGrowthModelContentManager
*/
- protected UrbanGrowthModelContentManager contManager;
+ //protected UrbanGrowthModelContentManager contManager;
// ********** Read/Write access, that has to be maintained ***
// ********** through the whole model run ********************
- private PropertyReadAccess RA_inputGrid = null; // Input Grid
- private PropertyWriteAccess WA_outputGrid = null; // Output Grid
- private PropertyReadAccess RA_steps = null; // Number of steps
- private PropertyReadAccess RA_areaRestr = null; //Area Restrictions
- private PropertyReadAccess RA_spread = null; //Spread-Koeffizient
- private PropertyReadAccess RA_disp = null; //Dispersions-Koeffizient
- private PropertyReadAccess RA_breed = null; //Breed-Koeffizient
- private PropertyReadAccess RA_roadGravity = null; //Road-Gravity-Koeffizient
- private PropertyReadAccess RA_slope = null; //Slope-Koeffizient
- private PropertyReadAccess RA_criticalSlope = null; //Critical Slope Value
- private PropertyReadAccess RA_roadGrid = null; //Road Grid
- private PropertyReadAccess RA_slopeGrid = null; //Slope Grid
- private PropertyWriteAccess WA_outStep = null; // Step Results
+ protected PropertyReadAccess RA_inputGrid = null; // Input Grid
+ protected PropertyWriteAccess WA_outputGrid = null; // Output Grid
+ protected PropertyReadAccess RA_steps = null; // Number of steps
+ protected PropertyReadAccess RA_areaRestr = null; //Area Restrictions
+ protected PropertyReadAccess RA_spread = null; //Spread-Koeffizient
+ protected PropertyReadAccess RA_disp = null; //Dispersions-Koeffizient
+ protected PropertyReadAccess RA_breed = null; //Breed-Koeffizient
+ protected PropertyReadAccess RA_roadGravity = null; //Road-Gravity-Koeffizient
+ protected PropertyReadAccess RA_slope = null; //Slope-Koeffizient
+ protected PropertyReadAccess RA_criticalSlope = null; //Critical Slope Value
+ protected PropertyReadAccess RA_roadGrid = null; //Road Grid
+ protected PropertyReadAccess RA_slopeGrid = null; //Slope Grid
+ protected PropertyWriteAccess WA_outStep = null; // Step Results
// **************** Variablen mit denen gearbeitet wird *******************
- private WritableGrid inputGrid = null; // Input Grid
- private WritableGrid outputGrid = null; // Output Grid
- private PropertyReadAccess steps = null; // Number of steps
- private WritableGrid areaRestr = null; //Area Restrictions
+ protected WritableGrid inputGrid = null; // Input Grid
+ protected WritableGrid outputGrid = null; // Output Grid
+ protected PropertyReadAccess steps = null; // Number of steps
+ protected WritableGrid areaRestr = null; //Area Restrictions
protected double spread = 0; //Spread-Koeffizient
protected double disp = 0; //Dispersions-Koeffizient
protected double breed = 0; //Breed-Koeffizient
protected double roadGravity = 0; //Road-Gravity-Koeffizient
protected double slope = 0; //Slope-Koeffizient
protected double criticalSlope = 0; //Critical Slope Value
- private WritableGrid roadGrid = null; //Road Grid
- private WritableGrid slopeGrid = null; //Slope Grid
- private MultiGrid outStep = null; //Step Results
+ protected WritableGrid roadGrid = null; //Road Grid
+ protected WritableGrid slopeGrid = null; //Slope Grid
+ protected MultiGrid outStep = null; //Step Results
/**
* Moore Neighborhood as a two dimensional array. It's the central element of a Cellular Automaton.
*/
- private static final int[][] NEIGHBOR = new int[][] {
+ protected static final int[][] NEIGHBOR = new int[][] {
{-1,-1}, {0,-1}, {1,-1},
{-1, 0}, {1, 0},
{-1, 1}, {0, 1}, {1, 1}
@@ -135,10 +136,14 @@
/**
* Creates a new model instance.
*/
- public UrbanGrowthModel() {
- super(new UrbanGrowthModelContentManager());
+ public UrbanGrowthModel(UrbanGrowthModelContentManager contManager) {
+ super(contManager);
this.contManager = (UrbanGrowthModelContentManager) super.contManager;
}
+
+ public UrbanGrowthModel(){
+ super(new UrbanGrowthModelContentManager());
+ }
/**
@@ -217,7 +222,7 @@
//count the number of starting individuals
int startAnz = 0;
- startAnz = countIndividuals();
+ startAnz = countSetIndividuals();
statusOut.println("Number of starting cells: "+startAnz);
statusOut.println("Neighborhood size: "+NEIGHBOR.length);
@@ -267,6 +272,8 @@
statusOut.println("RoadGravity-Value: "+rg_value);
max_search_index = Math.round(4*((int)rg_value*(1+(int)rg_value))); //area in which to look for a road cell
statusOut.println("MaxSearchIndex: "+max_search_index);
+
+ //outputGrid = inputGrid;
}
/**
@@ -403,12 +410,13 @@
}
/**
- * This function counts the starting individual cells for the urban growth model run.<br>
+ * This function counts the starting individual cells for the urban growth model run and sets the outputGrid
+ * to the base inputGrid.<br>
* It only works for a binary classification with urban cells having the value 1 and non-urban
* cells the value 0.
* @return startAnz
*/
- public int countIndividuals(){
+ public int countSetIndividuals(){
int startAnz = 0;
for (int i = 0; i < inputGrid.getWidth();i++ ) {
for (int ii = 0; ii < inputGrid.getHeight(); ii++ ) {
@@ -418,6 +426,8 @@
startAnz++; //count if value is 1
}
else val = 0f;
+ inputGrid.setRasterSample(val, inputGrid.getMinX() + i, inputGrid.getMinY() + ii);
+ outputGrid.setRasterSample(val, inputGrid.getMinX() + i, inputGrid.getMinY() + ii);
}
}
return startAnz;
Modified: trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelContentManager.java
===================================================================
--- trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelContentManager.java 2009-10-21 08:43:39 UTC (rev 62)
+++ trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelContentManager.java 2009-10-26 15:05:38 UTC (rev 63)
@@ -9,20 +9,14 @@
import edu.bonn.xulu.model.ValuePropertyResource;
import edu.bonn.xulu.plugin.data.grid.MultiGrid;
-
public class UrbanGrowthModelContentManager extends AbstractModelContentManager {
- public UrbanGrowthModelContentManager() {
- this(13);
- }
- protected UrbanGrowthModelContentManager(int resourceCount) {
- super(resourceCount);
-
+ public UrbanGrowthModelContentManager(int additionalRes) {
+ super(13+additionalRes);
+
resource[0] = new ValuePropertyResource(ModelResource.CATEGORY_INPUT,"Input Grid",ScalarProperty.class,WritableGrid.class,false);
resource[1] = new ValuePropertyResource(ModelResource.CATEGORY_OUTPUT,"Output Grid",ScalarProperty.class,WritableGrid.class,false);
- // Number of steps
resource[2] = new ValuePropertyResource(ModelResource.CATEGORY_INPUT,"Number of steps",ScalarProperty.class,Integer.class,false);
- // Spread Coefficient
resource[3] = new ValuePropertyResource(ModelResource.CATEGORY_INPUT,"Area Restrictions",ScalarProperty.class,WritableGrid.class,false);
resource[4] = new ValuePropertyResource(ModelResource.CATEGORY_INPUT,"Spread Coefficient",ScalarProperty.class,Double.class,false);
resource[5] = new ValuePropertyResource(ModelResource.CATEGORY_INPUT,"Dispersion Coefficient",ScalarProperty.class,Double.class,false);
@@ -38,7 +32,11 @@
resetCaptions(null);
}
+ public UrbanGrowthModelContentManager() {
+ this(0);
+ }
+
@Override
public void checkAndError() throws XuluDataException {
// TODO Auto-generated method stub
Added: trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel_MC.java
===================================================================
--- trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel_MC.java 2009-10-21 08:43:39 UTC (rev 62)
+++ trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel_MC.java 2009-10-26 15:05:38 UTC (rev 63)
@@ -0,0 +1,198 @@
+package edu.bonn.xulu.plugin.model.sleuth;
+
+
+import schmitzm.data.property.PropertyReadAccess;
+import schmitzm.data.property.ScalarProperty;
+import edu.bonn.xulu.model.XuluModel;
+
+/**
+ * <b>Urban Growth Model with Monte-Carlo Iterations</b><br>
+ * This model is based on the {@link UrbanGrowthModel Urban Growth Model}, developed by Keith Clarke at the UC Santa Barbara, CA, within the Gigalopolis Project, funded by the
+ * USGS. It has exactly the same growth rules as its parent class, but runs with n Monte-Carlo Iterations. So the resulting map does not contain the urban extent after a model
+ * run, but the probability for new urbanization. The more often a cell has been selected for urbanization during the Monte-Carlo Iterations, the higher is that value in the
+ * output map.
+ * For a detailed description refer to {@link UrbanGrowthModel Urban Growth Model}
+ *
+ * <br>
+ * In addition to the UGM parameters, this parameter is needed:<br>
+ * <ul>
+ * <li><b>Monte Carlo Iterations({@code slopeGrid})</b>: The number of Monte Carlo Iterations.</li>
+ * </ul>
+ *
+ * @see UrbanGrowthModel_MC_ContentManager
+ * @see UrbanGrowthModel
+ * @author <a href="mailto:goetzke at uni-bonn.de">Roland Goetzke</a>
+ * @version 1.0
+ */
+public class UrbanGrowthModel_MC extends UrbanGrowthModel{
+
+ protected PropertyReadAccess RA_MonteCarlo = null; // Number of MonteCarlo Iterations
+
+ protected int MonteCarlo = 0; // Number of MonteCarlo Iterations
+ protected int years = 0;
+
+ /**
+ * First Constructor
+ * @param contManager
+ */
+ public UrbanGrowthModel_MC(UrbanGrowthModel_MC_ContentManager contManager) {
+ super(contManager);
+ this.contManager = (UrbanGrowthModel_MC_ContentManager) super.contManager;
+ }
+ /**
+ * Second Constructor. The Content Manager is the parent content manager as well as the child content manager
+ */
+ public UrbanGrowthModel_MC(){
+ super(new UrbanGrowthModel_MC_ContentManager());
+ }
+
+ /**
+ * Initializes the model. Like in the init method of every {@link XuluModel}
+ * the resources are initalized.
+ */
+ public void performModelInit() {
+ super.performModelInit();
+
+
+ RA_MonteCarlo = null;
+ if (contManager.getResource(13).getData() != null)
+ RA_MonteCarlo = ((ScalarProperty) contManager.getResource(13).getData())
+ .getReadAccess(this);
+
+ MonteCarlo = RA_MonteCarlo.getValueAsInt();
+ this.stepCount = MonteCarlo;
+ years = steps.getValueAsInt();
+ }
+
+ /**
+ * like in every model: frees the resources
+ */
+ public void performModelDispose() {
+ super.performModelDispose();
+ releaseAccess(RA_MonteCarlo);
+ }
+
+ /**
+ * The main method of the Urban Growth Model. For a detailed description refer to the performModelStep in
+ * {@link UrbanGrowthModel UrbanGrowthModel}. The difference is, that the number of steps is not based on
+ * the years that have to be modelled, but on the number of Monte-Carlo iterations the model has to perform.
+ * In every iteration the full {@link UrbanGrowthModel UrbanGrowthModel} is included in a for-loop. In the
+ * StepResults GridList are the results for the final year for every Monte-Carlo iteration and the sum of
+ * all iterations, which indicates high values for pixels that have been selected several times for urbanization.
+ */
+ public void performModelStep(int stepNo) {
+
+ statusOut.println("Performing "+MonteCarlo+" Monte Carlo Iterations (years: "+stepNo);
+ long localStartTime = System.currentTimeMillis(); //time measure
+ Float actUrb = null; //urban cell in the raster
+ for(int timeSteps = 1;timeSteps <=years;timeSteps++){ //for every time step...
+ statusOut.println("Year "+timeSteps);
+ boolean[][] tmpGrid = new boolean[inputGrid.getWidth()][inputGrid.getHeight()]; //a temporary raster
+
+ /*****************************************************************
+ * DISPERSION and BREED (Growth Phase 1 and 2)
+ *****************************************************************/
+ boolean[][] tmpGridDisp = new boolean[inputGrid.getWidth()][inputGrid.getHeight()]; //a temporary raster
+ tmpGridDisp = DispersionGrowth(); //calls the method "DispersionBreed" to perform the Dispersion and Breed Growth Phase
+ int anzDispBreed = 0; //number of cells urbanized by Dispersion and Breed
+ for (int x = 0; x < inputGrid.getWidth();x++)
+ for(int y = 0; y < inputGrid.getHeight();y++){
+ int X = inputGrid.getMinX() + x;
+ int Y = inputGrid.getMinY() + y;
+ if (tmpGridDisp[X][Y]==true){
+ anzDispBreed++;
+ tmpGrid[X][Y] = true; //write the temporary Dispersion and Breed Cells to the overall temporary Cell array
+ }
+ }
+ statusOut.println("Number of Spontaneous and New Spreading Center Cells: "+anzDispBreed);
+ writeToGrid(tmpGrid); //calls the method "writeToGrid" to write the new urbanized cells to the output grid
+
+ /*********************************************************************
+ * EDGE
+ *********************************************************************/
+ boolean[][] tmpGridSpread = new boolean[inputGrid.getWidth()][inputGrid.getHeight()]; //a temporary raster
+ tmpGridSpread = EdgeGrowth(); //calls the method "EdgeGrowth" to perform the Spread (Edge Growth) Phase
+ int anzSpread = 0; //number of cells urbanized by Spread
+ for (int x = 0; x < inputGrid.getWidth();x++)
+ for(int y = 0; y < inputGrid.getHeight();y++){
+ int X = inputGrid.getMinX() + x;
+ int Y = inputGrid.getMinY() + y;
+ if (tmpGridSpread[X][Y]==true){
+ anzSpread++;
+ tmpGrid[X][Y] = true; //write the temporary Spread cells to the overall temporary Cell array
+ }
+ }
+ statusOut.println("Number of Edge Growth Cells: "+anzSpread);
+ writeToGrid(tmpGrid); //calls the method "writeToGrid" to write the new urbanized cells to the output grid
+
+ /*********************************************************************
+ * ROAD
+ *********************************************************************/
+
+ boolean[][] tmpGridRoad = new boolean[inputGrid.getWidth()][inputGrid.getHeight()]; //a temporary raster
+ tmpGridRoad = RoadGrowth(tmpGrid); //calls the method "RoadGrowth" to perform the Road weighted growth
+ int anzRoad = 0; //number of cells urbanized by Road Growth
+ for (int x = 0; x < inputGrid.getWidth();x++)
+ for(int y = 0; y < inputGrid.getHeight();y++){
+ int X = inputGrid.getMinX() + x;
+ int Y = inputGrid.getMinY() + y;
+ if (tmpGridRoad[X][Y]==true){
+ anzRoad++;
+ tmpGrid[X][Y] = true; //write the temporary Road Growth cells to the overall temporary Cell array
+ }
+ }
+ statusOut.println("Number of Road Growth Cells: "+anzRoad);
+ writeToGrid(tmpGrid); //calls the method "writeToGrid" to write the new urbanized cells to the output grid
+
+ int anzGesamt = 0;
+
+ // Write the temporary Grid to the Output Grid
+ for (int y = 1; y < inputGrid.getHeight()-1;y++ ) {
+ for (int x = 1; x < inputGrid.getWidth()-1; x++ ) {
+
+ int X = inputGrid.getMinX() + x;
+ int Y = inputGrid.getMinY() + y;
+
+ if (tmpGrid[x][y] == true)
+ anzGesamt++;
+
+ boolean lebt = outputGrid.getRasterSampleAsFloat(X , Y ) > 0f; //a cell is alive, when it is 1
+ if (tmpGrid[x][y] == false) //if there is nothing in the temporary raster
+ tmpGrid[x][y] = lebt; //take the values from the current output raster
+
+ outputGrid.setRasterSample( tmpGrid[x][y] ? 1f : 0f ,X ,Y); //write the results in the output raster
+ actUrb = (Float)outputGrid.getRasterSample(x,y); //the actual urban extent
+ // outStep.getGrid(stepNo-1).setRasterSample(actUrb,x,y); //put the layer in the raster list containing the step results
+ }
+ }
+ statusOut.println("Urban pixels at step "+timeSteps+": "+anzGesamt);
+ }
+ outStep.addGrid(); //add a raster to the GridList
+
+ // Write the temporary Grid to the Output Grid
+ for (int y = 1; y < inputGrid.getHeight()-1;y++ ) {
+ for (int x = 1; x < inputGrid.getWidth()-1; x++ ) {
+ actUrb = (Float)outputGrid.getRasterSample(x,y); //the actual urban extent
+ outStep.getGrid(stepNo-1).setRasterSample(actUrb,x,y); //put the layer in the raster list containing the step results
+ }
+ }
+
+ countSetIndividuals(); //sets the outputGrid to the initial inputGrid in order to start the next modelling step with the same initial map
+ System.out.println("Finished step " + (stepNo) + " in "
+ + ((System.currentTimeMillis() - localStartTime)) + " ms\n");
+ if (stepNo == MonteCarlo){
+ outStep.addGrid(); //add a final raster to the GridList (contains the sum of all iterations)
+
+ for (int y = 1; y < inputGrid.getHeight()-1;y++ ) {
+ for (int x = 1; x < inputGrid.getWidth()-1; x++ ) { //for every pixel...
+ float sumUrb = 0; //sum of pixel values
+ for (int gridNo = 0; gridNo <= stepNo; gridNo++){ //look in every grid of the GridList
+ float tempUrb = (Float) outStep.getGrid(gridNo).getRasterSample(x,y); //take the pixel value
+ sumUrb += tempUrb; //and add its value
+ }
+ outStep.getGrid(stepNo).setRasterSample(sumUrb,x,y); //put the layer in the raster list containing the step results
+ }
+ }
+ }
+ }
+}
Added: trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel_MC_ContentManager.java
===================================================================
--- trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel_MC_ContentManager.java 2009-10-21 08:43:39 UTC (rev 62)
+++ trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel_MC_ContentManager.java 2009-10-26 15:05:38 UTC (rev 63)
@@ -0,0 +1,26 @@
+package edu.bonn.xulu.plugin.model.sleuth;
+
+import schmitzm.data.property.ScalarProperty;
+import edu.bonn.xulu.data.XuluDataException;
+import edu.bonn.xulu.model.ModelResource;
+import edu.bonn.xulu.model.ValuePropertyResource;
+
+public class UrbanGrowthModel_MC_ContentManager extends UrbanGrowthModelContentManager {
+
+ public UrbanGrowthModel_MC_ContentManager(int additionalRes) {
+ super(1+additionalRes);
+ resource[13] = new ValuePropertyResource(ModelResource.CATEGORY_INPUT,"Monte-Carlo Iterations",ScalarProperty.class,Integer.class,false);
+ }
+
+ public UrbanGrowthModel_MC_ContentManager() {
+ this(0);
+
+ }
+
+ @Override
+ public void checkAndError() throws XuluDataException {
+ // TODO Auto-generated method stub
+ super.checkAndError();
+ }
+
+}
More information about the Xulu-commits
mailing list