Skip to content

Commit 691a70d

Browse files
merge cubes with one cube with a single timeline
1 parent a68212c commit 691a70d

14 files changed

+327
-238
lines changed

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ export(sits_combine_predictions)
438438
export(sits_confidence_sampling)
439439
export(sits_config)
440440
export(sits_config_show)
441+
export(sits_config_user_file)
441442
export(sits_cube)
442443
export(sits_cube_copy)
443444
export(sits_detect_change)

R/api_conf.R

+96-2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@
145145
.check_that(file.exists(yml_file))
146146
return(yml_file)
147147
}
148+
#' @title Return the user-relevant configuration file
149+
#' @name .config_file
150+
#' @keywords internal
151+
#' @noRd
152+
#' @return default user-relevant configuration file
153+
.config_file <- function() {
154+
.check_set_caller(".config_file")
155+
# load the default configuration file
156+
yml_file <- system.file("extdata", "config.yml", package = "sits")
157+
# check that the file name is valid
158+
.check_that(file.exists(yml_file))
159+
return(yml_file)
160+
}
148161
#' @title Return the message configuration files (only for developers)
149162
#' @name .conf_sources_files
150163
#' @keywords internal
@@ -282,7 +295,7 @@
282295
# pre condition - table contains name and hex code
283296
.check_chr_contains(
284297
x = colnames(color_tb),
285-
contains = .conf("sits_color_table_cols"),
298+
contains = .conf("color_table_cols"),
286299
discriminator = "all_of"
287300
)
288301
# replace all duplicates
@@ -450,7 +463,8 @@
450463
user_config[["gdalcubes_chunk_size"]],
451464
sources = user_config[["sources"]],
452465
colors = user_config[["colors"]],
453-
tmap = user_config[["tmap"]]
466+
view = user_config[["view"]],
467+
plot = user_config[["plot"]]
454468
)
455469
}
456470
}
@@ -484,6 +498,86 @@
484498
)
485499
return(invisible(bands))
486500
}
501+
#' @title List configuration parameters
502+
#' @name .conf_list_params
503+
#' @description List the contents of a source
504+
#'
505+
#' @keywords internal
506+
#' @noRd
507+
#' @param params parameter list
508+
#'
509+
#' @return Called for side effects.
510+
.conf_list_params <- function(params) {
511+
params <- lapply(params, function(x) {
512+
if (is.atomic(x)) {
513+
return(x)
514+
}
515+
list(names(x))
516+
})
517+
params_txt <- yaml::as.yaml(
518+
params,
519+
indent = 4,
520+
handlers = list(
521+
character = function(x) {
522+
res <- toString(x)
523+
class(res) <- "verbatim"
524+
res
525+
},
526+
integer = function(x) {
527+
res <- toString(x)
528+
class(res) <- "verbatim"
529+
res
530+
},
531+
numeric = function(x) {
532+
res <- toString(x)
533+
class(res) <- "verbatim"
534+
res
535+
}
536+
)
537+
)
538+
cat(params_txt, sep = "\n")
539+
}
540+
541+
#' @title List contents of a source
542+
#' @name .conf_list_source
543+
#' @description List the contents of a source
544+
#'
545+
#' @keywords internal
546+
#' @noRd
547+
#' @param source Data source
548+
#'
549+
#' @return Called for side effects.
550+
.conf_list_source <- function(source){
551+
cat(paste0(s, ":\n"))
552+
collections <- .source_collections(source = s)
553+
purrr::map(collections, function(c) {
554+
cat(paste0("- ", c))
555+
cat(paste0(
556+
" (", .source_collection_satellite(s, c),
557+
"/", .source_collection_sensor(s, c), ")\n",
558+
"- grid system: ", .source_collection_grid_system(s, c), "\n"
559+
))
560+
cat("- bands: ")
561+
cat(.source_bands(s, c))
562+
cat("\n")
563+
if (.source_collection_open_data(source = s, collection = c)) {
564+
cat("- opendata collection ")
565+
if (.source_collection_open_data(
566+
source = s,
567+
collection = c,
568+
token = TRUE
569+
)) {
570+
cat("(requires access token)")
571+
}
572+
} else {
573+
cat("- not opendata collection")
574+
}
575+
cat("\n")
576+
cat("\n")
577+
})
578+
}
579+
580+
487581
#' @title Get names associated to a configuration key
488582
#' @name .conf_names
489583
#' @param key key combination to access config information

R/api_plot_raster.R

+29-25
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# select the file to be plotted
3131
bw_file <- .tile_path(tile, band, date)
3232
# size of data to be read
33-
max_size <- .conf("view_max_size")
33+
max_size <- .conf("view", "max_size")
3434
sizes <- .tile_overview_size(tile = tile, max_size)
3535
# scale and offset
3636
band_conf <- .tile_band_conf(tile, band)
@@ -46,9 +46,11 @@
4646
# extract the values
4747
vals <- terra::values(rast)
4848
# obtain the quantiles
49+
fst_quant <- .as.numeric(.conf("plot", "first_quantile"))
50+
lst_quant <- .as.numeric(.conf("plot", "last_quantile"))
4951
quantiles <- stats::quantile(
5052
vals,
51-
probs = c(0, 0.02, 0.98, 1),
53+
probs = c(0, fst_quant, lst_quant, 1),
5254
na.rm = TRUE
5355
)
5456
minv <- quantiles[[1]]
@@ -70,11 +72,11 @@
7072
}
7173

