Monthly Archives: September 2014

SIMLANDER v.1.0.3 and 1.0.4 – Model updated September 2014

SIMLANDER R script versions 1.0.3 and 1.04

In Version 1.03, the selection of highest values from the transition potential map has been rewritten. Instead of extracting values through a GetValues command and then sorting, which I found difficult to code properly, the data are converted to a matrix, output to a dataframe (primarily to facilitate checking but also to make it easy to write out an excel file if desired) and then passed back to matrix again (almost certainly could be done in fewer lines of code, but it does work). A new raster is then generated with the highest values as “1” (urban land). This is the replacement code:

#Select the highest 164 values from the TTP map
#r1demand <- 164  #this is the number of cells we want to allocate from r1
x <- as.matrix(TTP)
n <- urbdemand1  #the demand, calculated by a countdown procedure, above
x2 <-  sort(-x, partial = n)
x2h <-  -sort(x2[1:n])
ix <- which(x %in% x2h)
ro <- ix %% 1151
ro <- ifelse(ro == 0L, 1151, ro)
co <- 1 + ix %/% 1151
x3 <- x[ix]
d <- data.frame(row = ro, col = co, x = x3)
result <- d[rev(order(d$x)), ]
#———————–
#turn selected 164 values in the dataframe into a matrix and then to a raster
x.mat <- matrix(0, 1151, 749) #create a matrix with the right number of rows and columns and fill with 0 values
#x.mat[cbind(result$row,result$col)] <-result$x   #works just fine.
x.mat[cbind(result$row,result$col)] <-1   #but actually we want values to be 1 (urban land), not the TP value.
#which(!is.na(x.mat), arr.ind =TRUE)  #pick out the non-NA values. Useful for testing that this has actually worked.
r <- raster(x.mat)
e <- extent(c(150938,225838,4070192,4185292))
extent(r) <- e

As in previous versions, new land to be allocated is calculated by: (urban cells in final map-urban cells in initial map/number of years). The new land to be allocated at each time step is then added to the existing urban land from the previous step. If this is not what you want, look at version 1.0.4.

SIMLANDER R script version 1.0.4

In Version 1.04, which includes all the updates made in version 1.0.3,  the principal change relates to the way the land is allocated at each time step.

Instead of adding the new land (calculated by urban cells in final map-urban cells in initial map/number of years) to be allocated at each time step (e.g as in version 1.03) now the model allocates all of the urban land cells in the map at each time step, according to the results of the transition potential calculation. The total urban land in each time step is calculated by taking the cell count for urban from the initial map and then increasing the cells allocated at each time step until the final desired demand is reached.

This means that each time step is effectively a blank sheet, and that urban land can, if necessary disappear between time steps. Though there may be few cases in which this is desirable, this is much closer to the way that original CA models (like the game of life) work.

 

Advertisements