Learn R Programming

sits (version 0.10.0)

sits_classify.raster_cube: Classify a data cube using multicore machines

Description

Takes a data cube, whose metadata is described by tibble (created by sits_cube), a set of samples used for training a classification model, a prediction model (created by sits_train), and produces a classified set of RasterLayers.

The "roi" parameter defines a region of interest. It can be an sf_object, a shapefile, or a bounding box vector with named XY values ("xmin", "xmax", "ymin", "ymax") or named lat/long values ("lat_min", "lat_max", "long_min", "long_max")

The "memsize" and "multicores" parameters define the The "multicores" parameter defines the number of cores used for processing. The "memsize" parameter controls the amount of memory available for classification.

Usage

# S3 method for raster_cube
sits_classify(
  data,
  ml_model,
  ...,
  roi = NULL,
  filter = NULL,
  impute_fn = sits_impute_linear(),
  memsize = 8,
  multicores = 2,
  output_dir = "./",
  version = "v1",
  .verbose = FALSE
)

Arguments

data

data cube

ml_model

R model trained by sits_train.

...

other parameters to be passed to specific functions

roi

a region of interest (see above)

filter

smoothing filter to be applied (if desired).

impute_fn

impute function to replace NA

memsize

memory available for classification (in GB).

multicores

number of cores to be used for classification.

output_dir

directory for output file

version

version of the output (for multiple classifications)

.verbose

print detailed information on processing steps

Value

cube with the metadata of a brick of probabilities.

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
# Classify a raster file with 23 instances for one year
ndvi_file <- c(system.file("extdata/raster/mod13q1/sinop-ndvi-2014.tif",
package = "sits"))

# create a data cube based on the information about the files
sinop_2014 <- sits_cube(
    type = "BRICK",
    name = "sinop-2014",
    timeline = timeline_2013_2014,
    satellite = "TERRA",
    sensor = "MODIS",
    bands = c("ndvi"),
    files = c(ndvi_file)
)

# select band "NDVI"
samples <- sits_select(samples_mt_4bands, bands = "NDVI")

# select a random forest model
rfor_model <- sits_train(samples, ml_method = sits_rfor(num_trees = 300))

# classify the raster image
sinop_probs <- sits_classify(sinop_2014,
    ml_model = rfor_model,
    output_dir = tempdir(),
    memsize = 4, multicores = 1
)

# label the classified image
sinop_label <- sits_label_classification(sinop_probs, output_dir = tempdir())
# }

Run the code above in your browser using DataLab