Skip to content

Commit 5f12c2e

Browse files
committed
fix conflicts
2 parents 9871b9f + 5188386 commit 5f12c2e

21 files changed

+268
-165
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
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]'),

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ S3method(.band_rename,sits)
1616
S3method(.check_samples,default)
1717
S3method(.check_samples,sits)
1818
S3method(.check_samples,tbl_df)
19+
S3method(.cube_adjust_crs,"mpc_cube_sentinel-1-grd")
20+
S3method(.cube_adjust_crs,default)
1921
S3method(.cube_as_sf,default)
2022
S3method(.cube_as_sf,raster_cube)
2123
S3method(.cube_bands,default)
@@ -304,6 +306,7 @@ S3method(sits_combine_predictions,average)
304306
S3method(sits_combine_predictions,default)
305307
S3method(sits_combine_predictions,uncertainty)
306308
S3method(sits_cube,"mpc_cube_sentinel-1-grd")
309+
S3method(sits_cube,"mpc_cube_sentinel-1-rtc")
307310
S3method(sits_cube,default)
308311
S3method(sits_cube,local_cube)
309312
S3method(sits_cube,stac_cube)

R/api_apply.R

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,21 @@
3939
#' @noRd
4040
#' @author Rolf Simoes, \email{rolf.simoes@@inpe.br}
4141
#'
42-
#' @param feature Subset of a data cube containing the input bands
43-
#' used in the expression
44-
#' @param block Individual block that will be processed
45-
#' @param window_size Size of the neighbourhood (if required)
46-
#' @param normalized A logical indicating if band is scaled
47-
#' @param expr Expression to be applied
48-
#' @param out_band Output band
49-
#' @param in_bands Input bands
50-
#' @param overlap Overlap between tiles (if required)
51-
#' @param output_dir Directory where image will be save
42+
#' @param feature Subset of a data cube containing the input bands
43+
#' used in the expression
44+
#' @param block Individual block that will be processed
45+
#' @param window_size Size of the neighbourhood (if required)
46+
#' @param expr Expression to be applied
47+
#' @param out_band Output band
48+
#' @param in_bands Input bands
49+
#' @param overlap Overlap between tiles (if required)
50+
#' @param normalized Produce normalized band?
51+
#' @param output_dir Directory where image will be save
5252
#'
53-
#' @return A feature compose by a combination of tile and band.
54-
.apply_feature <- function(feature, block, expr, window_size, normalized,
55-
out_band, in_bands, overlap, output_dir) {
53+
#' @return A feature compose by a combination of tile and band.
54+
.apply_feature <- function(feature, block, window_size, expr,
55+
out_band, in_bands, overlap,
56+
normalized, output_dir) {
5657
# Output file
5758
out_file <- .file_eo_name(
5859
tile = feature, band = out_band,
@@ -77,6 +78,14 @@
7778
chunks <- .tile_chunks_create(
7879
tile = feature, overlap = overlap, block = block
7980
)
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+
}
8089
# Process jobs sequentially
8190
block_files <- .jobs_map_sequential(chunks, function(chunk) {
8291
# Get job block
@@ -110,9 +119,6 @@
110119
)
111120
)
112121
# Prepare fractions to be saved
113-
band_conf <- .tile_band_conf(
114-
tile = feature, band = out_band, normalized = normalized
115-
)
116122
offset <- .offset(band_conf)
117123
if (.has(offset) && offset != 0) {
118124
values <- values - offset
@@ -139,6 +145,7 @@
139145
band_tile <- .tile_eo_merge_blocks(
140146
files = out_file,
141147
bands = out_band,
148+
band_conf = band_conf,
142149
base_tile = feature,
143150
block_files = block_files,
144151
multicores = 1,

R/api_cube.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,24 @@ NULL
277277
crs <- .cube_crs(cube)
278278
return(crs)
279279
}
280+
#' @title Adjust crs of a data cube
281+
#' @keywords internal
282+
#' @noRd
283+
#' @name .cube_adjust_crs
284+
#' @param cube data cube
285+
#' @return data cube with adjusted crs
286+
.cube_adjust_crs <- function(cube) {
287+
UseMethod(".cube_adjust_crs", cube)
288+
}
289+
#' @export
290+
`.cube_adjust_crs.mpc_cube_sentinel-1-grd` <- function(cube) {
291+
cube$crs <- NA
292+
return(cube)
293+
}
294+
#' @export
295+
.cube_adjust_crs.default <- function(cube) {
296+
return(cube)
297+
}
280298
#' @title Return the S3 class of the cube
281299
#' @name .cube_s3class
282300
#' @keywords internal

R/api_mixture_model.R

Lines changed: 9 additions & 6 deletions
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,9 +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(
83-
tile = feature, band = out_fracs, normalized = TRUE
84-
)
8584
offset <- .offset(band_conf)
8685
if (!is.null(offset) && offset != 0) {
8786
values <- values - offset
@@ -107,9 +106,13 @@
107106
})
108107
# Merge blocks into a new eo_cube tile feature
109108
fracs_feature <- .tile_eo_merge_blocks(
110-
files = out_files, bands = out_fracs, base_tile = feature,
111-
block_files = block_files, multicores = 1, update_bbox = FALSE,
112-
normalized = TRUE
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
113116
)
114117
# Return a eo_cube tile feature
115118
fracs_feature

R/api_plot_raster.R

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,20 @@
5151
tile = tile,
5252
tmap_options = tmap_options
5353
)
54-
54+
if (!.has(.crs(tile))) {
55+
temp <- tempfile(fileext = ".tif")
56+
.gdal_warp(
57+
file = temp,
58+
base_files = bw_file,
59+
params = list(
60+
"-ts" = list(size[["xsize"]], size[["ysize"]]),
61+
"-multi" = TRUE,
62+
"-q" = TRUE,
63+
"-overwrite" = FALSE
64+
),
65+
quiet = TRUE)
66+
bw_file <- temp
67+
}
5568
# read file
5669
stars_obj <- stars::read_stars(
5770
bw_file,

R/api_reduce.R

Lines changed: 3 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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_source_mpc.R

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
#' @param stac_query Query that follows the STAC protocol
100100
#' @param bands Names of the bands to filter
101101
#' @param ... Other parameters to be passed for specific types.
102-
#' @param orbit Name of the orbit (e.g. "Ascending" or "Descending")
102+
#' @param orbit Name of the orbit (e.g. "ascending" or "descending")
103103
#' @param tiles Selected tiles (optional)
104104
#' @param platform Satellite platform (optional).
105105
#' @return An object referring the images of a sits cube.
@@ -108,7 +108,7 @@
108108
source,
109109
collection,
110110
bands, ...,
111-
orbit = "Descending",
111+
orbit = "descending",
112112
start_date = NULL,
113113
end_date = NULL,
114114
dry_run = TRUE) {
@@ -130,7 +130,7 @@
130130
"ymin" = -10.1973,
131131
"xmax" = -50.410,
132132
"ymax" = -10.1510,
133-
"crs" = "EPSG:4386"
133+
"crs" = "EPSG:4326"
134134
),
135135
start_date = start_date,
136136
end_date = end_date,
@@ -201,6 +201,26 @@
201201
}
202202
return(invisible(NULL))
203203
}
204+
205+
`.source_collection_access_test.mpc_cube_sentinel-1-rtc` <- function(
206+
source,
207+
collection,
208+
bands, ...,
209+
orbit = "descending",
210+
start_date = NULL,
211+
end_date = NULL,
212+
dry_run = TRUE) {
213+
214+
`.source_collection_access_test.mpc_cube_sentinel-1-grd`(
215+
source = source,
216+
collection = collection,
217+
bands = bands, ...,
218+
orbit = orbit,
219+
start_date = start_date,
220+
end_date = end_date,
221+
dry_run = dry_run
222+
)
223+
}
204224
#' @title Get bbox from file info
205225
#' @keywords internal
206226
#' @noRd
@@ -237,6 +257,15 @@
237257
bbox <- c(xmin = xmin, ymin = ymin, xmax = xmax, ymax = ymax)
238258
return(bbox)
239259
}
260+
`.source_tile_get_bbox.mpc_cube_sentinel-1-rtc` <- function(source,
261+
file_info, ...,
262+
collection = NULL) {
263+
`.source_tile_get_bbox.mpc_cube_sentinel-1-grd`(
264+
source = source,
265+
file_info = file_info, ...,
266+
collection = collection
267+
)
268+
}
240269
#' @keywords internal
241270
#' @noRd
242271
#' @export
@@ -304,7 +333,19 @@
304333
)
305334
return(items_info)
306335
}
307-
336+
`.source_items_new.mpc_cube_sentinel-1-rtc` <- function(source,
337+
collection,
338+
stac_query, ...,
339+
tiles = NULL,
340+
orbit = "ascending") {
341+
`.source_items_new.mpc_cube_sentinel-1-grd`(
342+
source = source,
343+
collection = collection,
344+
stac_query = stac_query, ...,
345+
tiles = tiles,
346+
orbit = orbit
347+
)
348+
}
308349
#' @keywords internal
309350
#' @noRd
310351
#' @export
@@ -313,6 +354,15 @@
313354
collection = NULL) {
314355
rep("NoTilingSystem", rstac::items_length(items))
315356
}
357+
`.source_items_tile.mpc_cube_sentinel-1-rtc` <- function(source,
358+
items, ...,
359+
collection = NULL) {
360+
`.source_items_tile.mpc_cube_sentinel-1-grd`(
361+
source = source,
362+
items = items, ...,
363+
collection = collection
364+
)
365+
}
316366

