|
461 | 461 | # require gdalcubes package |
462 | 462 | .check_require_packages("gdalcubes") |
463 | 463 | # prepare temp_output_dir |
464 | | - temp_output_dir <- file.path(output_dir, ".sits") |
| 464 | + temp_output_dir <- file.path(output_dir, ".sits", "tmp") |
465 | 465 | if (!dir.exists(temp_output_dir)) { |
466 | 466 | dir.create(temp_output_dir, recursive = TRUE) |
467 | 467 | } |
468 | 468 | # set to delete all files in temp dir |
469 | | - on.exit(unlink(list.files(temp_output_dir, full.names = TRUE)), add = TRUE) |
| 469 | + on.exit(unlink(temp_output_dir, recursive = TRUE), add = TRUE) |
470 | 470 | if (.has_not(timeline)) { |
471 | 471 | # timeline of intersection |
472 | 472 | timeline <- .gc_get_valid_timeline(cube, period = period) |
|
520 | 520 | cube = cube, |
521 | 521 | local_cube = local_cube, |
522 | 522 | processed_cube = processed_cube, |
523 | | - timeline = timeline |
| 523 | + timeline = timeline, |
| 524 | + output_dir = output_dir |
524 | 525 | ) |
525 | 526 | # recovery mode |
526 | 527 | finished <- length(jobs) == 0 |
|
650 | 651 | cube = cube, |
651 | 652 | local_cube = local_cube, |
652 | 653 | processed_cube = processed_cube, |
653 | | - timeline = timeline |
| 654 | + timeline = timeline, |
| 655 | + output_dir = output_dir |
654 | 656 | ) |
655 | 657 |
|
656 | 658 | # have we finished? |
|
752 | 754 | #' @param local_cube Regularized local cube (may be missing tiles). |
753 | 755 | #' @param processed_cube Regularized processed cube. |
754 | 756 | #' @param timeline Timeline used by gdalcubes for regularized cube |
755 | | -#' @param period Period of timeline regularization. |
| 757 | +#' @param output_dir Output directory used to checked files |
756 | 758 | #' |
757 | 759 | #' @return Tiles that are missing from the regularized cube. |
758 | | -.gc_missing_tiles <- function(cube, local_cube, processed_cube, timeline) { |
| 760 | +.gc_missing_tiles <- function(cube, local_cube, processed_cube, timeline, output_dir) { |
759 | 761 | # do a cross product on tiles and bands |
760 | 762 | tiles_bands_times <- unlist(slider::slide(cube, function(tile) { |
761 | 763 | bands <- .cube_bands(tile, add_cloud = FALSE) |
|
773 | 775 | if (!is.null(local_cube)) { |
774 | 776 | # do a cross product on tiles and bands |
775 | 777 | local_tiles_bands_times <- unlist(slider::slide(local_cube, function(tile) { |
776 | | - purrr::pmap(tile$file_info[[1L]][, c("band", "date")], function(band, date) { |
777 | | - list(tile$tile, band, date) |
| 778 | + purrr::pmap(tile$file_info[[1L]][, c("band", "date", "path")], function(band, date, path) { |
| 779 | + list(tile$tile, band, date, path) |
778 | 780 | }) |
779 | 781 | }), recursive = FALSE) |
780 | 782 | } |
| 783 | + valids <- vapply(local_tiles_bands_times, function(x) { |
| 784 | + valid <- .raster_is_valid(x[[4L]], output_dir) |
| 785 | + if (!valid) unlink(x[[4L]]) |
| 786 | + valid |
| 787 | + }, logical(1L)) |
| 788 | + local_tiles_bands_times <- lapply(local_tiles_bands_times, function(x) { |
| 789 | + x[c(1L, 2L, 3L)] |
| 790 | + })[valids] |
781 | 791 |
|
782 | 792 | # Get processed cube tiles, bands and times |
783 | 793 | proc_tiles_bands_times <- NULL |
784 | 794 | if (!is.null(processed_cube)) { |
785 | 795 | # do a cross product on tiles and bands |
786 | 796 | proc_tiles_bands_times <- unlist(slider::slide(processed_cube, function(tile) { |
787 | | - purrr::pmap(tile$file_info[[1L]][, c("band", "date")], function(band, date) { |
788 | | - list(tile$tile, band, date) |
| 797 | + purrr::pmap(tile$file_info[[1L]][, c("band", "date", "path")], function(band, date, path) { |
| 798 | + list(tile$tile, band, date, path) |
789 | 799 | }) |
790 | 800 | }), recursive = FALSE) |
791 | 801 | } |
| 802 | + valids <- vapply(proc_tiles_bands_times, function(x) { |
| 803 | + valid <- .raster_is_valid(x[[4L]], output_dir) |
| 804 | + if (!valid) unlink(x[[4L]]) |
| 805 | + valid |
| 806 | + }, logical(1L)) |
| 807 | + proc_tiles_bands_times <- lapply(proc_tiles_bands_times, function(x) { |
| 808 | + x[c(1L, 2L, 3L)] |
| 809 | + })[valids] |
| 810 | + |
792 | 811 | # merge local and processed entries |
793 | 812 | gc_tiles_bands_times <- c(local_tiles_bands_times, proc_tiles_bands_times) |
794 | 813 |
|
|
0 commit comments