|
245 | 245 | } |
246 | 246 | } |
247 | 247 |
|
248 | | -#' @title Classify a chunk of raster data using multicores |
249 | | -#' @name .classify_vector_tile |
| 248 | +#' @title Classify segments |
| 249 | +#' @name .classify_segments |
250 | 250 | #' @keywords internal |
251 | 251 | #' @noRd |
252 | 252 | #' @author Rolf Simoes, \email{rolfsimoes@@gmail.com} |
253 | 253 | #' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} |
254 | 254 | #' @author Felipe Carvalho, \email{felipe.carvalho@@inpe.br} |
255 | 255 | #' @author Felipe Carlos, \email{efelipecarlos@@gmail.com} |
256 | 256 | #' |
257 | | -#' @description Classifies a block of data using multicores. Breaks |
258 | | -#' the data into blocks and divides them between the available cores. |
259 | | -#' After all cores process their blocks, |
260 | | -#' joins the result and then writes it. |
| 257 | +#' @description Classify segments based on a probability raster cube. |
| 258 | +#' The segments are split for each raster block and then combined the |
| 259 | +#' pixels probabilities using mean aggregation. |
261 | 260 | #' |
262 | 261 | #' @param tile Single tile of a data cube. |
263 | | -#' @param bands Bands to extract time series |
264 | | -#' @param base_bands Base bands to extract values |
265 | | -#' @param ml_model Model trained by \code{\link[sits]{sits_train}}. |
266 | 262 | #' @param block Optimized block to be read into memory. |
267 | | -#' @param roi Region of interest. |
268 | | -#' @param filter_fn Smoothing filter function to be applied to the data. |
269 | | -#' @param impute_fn Imputation function to remove NA values. |
270 | 263 | #' @param n_sam_pol Number of samples per polygon to be read |
271 | 264 | #' for POLYGON or MULTIPOLYGON vector objects. |
272 | 265 | #' @param multicores Number of cores for classification |
273 | | -#' @param gpu_memory Memory available in GPU (default = NULL) |
| 266 | +#' @param memsize Memory available for classification in GB |
274 | 267 | #' @param version Version of result. |
275 | 268 | #' @param output_dir Output directory. |
276 | 269 | #' @param progress Show progress bar? |
277 | 270 | #' @return List of the classified raster layers. |
278 | | -.classify_vector_tile <- function(tile, |
279 | | - bands, |
280 | | - base_bands, |
281 | | - ml_model, |
282 | | - block, |
283 | | - roi, |
284 | | - filter_fn, |
285 | | - impute_fn, |
286 | | - n_sam_pol, |
287 | | - multicores, |
288 | | - memsize, |
289 | | - gpu_memory, |
290 | | - version, |
291 | | - output_dir, |
292 | | - progress) { |
| 271 | +.classify_segments <- function(tile, |
| 272 | + block, |
| 273 | + n_sam_pol, |
| 274 | + multicores, |
| 275 | + memsize, |
| 276 | + version, |
| 277 | + output_dir, |
| 278 | + progress) { |
293 | 279 | # Define output vector file name and extension |
294 | 280 | out_file <- .file_derived_name( |
295 | 281 | tile = tile, |
|
307 | 293 | file = out_file, |
308 | 294 | band = "probs", |
309 | 295 | base_tile = tile, |
310 | | - labels = .ml_labels(ml_model), |
| 296 | + labels = .tile_labels(tile), |
311 | 297 | vector_class = "probs_vector_cube", |
312 | 298 | update_bbox = FALSE |
313 | 299 | ) |
|
319 | 305 | overlap = 0L, |
320 | 306 | block = block |
321 | 307 | ) |
322 | | - # By default, update_bbox is FALSE |
323 | | - if (.has(roi)) { |
324 | | - # Intersecting chunks with ROI |
325 | | - chunks <- .chunks_filter_spatial( |
326 | | - chunks = chunks, |
327 | | - roi = roi |
328 | | - ) |
329 | | - } |
330 | 308 | # Filter segments that intersects with each chunk |
331 | 309 | chunks <- .chunks_filter_segments( |
332 | 310 | chunks = chunks, |
|
354 | 332 | # Number of time series per segment is defined by n_sam_pol |
355 | 333 | segments_ts <- .segments_poly_read( |
356 | 334 | tile = tile, |
357 | | - bands = bands, |
358 | | - base_bands = base_bands, |
359 | 335 | chunk = chunk, |
360 | | - n_sam_pol = n_sam_pol, |
361 | | - impute_fn = impute_fn |
| 336 | + n_sam_pol = n_sam_pol |
362 | 337 | ) |
363 | 338 | # Deal with NO DATA cases (e.g., cloudy areas) |
364 | 339 | if (nrow(segments_ts) == 0L) { |
365 | 340 | return("") |
366 | 341 | } |
367 | | - # Classify times series |
368 | | - # This is the same function called to classify |
369 | | - # individual time series (with an extra polygon_id) |
370 | | - segments_ts <- .classify_ts( |
371 | | - samples = segments_ts, |
372 | | - ml_model = ml_model, |
373 | | - filter_fn = filter_fn, |
374 | | - impute_fn = impute_fn, |
375 | | - multicores = 1L, |
376 | | - gpu_memory = gpu_memory, |
377 | | - progress = progress |
378 | | - ) |
379 | 342 | # Join probability values with segments |
380 | 343 | segments_ts <- .segments_join_probs( |
381 | 344 | data = segments_ts, |
|
405 | 368 | file = out_file, |
406 | 369 | band = "probs", |
407 | 370 | base_tile = tile, |
408 | | - labels = .ml_labels(ml_model), |
| 371 | + labels = .tile_labels(tile), |
409 | 372 | vector_class = "probs_vector_cube", |
410 | 373 | update_bbox = FALSE |
411 | 374 | ) |
|
0 commit comments