317367
#' @keywords internal
318368
#' @noRd

R/api_tile.R

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -536,29 +536,22 @@ NULL
536536
UseMethod(".tile_band_conf", tile)
537537
}
538538
#' @export
539-
.tile_band_conf.eo_cube <- function(tile, band, ..., normalized = FALSE) {
540-
conf_band <- .conf_eo_band(
539+
.tile_band_conf.eo_cube <- function(tile, band) {
540+
band_conf <- .conf_eo_band(
541541
source = .tile_source(tile), collection = .tile_collection(tile),
542542
band = band[[1]]
543543
)
544-
if (.has(conf_band)) {
545-
return(conf_band)
546-
}
547-
# 1ft attempt => case band is normalized
548-
if (normalized) {
549-
return(.conf("default_values", "eo_cube", "INT2S"))
550-
}
551-
# 2nd attempt => verify raster data type
544+
if (.has(band_conf))
545+
return(band_conf)
546+
552547
if (band %in% .tile_bands(tile)) {
553-
# Get the first tile path
554548
band_path <- .tile_path(tile, band)
555-
# Get the raster data type
556-
data_type <- .raster_datatype(.raster_open_rast(band_path))
557-
return(.conf("default_values", "eo_cube", data_type))
549+
rast <- terra::rast(band_path)
550+
data_type <- terra::datatype(rast)
551+
band_conf <- .conf("default_values", data_type)
552+
return(band_conf)
558553
}
559-
# Otherwise write band in FLT4S
560-
return(.conf("default_values", "eo_cube", "FLT4S"))
561-
554+
return(NULL)
562555
}
563556
#' @export
564557
.tile_band_conf.derived_cube <- function(tile, band, ...) {
@@ -1070,21 +1063,18 @@ NULL
10701063
#' @name .tile_eo_merge_blocks
10711064
#' @keywords internal
10721065
#' @noRd
1073-
#' @param files files to be merged
1074-
#' @param bands bands to be used in the files
1075-
#' @param base_tile reference tile used in the operation
1076-
#' @param block_files files associated with the the blocks
1077-
#' @param multicores multicores for processing
1078-
#' @param update_bbox should bbox be updated?
1079-
#' @param normalized A logical indicating if band is normalized.
1066+
#' @param files Files to be merged
1067+
#' @param bands Bands to be merged
1068+
#' @param band_conf Band confuguration
1069+
#' @param base_tile Reference tile used in the operation
1070+
#' @param block_files Files associated with the the blocks
1071+
#' @param multicores Multicores for processing
1072+
#' @param update_bbox Should bbox be updated?
10801073
#' @return an EO tile with merged blocks
1081-
.tile_eo_merge_blocks <- function(files, bands, base_tile, block_files,
1082-
multicores, update_bbox, normalized = FALSE) {
1074+
.tile_eo_merge_blocks <- function(files, bands, band_conf,
1075+
base_tile, block_files,
1076+
multicores, update_bbox) {
10831077
base_tile <- .tile(base_tile)
1084-
# Get conf band
1085-
band_conf <- .tile_band_conf(
1086-
tile = base_tile, band = bands, normalized = normalized
1087-
)
10881078
# Create a template raster based on the first image of the tile
10891079
.raster_merge_blocks(
10901080
out_files = files,

0 commit comments

Comments
 (0)