|
17 | 17 | #' in the classified images for each corresponding year.
|
18 | 18 | #'
|
19 | 19 | #' @param tile Single tile of a data cube.
|
20 |
| -#' @param band Band to be produced. |
| 20 | +#' @param out_band Band to be produced. |
| 21 | +#' @param bands Bands to extract time series |
| 22 | +#' @param base_bands Base bands to extract values |
21 | 23 | #' @param ml_model Model trained by \code{\link[sits]{sits_train}}.
|
22 | 24 | #' @param block Optimized block to be read into memory.
|
23 | 25 | #' @param roi Region of interest.
|
|
29 | 31 | #' @param progress Show progress bar?
|
30 | 32 | #' @return List of the classified raster layers.
|
31 | 33 | .classify_tile <- function(tile,
|
32 |
| - band, |
| 34 | + out_band, |
| 35 | + bands, |
| 36 | + base_bands, |
33 | 37 | ml_model,
|
34 | 38 | block,
|
35 | 39 | roi,
|
|
42 | 46 | # Output file
|
43 | 47 | out_file <- .file_derived_name(
|
44 | 48 | tile = tile,
|
45 |
| - band = band, |
| 49 | + band = out_band, |
46 | 50 | version = version,
|
47 | 51 | output_dir = output_dir
|
48 | 52 | )
|
|
53 | 57 | }
|
54 | 58 | probs_tile <- .tile_derived_from_file(
|
55 | 59 | file = out_file,
|
56 |
| - band = band, |
| 60 | + band = out_band, |
57 | 61 | base_tile = tile,
|
58 | 62 | labels = .ml_labels_code(ml_model),
|
59 | 63 | derived_class = "probs_cube",
|
|
105 | 109 | values <- .classify_data_read(
|
106 | 110 | tile = tile,
|
107 | 111 | block = block,
|
108 |
| - bands = .ml_bands(ml_model), |
| 112 | + bands = bands, |
| 113 | + base_bands = base_bands, |
109 | 114 | ml_model = ml_model,
|
110 | 115 | impute_fn = impute_fn,
|
111 | 116 | filter_fn = filter_fn
|
|
138 | 143 | # Prepare probability to be saved
|
139 | 144 | band_conf <- .conf_derived_band(
|
140 | 145 | derived_class = "probs_cube",
|
141 |
| - band = band |
| 146 | + band = out_band |
142 | 147 | )
|
143 | 148 | offset <- .offset(band_conf)
|
144 | 149 | if (.has(offset) && offset != 0) {
|
|
181 | 186 | # Merge blocks into a new probs_cube tile
|
182 | 187 | probs_tile <- .tile_derived_merge_blocks(
|
183 | 188 | file = out_file,
|
184 |
| - band = band, |
| 189 | + band = out_band, |
185 | 190 | labels = .ml_labels_code(ml_model),
|
186 | 191 | base_tile = tile,
|
187 | 192 | block_files = block_files,
|
|
374 | 379 | #' @param tile Input tile to read data.
|
375 | 380 | #' @param block Bounding box in (col, row, ncols, nrows).
|
376 | 381 | #' @param bands Bands to extract time series
|
| 382 | +#' @param base_bands Base bands to extract values |
377 | 383 | #' @param ml_model Model trained by \code{\link[sits]{sits_train}}.
|
378 | 384 | #' @param impute_fn Imputation function
|
379 | 385 | #' @param filter_fn Smoothing filter function to be applied to the data.
|
380 | 386 | #' @return A matrix with values for classification.
|
381 |
| -.classify_data_read <- function(tile, block, bands, |
| 387 | +.classify_data_read <- function(tile, block, bands, base_bands, |
382 | 388 | ml_model, impute_fn, filter_fn) {
|
383 | 389 | # For cubes that have a time limit to expire (MPC cubes only)
|
384 | 390 | tile <- .cube_token_generator(tile)
|
|
388 | 394 | tile = tile,
|
389 | 395 | block = block
|
390 | 396 | )
|
391 |
| - # Read and preprocess values of each band |
| 397 | + # Read and preprocess values of each eo band |
392 | 398 | values <- purrr::map(bands, function(band) {
|
393 | 399 | # Get band values (stops if band not found)
|
394 | 400 | values <- .tile_read_block(
|
|
436 | 442 | # Return values
|
437 | 443 | return(as.data.frame(values))
|
438 | 444 | })
|
| 445 | + # Read and preprocess values of each base band |
| 446 | + values_base <- purrr::map(base_bands, function(band) { |
| 447 | + # Read and preprocess values of each base band |
| 448 | + values_base <- .tile_read_block( |
| 449 | + tile = .tile_base_info(tile), |
| 450 | + band = band, |
| 451 | + block = block |
| 452 | + ) |
| 453 | + # Return values |
| 454 | + return(as.data.frame(values_base)) |
| 455 | + }) |
| 456 | + # Combine two lists |
| 457 | + values <- c(values, values_base) |
439 | 458 | # collapse list to get data.frame
|
440 |
| - values <- suppressMessages(purrr::list_cbind(values, |
441 |
| - name_repair = "universal")) |
| 459 | + values <- suppressMessages( |
| 460 | + purrr::list_cbind(values, name_repair = "universal") |
| 461 | + ) |
442 | 462 | # Compose final values
|
443 | 463 | values <- as.matrix(values)
|
444 | 464 | # Set values features name
|
|
0 commit comments