Learn R Programming

sits (version 1.5.3)

sits_classify.segs_cube: Classify a segmented data cube

Description

This function is called when the input is a vector data cube. Vector data cubes are produced when closed regions are obtained from raster data cubes using sits_segment. Classification of a vector data cube produces a vector data structure with additional columns expressing the class probabilities for each segment. Probability cubes for vector data cubes are objects of class "probs_vector_cube".

Usage

# S3 method for vector_cube
sits_classify(
  data,
  ml_model,
  ...,
  roi = 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",
  n_sam_pol = 15L,
  verbose = FALSE,
  progress = TRUE
)

Value

Vector data cube with probabilities for each class included in new columns of the tibble. (tibble of class "probs_vector_cube").

Arguments

data

Data cube (tibble of class "raster_cube")

ml_model

R model trained by sits_train (closure of class "sits_model")

...

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").

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.

n_sam_pol

Number of time series per segment to be classified (integer, min = 10, max = 50).

verbose

Logical: print information about processing time?

progress

Logical: Show progress bar?

Examples

Run this code
if (sits_run_examples()) {
    # 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
    )
    # segment the image
    segments <- sits_segment(
        cube = cube,
        seg_fn = sits_slic(
            step = 5,
            compactness = 1,
            dist_fun = "euclidean",
            avg_fun = "median",
            iter = 50,
            minarea = 10,
            verbose = FALSE
        ),
        output_dir = tempdir()
    )
    # Create a classified vector cube
    probs_segs <- sits_classify(
        data = segments,
        ml_model = rf_model,
        output_dir = tempdir(),
        multicores = 4,
        n_sam_pol = 15,
        version = "segs"
    )
    # Create a labelled vector cube
    class_segs <- sits_label_classification(
        cube = probs_segs,
        output_dir = tempdir(),
        multicores = 2,
        memsize = 4,
        version = "segs_classify"
    )
    # plot class_segs
    plot(class_segs)
}

Run the code above in your browser using DataLab