RFspatialGridDataFrame-class: Class "RFspatialGridDataFrame"

Description Usage Arguments Creating Objects Slots Extends Methods Details Author(s) See Also Examples

Description

Class for spatial attributes that have spatial or spatio-temporal locations (at least of dimension 2) on a (full) regular grid. Direct extension of class SpatialGridDataFrame from the sp-package. See sp2RF for an explicit transformation.

Usage

1
2
## S4 method for signature 'RFspatialGridDataFrame'
RFspDataFrame2conventional(obj, data.frame=FALSE) 

Arguments

obj

an RFspatialGridDataFrame object

data.frame

logical. If TRUE a data.frame is returned.

Creating Objects

Objects can be created by using the functions RFspatialGridDataFrame or conventional2RFspDataFrame or by calls of the form as(x, "RFspatialGridDataFrame"), where x is of class RFspatialGridDataFrame.

Slots

.RFparams:

list of 2; .RFparams$n is the number of repetitions of the random field contained in the data slot; .RFparams$vdim gives the dimension of the values of the random field, equals 1 in most cases

data:

object of class data.frame; containing attribute data

grid:

object of class GridTopology; grid parameters

bbox:

matrix specifying the bounding box

proj4string:

object of class CRS; projection

Extends

Class "SpatialGridDataFrame", directly. Class "SpatialGrid", by class "SpatialGridDataFrame". Class "Spatial", by class "SpatialGrid".

Methods

contour

signature(obj = "RFspatialGridDataFrame"): generates contour plots

plot

signature(obj = "RFspatialGridDataFrame"): generates nice image plots of the random field; if space-time-dim2, a two-dimensional subspace can be selected using the argument MARGIN; to get different slices in a third direction, the argument MARGIN.slices can be used; for more details see plot-method or type method?plot("RFspatialGridDataFrame")

persp

signature(obj = "RFspatialGridDataFrame"): generates persp plots

show

signature(x = "RFspatialGridDataFrame"): uses the show-method for class SpatialGridDataFrame.

print

signature(x = "RFspatialGridDataFrame"): identical to show-method

RFspDataFrame2conventional

signature(obj = "RFspatialGridDataFrame"): conversion to a list of non-sp-package based objects; the data-slot is converted to an array of dimension [1*(vdim>1) + space-time-dimension + 1*(n>1)]; the grid-slot is converted to a 3-row matrix; the grid definition of a possible time-dimension becomes a separate list element

RFspDataFrame2dataArray

signature(obj = "RFspatialGridDataFrame"): conversion of the data-slot to an array of dimension [space-time-dimension + 2], where the space-time-dimensions run fastest, and vdim and n are the last two dimensions

coordinates

signature(x = "RFspatialGridDataFrame"): calculates the coordinates from grid definition

