Skip to content

Commit f6be56c

Browse files
committed
Merge branch 'dev' of https://github.com/e-sensing/sits into feat/dev-sits
2 parents 292098c + 1a4802c commit f6be56c

File tree

4 files changed

+19
-78
lines changed

4 files changed

+19
-78
lines changed

R/api_data.R

+16-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,22 @@
9797
multicores = multicores,
9898
progress = progress
9999
)
100-
# save base data
101-
ts_tbl[["base_data"]] <- base_tbl[["time_series"]]
100+
# prepare output data
101+
base_tbl <- base_tbl |>
102+
dplyr::select("longitude", "latitude", "time_series") |>
103+
dplyr::rename("base_data" = "time_series")
104+
# Assuming `ts_tbl` as the source of truth, the size of the following
105+
# `join` must be the same as the current `ts_tbl`.
106+
ts_tbl_size <- nrow(ts_tbl)
107+
# joining samples data from cube and base_cube by longitude / latitude
108+
ts_tbl <- dplyr::left_join(
109+
x = ts_tbl,
110+
y = base_tbl,
111+
by = c("longitude", "latitude")
112+
) |>
113+
tidyr::drop_na()
114+
# checking samples consistency
115+
.data_check(ts_tbl_size, nrow(ts_tbl))
102116
# add base class
103117
class(ts_tbl) <- c("sits_base", class(ts_tbl))
104118
}

R/api_segments.R

+1-74
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
block = block
158158
)
159159
# Get tile bands
160-
tile_bands <- .tile_bands(
160+
tile_bands <- .tile_bands.raster_cube(
161161
tile = tile,
162162
add_cloud = FALSE
163163
)
@@ -406,76 +406,3 @@
406406
class(samples) <- c("sits", class(samples))
407407
return(samples)
408408
}
409-
410-
#' @title Split tile bands for extraction of values inside segments
411-
#' @name .segments_split_tile_bands
412-
#' @keywords internal
413-
#' @noRd
414-
#' @param tile input tile
415-
#' @param bands bands where data will be extracted
416-
#'
417-
#' @return tibble with band-files pairs
418-
#'
419-
.segments_split_tile_bands <- function(tile, bands) {
420-
tile_bands <- purrr::map(bands, function(band) {
421-
band_files <- .fi_filter_bands(.fi(tile), band)[["path"]]
422-
tibble::tibble(
423-
band = band,
424-
files = list(band_files),
425-
segs_path = .segments_path(tile),
426-
params = list(.tile_band_conf(tile, band))
427-
)
428-
})
429-
tile_bands <- dplyr::bind_rows(tile_bands)
430-
return(tile_bands)
431-
}
432-
#' @title Split tile bands for extraction of values inside segments
433-
#' @name .segments_split_tile_bands_list
434-
#' @keywords internal
435-
#' @noRd
436-
#' @param tile input tile
437-
#' @param bands bands where data will be extracted
438-
#' @param segments large set of segments
439-
#' @param n_iterations number of parts to break the segments
440-
#' @param output_dir directory to write the segments
441-
#' @return list of tibbles with band-files pairs
442-
#'
443-
.segments_split_tile_bands_list <- function(tile,
444-
bands,
445-
segments,
446-
n_iterations,
447-
output_dir) {
448-
449-
segments[["group"]] <- rep(
450-
seq_len(n_iterations), each = ceiling(nrow(segments) / n_iterations)
451-
)[seq_len(nrow(segments))]
452-
453-
segments_lst <- dplyr::group_split(
454-
dplyr::group_by(segments, .data[["group"]])
455-
)
456-
segment_files <- purrr::map_chr(segments_lst, function(seg_part) {
457-
# Block file name
458-
hash_bundle <- digest::digest(seg_part, algo = "md5")
459-
seg_file <- .file_path(
460-
paste0(hash_bundle, "_segments"),
461-
ext = "gpkg",
462-
output_dir = output_dir
463-
)
464-
.vector_write_vec(seg_part, seg_file)
465-
return(seg_file)
466-
})
467-
seg_tile_band_lst <- purrr::map(segment_files, function(seg_file) {
468-
tile_bands <- purrr::map(bands, function(band) {
469-
band_files <- .fi_filter_bands(.fi(tile), band)[["path"]]
470-
tibble::tibble(
471-
band = band,
472-
files = list(band_files),
473-
segs_path = seg_file,
474-
params = list(.tile_band_conf(tile, band))
475-
)
476-
})
477-
seg_tile_band <- dplyr::bind_rows(tile_bands)
478-
return(seg_tile_band)
479-
})
480-
return(seg_tile_band_lst)
481-
}

inst/extdata/sources/config_source_mpc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ sources:
128128
resolution : 30
129129
data_type : "FLT4S"
130130
missing_value : -32768
131-
minimum_value : 0
131+
minimum_value : -32767
132132
maximum_value : 65534
133133
scale_factor : 1
134134
offset_value : 0

tests/testthat/test-segmentation.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ test_that("Segmentation of large files",{
200200
seg_fn = sits_slic(
201201
step = 50,
202202
iter = 10,
203-
minarea = 100
203+
minarea = 50
204204
),
205205
output_dir = output_dir,
206206
multicores = 4,

0 commit comments

Comments
 (0)