|
174 | 174 | .merge_cube_compactify <- function(data1, data2) { |
175 | 175 | # extract tiles |
176 | 176 | tiles <- .merge_get_common_tiles(data1, data2) |
177 | | - if (.has(tiles)) { |
178 | | - # align timeline tile by tile. |
179 | | - merged_cube <- .map_dfr(tiles, function(tile) { |
180 | | - # get tiles |
181 | | - tile1 <- .cube_filter_tiles(data1, tile) |
182 | | - tile2 <- .cube_filter_tiles(data2, tile) |
183 | | - # get tile timelines |
184 | | - ts1 <- .tile_timeline(tile1) |
185 | | - ts2 <- .tile_timeline(tile2) |
186 | | - # adjust timeline using zipper strategy |
187 | | - ts_overlap <- .merge_zipper_strategy(ts1, ts2) |
188 | | - # filter cubes in the overlapping dates |
189 | | - tile1 <- .cube_filter_dates(tile1, ts_overlap) |
190 | | - tile2 <- .cube_filter_dates(tile2, ts_overlap) |
191 | | - # merge by file |
192 | | - .merge_strategy_file(tile1, tile2) |
193 | | - }) |
194 | | - } else { |
195 | | - # It is not possible to merge non-common tiles with multiple bands using |
196 | | - # the same sensor |
197 | | - .check_that( |
198 | | - .cube_sensor(data1) != .cube_sensor(data2), |
199 | | - msg = .conf("messages", ".merge_irregular_bands") |
200 | | - ) |
201 | | - # if no common tiles are available, use a global reference timeline. |
202 | | - # in this case, this timeline is generated by the merge of all timelines |
203 | | - # in the reference cube (cube 1) |
204 | | - reference_timeline <- as.Date(unlist(.cube_timeline(data1))) |
205 | | - # based on the global timeline, cut the timeline of all tiles in cube 2 |
206 | | - merged_cube <- .cube_foreach_tile(data2, function(row) { |
207 | | - # get row timeline |
208 | | - row_timeline <- .tile_timeline(row) |
209 | | - # search overlaps between the reference timeline and row timeline |
210 | | - t_overlap <- .merge_zipper_strategy( |
211 | | - t1 = reference_timeline, |
212 | | - t2 = row_timeline |
213 | | - ) |
214 | | - # cut the timeline |
215 | | - .cube_filter_dates(row, t_overlap) |
216 | | - }) |
217 | | - # as there is no tile reference, merge using `bind` strategy (cube row) |
218 | | - merged_cube <- .merge_strategy_bind(data1, merged_cube) |
219 | | - # assign `combined cube` class, meaning the cube is a combination of |
220 | | - # cubes that contains different timelines in different tiles |
221 | | - class(merged_cube) <- c("combined_cube", class(data1)) |
222 | | - merged_cube |
223 | | - } |
| 177 | + # align timeline tile by tile. |
| 178 | + merged_cube <- .map_dfr(tiles, function(tile) { |
| 179 | + # get tiles |
| 180 | + tile1 <- .cube_filter_tiles(data1, tile) |
| 181 | + tile2 <- .cube_filter_tiles(data2, tile) |
| 182 | + # get tile timelines |
| 183 | + ts1 <- .tile_timeline(tile1) |
| 184 | + ts2 <- .tile_timeline(tile2) |
| 185 | + # adjust timeline using zipper strategy |
| 186 | + ts_overlap <- .merge_zipper_strategy(ts1, ts2) |
| 187 | + # filter cubes in the overlapping dates |
| 188 | + tile1 <- .cube_filter_dates(tile1, ts_overlap) |
| 189 | + tile2 <- .cube_filter_dates(tile2, ts_overlap) |
| 190 | + # merge by file |
| 191 | + .merge_strategy_file(tile1, tile2) |
| 192 | + }) |
224 | 193 | } |
225 | 194 | #' @title Define merge strategy based on intersecting the timeline |
226 | 195 | #' @name .merge_strategy_intersects |
|
396 | 365 | # Return merged cube |
397 | 366 | merged_cube |
398 | 367 | } |
399 | | -#' @title Merge strategy for irregular cubes |
400 | | -#' @name .merge.irregular_case |
401 | | -#' @author Felipe Carvalho, \email{filipe.carvalho@@inpe.br} |
402 | | -#' @author Felipe Carlos, \email{efelipecarlos@@gmail.com} |
403 | | -#' @noRd |
404 | | -#' @param data1 Data cube |
405 | | -#' @param data2 Data cube |
406 | | -#' @return Merged data cube |
407 | | -.merge.irregular_case <- function(data1, data2) { |
408 | | - # verify if cube has the same bands |
409 | | - has_same_bands <- .merge_has_equal_bands(data1, data2) |
410 | | - # rule 1: if the bands are the same, combine cubes (`densify`) |
411 | | - if (has_same_bands) { |
412 | | - # merge! |
413 | | - .merge_cube_densify(data1, data2) |
414 | | - } else { |
415 | | - # rule 2: if the bands are different and their timelines are |
416 | | - # compatible, the bands are joined. The resulting timeline is the one |
417 | | - # from the first cube. |
418 | | - .merge_cube_compactify(data1, data2) |
419 | | - } |
420 | | -} |
421 | 368 |
|
422 | 369 | #' @title Merges cubes based on adequate strategy |
423 | 370 | #' @name .merge |
|
434 | 381 | if (.merge_type_hls(data1, data2)) { |
435 | 382 | return("hls_case") |
436 | 383 | } |
437 | | - if (.merge_type_deaustralia_s2(data1, data2)) { |
438 | | - return("irregular_case") |
439 | | - } |
440 | 384 | if (.merge_type_regular(data1, data2)) { |
441 | 385 | return("regular_case") |
442 | 386 | } |
443 | | - if (.merge_type_irregular(data1, data2)) { |
444 | | - return("irregular_case") |
445 | | - } |
446 | 387 | # find no alternative? error messages |
447 | 388 | stop(.conf("messages", ".merge_type"), toString(class(data1))) |
448 | 389 | } |
449 | 390 | .merge_type_regular <- function(data1, data2) { |
450 | 391 | .cube_is_regular(data1) && |
451 | | - .cube_is_regular(data2) && |
452 | | - .cube_has_unique_period(data1) && |
453 | | - .cube_has_unique_period(data2) |
| 392 | + .cube_is_regular(data2) |
454 | 393 | } |
455 | 394 | .merge_type_dem <- function(data1, data2) { |
456 | 395 | any(inherits(data1, "dem_cube"), inherits(data2, "dem_cube")) |
457 | 396 | } |
458 | 397 | .merge_type_hls <- function(data1, data2) { |
459 | 398 | all(inherits(data1, "hls_cube"), inherits(data2, "hls_cube")) |
460 | 399 | } |
461 | | -.merge_type_deaustralia_s2 <- function(data1, data2) { |
462 | | - all( |
463 | | - inherits(data1, "deaustralia_cube_ga_s2am_ard_3"), |
464 | | - inherits(data2, "deaustralia_cube_ga_s2am_ard_3") |
465 | | - ) || |
466 | | - all( |
467 | | - inherits(data1, "deaustralia_cube_ga_s2bm_ard_3"), |
468 | | - inherits(data2, "deaustralia_cube_ga_s2bm_ard_3") |
469 | | - ) |
470 | | -} |
471 | | -.merge_type_irregular <- function(data1, data2) { |
472 | | - !(.merge_type_regular(data1, data2)) |
473 | | -} |
0 commit comments