Skip to content

Commit 06ab1b3

Browse files
authored
Merge pull request #1058 from e-sensing/dev
Pre-realease 1.4.2-3
2 parents f622356 + 39d9aba commit 06ab1b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1749
-719
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ inst/doc
2121
doc
2222
Meta
2323
*.bkp
24+
*.pdf
2425
.sits/
2526
*.gcda
2627
*.gcno

DESCRIPTION

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: sits
22
Type: Package
3-
Version: 1.4.2-2
3+
Version: 1.4.2-3
44
Title: Satellite Image Time Series Analysis for Earth Observation Data Cubes
55
Authors@R: c(person('Rolf', 'Simoes', role = c('aut'), email = '[email protected]'),
66
person('Gilberto', 'Camara', role = c('aut', 'cre'), email = '[email protected]'),
@@ -91,6 +91,7 @@ Suggests:
9191
randomForestExplainer,
9292
RcppArmadillo (>= 0.12),
9393
scales,
94+
spdep,
9495
stars (>= 0.6),
9596
stringr,
9697
supercells,
@@ -203,6 +204,7 @@ Collate:
203204
'sits_csv.R'
204205
'sits_cube.R'
205206
'sits_cube_copy.R'
207+
'sits_clean.R'
206208
'sits_cluster.R'
207209
'sits_factory.R'
208210
'sits_filters.R'

NAMESPACE

+13-3
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ S3method(.tile_yres,raster_cube)
237237
S3method(.values_ts,bands_cases_dates)
238238
S3method(.values_ts,bands_dates_cases)
239239
S3method(.values_ts,cases_dates_bands)
240+
S3method(.view_add_overlay_grps,class_cube)
240241
S3method(.view_add_overlay_grps,derived_cube)
241242
S3method(.view_add_overlay_grps,raster_cube)
242243
S3method(.view_add_overlay_grps,vector_cube)
@@ -256,6 +257,7 @@ S3method(plot,som_evaluate_cluster)
256257
S3method(plot,som_map)
257258
S3method(plot,torch_model)
258259
S3method(plot,uncertainty_cube)
260+
S3method(plot,uncertainty_vector_cube)
259261
S3method(plot,variance_cube)
260262
S3method(plot,vector_cube)
261263
S3method(plot,xgb_model)
@@ -290,6 +292,11 @@ S3method(sits_classify,raster_cube)
290292
S3method(sits_classify,segs_cube)
291293
S3method(sits_classify,sits)
292294
S3method(sits_classify,tbl_df)
295+
S3method(sits_clean,class_cube)
296+
S3method(sits_clean,default)
297+
S3method(sits_clean,derived_cube)
298+
S3method(sits_clean,raster_cube)
299+
S3method(sits_clean,tbl_df)
293300
S3method(sits_cluster_dendro,default)
294301
S3method(sits_cluster_dendro,sits)
295302
S3method(sits_cluster_dendro,tbl_df)
@@ -356,10 +363,11 @@ S3method(sits_timeline,tbl_df)
356363
S3method(sits_to_csv,default)
357364
S3method(sits_to_csv,sits)
358365
S3method(sits_to_csv,tbl_df)
366+
S3method(sits_to_xlsx,list)
367+
S3method(sits_to_xlsx,sits_accuracy)
359368
S3method(sits_uncertainty,default)
360-
S3method(sits_uncertainty,entropy)
361-
S3method(sits_uncertainty,least)
362-
S3method(sits_uncertainty,margin)
369+
S3method(sits_uncertainty,probs_cube)
370+
S3method(sits_uncertainty,probs_vector_cube)
363371
S3method(sits_variance,default)
364372
S3method(sits_variance,derived_cube)
365373
S3method(sits_variance,probs_cube)
@@ -389,6 +397,7 @@ export(sits_as_sf)
389397
export(sits_bands)
390398
export(sits_bbox)
391399
export(sits_classify)
400+
export(sits_clean)
392401
export(sits_cluster_clean)
393402
export(sits_cluster_dendro)
394403
export(sits_cluster_frequency)
@@ -434,6 +443,7 @@ export(sits_rfor)
434443
export(sits_run_examples)
435444
export(sits_run_tests)
436445
export(sits_sample)
446+
export(sits_sampling_design)
437447
export(sits_segment)
438448
export(sits_select)
439449
export(sits_sgolay)

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
# What's new in SITS version 1.4
44

5+
### Hotfix version 1.4.2-3
6+
* Fix font download in package initialization
7+
58
### Hotfix version 1.4.2-2
69
* Fix integer overflow bug in `sits_classify()` segments
710

R/api_check.R

+5-3
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
#' @rdname check_functions
256256
#' @keywords internal
257257
#' @noRd
258-
.check_cube_files <- function(x, ...) {
258+
.check_raster_cube_files <- function(x, ...) {
259259
# check for data access
260260
robj <- tryCatch(
261261
.raster_open_rast(.tile_path(x)),
@@ -1105,16 +1105,18 @@
11051105
#' @param max maximum value
11061106
#' @param len_min minimum length of vector
11071107
#' @param len_max maximum length of vector
1108+
#' @param allow_null Allow NULL value?
11081109
#' @param msg Error message
11091110
#' @return Called for side effects.
11101111
#' @keywords internal
11111112
#' @noRd
11121113
.check_int_parameter <- function(param, min = 1, max = 2^31 - 1,
1113-
len_min = 1, len_max = 1, msg = NULL) {
1114+
len_min = 1, len_max = 1,
1115+
allow_null = FALSE, msg = NULL) {
11141116
.check_num(
11151117
x = param,
11161118
allow_na = FALSE,
1117-
allow_null = FALSE,
1119+
allow_null = allow_null,
11181120
min = min,
11191121
max = max,
11201122
len_min = len_min,

R/api_classify.R

+6-6
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
progress = FALSE
267267
)
268268
# Classify segments
269-
classified_ts <- .classify_ts(
269+
segments_ts <- .classify_ts(
270270
samples = segments_ts,
271271
ml_model = ml_model,
272272
filter_fn = filter_fn,
@@ -275,13 +275,13 @@
275275
progress = progress
276276
)
277277
# Join probability values with segments
278-
joined_segments <- .segments_join_probs(
279-
data = classified_ts,
280-
segments = .segments_read_vec(tile),
281-
aggregate = .has(n_sam_pol)
278+
segments_ts <- .segments_join_probs(
279+
data = segments_ts,
280+
segments = .segments_read_vec(tile)
282281
)
282+
283283
# Write all segments
284-
.vector_write_vec(v_obj = joined_segments, file_path = out_file)
284+
.vector_write_vec(v_obj = segments_ts, file_path = out_file)
285285
# Create tile based on template
286286
probs_tile <- .tile_segments_from_file(
287287
file = out_file,

R/api_clean.R

+17-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' the most frequently values within the neighborhood.
88
#' In a tie, the first value of the vector is considered.
99
#'
10-
#' @param asset Subset of a data cube
10+
#' @param tile Subset of a data cube
1111
#' @param block Image block to be cleaned
1212
#' @param band Band to be processed
1313
#' @param window_size Size of local neighborhood
@@ -26,6 +26,19 @@
2626
out_file <- .file_derived_name(
2727
tile = tile, band = band, version = version, output_dir = output_dir
2828
)
29+
# Resume tile
30+
if (.raster_is_valid(out_file, output_dir = output_dir)) {
31+
# recovery message
32+
.check_recovery(out_file)
33+
# Create tile based on template
34+
tile <- .tile_derived_from_file(
35+
file = out_file, band = band,
36+
base_tile = tile, derived_class = .tile_derived_class(tile),
37+
labels = .tile_labels(tile),
38+
update_bbox = FALSE
39+
)
40+
return(tile)
41+
}
2942
# Create chunks as jobs
3043
chunks <- .tile_chunks_create(
3144
tile = tile, overlap = overlap, block = block
@@ -86,8 +99,9 @@
8699
update_bbox = FALSE
87100
)
88101
# Return a asset
89-
band_tile
102+
return(band_tile)
90103
}
104+
91105
#' @title Read data for cleaning operation
92106
#' @name .clean_data_read
93107
#' @author Felipe Carvalho, \email{felipe.carvalho@@inpe.br}
@@ -103,5 +117,5 @@
103117
# Set columns name
104118
colnames(values) <- band
105119
# Return values
106-
values
120+
return(values)
107121
}

R/api_conf.R

+44-29
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176

177177
return(yml_file)
178178
}
179-
#' @title Get color table
179+
#' @title Loads default color table and legends
180180
#' @name .conf_load_color_table
181181
#' @description Loads the default color table
182182
#' @keywords internal
@@ -189,11 +189,12 @@
189189
input = color_yml_file,
190190
merge.precedence = "override"
191191
)
192-
class_schemes <- config_colors$class_schemes
193-
sits_env[["config"]] <- utils::modifyList(sits_env[["config"]],
194-
class_schemes,
195-
keep.null = FALSE
196-
)
192+
# set the legends
193+
sits_env$legends <- config_colors$legends
194+
# sits_env[["config"]] <- utils::modifyList(sits_env[["config"]],
195+
# class_schemes,
196+
# keep.null = FALSE
197+
# )
197198
colors <- config_colors$colors
198199
color_table <- purrr::map2_dfr(colors, names(colors),
199200
function(cl, nm) {
@@ -203,38 +204,39 @@
203204
)
204205
return(cc_tb)
205206
})
207+
206208
# set the color table
207-
.conf_set_color_table(color_table)
209+
sits_env$color_table <- color_table
208210
return(invisible(color_table))
209211
}
210-
#' @title Set user color table
211-
#' @name .conf_set_color_table
212+
#' @title Add user color table
213+
#' @name .conf_add_color_table
212214
#' @description Loads a user color table
213215
#' @keywords internal
214216
#' @noRd
215-
#' @return Called for side effects
216-
.conf_set_color_table <- function(color_tb) {
217+
#' @return new color table (invisible)
218+
.conf_add_color_table <- function(color_tb) {
217219
# pre condition - table contains name and hex code
218220
.check_chr_contains(
219221
x = colnames(color_tb),
220222
contains = .conf("sits_color_table_cols"),
221223
discriminator = "all_of",
222224
msg = "invalid colour table - missing either name or hex columns"
223225
)
224-
# pre condition - table contains no duplicates
225-
tbd <- dplyr::distinct(color_tb, .data[["name"]])
226-
.check_that(nrow(tbd) == nrow(color_tb),
227-
msg = "color table contains duplicate names"
228-
)
229-
sits_env$color_table <- color_tb
230-
return(invisible(color_tb))
226+
# replace all duplicates
227+
new_colors <- dplyr::pull(color_tb, .data[["name"]])
228+
# remove duplicate colors
229+
old_color_tb <- dplyr::filter(sits_env$color_table,
230+
!(.data[["name"]] %in% new_colors))
231+
sits_env$color_table <- dplyr::bind_rows(old_color_tb, color_tb)
232+
return(invisible(sits_env$color_table))
231233
}
232234
#' @title Merge user colors with default colors
233235
#' @name .conf_merge_colors
234236
#' @description Combines user colors with default color table
235237
#' @keywords internal
236238
#' @noRd
237-
#' @return NULL, called for side effects
239+
#' @return new color table
238240
.conf_merge_colors <- function(user_colors) {
239241
# get the current color table
240242
color_table <- .conf_colors()
@@ -253,8 +255,25 @@
253255
)
254256
}
255257
}
256-
.conf_set_color_table(color_table)
257-
return(invisible(color_table))
258+
sits_env$color_table <- color_table
259+
return(color_table)
260+
}
261+
.conf_merge_legends <- function(user_legends){
262+
# check legends are valid names
263+
.check_chr_parameter(names(user_legends), len_max = 100,
264+
msg = "invalid user legends")
265+
# check legend names do not already exist
266+
.check_that(!(all(names(user_legends) %in% names (sits_env$legends))),
267+
msg = "user defined legends already exist in sits")
268+
# check colors names are valid
269+
ok <- purrr::map_lgl(user_legends, function(leg){
270+
.check_chr_parameter(leg, len_max = 100,
271+
msg = "invalid color names in user legend")
272+
return(TRUE)
273+
})
274+
sits_env$legends <- c(sits_env$legends, user_legends)
275+
return(invisible(sits_env$legends))
276+
258277
}
259278
#' @title Return the default color table
260279
#' @name .conf_colors
@@ -343,14 +362,10 @@
343362
.conf_merge_colors(user_colors)
344363
user_config$colors <- NULL
345364
}
346-
if (!purrr::is_null(user_config$class_schemes)) {
347-
class_schemes <- user_config$class_schemes
348-
sits_env[["config"]] <- utils::modifyList(
349-
sits_env[["config"]],
350-
class_schemes,
351-
keep.null = FALSE
352-
)
353-
user_config$class_schemes <- NULL
365+
if (!purrr::is_null(user_config$legends)) {
366+
user_legends <- user_config$legends
367+
.conf_merge_legends(user_legends)
368+
user_config$legends <- NULL
354369
}
355370
if (length(user_config) > 0) {
356371
user_config <- utils::modifyList(sits_env[["config"]],

R/api_cube.R

+42
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,48 @@ NULL
132132
# return the cube
133133
x
134134
}
135+
#' @title Return areas of classes of a class_cue
136+
#' @keywords internal
137+
#' @noRd
138+
#' @name .cube_class_areas
139+
#' @param cube class cube
140+
#'
141+
#' @return A \code{vector} with the areas of the cube labels.
142+
.cube_class_areas <- function(cube) {
143+
.check_cube_is_class_cube(cube)
144+
labels_cube <- sits_labels(cube)
145+
146+
# Get area for each class for each row of the cube
147+
freq_lst <- slider::slide(cube, function(tile) {
148+
# Get the frequency count and value for each labelled image
149+
freq <- .tile_area_freq(tile)
150+
# pixel area
151+
# convert the area to hectares
152+
# assumption: spatial resolution unit is meters
153+
area <- freq$count * .tile_xres(tile) * .tile_yres(tile) / 10000
154+
# Include class names
155+
freq <- dplyr::mutate(freq,
156+
area = area,
157+
class = labels_cube[.as_chr(freq$value)]
158+
)
159+
return(freq)
160+
})
161+
# Get a tibble by binding the row (duplicated labels with different counts)
162+
freq <- do.call(rbind, freq_lst)
163+
# summarize the counts for each label
164+
freq <- freq |>
165+
dplyr::filter(!is.na(class)) |>
166+
dplyr::group_by(class) |>
167+
dplyr::summarise(area = sum(.data[["area"]]))
168+
169+
# Area is taken as the sum of pixels
170+
class_areas <- freq$area
171+
# Names of area are the classes
172+
names(class_areas) <- freq$class
173+
# NAs are set to 0
174+
class_areas[is.na(class_areas)] <- 0
175+
return(class_areas)
176+
}
135177

136178
#' @title Return bands of a data cube
137179
#' @keywords internal

0 commit comments

Comments
 (0)