Skip to content

Commit bc08ae4

Browse files
authored
Merge pull request #1067 from rolfsimoes/dev2
Fix MPC S1 cube, added orbit parameter to `sits_cube()`, Fix ROI XY bug in `sits_regularize()`
2 parents 5bfd721 + 5a96838 commit bc08ae4

9 files changed

+86
-11
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Config/testthat/start-first: cube, raster, regularize, data, ml
106106
LinkingTo:
107107
Rcpp,
108108
RcppArmadillo
109-
RoxygenNote: 7.2.3
109+
RoxygenNote: 7.3.1
110110
Collate:
111111
'api_accessors.R'
112112
'api_accuracy.R'

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ S3method(sits_cluster_dendro,tbl_df)
303303
S3method(sits_combine_predictions,average)
304304
S3method(sits_combine_predictions,default)
305305
S3method(sits_combine_predictions,uncertainty)
306+
S3method(sits_cube,"mpc_cube_sentinel-1-grd")
306307
S3method(sits_cube,default)
307308
S3method(sits_cube,local_cube)
308309
S3method(sits_cube,stac_cube)

R/api_source_mpc.R

+23-7
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@
9797
#' @param source Name of the STAC provider.
9898
#' @param collection Collection to be searched in the data source.
9999
#' @param stac_query Query that follows the STAC protocol
100+
#' @param bands Names of the bands to filter
100101
#' @param ... Other parameters to be passed for specific types.
102+
#' @param orbit Name of the orbit (e.g. "Ascending" or "Descending")
101103
#' @param tiles Selected tiles (optional)
102104
#' @param platform Satellite platform (optional).
103105
#' @return An object referring the images of a sits cube.
@@ -106,33 +108,39 @@
106108
source,
107109
collection,
108110
bands, ...,
111+
orbit = "Descending",
109112
start_date = NULL,
110113
end_date = NULL,
111114
dry_run = TRUE) {
112115

113116
# require package
114117
.check_require_packages("rstac")
118+
orbits <- .conf("sources", source, "collections", collection, "orbits")
119+
.check_chr_within(
120+
x = orbit,
121+
within = orbits,
122+
msg = "Invalid `orbit` parameter"
123+
)
115124

116125
stac_query <- .stac_create_items_query(
117126
source = source,
118127
collection = collection,
119128
roi = list(
120-
"xmin" = -50.379,
121-
"ymin" = -10.1573,
129+
"xmin" = -50.479,
130+
"ymin" = -10.1973,
122131
"xmax" = -50.410,
123-
"ymax" = -10.1910,
132+
"ymax" = -10.1510,
124133
"crs" = "EPSG:4386"
125134
),
126135
start_date = start_date,
127136
end_date = end_date,
128137
limit = 1
129138
)
130-
131139
stac_query <- rstac::ext_filter(
132140
stac_query,
133141
`sar:frequency_band` == "C" &&
134142
`sar:instrument_mode` == "IW" &&
135-
`sat:orbit_state` == "descending"
143+
`sat:orbit_state` == {{orbit}}
136144
)
137145

138146
# assert that service is online
@@ -235,15 +243,23 @@
235243
`.source_items_new.mpc_cube_sentinel-1-grd` <- function(source,
236244
collection,
237245
stac_query, ...,
238-
tiles = NULL) {
246+
tiles = NULL,
247+
orbit = "ascending") {
239248

240249
# set caller to show in errors
241250
.check_set_caller(".source_items_new.mpc_cube_sentinel-1-grd")
251+
orbits <- .conf("sources", source, "collections", collection, "orbits")
252+
.check_chr_within(
253+
x = orbit,
254+
within = orbits,
255+
msg = "Invalid `orbit` parameter"
256+
)
242257

243258
stac_query <- rstac::ext_filter(
244259
stac_query,
245260
`sar:frequency_band` == "C" &&
246-
`sar:instrument_mode` == "IW"
261+
`sar:instrument_mode` == "IW" &&
262+
`sat:orbit_state` == {{orbit}}
247263
)
248264

249265
# mpc does not support %in% operator, so we have to

R/sits_cube.R

+29
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#' in the cube (optional - character vector).
3434
#' Use \code{\link{sits_list_collections}()} to find out
3535
#' the bands available for each collection.
36+
#' @param orbit Orbit name ("ascending", "descending") for SAR cubes.
3637
#' @param vector_band Band for vector cube ("segments", "probs", "class")
3738
#' @param start_date,end_date Initial and final dates to include
3839
#' images from the collection in the cube (optional).
@@ -253,6 +254,7 @@
253254
#' source = "MPC",
254255
#' collection = "SENTINEL-1-GRD",
255256
#' bands = c("VV", "VH"),
257+
#' orbit = "ascending",
256258
#' roi = roi_sar,
257259
#' start_date = "2020-06-01",
258260
#' end_date = "2020-09-28"
@@ -281,6 +283,33 @@ sits_cube <- function(source, collection, ...) {
281283
# Dispatch
282284
UseMethod("sits_cube", source)
283285
}
286+
#' @rdname sits_cube
287+
#'
288+
#' @export
289+
`sits_cube.mpc_cube_sentinel-1-grd` <- function(source,
290+
collection, ...,
291+
orbit = "ascending",
292+
bands = NULL,
293+
tiles = NULL,
294+
roi = NULL,
295+
start_date = NULL,
296+
end_date = NULL,
297+
platform = NULL,
298+
progress = TRUE) {
299+
sits_cube.stac_cube(
300+
source = source,
301+
collection = collection,
302+
bands = bands,
303+
tiles = tiles,
304+
roi = roi,
305+
start_date = start_date,
306+
end_date = end_date,
307+
platform = platform,
308+
progress = progress,
309+
orbit = orbit
310+
)
311+
}
312+
284313
#' @rdname sits_cube
285314
#'
286315
#' @export

R/sits_regularize.R

+12-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,18 @@ sits_regularize.raster_cube <- function(cube,
132132
}
133133
}
134134
if (.has(roi)) {
135-
roi <- .roi_as_sf(roi)
135+
crs <- NULL
136+
if (.roi_type(roi) == "bbox" && !.has(roi[["crs"]])) {
137+
crs <- .crs(cube)
138+
if (length(crs) > 1 && .check_warnings()) {
139+
warning("Multiple CRS found in provided cube.",
140+
"Using the CRS of the first tile to create ROI.",
141+
call. = FALSE,
142+
immediate. = TRUE
143+
)
144+
}
145+
}
146+
roi <- .roi_as_sf(roi, default_crs = crs[[1]])
136147
}
137148
# Display warning message in case STAC cube
138149
if (!.cube_is_local(cube)) {

inst/extdata/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,7 @@ sources:
12501250
band_name : "vh"
12511251
satellite : "SENTINEL-1"
12521252
sensor : "GRD"
1253+
orbits : ["ascending", "descending"]
12531254
platforms :
12541255
SENTINEL-1A: "Sentinel-1A"
12551256
SENTINEL-1B: "Sentinel-1B"

inst/extdata/config_internals.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ default_values :
112112

113113
INT4S : &conf_default_int4s
114114
data_type : "INT4S"
115-
missing_value: -2147483648
115+
missing_value: -2147483647
116116
minimum_value: -2147483647
117117
maximum_value: 2147483647
118118
offset_value : 0

man/sits-package.Rd

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

man/sits_cube.Rd

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

0 commit comments

Comments
 (0)