Skip to content

Commit

Permalink
adjust CRS for Sentinel-1-RTC data cubes
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertocamara committed Mar 24, 2024
1 parent 2e46779 commit d76c69f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 49 deletions.
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ S3method(.check_samples,default)
S3method(.check_samples,sits)
S3method(.check_samples,tbl_df)
S3method(.cube_adjust_crs,"mpc_cube_sentinel-1-grd")
S3method(.cube_adjust_crs,"mpc_cube_sentinel-1-rtc")
S3method(.cube_adjust_crs,default)
S3method(.cube_as_sf,default)
S3method(.cube_as_sf,raster_cube)
Expand Down Expand Up @@ -292,7 +291,6 @@ S3method(sits_bands,raster_cube)
S3method(sits_bands,sits)
S3method(sits_bands,sits_model)
S3method(sits_bbox,"mpc_cube_sentinel-1-grd")
S3method(sits_bbox,"mpc_cube_sentinel-1-rtc")
S3method(sits_bbox,default)
S3method(sits_bbox,raster_cube)
S3method(sits_bbox,sits)
Expand Down
4 changes: 0 additions & 4 deletions R/api_cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,6 @@ NULL
return(cube)
}
#' @export
`.cube_adjust_crs.mpc_cube_sentinel-1-rtc` <- function(cube) {
`.cube_adjust_crs.mpc_cube_sentinel-1-grd`(cube)
}
#' @export
.cube_adjust_crs.default <- function(cube) {
return(cube)
}
Expand Down
6 changes: 0 additions & 6 deletions R/sits_bbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ sits_bbox.raster_cube <- function(data, crs = "EPSG:4326", as_crs = NULL) {
}
#' @rdname sits_bbox
#' @export
`sits_bbox.mpc_cube_sentinel-1-rtc` <- function(data, crs = "EPSG:4326",
as_crs = NULL) {
`sits_bbox.mpc_cube_sentinel-1-grd`(data, crs = crs, as_crs = as_crs)
}
#' @rdname sits_bbox
#' @export
sits_bbox.tbl_df <- function(data, crs = "EPSG:4326", as_crs = NULL) {
data <- tibble::as_tibble(data)
if (all(.conf("sits_cube_cols") %in% colnames(data))) {
Expand Down
3 changes: 0 additions & 3 deletions man/sits_bbox.Rd

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

71 changes: 37 additions & 34 deletions tests/testthat/test-cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ test_that("Creating cubes from BDC - SENTINEL-2 - tile", {
cube_nrows <- .tile_nrows(bdc_s2_cube_t)
expect_true(.raster_nrows(r_obj) == cube_nrows)
})
test_that("Creating cubes from DEA", {
test_that("Creating S2 cubes from DEA using ROI", {
# try to create a DEA cube
dea_cube <- .try(
{
Expand Down Expand Up @@ -464,7 +464,7 @@ test_that("Creating cubes from DEA", {
expect_equal(dea_cube$xmax[[1]], .raster_xmax(r), tolerance = 1)
expect_equal(dea_cube$xmin[[1]], .raster_xmin(r), tolerance = 1)
})
test_that("Creating cubes from DEA - using tiles", {
test_that("Creating S2 cubes from DEA - using tiles", {
dea_cube <- .try(
{
sits_cube(
Expand All @@ -489,7 +489,7 @@ test_that("Creating cubes from DEA - using tiles", {
expect_true(all(dea_cube$tile %in% c("37MDT","37MET")))

})
test_that("Creating Sentinel cubes from MPC", {
test_that("Creating S2 cubes from MPC using tiles", {
mpc_token <- Sys.getenv("MPC_TOKEN")
Sys.setenv("MPC_TOKEN" = "")
s2_cube <- .try(
Expand Down Expand Up @@ -538,7 +538,7 @@ test_that("Creating Sentinel cubes from MPC", {
n_images_2 <- nrow(s2_cube_s2a$file_info[[1]])
expect_true(n_images_2 < n_images_1)
})
test_that("Creating Sentinel cubes from MPC with ROI", {
test_that("Creating S2 cubes from MPC with ROI", {
roi <- c(
lon_min = -48.28579, lat_min = -16.05026,
lon_max = -47.30839, lat_max = -15.50026
Expand Down Expand Up @@ -568,36 +568,6 @@ test_that("Creating Sentinel cubes from MPC with ROI", {
cube_nrows <- .tile_nrows(s2_cube_mpc)
expect_true(.raster_nrows(r_obj) == cube_nrows)
})
test_that("Creating Sentinel-1 RTC cubes from MPC", {
cube_s1_rtc <- sits_cube(
source = "MPC",
collection = "SENTINEL-1-RTC",
bands = c("VV", "VH"),
orbit = "descending",
tiles = c("24MUS", "24MVS"),
start_date = "2021-03-01",
end_date = "2021-09-30"
)
bbox <- sits_bbox(cube_s1_rtc)
expect_equal("EPSG:4326", bbox[["crs"]])
expect_equal(381340, bbox[["xmin"]])
expect_equal(701860, bbox[["xmax"]])

# output_dir <- paste0(tempdir(), "/s1rtc2")
# if (!dir.exists(output_dir)) {
# dir.create(output_dir)
# }
#
# cube_s1_20LKP_rtc <- sits_regularize(
# cube = cube_s1_rtc,
# period = "P12D",
# res = 120,
# roi = roi,
# multicores = 4,
# output_dir = output_dir,
# progress = TRUE
# )
})
test_that("Creating Sentinel-1 GRD cubes from MPC using tiles", {

cube_s1_grd <- sits_cube(
Expand Down Expand Up @@ -636,6 +606,39 @@ test_that("Creating Sentinel-1 GRD cubes from MPC using tiles", {
progress = TRUE
)
})
test_that("Creating S1 RTC cubes from MPC", {
cube_s1_rtc <- sits_cube(
source = "MPC",
collection = "SENTINEL-1-RTC",
bands = c("VV", "VH"),
orbit = "descending",
tiles = c("24MUS", "24MVS"),
start_date = "2021-03-01",
end_date = "2021-09-30"
)
bbox <- sits_bbox(cube_s1_rtc)
expect_true(grepl("32724", bbox[["crs"]]))
expect_equal(20600, bbox[["xmin"]])
expect_equal(749090, bbox[["xmax"]])
expect_equal(nrow(cube_s1_rtc$file_info[[1]]), 136)
expect_true(all)

output_dir <- paste0(tempdir(), "/s1rtc2")
if (!dir.exists(output_dir)) {
dir.create(output_dir)
}

cube_s1_20LKP_rtc <- sits_regularize(
cube = cube_s1_rtc,
period = "P12D",
res = 120,
roi = roi,
multicores = 4,
output_dir = output_dir,
progress = TRUE
)
})

test_that("Creating LANDSAT cubes from MPC with ROI", {
roi <- c(
lon_min = -48.28579, lat_min = -16.05026,
Expand Down

0 comments on commit d76c69f

Please sign in to comment.