loadSimulations: Load values from raster or text files into Simulations...

Description Usage Arguments Details Value Author(s) Examples

View source: R/loadSimulations.R

Description

Plume simulations for one scenario are a set of maps of the same area, each showing one plume. This function generates a Simulations object from all data of a scenario which can then be used to compute cost and to optimise sampling designs. Data may extend the size of the memory; it can be provided either as raster maps or as values in text files (in this case spatial reference can be added later). The resulting values are saved to disk as a raster object.

Usage

1
2
3
loadSimulations(basicPath = ".", readBy = NA, 
  multilayer = "kinds", region, bBox, 
  nameSave = NA, overwrite = FALSE, ...)

Arguments

basicPath

path to directory with files; it must not contain any but the files with simulations to be used

multilayer

way to interpret files with several layers/columns; "kinds" (default): layers/columns are interpreted as different kinds of values (number of layers/columns must be the same in all files) or "plumes": layers/columns are interpreted as values of different plumes, all being of the same kind

readBy

method to read the files; for some suffixes the reading method is determined automatically (all files must have the same suffix): "scan" for ".txt" or ".csv", and "raster" for ".tif" or ".grd"; else it has to be specified here, (default is NA)

region

logical indicating in which locations to keep the values (for raster files, order is row-wise), length must equal number of locations (if combined with bBox length must fit locations inside bBox)

bBox

bounding box of locations to keep, given as vector c(xmin, xmax, ymin, ymax); works only for raster data, for text files it is ignored

nameSave

name to save resulting raster files that are created automatically and then contain the final data, files are created by appending names to it, starting with "_"

overwrite

logical if files at nameSave may be overwritten

...

parameters to be forwarded to read.table and scan like skip, sep, dec

Details

Plume simulations have to be a set of maps all defined by values at the same set of locations; there may be several kinds of maps for each plume. Such data can be loaded from files automatically if these have the following properties:
Files can either all be loaded by brick (.grd/.gri, .tif) or by scan (.txt, .csv). If they have one of the listed suffixes, the method is derived automatically; for other suffixes it must be given by the user in readBy.
Each file must contain the values of a plume in all locations.
Files may contain several kinds of values; in this case each layer (of .tif or .grd files) or each column (in .txt or .csv files) belongs to different kind of map, the structure (number and meaning of columns/layers and rows) must be common to all files.
If there is only one kind of map, files may contain columns/layers with the values of several plumes.
File names must follow some rules: They must not contain any "." except the one to start the suffix. They must not contain "_", except for the case described below; they are interpreted as the names of plumes. If there are several kinds of maps, either all kinds for a plume are in the same file or there is a separate file for each kind and each plume. In the latter case file names must be of the form plumeName_kindName.suffix. For each plume there must be a file for each kind.

Value

The output of this function depends on the file type: raster files result in a Simulations object, with spatial properties kept in the locations (projection etc. of GeoTiff); text files do not contain spatial information, therefore a list of plumes and values is returned that can be used to generate a Simulations object together with appropriate locations.

The function may generate (and overwrite or delete) files at nameSave.

Author(s)

Kristina B. Helle, kristina.helle@uni-muenster.de

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
35
36
## Not run: 
# examples for possible input is given in package sensors4plumesData in the 
# subfolders of inst/extdata/fileFormats

# from raster files
Simulations1 = loadSimulations(
  basicPath = paste0(path.package("sensors4plumesData"),
                     "/extdata/fileFormats/raster"),
  nameSave = "t1_",
  overwrite = TRUE
)

# from text files
Simulations2 = loadSimulations(
  basicPath = paste0(path.package("sensors4plumesData"),
                     "/extdata/fileFormats/text_multicolumn"),
  readBy = "scan",  
  nameSave = "t2_",
  overwrite = TRUE,
  skip = 1
)

# from multilayer raster files, selecting locations in a bounding box
region = as.logical(replicate(20, sample.int(2,1)) - 1)
bBox = c(0.2, 0.7, 0.4, 0.8)

Simulations3 = loadSimulations(
  basicPath = paste0(path.package("sensors4plumesData"),
                     "/extdata/fileFormats/raster_multilayer"),
  nameSave = "t3_",
  region = region,
  bBox = bBox,
  overwrite = TRUE
)

## End(Not run)

KristinaHelle/sensors4plumes documentation built on May 7, 2019, 12:31 p.m.