[

signature(x = "RFspatialGridDataFrame"): selects columns of data-slot; returns an object of class RFspatialGridDataFrame.

[<-

signature(x = "RFspatialGridDataFrame"): replaces columns of data-slot; returns an object of class RFspatialGridDataFrame.

as

signature(x = "RFspatialGridDataFrame"): converts into other formats, only implemented for target class RFspatialPointsDataFrame

cbind

signature(...): if arguments have identical topology, combine their attribute values

range

signature(x = "RFspatialGridDataFrame"): returns the range

hist

signature(x = "RFspatialGridDataFrame"): plots histogram

as.matrix

signature(x = "RFspatialGridDataFrame"): converts data-slot to matrix

as.array

signature(x = "RFspatialGridDataFrame"): converts data-slot to array

as.vector

signature(x = "RFspatialGridDataFrame"): converts data-slot to vector

as.data.frame

signature(x = "RFspatialGridDataFrame"): converts data-slot and coordinates to a data.frame

Details

Note that in the data-slot, each column is ordered according to the ordering of coordinates(grid), the first dimension runs fastest and for all BUT the second dimension, coordinate values are in ascending order. In the second dimension, coordinate values run from high to low. Hence, when converting to conventional formats using RFspDataFrame2conventional or RFspDataFrame2dataArray, the data array is re-ordered such that all dimensions are in ascending order. as.matrix does not perform re-ordering.

Methods summary, and dimensions are defined for the “parent”-class RFsp.

Author(s)

Alexander Malinowski, \martin

See Also

RFspatialPointsDataFrame-class, which is for point locations that are not on a grid, RFgridDataFrame-class which is for one-dimensional locations, RFsp, sp2RF

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
##                   RFoptions(seed=NA) to make them all random again

n <- 3

x <- GridTopology(cellcentre.offset=c(0, 0),
 cellsize=c(1, 0.2),
 cells.dim=c(10, 30))
f <- RFsimulate(model=RMexp(), x=x, n=n)

str(f)
str(RFspDataFrame2conventional(f))
str(RFspDataFrame2dataArray(f))
head(coordinates(f))
str(f[2]) ## selects second column of data-slot
all.equal(f, cbind(f,f)[1:3]) ## TRUE
str(as(f, "RFspatialPointsDataFrame"))

plot(f, nmax=2)

steps <- c(10, 1, 10, 10)

x2 <- rbind(c(0, 0, 0, 0),
 c(1, 0.2, 2, 5),
 steps)
scale <- 10

f2 <- RFsimulate(model=RMwhittle(nu=1.2, scale=scale), x=x2, n=n,
                 grid = TRUE)
plot(f2, MARGIN=c(3,4), MARGIN.slices=1, n.slices=6, nmax=2)

f.sp <- RFsimulate(model=RMexp(), x=x, n=n)
f.old <- RFsimulate(model=RMexp(), x=x, n=n, spConform=FALSE)
all.equal(RFspDataFrame2conventional(f.sp)$data, f.old, check.attributes=FALSE) ## TRUE

Example output

Loading required package: sp
Loading required package: RandomFieldsUtils

Attaching package: 'RandomFields'

The following object is masked from 'package:RandomFieldsUtils':

    RFoptions

NOTE: simulation is performed with fixed random seed 0.
Set 'RFoptions(seed=NA)' to make the seed arbitrary.
...
New output format of RFsimulate: S4 object of class 'RFsp';
for a bare, but faster array format use 'RFoptions(spConform=FALSE)'.
Formal class 'RFspatialGridDataFrame' [package ""] with 5 slots
  ..@ .RFparams  :List of 5
  .. ..$ n         : num 3
  .. ..$ vdim      : int 1
  .. ..$ T         : num(0) 
  .. ..$ coordunits: NULL
  .. ..$ varunits  : NULL
  ..@ data       :'data.frame':	300 obs. of  3 variables:
  .. ..$ variable1.n1: num [1:300] 0.921 0.854 0.73 0.148 0.623 ...
  .. ..$ variable1.n2: num [1:300] -0.891 0.22 0.821 -0.115 -0.157 ...
  .. ..$ variable1.n3: num [1:300] -0.5903 -2.1702 0.0809 -0.7669 -2.836 ...
  ..@ grid       :Formal class 'GridTopology' [package "sp"] with 3 slots
  .. .. ..@ cellcentre.offset: Named num [1:2] 0 0
  .. .. .. ..- attr(*, "names")= chr [1:2] "coords.x1" "coords.x2"
  .. .. ..@ cellsize         : Named num [1:2] 1 0.2
  .. .. .. ..- attr(*, "names")= chr [1:2] "coords.x1" "coords.x2"
  .. .. ..@ cells.dim        : int [1:2] 10 30
  ..@ bbox       : num [1:2, 1:2] -0.5 -0.1 9.5 5.9
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
  .. .. ..@ projargs: chr NA
List of 5
 $ data     : num [1:10, 1:30, 1:3] -0.605 -0.86 1.397 1.243 0.778 ...
  ..- attr(*, "dimnames")=List of 3
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : chr [1:3] "variable1.n1" "variable1.n2" "variable1.n3"
 $ x        : num [1:3, 1:2] 0 1 10 0 0.2 30
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:2] "coords.x1" "coords.x2"
 $ T        : NULL
 $ .RFparams:List of 5
  ..$ n         : num 3
  ..$ vdim      : int 1
  ..$ T         : num(0) 
  ..$ coordunits: NULL
  ..$ varunits  : NULL
 $ .names   : chr [1, 1:3] "variable1.n1" "variable1.n2" "variable1.n3"
 num [1:10, 1:30, 1, 1:3] -0.605 -0.86 1.397 1.243 0.778 ...
     coords.x1 coords.x2
[1,]         0       5.8
[2,]         1       5.8
[3,]         2       5.8
[4,]         3       5.8
[5,]         4       5.8
[6,]         5       5.8
Formal class 'RFspatialGridDataFrame' [package ""] with 5 slots
  ..@ .RFparams  :List of 5
  .. ..$ n         : num 1
  .. ..$ vdim      : int 1
  .. ..$ T         : num(0) 
  .. ..$ coordunits: NULL
  .. ..$ varunits  : NULL
  ..@ data       :'data.frame':	300 obs. of  1 variable:
  .. ..$ variable1.n2: num [1:300] -0.891 0.22 0.821 -0.115 -0.157 ...
  ..@ grid       :Formal class 'GridTopology' [package "sp"] with 3 slots
  .. .. ..@ cellcentre.offset: Named num [1:2] 0 0
  .. .. .. ..- attr(*, "names")= chr [1:2] "coords.x1" "coords.x2"
  .. .. ..@ cellsize         : Named num [1:2] 1 0.2
  .. .. .. ..- attr(*, "names")= chr [1:2] "coords.x1" "coords.x2"
  .. .. ..@ cells.dim        : int [1:2] 10 30
  ..@ bbox       : num [1:2, 1:2] -0.5 -0.1 9.5 5.9
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
  .. .. ..@ projargs: chr NA
[1] TRUE
Formal class 'RFspatialPointsDataFrame' [package ""] with 6 slots
  ..@ .RFparams  :List of 7
  .. ..$ n         : int 3
  .. ..$ vdim      : int 1
  .. ..$ T         : num(0) 
  .. ..$ coordunits: NULL
  .. ..$ varunits  : NULL
  .. ..$ coordunits: NULL
  .. ..$ varunits  : NULL
  ..@ data       :'data.frame':	300 obs. of  3 variables:
  .. ..$ variable1.n1: num [1:300] 0.921 0.854 0.73 0.148 0.623 ...
  .. ..$ variable1.n2: num [1:300] -0.891 0.22 0.821 -0.115 -0.157 ...
  .. ..$ variable1.n3: num [1:300] -0.5903 -2.1702 0.0809 -0.7669 -2.836 ...
  ..@ coords.nrs : num(0) 
  ..@ coords     : num [1:300, 1:2] 0 1 2 3 4 5 6 7 8 9 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : NULL
  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
  ..@ bbox       : num [1:2, 1:2] 0 0 9 5.8
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
  .. .. ..@ projargs: chr NA
NOTE: simulation is performed with fixed random seed 0.
...
only first realization is shown
NOTE: simulation is performed with fixed random seed 0.
...
NOTE: simulation is performed with fixed random seed 0.
...
[1] TRUE

RandomFields documentation built on Jan. 19, 2022, 1:06 a.m.