Skip to content

Tessellation error in spatstat

1 message · Adrian Baddeley

#
Richard Mort wrote (on R-help):

...................
*** Error here ^^^
*** Error here ^^^
................................

The output shows that the enclosing rectangle for 'd' is [0.5, 512.5] x [0.5, 512.5] 
while the point pattern 'data02' is enclosed in the rectangle [0, 512] x [0, 512]. 
If there are data points which have x-coordinates between 0 and 0.5 (for example) then these points 
will lie outside the domain of the tessellation 'd', causing an error, although the problem 
would probably not be visible in a plot. This appears to have happened with the pattern 'data02'.

The problem is with the following commands
'as.matrix' is part of the base R system. It doesn't have arguments 'xrange', 'yrange'
and these will be ignored (silently!). So b is just an ordinary matrix.
Then in the call to 'im' you have specified the coordinates of the pixel CENTRES to be
(1,1), ...., (512, 512) and the pixels are squares of side 1, so the pixels cover the
rectangle [0.5, 512.5] x [0.5, 512.5]. 

If I understand correctly you want 'b' to be a 512 x 512 matrix, 
and 'c' to be an image defined on the rectangle [0, 512] x [0,512].
To do that, it's probably easiest to use 'as.im':

     b <- matrix(b, nrow=512)
     c <- as.im(b, owin(c(0,512),c(0,512)))

or more portably
 
     c <- as.im(b, as.owin(data02))

the last line ensures that the windows of 'data02' and 'c' are identical.

It's probably wise to avoid using 'c' as the name of a dataset, 
because 'c' is also a function name

regards
Adrian Baddeley