[Xulu-commits] r96 - in trunk: dist src/edu/bonn/xulu/plugin/model/sleuth

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 5 11:29:45 CEST 2010


Author: rgoetzke
Date: 2010-10-05 11:29:37 +0200 (Tue, 05 Oct 2010)
New Revision: 96

Modified:
   trunk/dist/xulu-doc.zip
   trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel.java
   trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelCalibration.java
   trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelCalibrationSelfModification.java
   trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelSelfModification.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	2010-09-09 18:04:43 UTC (rev 95)
+++ trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModel.java	2010-10-05 09:29:37 UTC (rev 96)
@@ -44,7 +44,7 @@
  *  The following input parameters/images are required:<br>
  * <ul>
  *  <li><b>Input Grid ({@code inputGrid})</b>: A grid containing the input (initial) urban land cover.</li>
- *  <li><b>Area Restriction ({@code areaRestr})</b>: A grid containing the area restrictions (e.g. water, natural reserves, areas with lower probability, etc.).</li>
+ *  <li><b>Area Restriction ({@code areaRestr})</b>: A grid containing the area restrictions (e.g. water, natural reserves, areas with lower probability, etc.). A value of 1 indicates total restriction and 0 total availability for new urbanization. Floating point values in between allow gradual availability for urbanization.</li>
  *  <li><b>Transportation Grid ({@code roadGrid})</b>: A grid containing the road network.</li>
  *  <li><b>Slope Grid ({@code slopeGrid})</b>: A grid containing the slope.</li>
  *  <li><b>Number of steps ({@code steps})</b>: The number of time steps to compute.</li>
@@ -65,7 +65,7 @@
  * 
  * @see UrbanGrowthModelContentManager
  * @author <a href="mailto:goetzke at uni-bonn.de">Roland Goetzke</a>
