Skip to content

Commit

Permalink
add docs in sits_merge
Browse files Browse the repository at this point in the history
  • Loading branch information
OldLipe committed Apr 30, 2024
1 parent c84fdce commit b590003
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
24 changes: 24 additions & 0 deletions R/api_merge.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.merge_diff_timeline <- function(t1, t2) {
abs(as.Date(t1) - as.Date(t2))
}

.merge_fi <- function(data1, data2) {
data1 <- slider::slide2_dfr(data1, data2, function(x, y) {
.fi(x) <- dplyr::arrange(
dplyr::bind_rows(.fi(x), .fi(y)),
.data[["date"]],
.data[["band"]],
.data[["fid"]]
)
# remove duplicates
.fi(x) <- dplyr::distinct(
.fi(x),
.data[["band"]],
.data[["date"]],
.keep_all = TRUE
)

return(x)
})
return(data1)
}
44 changes: 19 additions & 25 deletions R/sits_merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
#' 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")
Expand All @@ -19,6 +30,14 @@
#' @param suffix If there are duplicate bands in data1 and data2
#' these suffixes will be added
#' (character vector).
#' @param tolerance A period tolerance to merge both cubes.
#' ISO8601-compliant time period for regular data cubes,
#' with number and unit, where "D", "M" and "Y" stand
#' for days, month and year; e.g., "P16D" for 16 days.
#' The temporal tolerance parameter should be less than
#' the time interval between two images of both cubes.
#' @param output_dir Valid directory for storing merged images.
#'
#' @return merged data sets (tibble of class "sits" or
#' tibble of class "raster_cube")
#' @examples
Expand Down Expand Up @@ -152,31 +171,6 @@ sits_merge.raster_cube <- function(data1, data2, ...,
return(data1)
}

.merge_diff_timeline <- function(t1, t2) {
abs(as.Date(t1) - as.Date(t2))
}

.merge_fi <- function(data1, data2) {
data1 <- slider::slide2_dfr(data1, data2, function(x, y) {
.fi(x) <- dplyr::arrange(
dplyr::bind_rows(.fi(x), .fi(y)),
.data[["date"]],
.data[["band"]],
.data[["fid"]]
)
# remove duplicates
.fi(x) <- dplyr::distinct(
.fi(x),
.data[["band"]],
.data[["date"]],
.keep_all = TRUE
)

return(x)
})
return(data1)
}

#' @rdname sits_merge
#' @export
sits_merge.default <- function(data1, data2, ...) {
Expand Down
20 changes: 20 additions & 0 deletions man/sits_merge.Rd

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

0 comments on commit b590003

Please sign in to comment.