Learn R Programming

sits (version 1.5.3)

sits_classify.raster_cube: Classify a regular raster cube

Description

Called when the input is a regular raster data cube. The output is a probability cube, which has the same tiles as the raster cube. Each tile contains a multiband image; each band contains the probability that each pixel belongs to a given class. Probability cubes are objects of class "probs_cube".

Usage

# S3 method for raster_cube
sits_classify(
  data,
  ml_model,
  ...,
  roi = NULL,
  exclusion_mask = NULL,
  filter_fn = NULL,
  impute_fn = impute_linear(),
  start_date = NULL,
  end_date = NULL,
  memsize = 8L,
  multicores = 2L,
  gpu_memory = 4L,
  batch_size = 2L^gpu_memory,
  output_dir,
  version = "v1",
  verbose = FALSE,
  progress = TRUE
)

Value

Time series with predicted labels for each point (tibble of class "sits") or a data cube with probabilities for each class (tibble of class "probs_cube").

Arguments

data

Data cube (tibble of class "raster_cube")

ml_model

R model trained by sits_train

...

Other parameters for specific functions.

roi

Region of interest (either an sf object, shapefile, or a numeric vector in WGS 84 with named XY values ("xmin", "xmax", "ymin", "ymax") or named lat/long values ("lon_min", "lat_min", "lon_max", "lat_max").

exclusion_mask

Areas to be excluded from the classification process. It can be defined by a sf object or by a shapefile.

filter_fn

Smoothing filter to be applied - optional (closure containing object of class "function").

impute_fn

Imputation function to remove NA.

start_date

Starting date for the classification (Date in YYYY-MM-DD format).

end_date

Ending date for the classification (Date in YYYY-MM-DD format).

memsize

Memory available for classification in GB (integer, min = 1, max = 16384).

multicores

Number of cores to be used for classification (integer, min = 1, max = 2048).

gpu_memory

Memory available in GPU in GB (default = 4)

batch_size

Batch size for GPU classification.

output_dir

Directory for output file.

version

Version of the output.

verbose

Logical: print information about processing time?

progress

Logical: Show progress bar?

Examples

Run this code
if (sits_run_examples()) {
    # Retrieve the samples for Mato Grosso
    # train a random forest model
    rf_model <- sits_train(samples_modis_ndvi, ml_method = sits_rfor)
    # Example of classification of a data cube
    # create a data cube from local files
    data_dir <- system.file("extdata/raster/mod13q1", package = "sits")
    cube <- sits_cube(
        source = "BDC",
        collection = "MOD13Q1-6.1",
        data_dir = data_dir
    )
    # classify a data cube
    probs_cube <- sits_classify(
        data = cube,
        ml_model = rf_model,
        output_dir = tempdir(),
        version = "classify"
    )
    # label the probability cube
    label_cube <- sits_label_classification(
        probs_cube,
        output_dir = tempdir(),
        version = "ex_classify"
    )
    # plot the classified image
    plot(label_cube)
}

Run the code above in your browser using DataLab