7274
# tmap params
73-
labels_size <- as.numeric(.conf("tmap", "graticules_labels_size"))
74-
legend_bg_color <- .conf("tmap", "legend_bg_color")
75-
legend_bg_alpha <- as.numeric(.conf("tmap", "legend_bg_alpha"))
76-
legend_title_size <- as.numeric(.conf("tmap", "legend_title_size"))
77-
legend_text_size <- as.numeric(.conf("tmap", "legend_text_size"))
75+
labels_size <- as.numeric(.conf("plot", "graticules_labels_size"))
76+
legend_bg_color <- .conf("plot", "legend_bg_color")
77+
legend_bg_alpha <- as.numeric(.conf("plot", "legend_bg_alpha"))
78+
legend_title_size <- as.numeric(.conf("plot", "legend_title_size"))
79+
legend_text_size <- as.numeric(.conf("plot", "legend_text_size"))
7880

7981
# generate plot
8082
p <- tmap::tm_shape(rast, raster.downsample = FALSE) +
@@ -135,7 +137,7 @@
135137
green_file <- .tile_path(tile, band, dates[[2]])
136138
blue_file <- .tile_path(tile, band, dates[[3]])
137139
# size of data to be read
138-
max_size <- .conf("plot_max_size")
140+
max_size <- .conf("plot", "max_size")
139141
sizes <- .tile_overview_size(tile = tile, max_size)
140142
# get the max values
141143
band_params <- .tile_band_conf(tile, band)
@@ -197,7 +199,7 @@
197199
band_params <- .tile_band_conf(tile, red)
198200
max_value <- .max_value(band_params)
199201
# size of data to be read
200-
max_size <- .conf("plot_max_size")
202+
max_size <- .conf("plot", "max_size")
201203
sizes <- .tile_overview_size(tile = tile, max_size)
202204
# used for SAR images
203205
if (tile[["tile"]] == "NoTilingSystem") {
@@ -257,16 +259,18 @@
257259
),
258260
proxy = FALSE
259261
)
262+
fst_quant <- .as.numeric(.conf("plot", "first_quantile"))
263+
lst_quant <- .as.numeric(.conf("plot", "last_quantile"))
260264
# open RGB stars
261265
rgb_st <- stars::st_rgb(rgb_st[, , , 1:3],
262266
dimension = "band",
263267
maxColorValue = max_value,
264268
use_alpha = FALSE,
265-
probs = c(0.05, 0.95),
269+
probs = c(fst_quant, las_quant),
266270
stretch = TRUE
267271
)
268272
# tmap params
269-
labels_size <- as.numeric(.conf("tmap", "graticules_labels_size"))
273+
labels_size <- as.numeric(.conf("plot", "graticules_labels_size"))
270274

271275
p <- tmap::tm_shape(rgb_st, raster.downsample = FALSE) +
272276
tmap::tm_raster() +
@@ -306,7 +310,7 @@
306310
# verifies if stars package is installed
307311
.check_require_packages("stars")
308312
# verifies if tmap package is installed
309-
.check_require_packages("tmap")
313+
.check_require_packages("plot")
310314

311315
# deal with color palette
312316
.check_palette(palette)
@@ -321,7 +325,7 @@
321325
)
322326
names(colors) <- names(labels)
323327
# size of data to be read
324-
max_size <- .conf("plot_max_size")
328+
max_size <- .conf("plot", "max_size")
325329
sizes <- .tile_overview_size(tile = tile, max_size)
326330
# select the image to be plotted
327331
class_file <- .tile_path(tile)
@@ -340,11 +344,11 @@
340344
stars_obj <- stats::setNames(stars_obj, "labels")
341345

342346
# tmap params
343-
labels_size <- as.numeric(.conf("tmap", "graticules_labels_size"))
344-
legend_bg_color <- .conf("tmap", "legend_bg_color")
345-
legend_bg_alpha <- as.numeric(.conf("tmap", "legend_bg_alpha"))
346-
legend_title_size <- as.numeric(.conf("tmap", "legend_title_size"))
347-
legend_text_size <- as.numeric(.conf("tmap", "legend_text_size"))
347+
labels_size <- as.numeric(.conf("plot", "graticules_labels_size"))
348+
legend_bg_color <- .conf("plot", "legend_bg_color")
349+
legend_bg_alpha <- as.numeric(.conf("plot", "legend_bg_alpha"))
350+
legend_title_size <- as.numeric(.conf("plot", "legend_title_size"))
351+
legend_text_size <- as.numeric(.conf("plot", "legend_text_size"))
348352

