Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MPC S1 cube, added orbit parameter to sits_cube(), Fix ROI XY bug in sits_regularize() #1067

Merged
merged 4 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Config/testthat/start-first: cube, raster, regularize, data, ml
LinkingTo:
Rcpp,
RcppArmadillo
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Collate:
'api_accessors.R'
'api_accuracy.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ S3method(sits_cluster_dendro,tbl_df)
S3method(sits_combine_predictions,average)
S3method(sits_combine_predictions,default)
S3method(sits_combine_predictions,uncertainty)
S3method(sits_cube,"mpc_cube_sentinel-1-grd")
S3method(sits_cube,default)
S3method(sits_cube,local_cube)
S3method(sits_cube,stac_cube)
Expand Down
30 changes: 23 additions & 7 deletions R/api_source_mpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
#' @param source Name of the STAC provider.
#' @param collection Collection to be searched in the data source.
#' @param stac_query Query that follows the STAC protocol
#' @param bands Names of the bands to filter
#' @param ... Other parameters to be passed for specific types.
#' @param orbit Name of the orbit (e.g. "Ascending" or "Descending")
#' @param tiles Selected tiles (optional)
#' @param platform Satellite platform (optional).
#' @return An object referring the images of a sits cube.
Expand All @@ -106,33 +108,39 @@
source,
collection,
bands, ...,
orbit = "Descending",
start_date = NULL,
end_date = NULL,
dry_run = TRUE) {

# require package
.check_require_packages("rstac")
orbits <- .conf("sources", source, "collections", collection, "orbits")
.check_chr_within(
x = orbit,
within = orbits,
msg = "Invalid `orbit` parameter"
)

stac_query <- .stac_create_items_query(
source = source,
collection = collection,
roi = list(
"xmin" = -50.379,
"ymin" = -10.1573,
"xmin" = -50.479,
"ymin" = -10.1973,
"xmax" = -50.410,
"ymax" = -10.1910,
"ymax" = -10.1510,
"crs" = "EPSG:4386"
),
start_date = start_date,
end_date = end_date,
limit = 1
)

stac_query <- rstac::ext_filter(
stac_query,
`sar:frequency_band` == "C" &&
`sar:instrument_mode` == "IW" &&
`sat:orbit_state` == "descending"
`sat:orbit_state` == {{orbit}}
)

# assert that service is online
Expand Down Expand Up @@ -235,15 +243,23 @@
`.source_items_new.mpc_cube_sentinel-1-grd` <- function(source,
collection,
stac_query, ...,
tiles = NULL) {
tiles = NULL,
orbit = "ascending") {

# set caller to show in errors
.check_set_caller(".source_items_new.mpc_cube_sentinel-1-grd")
orbits <- .conf("sources", source, "collections", collection, "orbits")
.check_chr_within(
x = orbit,
within = orbits,
msg = "Invalid `orbit` parameter"
)

stac_query <- rstac::ext_filter(
stac_query,
`sar:frequency_band` == "C" &&
`sar:instrument_mode` == "IW"
`sar:instrument_mode` == "IW" &&
`sat:orbit_state` == {{orbit}}
)

# mpc does not support %in% operator, so we have to
Expand Down
29 changes: 29 additions & 0 deletions R/sits_cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#' in the cube (optional - character vector).
#' Use \code{\link{sits_list_collections}()} to find out
#' the bands available for each collection.
#' @param orbit Orbit name ("ascending", "descending") for SAR cubes.
#' @param vector_band Band for vector cube ("segments", "probs", "class")
#' @param start_date,end_date Initial and final dates to include
#' images from the collection in the cube (optional).
Expand Down Expand Up @@ -253,6 +254,7 @@
#' source = "MPC",
#' collection = "SENTINEL-1-GRD",
#' bands = c("VV", "VH"),
#' orbit = "ascending",
#' roi = roi_sar,
#' start_date = "2020-06-01",
#' end_date = "2020-09-28"
Expand Down Expand Up @@ -281,6 +283,33 @@ sits_cube <- function(source, collection, ...) {
# Dispatch
UseMethod("sits_cube", source)
}
#' @rdname sits_cube
#'
#' @export
`sits_cube.mpc_cube_sentinel-1-grd` <- function(source,
collection, ...,
orbit = "ascending",
bands = NULL,
tiles = NULL,
roi = NULL,
start_date = NULL,
end_date = NULL,
platform = NULL,
progress = TRUE) {
sits_cube.stac_cube(
source = source,
collection = collection,
bands = bands,
tiles = tiles,
roi = roi,
start_date = start_date,
end_date = end_date,
platform = platform,
progress = progress,
orbit = orbit
)
}

#' @rdname sits_cube
#'
#' @export
Expand Down
13 changes: 12 additions & 1 deletion R/sits_regularize.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,18 @@ sits_regularize.raster_cube <- function(cube,
}
}
if (.has(roi)) {
roi <- .roi_as_sf(roi)
crs <- NULL
if (.roi_type(roi) == "bbox" && !.has(roi[["crs"]])) {
crs <- .crs(cube)
if (length(crs) > 1 && .check_warnings()) {
warning("Multiple CRS found in provided cube.",
"Using the CRS of the first tile to create ROI.",
call. = FALSE,
immediate. = TRUE
)
}
}
roi <- .roi_as_sf(roi, default_crs = crs[[1]])
}
# Display warning message in case STAC cube
if (!.cube_is_local(cube)) {
Expand Down
1 change: 1 addition & 0 deletions inst/extdata/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,7 @@ sources:
band_name : "vh"
satellite : "SENTINEL-1"
sensor : "GRD"
orbits : ["ascending", "descending"]
platforms :
SENTINEL-1A: "Sentinel-1A"
SENTINEL-1B: "Sentinel-1B"
Expand Down
2 changes: 1 addition & 1 deletion inst/extdata/config_internals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ default_values :

INT4S : &conf_default_int4s
data_type : "INT4S"
missing_value: -2147483648
missing_value: -2147483647
minimum_value: -2147483647
maximum_value: 2147483647
offset_value : 0
Expand Down
1 change: 0 additions & 1 deletion man/sits-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions man/sits_cube.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading