Skip to content

Commit 5188386

Browse files
version 1.5.0
1 parent fc825d1 commit 5188386

11 files changed

+57
-38
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: sits
22
Type: Package
3-
Version: 1.4.2-3
3+
Version: 1.5.0
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]'),

R/api_apply.R

+12-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@
4747
#' @param out_band Output band
4848
#' @param in_bands Input bands
4949
#' @param overlap Overlap between tiles (if required)
50+
#' @param normalized Produce normalized band?
5051
#' @param output_dir Directory where image will be save
5152
#'
5253
#' @return A feature compose by a combination of tile and band.
5354
.apply_feature <- function(feature, block, window_size, expr,
54-
out_band, in_bands, overlap, output_dir) {
55+
out_band, in_bands, overlap,
56+
normalized, output_dir) {
5557
# Output file
5658
out_file <- .file_eo_name(
5759
tile = feature, band = out_band,
@@ -76,6 +78,14 @@
7678
chunks <- .tile_chunks_create(
7779
tile = feature, overlap = overlap, block = block
7880
)
81+
# Get band configuration
82+
band_conf <- .tile_band_conf(tile = feature, band = out_band)
83+
if (!.has(band_conf)) {
84+
if (normalized)
85+
band_conf <- .conf("default_values", "INT2S")
86+
else
87+
band_conf <- .conf("default_values", "FLT4S")
88+
}
7989
# Process jobs sequentially
8090
block_files <- .jobs_map_sequential(chunks, function(chunk) {
8191
# Get job block
@@ -109,7 +119,6 @@
109119
)
110120
)
111121
# Prepare fractions to be saved
112-
band_conf <- .tile_band_conf(tile = feature, band = out_band)
113122
offset <- .offset(band_conf)
114123
if (.has(offset) && offset != 0) {
115124
values <- values - offset
@@ -136,6 +145,7 @@
136145
band_tile <- .tile_eo_merge_blocks(
137146
files = out_file,
138147
bands = out_band,
148+
band_conf = band_conf,
139149
base_tile = feature,
140150
block_files = block_files,
141151
multicores = 1,

R/api_conf.R

+1-4
Original file line numberDiff line numberDiff line change
@@ -939,10 +939,7 @@ NULL
939939
band <- .band_eo(band)
940940
# Return a default value if band does not exists in config
941941
if (!.conf_eo_band_exists(source, collection, band)) {
942-
if (band %in% .conf_names("default_values", "eo_cube")) {
943-
return(.conf("default_values", "eo_cube", band))
944-
}
945-
return(.conf("default_values", "eo_cube", "default"))
942+
return(NULL)
946943
}
947944
# Get band config value and return it
948945
.conf("sources", source, "collections", collection, "bands", band)

R/api_mixture_model.R

+9-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
}
5959
# Remove remaining incomplete fractions files
6060
unlink(out_files)
61+
# Get band configuration
62+
band_conf <- .conf("default_values", "INT2S")
6163
# Create chunks as jobs
6264
chunks <- .tile_chunks_create(tile = feature, overlap = 0, block = block)
6365
# Process jobs sequentially
@@ -79,7 +81,6 @@
7981
# Apply the non-negative least squares solver
8082
values <- mixture_fn(values = as.matrix(values))
8183
# Prepare fractions to be saved
82-
band_conf <- .tile_band_conf(tile = feature, band = out_fracs)
8384
offset <- .offset(band_conf)
8485
if (!is.null(offset) && offset != 0) {
8586
values <- values - offset
@@ -105,8 +106,13 @@
105106
})
106107
# Merge blocks into a new eo_cube tile feature
107108
fracs_feature <- .tile_eo_merge_blocks(
108-
files = out_files, bands = out_fracs, base_tile = feature,
109-
block_files = block_files, multicores = 1, update_bbox = FALSE
109+
files = out_files,
110+
bands = out_fracs,
111+
band_conf = band_conf,
112+
base_tile = feature,
113+
block_files = block_files,
114+
multicores = 1,
115+
update_bbox = FALSE
110116
)
111117
# Return a eo_cube tile feature
112118
fracs_feature

R/api_reduce.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
in_bands <- c(in_bands, .band_cloud())
3737
}
3838
tile <- .tile_filter_bands(tile, in_bands)
39+
# Get band configuration
40+
band_conf <- .conf("default_values", "INT2S")
3941
# Process jobs in parallel
4042
block_files <- .jobs_map_parallel_chr(chunks, function(chunk) {
4143
# Get job block
@@ -69,7 +71,6 @@
6971
enclos = .temp_functions()
7072
)
7173
# Prepare fractions to be saved
72-
band_conf <- .tile_band_conf(tile = tile, band = out_band)
7374
offset <- .offset(band_conf)
7475
if (.has(offset) && offset != 0) {
7576
values <- values - offset
@@ -97,6 +98,7 @@
9798
band_tile <- .tile_eo_merge_blocks(
9899
files = out_file,
99100
bands = out_band,
101+
band_conf = band_conf,
100102
base_tile = tile,
101103
block_files = block_files,
102104
multicores = 1,

R/api_smooth.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#' @title Smooth a tile
2-
#' @name .apply_feature
2+
#' @name .smooth_tile
33
#' @keywords internal
44
#' @noRd
55
#' @author Rolf Simoes, \email{rolf.simoes@@inpe.br}

R/api_tile.R

+21-10
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,21 @@ NULL
535535
}
536536
#' @export
537537
.tile_band_conf.eo_cube <- function(tile, band) {
538-
.conf_eo_band(
538+
band_conf <- .conf_eo_band(
539539
source = .tile_source(tile), collection = .tile_collection(tile),
540540
band = band[[1]]
541541
)
542+
if (.has(band_conf))
543+
return(band_conf)
544+
545+
if (band %in% .tile_bands(tile)) {
546+
band_path <- .tile_path(tile, band)
547+
rast <- terra::rast(band_path)
548+
data_type <- terra::datatype(rast)
549+
band_conf <- .conf("default_values", data_type)
550+
return(band_conf)
551+
}
552+
return(NULL)
542553
}
543554
#' @export
544555
.tile_band_conf.derived_cube <- function(tile, band) {
@@ -1050,18 +1061,18 @@ NULL
10501061
#' @name .tile_eo_merge_blocks
10511062
#' @keywords internal
10521063
#' @noRd
1053-
#' @param files files to be merged
1054-
#' @param bands bands to be used in the files
1055-
#' @param base_tile reference tile used in the operation
1056-
#' @param block_files files associated with the the blocks
1057-
#' @param multicores multicores for processing
1058-
#' @param update_bbox should bbox be updated?
1064+
#' @param files Files to be merged
1065+
#' @param bands Bands to be merged
1066+
#' @param band_conf Band confuguration
1067+
#' @param base_tile Reference tile used in the operation
1068+
#' @param block_files Files associated with the the blocks
1069+
#' @param multicores Multicores for processing
1070+
#' @param update_bbox Should bbox be updated?
10591071
#' @return an EO tile with merged blocks
1060-
.tile_eo_merge_blocks <- function(files, bands, base_tile, block_files,
1072+
.tile_eo_merge_blocks <- function(files, bands, band_conf,
1073+
base_tile, block_files,
10611074
multicores, update_bbox) {
10621075
base_tile <- .tile(base_tile)
1063-
# Get conf band
1064-
band_conf <- .tile_band_conf(tile = base_tile, band = bands)
10651076
# Create a template raster based on the first image of the tile
10661077
.raster_merge_blocks(
10671078
out_files = files,

R/sits_apply.R

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#' @param memsize Memory available for classification (in GB).
2121
#' @param multicores Number of cores to be used for classification.
2222
#' @param output_dir Directory where files will be saved.
23+
#' @param normalized Produce normalized band?
2324
#' @param progress Show progress bar?
2425
#' @param ... Named expressions to be evaluated (see details).
2526
#'
@@ -116,6 +117,7 @@ sits_apply.raster_cube <- function(data, ...,
116117
window_size = 3L,
117118
memsize = 4L,
118119
multicores = 2L,
120+
normalized = TRUE,
119121
output_dir,
120122
progress = FALSE) {
121123
# Check cube
@@ -182,6 +184,7 @@ sits_apply.raster_cube <- function(data, ...,
182184
out_band = out_band,
183185
in_bands = in_bands,
184186
overlap = overlap,
187+
normalized = normalized,
185188
output_dir = output_dir
186189
)
187190
return(output_feature)

inst/extdata/config_internals.yml

-14
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,6 @@ default_values :
126126
offset_value : 0
127127
scale_factor : 1
128128

129-
NDVI :
130-
<<: *conf_default_int2s
131-
132-
EVI :
133-
<<: *conf_default_int2s
134-
135-
eo_cube :
136-
data_type : "INT2S"
137-
missing_value: -32768
138-
minimum_value: -10000
139-
maximum_value: 10000
140-
offset_value : 0
141-
scale_factor : 0.0001
142-
143129
# Derived cube definitions
144130
derived_cube :
145131
probs_cube :

man/sits_apply.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-apply.R

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test_that("EVI generation", {
4444

4545
gc_cube_new <- sits_apply(gc_cube,
4646
EVI2 = 2.5 * (B8A - B05) / (B8A + 2.4 * B05 + 1),
47-
multicores = 2,
47+
multicores = 1,
4848
output_dir = dir_images
4949
)
5050

@@ -100,7 +100,8 @@ test_that("EVI generation", {
100100
csv_file <- paste0(tempdir(), "/csv_gc_cube.csv")
101101
write.csv(csv_tb, file = csv_file)
102102

103-
evi_tibble <- sits_get_data(gc_cube_new, csv_file, progress = FALSE)
103+
evi_tibble <- sits_get_data(gc_cube_new, csv_file, multicores = 1,
104+
progress = FALSE)
104105
evi_tibble_2 <- sits_apply(
105106
evi_tibble,
106107
EVI2_NEW = 2.5 * (B8A - B05) / (B8A + 2.4 * B05 + 1)

0 commit comments

Comments
 (0)