- * @version 1.0
+ * @version 1.1
  */
 public class UrbanGrowthModel extends AbstractStepModel {
 
@@ -501,11 +501,12 @@
 			if ( dispRandX < areaMinX || dispRandY < areaMinY || dispRandX > areaMaxX || dispRandY > areaMaxY ||
 					Float.isNaN(outputGrid.getRasterSampleAsFloat(dispRandX,dispRandY)) ) 
 				continue;		//if a cell is outside the raster (NaN), break and continue loop from the beginning
-			if (areaRestr.getRasterSampleAsFloat(dispRandX,dispRandY) != 0 || outputGrid.getRasterSampleAsFloat(dispRandX,dispRandY) == 1)
+			if (areaRestr.getRasterSampleAsFloat(dispRandX,dispRandY) == 1 || outputGrid.getRasterSampleAsFloat(dispRandX,dispRandY) == 1)
 	        	continue;		//if a cell is inside an excluded area or already exists, break and continue loop from the beginning
 	        slopeRandDisp = (float) Math.random();	//a random slope value between 0.0 and 1.0
 	        double slopeDouble = getSlopeValue(dispRandX,dispRandY,slopeLUT);	//returns the slope value for the cell
-	        if(slopeDouble < slopeRandDisp){	//if the slope value of the pixel is smaller than the slope value
+	        double restrDouble = areaRestr.getRasterSampleAsFloat(dispRandX,dispRandY); //returns the area restriction value for the cell
+	        if(slopeDouble < slopeRandDisp && restrDouble < slopeRandDisp){	//if the slope value of the pixel is smaller than the slope value AND the restriction value 
 	        	tmpGridDispBreed[dispRandX][dispRandY] = true;	//true is written in the temporary raster
 	        	anzDispTreffer++;		//count number of dispersion cells
 	        	
@@ -564,15 +565,16 @@
     			if ( nbBreedX < areaMinX || nbBreedY < areaMinY || nbBreedX > areaMaxX || nbBreedY > areaMaxY ||
     					Float.isNaN(outputGrid.getRasterSampleAsFloat(nbBreedX,nbBreedY)) ) 
     				continue;	//if a cell is outside the raster (NaN), break and continue loop from the beginning
-    			if (areaRestr.getRasterSampleAsFloat(nbBreedX,nbBreedY) != 0)
+    			if (areaRestr.getRasterSampleAsFloat(nbBreedX,nbBreedY) == 1)
     				continue;	//if a cell is inside an excluded area, break and continue loop from the beginning
     			RNBreedSlope = (float)Math.random();	//a random slope value between 0.0 and 1.0
     			double slopeDoubleNb = getSlopeValue(nbBreedX,nbBreedY,slopeLUT);	//returns the slope value for the neighboring cells which are available for breed
+    			double restrDoubleNb = areaRestr.getRasterSampleAsFloat(nbBreedX,nbBreedY);	//returns the restriction value for the neighboring cells which are avaliable for breed
     			float breedSample = outputGrid.getRasterSampleAsFloat(nbBreedX,nbBreedY);	//takes the value from the input grid
     			if (breedSample == 0f){		//if it is free for urbanization...
     				anzBreedTemp++;		//increase the number of temporary breed cells
     				nbPossibleBreedUrban = new int[] {nbBreedX,nbBreedY,anzBreedTemp};	//create a new array containing the x and y coordinates and the number of the breed pixel
-    				if (nbPossibleBreedUrban[2] == RNBreed1 || nbPossibleBreedUrban[2] == RNBreed2 && slopeDoubleNb < RNBreedSlope){	//if the cell has the same value as the first or second random value and its slope value is smaller than the random slope value...
+    				if (nbPossibleBreedUrban[2] == RNBreed1 || nbPossibleBreedUrban[2] == RNBreed2 && slopeDoubleNb < RNBreedSlope && restrDoubleNb < RNBreedSlope){	//if the cell has the same value as the first or second random value and its slope and restriction values are smaller than the random slope value...
     					tmpBreedArray[anzBreedTreffer][0] = nbBreedX;	//x-coordinate
     					tmpBreedArray[anzBreedTreffer][1] = nbBreedY;	//y-coordinate
     					tmpGridBreed[nbBreedX][nbBreedY] = true;	//urbanize the cell in the temporary grid
@@ -624,18 +626,19 @@
 						if ( nbX < areaMinX || nbY < areaMinY || nbX > areaMaxX || nbY > areaMaxY ||
 					               Float.isNaN(outputGrid.getRasterSampleAsFloat(nbX,nbY)))
 					             continue;	//if a cell is outside the raster (NaN), break and continue loop from the beginning
-						if (areaRestr.getRasterSampleAsFloat(nbX,nbY) != 0)
+						if (areaRestr.getRasterSampleAsFloat(nbX,nbY) == 1)
 				        	continue;	//if a cell is inside an excluded area, break and continue loop from the beginning
 						RNEdgeSlope = (float)Math.random();		//a random number to be compared with the slope value
 						double slopeDoubleNb = getSlopeValue(nbX,nbY,slopeLUT);	//returns the slope value for the neighboring cells which are available for breed
-	        			float rasterSample = outputGrid.getRasterSampleAsFloat(nbX,nbY);	//takes the value from the input gridn
+						double restrDoubleNb = areaRestr.getRasterSampleAsFloat(nbX,nbY);	//returns the restriction value for the neighboring cells which are available for breed 
+	        			float rasterSample = outputGrid.getRasterSampleAsFloat(nbX,nbY);	//takes the value from the input grid
 						if (rasterSample == 0f){	//if the value is 0 and thus is possible for urbanization
 							anzTemp++;				//count it
 							nbPossibleUrban = new int[] {nbX,nbY,anzTemp};	//write it with its coordinates in an array
 							//float NbValueEdge = 1f;
 							if (nbPossibleUrban[2] == RN){	//if the number in the "possible for urbanization" array is the same as the random number...
 								//int urbanNbTemp = calculateNeighbors(nbX,nbY,NbValueEdge);	//to reduce the effect of edge growth here could be included an option that allows only growth when a new urban cell has at least 2 urban neighbors
-								if (tmpGridSpread[nbX][nbY]==false && slopeDoubleNb < RNEdgeSlope){	// if the cell is non-urban and it passes the slope test //urbanNbTemp >= 2 && 
+								if (tmpGridSpread[nbX][nbY]==false && slopeDoubleNb < RNEdgeSlope && restrDoubleNb < RNEdgeSlope){	// if the cell is non-urban and it passes the slope and restriction tests //urbanNbTemp >= 2 && 
 									tmpGridSpread[nbX][nbY] = true;	//write it in the temporary raster
 									anzSpreadTreffer++;	//count the hits
 								}
@@ -846,15 +849,16 @@
 										if ( nbUrbanizeX < areaMinX || nbUrbanizeY < areaMinY || nbUrbanizeX > areaMaxX || nbUrbanizeY > areaMaxY ||
 												Float.isNaN(outputGrid.getRasterSampleAsFloat(nbUrbanizeX,nbUrbanizeY)) ) 
 											continue;	//if a cell is outside the raster (NaN), break and continue loop from the beginning
-										if (areaRestr.getRasterSampleAsFloat(nbUrbanizeX,nbUrbanizeY) != 0)
+										if (areaRestr.getRasterSampleAsFloat(nbUrbanizeX,nbUrbanizeY) == 1)
 											continue;	//if a cell is inside an excluded area, break and continue loop from the beginning
 										float rasterSample = outputGrid.getRasterSampleAsFloat(nbUrbanizeX,nbUrbanizeY);	//take the raster value
 										RNRoadSlope = (float)Math.random();	//generate a random number in order to compare it with the slope
 										double slopeDoubleNb = getSlopeValue(nbUrbanizeX,nbUrbanizeY,slopeLUT);	//returns the slope value for the neighboring cells which are available for breed
+										double restrDoubleNb = areaRestr.getRasterSampleAsFloat(nbUrbanizeX,nbUrbanizeY);	//returns the restriction value for the neighboring cells which are available for breed
 										if (rasterSample == 0f){	//if the raster sample is available for urbanization...
 											NbTemp++;	//count it
 											nbCellTemp = new int[] {nbUrbanizeX,nbUrbanizeY,NbTemp};	//create an array holding the coordinates and the number of that neighbor cell
-											if (nbCellTemp[2] == RN && slopeDoubleNb < RNRoadSlope){	//if its number is the same as the random number and it passes the slope-test..
+											if (nbCellTemp[2] == RN && slopeDoubleNb < RNRoadSlope && restrDoubleNb < RNRoadSlope){	//if its number is the same as the random number and it passes the slope-test..
 												nbCellNew = new int[] {nbCellTemp[0],nbCellTemp[1],nbCellTemp[2]};	//write its coordinates in the array to be returned
 											}
 										}	
@@ -898,7 +902,7 @@
 			if ( nbX < areaMinX || nbY < areaMinY || nbX > areaMaxX || nbY > areaMaxY ||
 		               Float.isNaN(outputGrid.getRasterSampleAsFloat(nbX,nbY)))
 		             continue;	//if a cell is outside the raster (NaN), break and continue loop from the beginning
-			if (areaRestr.getRasterSampleAsFloat(nbX,nbY) != 0)
+			if (areaRestr.getRasterSampleAsFloat(nbX,nbY) == 1)
 	        	continue;	//if a cell is inside an excluded area, break and continue loop from the beginning
 			float rasterSample = outputGrid.getRasterSampleAsFloat(nbX,nbY);	//take the raster value
 			if (rasterSample == NbValue)	//if it is the same as the value we look for...

Modified: trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelCalibration.java
===================================================================
--- trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelCalibration.java	2010-09-09 18:04:43 UTC (rev 95)
+++ trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelCalibration.java	2010-10-05 09:29:37 UTC (rev 96)
@@ -48,7 +48,7 @@
  * @see UrbanGrowthModel
  * @see UrbanGrowthModel_MC
  * @author <a href="mailto:goetzke at uni-bonn.de">Roland Goetzke</a>
- * @version 1.0
+ * @version 1.1
  */
 public class UrbanGrowthModelCalibration extends UrbanGrowthModel {
 
@@ -508,8 +508,8 @@
 									System.out.print("//Weighted Averages (FT, WA): ");
 									for(int j = 0;j < 2;j++){
 										//print every element of the result array comma separated in one line in the status output
-										finalArray[numSteps+j] = mrvTempResultArray[j]/MonteCarlo;
-										System.out.print(finalArray[j]+",");
+										finalArray[numSteps+j] = mrvTempResultArray[numSteps+j]/MonteCarlo;
+										System.out.print(finalArray[numSteps+j]+",");
 									}
 									for (int grids = MC-1; grids >= 0; grids--){
 										outStep.removeGrid(grids); 				//empty GridList

Modified: trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelCalibrationSelfModification.java
===================================================================
--- trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelCalibrationSelfModification.java	2010-09-09 18:04:43 UTC (rev 95)
+++ trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelCalibrationSelfModification.java	2010-10-05 09:29:37 UTC (rev 96)
@@ -28,7 +28,7 @@
  * @see UrbanGrowthModel
  * @see UrbanGrowthModel_MC
  * @author <a href="mailto:goetzke at uni-bonn.de">Roland Goetzke</a>
- * @version 1.0
+ * @version 1.1
  */
 public class UrbanGrowthModelCalibrationSelfModification extends UrbanGrowthModelCalibration {
 
@@ -117,7 +117,7 @@
 			            Float.isNaN(outputGrid.getRasterSampleAsFloat(x,y)) ) //ignore neighbor, if outside the raster
 			             continue;
 				totalPixels++;
-				if (areaRestr.getRasterSampleAsFloat(x,y) != 0 && !Float.isNaN(areaRestr.getRasterSampleAsFloat(x,y)))
+				if (areaRestr.getRasterSampleAsFloat(x,y) == 1 && !Float.isNaN(areaRestr.getRasterSampleAsFloat(x,y)))
 					excldCount++;
 			}
 	}
@@ -149,9 +149,9 @@
 		double dispF = 0;
 		double breedF = 0;
 		double roadGravityF = 0;
-		double growthRate = 0;
-		int thisYear = 0;
-		int roadCount = 0;
+		//double growthRate = 0;
+		int thisYear;
+		int roadCount;
 		
 		//Definition of variables needed in the whole model run
 		long localStartTime = System.currentTimeMillis(); //time measure
@@ -200,14 +200,17 @@
 								dispF = (double) disp;		//dispF is disp at the beginning of the loop and is modified within the loop.
 								breedF = (double)breed;	//breedF is breed at the beginning of the loop and is modified within the loop.
 								roadGravityF = (double) roadGravity;	//roadGravityF is roadGravity at the beginning of the loop and is modified within the loop.
-								
+								double growthRate = 0;
 								/**
 								 * The model run is being performed for every time step. For the final evaluation 
 								 * only the image of the final step is needed.
 								 */
 									for(int timeSteps = 1;timeSteps <=years;timeSteps++){
-									
-										statusOut.println("Year "+timeSteps);
+
+										thisYear = 0;
+										roadCount = 0;
+										statusOut.println("Year "+timeSteps);										
+										
 										boolean[][] tmpGrid = new boolean[inputGrid.getWidth()][inputGrid.getHeight()];	//a temporary raster
 
 										//recalculate the slope values
@@ -286,18 +289,21 @@
 										//is reached. After that the next Monte Carlo iteration is performed for the specific parameter combination. 									
 										
 										// Write the temporary Grid to the Output Grid
-										int anzGesamt = 0;
+										//int anzGesamt = 0;
+										int anzGesamt = anzDispBreed+anzSpread+anzRoad;
+										
 										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++;
+											//	if (tmpGrid[x][y] == true)
+											//		anzGesamt++;
 												
 												boolean lebt = outputGrid.getRasterSampleAsFloat(X , Y ) > 0f;	//a cell is alive, when it is 1
 												boolean road = roadGrid.getRasterSampleAsFloat(X, Y) > 0f;	//eine Zelle beinhaltet eine Straße...
+												
 												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
 												if(lebt == true)
@@ -310,11 +316,13 @@
 											}
 										}
 										statusOut.println("Urban pixels at step "+timeSteps+": "+anzGesamt);
-										
+	
 										//SELF-MODIFICATION
+
+										//growthRate = ((float)thisYear/(float)anzGesamt)*100;
 										growthRate = ((float)anzGesamt / (float)thisYear)*100;	//growth rate
-										statusOut.println("Wachstumsrate: "+growthRate+", Urban: "+anzGesamt);
 										double percent_urban = (100.0 *(thisYear+roadCount) / (totalPixels-roadCount-excldCount));
+										statusOut.println("Wachstumsrate: "+growthRate+", Urban: "+anzGesamt+", thisYear: "+thisYear+", percentUrban: "+percent_urban);
 										
 										//Boom-Year
 										if(growthRate > criticalHigh){	//if the growth rate exceeds the critical high value
@@ -358,6 +366,7 @@
 											}
 										}
 										
+										statusOut.println("Koeffizienten veraendert: slope "+slopeF+", road "+roadGravityF+", disp "+dispF+", spread "+spreadF+", breed "+breedF);
 										
 										if (timeSteps == years){
 											outStep.addGrid();	//add a raster to the GridList
@@ -404,8 +413,8 @@
 										System.out.print("//Weighted Averages (FT, WA): ");
 										for(int j = 0;j < 2;j++){
 											//print every element of the result array comma separated in one line in the status output
-											finalArray[numSteps+j] = mrvTempResultArray[j]/MonteCarlo;
-											System.out.print(finalArray[j]+",");
+											finalArray[numSteps+j] = mrvTempResultArray[numSteps+j]/MonteCarlo;
+											System.out.print(finalArray[numSteps+j]+",");
 										}
 										for (int grids = MC-1; grids >= 0; grids--){
 											outStep.removeGrid(grids); 				//empty GridList

Modified: trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelSelfModification.java
===================================================================
--- trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelSelfModification.java	2010-09-09 18:04:43 UTC (rev 95)
+++ trunk/src/edu/bonn/xulu/plugin/model/sleuth/UrbanGrowthModelSelfModification.java	2010-10-05 09:29:37 UTC (rev 96)
@@ -24,7 +24,7 @@
  * @see UrbanGrowthModelSelfModificationContentManager
  * @see UrbanGrowthModel
  * @author <a href="mailto:goetzke at uni-bonn.de">Roland Goetzke</a>
- * @version 1.0
+ * @version 1.1
  */
 public class UrbanGrowthModelSelfModification extends UrbanGrowthModel {
 
@@ -114,7 +114,7 @@
 			            Float.isNaN(outputGrid.getRasterSampleAsFloat(x,y)) ) //ignore neighbor, if outside the raster
 			             continue;
 				totalPixels++;
-				if (areaRestr.getRasterSampleAsFloat(x,y) != 0 && !Float.isNaN(areaRestr.getRasterSampleAsFloat(x,y)))
+				if (areaRestr.getRasterSampleAsFloat(x,y) == 1 && !Float.isNaN(areaRestr.getRasterSampleAsFloat(x,y)))
 					excldCount++;
 			}
 		
@@ -224,7 +224,7 @@
 		
 		
 		outStep.addGrid();
-		int anzGesamt = 0;
+		int anzGesamt = anzDispBreed+anzSpread+anzRoad;
 		
 		// Write the temporary Grid to the Output Grid
 		for (int y = 1; y < inputGrid.getHeight()-1;y++ ) {
@@ -233,8 +233,8 @@
 				int X = inputGrid.getMinX() + x;
 				int Y = inputGrid.getMinY() + y;
 				
-				if (tmpGrid[x][y] == true)
-					anzGesamt++;
+				//if (tmpGrid[x][y] == true)
+				//	anzGesamt++;
 				
 				boolean lebt = outputGrid.getRasterSampleAsFloat(X , Y ) > 0f;	//a cell is alive, when it is 1
 				boolean road = roadGrid.getRasterSampleAsFloat(X, Y) > 0f;	//a cell contains a road...



More information about the Xulu-commits mailing list