Skip to content

Commit 5bb3c68

Browse files
Merge branch 'dev' into feat/appy_prop
2 parents ca94dba + bc08ae4 commit 5bb3c68

10 files changed

+141
-49
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_accuracy.R

+18
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@
4848
.check_set_caller(".sits_accuracy_area_assess")
4949
# check if cube has the right type
5050
.check_cube_is_class_cube(cube)
51+
# In the case where some classes are not in the classified cube, but
52+
# are in the validation file
53+
diff_classes <- setdiff(rownames(error_matrix), names(area))
54+
if (length(diff_classes) > 0 &&
55+
length(diff_classes) < length(rownames(error_matrix))) {
56+
warning(
57+
paste("The classified cube does not have all the classes in the",
58+
"validation file."),
59+
call. = FALSE
60+
)
61+
# Create a numeric vector with zeros
62+
vec_areas <- rep(0, length(diff_classes))
63+
names(vec_areas) <- diff_classes
64+
# Join with all area classes
65+
area <- c(area, vec_areas)
66+
area <- area[sort(names(area))]
67+
68+
}
5169
# check error matrix
5270
.check_error_matrix_area(error_matrix, area)
5371

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

+38-39
Original file line numberDiff line numberDiff line change
@@ -101,45 +101,44 @@ probs_cube_class : ["probs_cube", "raster_cube", "sits_cube", "tbl_df",
101101
"tbl", "data.frame"]
102102

103103
# Default values for non-registered bands
104-
default_values :
105-
eo_cube :
106-
NDVI : &ndvi_int2s_eo
107-
data_type : "INT2S"
108-
missing_value: -32767
109-
minimum_value: -10000
110-
maximum_value: 10000
111-
offset_value : 0
112-
scale_factor : 0.0001
113-
NDNI : &ndni_int2s_eo
114-
data_type : "INT2S"
115-
missing_value: -32767
116-
minimum_value: 0
117-
maximum_value: 10000
118-
offset_value : 0
119-
scale_factor : 0.0001
120-
EVI :
121-
<<: *ndvi_int2s_eo
122-
NDWI :
123-
<<: *ndvi_int2s_eo
124-
GNDVI :
125-
<<: *ndvi_int2s_eo
126-
NBR :
127-
<<: *ndvi_int2s_eo
128-
NDSI :
129-
<<: *ndvi_int2s_eo
130-
NDRE :
131-
<<: *ndvi_int2s_eo
132-
SAVI :
133-
<<: *ndvi_int2s_eo
134-
MSAVI2 :
135-
<<: *ndvi_int2s_eo
136-
default :
137-
data_type : "FLT4S"
138-
missing_value: -3.402823466385288e+38
139-
minimum_value: -3.402823466385288e+38
140-
maximum_value: 1.7014118346015974e+38
141-
offset_value : 0
142-
scale_factor : 1
104+
default_values :
105+
INT2S : &conf_default_int2s
106+
data_type : "INT2S"
107+
missing_value: -32768
108+
minimum_value: -10000
109+
maximum_value: 10000
110+
offset_value : 0
111+
scale_factor : 0.0001
112+
113+
INT4S : &conf_default_int4s
114+
data_type : "INT4S"
115+
missing_value: -2147483647
116+
minimum_value: -2147483647
117+
maximum_value: 2147483647
118+
offset_value : 0
119+
scale_factor : 0.0001
120+
121+
FLT4S :
122+
data_type : "INT4S"
123+
missing_value: -Inf
124+
minimum_value: -Inf
125+
maximum_value: Inf
126+
offset_value : 0
127+
scale_factor : 1
128+
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
143142

144143
# Derived cube definitions
145144
derived_cube :

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)