if (sits_run_examples()) {
# view samples
sits_view(cerrado_2classes)
. # create a local data cube
data_dir <- system.file("extdata/raster/mod13q1", package = "sits")
modis_cube <- sits_cube(
source = "BDC",
collection = "MOD13Q1-6",
data_dir = data_dir
)
# view the data cube
sits_view(modis_cube,
band = "NDVI"
)
# train a model
rf_model <- sits_train(samples_modis_ndvi, sits_rfor())
. # classify the cube
modis_probs <- sits_classify(
data = modis_cube,
ml_model = rf_model,
output_dir = tempdir()
)
# view the probs
sits_view(modis_probs)
# generate a map
modis_label <- sits_label_classification(
modis_probs,
output_dir = tempdir()
)
. # view the classified map
sits_view(modis_label)
. # view the classified map with the B/W image
sits_view(modis_cube,
band = "NDVI",
class_cube = modis_label,
dates = sits_timeline(modis_cube)[[1]]
)
# view the classified map with the RGB image
sits_view(modis_cube,
red = "NDVI", green = "NDVI", blue = "NDVI",
class_cube = modis_label,
dates = sits_timeline(modis_cube)[[1]]
)
# create an uncertainty cube
modis_uncert <- sits_uncertainty(
cube = modis_probs,
output_dir = tempdir()
)
# view the uncertainty cube
sits_view(modis_uncert)
# segment the image
segments <- sits_segment(
cube = modis_cube,
tile = "012010",
bands = "NDVI",
date = sits_timeline(modis_cube)[1],
seg_fn = sits_slic(step = 20)
)
# view image and segments
sits_view (
modis_cube,
band = "NDVI",
segments = segments
)
# view image, classified image and segments
sits_view (
modis_cube,
red = "NDVI",
green = "NDVI",
blue = "NDVI",
class_cube = modis_label,
segments = segments
)
# view B/W image, classified image and segments
sits_view (
modis_cube,
band = "NDVI",
class_cube = modis_label,
segments = segments
)
# get the average value per segment
samples_seg <- sits_get_data(
cube = modis_cube,
samples = segments
)
# train a model
tcnn_model <- sits_train(samples_modis_ndvi, sits_tempcnn())
# classify the segments
seg_class <- sits_classify(
data = samples_seg,
ml_model = tcnn_model
)
# add a column to the segments by class
segments <- sits_join_segments(
data = seg_class,
segments = segments
)
# view image and classified segments
sits_view (
modis_cube,
band = "NDVI",
segments = segments
)
# view image, classified image and segments
sits_view (
modis_cube,
red = "NDVI",
green = "NDVI",
blue = "NDVI",
class_cube = modis_label,
segments = segments
)
}
Run the code above in your browser using DataLab