349353
# plot using tmap
350354
p <- suppressMessages(
@@ -390,7 +394,7 @@
390394
# verifies if stars package is installed
391395
.check_require_packages("stars")
392396
# verifies if tmap package is installed
393-
.check_require_packages("tmap")
397+
.check_require_packages("plot")
394398
# precondition - check color palette
395399
.check_palette(palette)
396400
# revert the palette
@@ -408,7 +412,7 @@
408412
.check_that(all(labels_plot %in% labels))
409413
}
410414
# size of data to be read
411-
max_size <- .conf("plot_max_size")
415+
max_size <- .conf("plot", "max_size")
412416
sizes <- .tile_overview_size(tile = tile, max_size)
413417
# get the path
414418
probs_path <- .tile_path(tile)
@@ -432,11 +436,11 @@
432436
# select stars bands to be plotted
433437
bds <- as.numeric(names(labels[labels %in% labels_plot]))
434438

435-
labels_size <- as.numeric(.conf("tmap", "graticules_labels_size"))
436-
legend_bg_color <- .conf("tmap", "legend_bg_color")
437-
legend_bg_alpha <- as.numeric(.conf("tmap", "legend_bg_alpha"))
438-
legend_title_size <- as.numeric(.conf("tmap", "legend_title_size"))
439-
legend_text_size <- as.numeric(.conf("tmap", "legend_text_size"))
439+
labels_size <- as.numeric(.conf("plot", "graticules_labels_size"))
440+
legend_bg_color <- .conf("plot", "legend_bg_color")
441+
legend_bg_alpha <- as.numeric(.conf("plot", "legend_bg_alpha"))
442+
legend_title_size <- as.numeric(.conf("plot", "legend_title_size"))
443+
legend_text_size <- as.numeric(.conf("plot", "legend_text_size"))
440444

441445
p <- tmap::tm_shape(probs_st[, , , bds]) +
442446
tmap::tm_raster(

R/api_plot_vector.R

+11-11
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848
palette = colors
4949
) +
5050
tmap::tm_graticules(
51-
labels.size = as.numeric(.conf("tmap", "graticules_labels_size"))
51+
labels.size = as.numeric(.conf("plot", "graticules_labels_size"))
5252
) +
5353
tmap::tm_compass() +
5454
tmap::tm_layout(
5555
scale = scale,
56-
legend.bg.color = .conf("tmap", "legend_bg_color"),
57-
legend.bg.alpha = as.numeric(.conf("tmap", "legend_bg_alpha"))
56+
legend.bg.color = .conf("plot", "legend_bg_color"),
57+
legend.bg.alpha = as.numeric(.conf("plot", "legend_bg_alpha"))
5858
) +
5959
tmap::tm_borders(lwd = 0.2)
6060
return(p)
@@ -87,7 +87,7 @@
8787
# verifies if stars package is installed
8888
.check_require_packages("stars")
8989
# verifies if tmap package is installed
90-
.check_require_packages("tmap")
90+
.check_require_packages("plot")
9191
# precondition - check color palette
9292
.check_palette(palette)
9393
# revert the palette
@@ -115,14 +115,14 @@
115115
midpoint = 0.5,
116116
title = labels[labels %in% labels_plot]) +
117117
tmap::tm_graticules(
118-
labels.size = as.numeric(.conf("tmap", "graticules_labels_size"))
118+
labels.size = as.numeric(.conf("plot", "graticules_labels_size"))
119119
) +
120120
tmap::tm_facets() +
121121
tmap::tm_compass() +
122122
tmap::tm_layout(
123123
scale = scale,
124-
legend.bg.color = .conf("tmap", "legend_bg_color"),
125-
legend.bg.alpha = as.numeric(.conf("tmap", "legend_bg_alpha"))
124+
legend.bg.color = .conf("plot", "legend_bg_color"),
125+
legend.bg.alpha = as.numeric(.conf("plot", "legend_bg_alpha"))
126126
) +
127127
tmap::tm_borders(lwd = 0.1)
128128

@@ -150,7 +150,7 @@
150150
# verifies if stars package is installed
151151
.check_require_packages("stars")
152152
# verifies if tmap package is installed
153-
.check_require_packages("tmap")
153+
.check_require_packages("plot")
154154
# precondition - check color palette
155155
.check_palette(palette)
156156
# revert the palette
@@ -167,16 +167,16 @@
167167
palette = palette,
168168
style = "cont") +
169169
tmap::tm_graticules(
170-
labels.size = as.numeric(.conf("tmap", "graticules_labels_size"))
170+
labels.size = as.numeric(.conf("plot", "graticules_labels_size"))
171171
) +
172172
tmap::tm_compass() +
173173
tmap::tm_layout(
174174
main.title = main_title,
175175
main.title.size = 1,
176176
main.title.position = "center",
177177
scale = scale,
178-
legend.bg.color = .conf("tmap", "legend_bg_color"),
179-
legend.bg.alpha = as.numeric(.conf("tmap", "legend_bg_alpha"))
178+
legend.bg.color = .conf("plot", "legend_bg_color"),
179+
legend.bg.alpha = as.numeric(.conf("plot", "legend_bg_alpha"))
180180
) +
181181
tmap::tm_borders(lwd = 0.2)
182182

0 commit comments

Comments
 (0)