Hi Dan,

By setting values to 0 you risk creating "islands" and that may upset the matrix calculation processes. Connecting cells with very low conductance values will probably solve your problem.

Best,

Jacob.



On Friday, 21 March 2014, 0:46, Dan Rosauer <dan.rosauer@anu.edu.au> wrote:
 
 
Hi all
 
I’m trying to get the passage() function in gdistance to work, but get the following error, and have not been able to find a reliable workaround.
 
passage.ras <- passage(trR,origin.ras,goal.ras,theta=3)
Error in .local(a, b, ...) : 
  Dimensions of system to be solved are inconsistent
 
The transition matrix, origin raster and goal raster are definitely identical in resolution, extent, number of cells – see below .  The transition matrix used here has works fine for other functions such as accCost().
 
The most puzzling thing is that the error does not occur all of the time.  After wrestling with the error, I cropped the analysis to a smaller area, and it worked.  But even with an extent that worked, setting the transition values of certain cells to 0 (to create an artificial barrier) also generated that same error. 
 
One possibility is a problem with setting values of the origin and goal rasters to TRUE and FALSE.  I found this discussion in the r-sig-geo archives http://grokbase.com/t/r/r-sig-geo/131g9qq8nv/rasterlayer-for-origin-and-goal-in-passage-function-gdistance.  In my case also, rasters set to TRUE and FALSE switch to values of 0 and 1.  I followed Jacob van Etten’s advice to set all values in the raster using a vector of values, but the rasters still switch to values of 0 and 1.  This may not be the problem, however, as many of the runs worked despite this.
 
Another example of a function call, and the resulting traceback are pasted in at the bottom. 
 
Thanks in advance for any help – especially if you have hit this problem before..   (and if someone does want to have a look, I could paste full code and data)
 
Dan Rosauer
 
> trR
class       : TransitionLayer 
dimensions  : 500, 500, 250000  (nrow, ncol, ncell)
resolution  : 0.01, 0.01  (x, y)
extent      : 130, 135, -22, -17  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
values      : conductance 
matrix class: dsCMatrix 
 
> origin.ras
class       : RasterLayer 
dimensions  : 500, 500, 250000  (nrow, ncol, ncell)
resolution  : 0.01, 0.01  (x, y)
extent      : 130, 135, -22, -17  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
data source : in memory
names       : layer 
values      : 0, 1  (min, max)
 
> goal.ras
class       : RasterLayer 
dimensions  : 500, 500, 250000  (nrow, ncol, ncell)
resolution  : 0.01, 0.01  (x, y)
extent      : 130, 135, -22, -17  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
data source : in memory
names       : layer 
values      : 0, 1  (min, max)
 
 
> passage_total.ras <- passage(trR,origin.ras,goal.ras,theta=0.0000005, totalNet="total")
Error in .solve.dgC(a, as(b, "denseMatrix"), tol = tol, sparse = sparse) : 
  Dimensions of system to be solved are inconsistent
> traceback()
14: .solve.dgC(a, as(b, "denseMatrix"), tol = tol, sparse = sparse)
13: .local(a, b, ...)
12: solve(a, Matrix(b))
11: solve(a, Matrix(b))
10: eval(expr, envir, enclos)
9: eval(call, sys.frame(sys.parent()))
8: callGeneric(a, Matrix(b))
7: solve(IdMinusWj, ej)
6: solve(IdMinusWj, ej)
5: .probPass(x, Id, W, nr, ci, cj, tc, totalNet, output)
4: .randomShPaths(x, ci, cj, theta, tc, totalNet, output)
3: .local(x, origin, goal, theta, ...)
2: passage(trR, origin.ras, goal.ras, theta = 5e-07, totalNet = "total")
1: passage(trR, origin.ras, goal.ras, theta = 5e-07, totalNet = "total")
 
~~~~~~~~~~~~~~~~~~~~~~
Dan Rosauer
Postdoctoral Researcher
Moritz Lab
Ecology, Evolution & Genetics
Research School of Biology
Gould Building, Daley Road
Australian National University
Canberra ACT 0200
 
+61 413 950 275 (mobile)
+61 2 6125 1028 (office)
dan.rosauer@anu.edu.au
sites.google.com/site/danielrosauer
	[[alternative HTML version deleted]]

