Skip to content

Commit

Permalink
fix merge in test-cube
Browse files Browse the repository at this point in the history
  • Loading branch information
M3nin0 committed May 7, 2024
1 parent 85af7f3 commit 847489f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 99 deletions.
18 changes: 2 additions & 16 deletions R/sits_merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 11,12 @@
#' To merge data cubes, they should share the same sensor, resolution,
#' bounding box, timeline, and have different bands.
#'
#' When the user requests a sits_merge operation for two regular cubes with
#' the same number of time intervals but with timelines that are not equal
#' the system issues a warning and asks the user to provide a \code{tolerance}
#' parameter which will be used in the merging operation.
#' The temporal tolerance parameter should be less than the time interval
#' between two images of both cubes.
#' In this case the second cube will have its timeline and the image
#' file names changed to match the timeline of the first cube.
#' The images of the second cube will be written in \code{output_dir}
#' directory.
#'
#' @param data1 Time series (tibble of class "sits")
#' or data cube (tibble of class "raster_cube") .
#' @param data2 Time series (tibble of class "sits")
#' or data cube (tibble of class "raster_cube") .
#'
#' @param ... Additional parameters
#' @param tolerance Allowable amount of variation in time interval
#' between two dates of cubes to be merged
#' @param output_dir Directory where transformed images will be saved
#' @param suffix If there are duplicate bands in data1 and data2
#' these suffixes will be added
#' (character vector).
Expand Down Expand Up @@ -176,11 162,11 @@ sits_merge.raster_cube <- function(data1, data2) {
d2_period <- as.numeric(
lubridate::as.period(lubridate::int_diff(d2_tl)), "days"
)
# pre-condition - are cubes period regular?
# pre-condition - are periods regular?
.check_that(
length(unique(d1_period)) == 1 && length(unique(d2_period)) == 1
)
# pre-condition - are cubes have same period?
# pre-condition - Do cubes have the same periods?
.check_that(
unique(d1_period) == unique(d2_period)
)
Expand Down
16 changes: 0 additions & 16 deletions man/sits_merge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 6 additions & 67 deletions tests/testthat/test-cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 118,6 @@ test_that("Combining Sentinel-1 with Sentinel-2 cubes", {
if (!dir.exists(dir_images)) {
suppressWarnings(dir.create(dir_images))
}
merge_images <- paste0(tempdir(), "/images_merge_new/")
if (!dir.exists(merge_images)) {
suppressWarnings(dir.create(merge_images))
}

testthat::skip_if(
purrr::is_null(s2_cube),
Expand Down Expand Up @@ -170,80 166,23 @@ test_that("Combining Sentinel-1 with Sentinel-2 cubes", {
)
)

testthat::expect_warning(
sits_merge(
s2_reg,
s1_reg,
tolerance = "P3D"
),
regexp = "use the `output_dir` parameter."
)

testthat::expect_error(
sits_merge(
s2_reg,
s1_reg,
tolerance = "P1D",
output_dir = merge_images
)
)
# Merging with writing images
cube_merged <- suppressWarnings(
sits_merge(
s2_reg,
s1_reg,
tolerance = "P3D",
output_dir = merge_images
)
)
testthat::expect_true(
all(sits_timeline(cube_merged) == sits_timeline(s2_reg))
# Merging images without writing
cube_merged <- sits_merge(
s2_reg,
s1_reg
)
testthat::expect_true(
all(
sits_bands(cube_merged) %in% c(sits_bands(s2_reg),
sits_bands(s1_reg)))
)
testthat::expect_error(
suppressWarnings(
sits_merge(
s2_cube,
s1_cube,
tolerance = "P10D",
output_dir = merge_images
)
)
)
# Merging images without writing
cube_merged2 <- suppressWarnings(
sits_merge(
s2_reg,
s1_reg,
tolerance = "P3D"
)
)
testthat::expect_true(
all(sits_timeline(cube_merged) == sits_timeline(cube_merged2))
)
testthat::expect_true(
all(
sits_bands(cube_merged) %in% sits_bands(cube_merged2)
)
)
testthat::expect_true(
all(
.fi_paths(.fi_filter_bands(.fi(s1_reg), "VV")) %in%
.fi_paths(.fi_filter_bands(.fi(cube_merged2), "VV"))
)
)
testthat::expect_false(
all(
.fi_paths(.fi_filter_bands(.fi(cube_merged), "VV")) %in%
.fi_paths(.fi_filter_bands(.fi(cube_merged2), "VV"))
s2_cube,
s1_cube
)
)

unlink(list.files(merge_images, pattern = ".tif", full.names = TRUE))
unlink(list.files(dir_images, pattern = ".tif", full.names = TRUE))
})

Expand Down

0 comments on commit 847489f

Please sign in to comment.