diff --git a/NAMESPACE b/NAMESPACE index 926001c04..2acc3aa1c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -132,6 +132,7 @@ S3method(.source_collection_access_test,stac_cube) S3method(.source_collection_access_test,usgs_cube) S3method(.source_cube,stac_cube) S3method(.source_filter_tiles,"cdse_cube_sentinel-1-rtc") +S3method(.source_filter_tiles,"deafrica_cube_sentinel-1-rtc") S3method(.source_filter_tiles,"mpc_cube_sentinel-1-grd") S3method(.source_filter_tiles,stac_cube) S3method(.source_item_get_bands,stac_cube) @@ -150,6 +151,8 @@ S3method(.source_items_bands_select,stac_cube) S3method(.source_items_cube,stac_cube) S3method(.source_items_fid,stac_cube) S3method(.source_items_new,"aws_cube_landsat-c2-l2") +S3method(.source_items_new,"deafrica_cube_sentinel-1-rtc") +S3method(.source_items_new,"deafrica_cube_sentinel-2-l2a") S3method(.source_items_new,"mpc_cube_landsat-c2-l2") S3method(.source_items_new,"mpc_cube_sentinel-1-grd") S3method(.source_items_new,"mpc_cube_sentinel-1-rtc") @@ -158,12 +161,13 @@ S3method(.source_items_new,aws_cube) S3method(.source_items_new,bdc_cube) S3method(.source_items_new,cdse_cube) S3method(.source_items_new,deafrica_cube) -S3method(.source_items_new,deafrica_cube_s2_l2a) S3method(.source_items_new,hls_cube) S3method(.source_items_new,sdc_cube) S3method(.source_items_new,usgs_cube) S3method(.source_items_tile,"aws_cube_landsat-c2-l2") S3method(.source_items_tile,"cdse_cube_sentinel-1-rtc") +S3method(.source_items_tile,"deafrica_cube_rainfall-chirps-daily") +S3method(.source_items_tile,"deafrica_cube_rainfall-chirps-monthly") S3method(.source_items_tile,"mpc_cube_landsat-c2-l2") S3method(.source_items_tile,"mpc_cube_sentinel-1-grd") S3method(.source_items_tile,"mpc_cube_sentinel-1-rtc") @@ -172,8 +176,6 @@ S3method(.source_items_tile,aws_cube) S3method(.source_items_tile,bdc_cube) S3method(.source_items_tile,cdse_cube) S3method(.source_items_tile,deafrica_cube) -S3method(.source_items_tile,deafrica_cube_rainfall_chirps_daily) -S3method(.source_items_tile,deafrica_cube_rainfall_chirps_monthly) S3method(.source_items_tile,hls_cube) S3method(.source_items_tile,sdc_cube) S3method(.source_items_tile,usgs_cube) diff --git a/R/api_opensearch.R b/R/api_opensearch.R index 7f9a0f5b4..a76c38720 100644 --- a/R/api_opensearch.R +++ b/R/api_opensearch.R @@ -144,6 +144,7 @@ .opensearch_as_stac_items(features_result) } +# ---- open search specializations ---- #' @title Extract `tile` from Open Search Items. #' @keywords internal #' @noRd @@ -210,14 +211,15 @@ #' @keywords internal #' @noRd -.opensearch_cdse_search.S2MSI2A <- function(product_type, ..., - source, - collection, - start_date, - end_date, +.opensearch_cdse_search.S2MSI2A <- function(product_type, + source, collection, + start_date, end_date, bbox, + platform = NULL, paginate = TRUE, - limit = 1000) { + limit = 1000, ...) { + .check_set_caller(".opensearch_cdse_search_s2msi2a") + # Search! .opensearch_cdse_client( product_type, source, @@ -227,25 +229,26 @@ bbox, paginate, limit, - status = "ONLINE" + status = "ONLINE", + instrument = "MSI", + platform = platform, + processingLevel = "S2MSI2A" ) } #' @keywords internal #' @noRd -.opensearch_cdse_search.RTC <- function(product_type, ..., - source, - collection, - start_date, - end_date, +.opensearch_cdse_search.RTC <- function(product_type, + source, collection, + start_date, end_date, bbox, - paginate = TRUE, - limit = 1000, - orbit = "descending") { + platform = NULL, + orbit = NULL, + paginate = TRUE, limit = 1000, ...) { .check_set_caller(".opensearch_cdse_search_rtc") - # Checks - Orbit + # check orbit orbits <- .conf("sources", source, "collections", collection, "orbits") - .check_chr_within(orbit, orbits) + .check_chr_within(x = orbit, within = orbits) # Search! .opensearch_cdse_client( product_type, @@ -257,6 +260,9 @@ paginate, limit, status = "ONLINE", + sensorMode = "IW", + instrument = "C-SAR", + platform = platform, orbitDirection = stringr::str_to_upper(orbit) ) } diff --git a/R/api_source_cdse.R b/R/api_source_cdse.R index cfc461783..b8e6bc510 100644 --- a/R/api_source_cdse.R +++ b/R/api_source_cdse.R @@ -1,5 +1,4 @@ - -# ---- general utilities ---- +# ---- general cdse utilities ---- #' @title Extract item type of a given `collection`. #' @keywords internal #' @noRd @@ -23,10 +22,6 @@ item_type } - - - - #' @title Fix STAC Items from CDSE with assets metadata. #' @keywords internal #' @noRd @@ -114,11 +109,12 @@ #' @param dry_run TRUE/FALSE. #' @return Called for side effects #' @export -.source_collection_access_test.cdse_cube <- function(source, collection, +.source_collection_access_test.cdse_cube <- function(source, + collection, bands, ..., start_date = NULL, end_date = NULL, - dry_run = FALSE) { + dry_run = TRUE) { # check if `aws.s3` is installed .check_require_packages("aws.s3") # as CDSE STAC returns many types of items in the same collection, @@ -142,7 +138,8 @@ end_date = end_date, bbox = NULL, paginate = FALSE, - limit = 1 + limit = 1, + ... ) }, .default = NULL) # Check items @@ -189,13 +186,21 @@ .source_items_new.cdse_cube <- function(source, ..., collection, stac_query, - tiles = NULL, - orbit = "descending", - multicores = 2L) { + tiles, + multicores, + platform) { # set caller to show in errors .check_set_caller(".source_items_new_cdse_cube") - # check parameters + # check multicores .check_int_parameter(multicores, min = 1, max = 2048) + # check platform (filter available for CDSE collections supported by sits) + if (!is.null(platform)) { + platform <- .stac_format_platform( + source = source, + collection = collection, + platform = platform + ) + } # define the maximum number of records per request cdse_query_limit <- 1000 # as CDSE STAC returns many types of items in the same collection, @@ -236,7 +241,8 @@ end_date = query_date$end_date, bbox = query_bbox$bbox, limit = cdse_query_limit, - orbit = orbit + platform = platform, + ... ) # Validate results .check_length(items[["features"]], len_min = 1) diff --git a/R/api_source_deafrica.R b/R/api_source_deafrica.R index 235a4159a..03570452e 100644 --- a/R/api_source_deafrica.R +++ b/R/api_source_deafrica.R @@ -1,3 +1,4 @@ +# ---- source api ---- #' @title Create an items object in an DEAfrica cube #' @keywords internal #' @noRd @@ -17,14 +18,10 @@ stac_query, tiles = NULL, platform = NULL) { - # Convert roi to bbox - lon <- stac_query[["params"]][["intersects"]][["coordinates"]][, , 1] - lat <- stac_query[["params"]][["intersects"]][["coordinates"]][, , 2] + roi <- .stac_intersects_as_bbox(stac_query) stac_query[["params"]][["intersects"]] <- NULL - stac_query[["params"]][["bbox"]] <- - c(min(lon), min(lat), max(lon), max(lat)) - + stac_query[["params"]][["bbox"]] <- roi$bbox # making the request items_info <- rstac::post_request(q = stac_query, ...) .check_stac_items(items_info) @@ -55,48 +52,119 @@ #' @param platform Satellite platform (optional). #' @return An object referring the images of a sits cube. #' @export -.source_items_new.deafrica_cube_s2_l2a <- function(source, ..., - collection, - stac_query, - tiles = NULL, - platform = NULL) { +`.source_items_new.deafrica_cube_sentinel-2-l2a` <- function(source, ..., + collection, + stac_query, + tiles = NULL, + platform = NULL) { # set caller to show in errors .check_set_caller(".source_items_new") - + # check platform + if (!is.null(platform)) { + platform <- .stac_format_platform( + source = source, + collection = collection, + platform = platform + ) + } + # check spatial extensions if (!is.null(tiles)) { roi <- .s2_mgrs_to_roi(tiles) stac_query[["params"]][["intersects"]] <- NULL stac_query[["params"]][["bbox"]] <- c(roi[["lon_min"]], roi[["lat_min"]], roi[["lon_max"]], - roi[["lat_max"]] - ) + roi[["lat_max"]]) } else { - # Convert roi to bbox - lon <- stac_query[["params"]][["intersects"]][["coordinates"]][, , 1] - lat <- stac_query[["params"]][["intersects"]][["coordinates"]][, , 2] + roi <- .stac_intersects_as_bbox(stac_query) stac_query[["params"]][["intersects"]] <- NULL - stac_query[["params"]][["bbox"]] <- c(min(lon), - min(lat), - max(lon), - max(lat) - ) + stac_query[["params"]][["bbox"]] <- roi$bbox } - # making the request + # make request items_info <- rstac::post_request(q = stac_query, ...) + items_info <- rstac::items_fetch(items = items_info, progress = FALSE) + # filter items + items_info <- rstac::items_filter(items_info, + filter_fn = function(feature) { + lgl_res <- TRUE + + if (!is.null(platform)) { + lgl_res <- feature[["properties"]][["platform"]] == platform + } + + lgl_res + }) + # check results .check_stac_items(items_info) - # if more than 2 times items pagination are found the progress bar - # is displayed - progress <- rstac::items_matched(items_info) > - 2 * .conf("rstac_pagination_limit") - # check documentation mode - progress <- .check_documentation(progress) + # done + items_info +} +#' @keywords internal +#' @noRd +#' @export +`.source_items_new.deafrica_cube_sentinel-1-rtc` <- function( + source, ..., + collection, + stac_query, + tiles = NULL, + platform = NULL, + orbit = NULL) { + # set caller to show in errors + .check_set_caller(".source_items_new") + # check orbits + orbits <- .conf("sources", source, "collections", collection, "orbits") + .check_chr_within(orbit, orbits) + # check platform + if (!is.null(platform)) { + platform <- .stac_format_platform( + source = source, + collection = collection, + platform = platform + ) + } + # check spatial extensions + if (!is.null(tiles)) { + roi <- .s2_mgrs_to_roi(tiles) + stac_query[["params"]][["intersects"]] <- NULL + stac_query[["params"]][["bbox"]] <- c(roi[["lon_min"]], + roi[["lat_min"]], + roi[["lon_max"]], + roi[["lat_max"]]) + } else { + roi <- .stac_intersects_as_bbox(stac_query) + stac_query[["params"]][["intersects"]] <- NULL + stac_query[["params"]][["bbox"]] <- roi$bbox + } + # make request + items_info <- rstac::post_request(q = stac_query, ...) + items_info <- rstac::items_fetch(items = items_info, progress = FALSE) + # filter items + items_info <- rstac::items_filter(items_info, + filter_fn = function(feature) { + lgl_res <- feature[["properties"]][["sat:orbit_state"]] == orbit && + feature[["properties"]][["sar:instrument_mode"]] == "IW" && + feature[["properties"]][["sar:frequency_band"]] == "C" - # fetching all the metadata and updating to upper case instruments - items_info <- rstac::items_fetch(items = items_info, progress = progress) - # checks if the items returned any items + if (!is.null(platform)) { + lgl_res <- lgl_res && + feature[["properties"]][["platform"]] == platform + } + + lgl_res + }) + # check results .check_stac_items(items_info) - return(items_info) + # done + items_info +} +#' @keywords internal +#' @noRd +#' @export +`.source_filter_tiles.deafrica_cube_sentinel-1-rtc` <- function(source, + collection, + cube, + tiles) { + return(cube) } #' @keywords internal #' @noRd @@ -128,14 +196,14 @@ #' @keywords internal #' @noRd #' @export -`.source_items_tile.deafrica_cube_rainfall_chirps_daily` <- +`.source_items_tile.deafrica_cube_rainfall-chirps-daily` <- function(source, items, ..., collection = NULL) { rep("NoTilingSystem", rstac::items_length(items)) } #' @keywords internal #' @noRd #' @export -`.source_items_tile.deafrica_cube_rainfall_chirps_monthly` <- +`.source_items_tile.deafrica_cube_rainfall-chirps-monthly` <- function(source, items, ..., collection = NULL) { rep("NoTilingSystem", rstac::items_length(items)) } diff --git a/R/api_source_stac.R b/R/api_source_stac.R index 19569e4ed..32fe7e5cb 100644 --- a/R/api_source_stac.R +++ b/R/api_source_stac.R @@ -110,14 +110,16 @@ collection = collection, stac_query = items_query, tiles = tiles, - platform = platform, ... + platform = platform, + multicores = multicores, ... ) # filter bands in items items <- .source_items_bands_select( source = source, items = items, bands = bands, - collection = collection, ... + collection = collection, + multicores = multicores, ... ) # make a cube cube <- .source_items_cube( diff --git a/R/api_stac.R b/R/api_stac.R index befedbbad..0e16a0f97 100644 --- a/R/api_stac.R +++ b/R/api_stac.R @@ -183,7 +183,6 @@ result[["bbox"]] <- c(min_x, min_y, max_x, max_y) result } -# ---- stac utilities ---- #' @title Extract datetime from a STAC Query. #' @keywords internal #' @noRd diff --git a/R/sits_cube.R b/R/sits_cube.R index bb93cf1ae..f3ea767b5 100755 --- a/R/sits_cube.R +++ b/R/sits_cube.R @@ -203,7 +203,7 @@ #' # DEAFRICA does not support definition of tiles #' cube_dea <- sits_cube( #' source = "DEAFRICA", -#' collection = "S2_L2A", +#' collection = "SENTINEL-2-L2A", #' bands = c("B04", "B08"), #' roi = c( #' "lat_min" = 17.379, diff --git a/inst/extdata/sources/config_source_cdse.yml b/inst/extdata/sources/config_source_cdse.yml index 9184dc35a..b3f6af754 100644 --- a/inst/extdata/sources/config_source_cdse.yml +++ b/inst/extdata/sources/config_source_cdse.yml @@ -28,8 +28,8 @@ sources: sensor : "RTC" orbits : ["ascending", "descending"] platforms : - SENTINEL-1A: "Sentinel-1A" - SENTINEL-1B: "Sentinel-1B" + SENTINEL-1A: "S1A" + SENTINEL-1B: "S1B" collection_name: "SENTINEL-1-RTC" sar_cube: true open_data: true @@ -129,8 +129,8 @@ sources: satellite : "SENTINEL-2" sensor : "MSI" platforms : - SENTINEL-2A: "Sentinel-2A" - SENTINEL-2B: "Sentinel-2B" + SENTINEL-2A: "S2A" + SENTINEL-2B: "S2B" access_vars: AWS_S3_ENDPOINT : "eodata.dataspace.copernicus.eu" AWS_VIRTUAL_HOSTING : "FALSE" diff --git a/inst/extdata/sources/config_source_deafrica.yml b/inst/extdata/sources/config_source_deafrica.yml index e31305209..32e2597af 100644 --- a/inst/extdata/sources/config_source_deafrica.yml +++ b/inst/extdata/sources/config_source_deafrica.yml @@ -8,7 +8,7 @@ sources: service : "STAC" url : "https://explorer.digitalearth.africa/stac/" collections : - ALOS_PALSAR_MOSAIC : + ALOS-PALSAR-MOSAIC : bands : HH : &deafrica_alos_25m missing_value : 0 @@ -41,13 +41,14 @@ sources: AWS_S3_ENDPOINT: "s3.af-south-1.amazonaws.com" AWS_NO_SIGN_REQUEST: true collection_name: "alos_palsar_mosaic" + sar_cube : true open_data: true open_data_token: false metadata_search: "feature" ext_tolerance: 0 grid_system : "" - DEM_COP_30: + DEM-COP-30 : bands: ELEVATION: band_name : "elevation" @@ -72,7 +73,7 @@ sources: ext_tolerance : 0 grid_system : "" - LS5_SR : + LS5-SR : bands : B01 : &deafrica_ls5_30m band_name : "SR_B1" @@ -134,7 +135,7 @@ sources: metadata_search : "tile" ext_tolerance : 0 grid_system : "WRS-2" - LS7_SR : + LS7-SR : bands : B01 : &deafrica_ls7_30m band_name : "SR_B1" @@ -196,7 +197,7 @@ sources: metadata_search : "tile" ext_tolerance : 0 grid_system : "WRS-2" - LS8_SR : &deafrica_l8 + LS8-SR : &deafrica_l8 bands : B01 : &deafrica_oli_30m missing_value : 0 @@ -257,7 +258,7 @@ sources: metadata_search : "tile" ext_tolerance: 0 grid_system : "WRS-2" - LS9_SR : + LS9-SR : bands: B01: &deafrica_ls9_30m band_name : "SR_B1" @@ -323,7 +324,7 @@ sources: ext_tolerance : 0 grid_system : "WRS-2" - NDVI_ANOMALY : + NDVI-ANOMALY : bands : NDVI-MEAN : &deafrica_ndvi_anomaly_30m band_name : "ndvi_mean" @@ -350,7 +351,7 @@ sources: metadata_search : "tile" ext_tolerance : 0 grid_system : "" - RAINFALL_CHIRPS_DAILY : + RAINFALL-CHIRPS-DAILY : bands: RAINFALL: band_name : "rainfall" @@ -374,7 +375,7 @@ sources: metadata_search : "feature" ext_tolerance : 0 grid_system : "" - RAINFALL_CHIRPS_MONTHLY : + RAINFALL-CHIRPS-MONTHLY : bands: RAINFALL: band_name : "rainfall" @@ -399,7 +400,38 @@ sources: ext_tolerance : 0 grid_system : "" - S2_L2A : + SENTINEL-1-RTC : + bands : + VV : &deafrica_rtc_20m + missing_value : -32768.0 + minimum_value : 0 + maximum_value : 65534 + scale_factor : 1 + offset_value : 0 + resolution : 20 + band_name : "VV" + data_type : "FLT4S" + VH : + <<: *deafrica_rtc_20m + band_name : "VH" + satellite : "SENTINEL-1" + sensor : "RTC" + platforms : + SENTINEL-1A: "sentinel-1a" + SENTINEL-1B: "sentinel-1b" + orbits : ["ascending", "descending"] + access_vars : + AWS_DEFAULT_REGION : "af-south-1" + AWS_S3_ENDPOINT : "s3.af-south-1.amazonaws.com" + AWS_NO_SIGN_REQUEST : true + collection_name : "s1_rtc" + sar_cube : true + open_data : true + open_data_token : false + metadata_search : "tile" + ext_tolerance : 0 + grid_system : "MGRS" + SENTINEL-2-L2A : bands : B01 : &deafrica_msi_60m missing_value : -9999 @@ -476,6 +508,9 @@ sources: data_type : "INT1U" satellite : "SENTINEL-2" sensor : "MSI" + platforms : + SENTINEL-2A: "sentinel-2a" + SENTINEL-2B: "sentinel-2b" collection_name: "s2_l2a" access_vars : AWS_DEFAULT_REGION: "af-south-1" @@ -486,31 +521,3 @@ sources: metadata_search : "tile" ext_tolerance: 0 grid_system : "MGRS" - SENTINEL-1-RTC : - bands : - VV : &deafrica_rtc_20m - missing_value : -32768.0 - minimum_value : 0 - maximum_value : 65534 - scale_factor : 1 - offset_value : 0 - resolution : 20 - band_name : "VV" - data_type : "FLT4S" - VH : - <<: *deafrica_rtc_20m - band_name : "VH" - satellite : "SENTINEL-1" - sensor : "RTC" - orbits : ["ascending", "descending"] - access_vars : - AWS_DEFAULT_REGION : "af-south-1" - AWS_S3_ENDPOINT : "s3.af-south-1.amazonaws.com" - AWS_NO_SIGN_REQUEST : true - collection_name : "s1_rtc" - sar_cube : true - open_data : true - open_data_token : false - metadata_search : "tile" - ext_tolerance : 0 - grid_system : "MGRS" diff --git a/man/sits_cube.Rd b/man/sits_cube.Rd index 2d848d560..b3c4920f1 100644 --- a/man/sits_cube.Rd +++ b/man/sits_cube.Rd @@ -281,7 +281,7 @@ if (sits_run_examples()) { # DEAFRICA does not support definition of tiles cube_dea <- sits_cube( source = "DEAFRICA", - collection = "S2_L2A", + collection = "SENTINEL-2-L2A", bands = c("B04", "B08"), roi = c( "lat_min" = 17.379, diff --git a/tests/testthat/test-cube-cdse.R b/tests/testthat/test-cube-cdse.R index 9c8b89fa4..256fa7786 100644 --- a/tests/testthat/test-cube-cdse.R +++ b/tests/testthat/test-cube-cdse.R @@ -23,7 +23,13 @@ test_that("Creating S2 cubes from CDSE with ROI", { }, .default = NULL ) - testthat::skip_if(purrr::is_null(s2_cube_cdse), "CDSE is not accessible") + + if (purrr::is_null(s2_cube_cdse)) { + .environment_rollback(cdse_env_config) + + testthat::skip("CDSE is not accessible") + } + expect_true(all(sits_bands(s2_cube_cdse) %in% c("B05", "CLOUD"))) expect_equal(nrow(s2_cube_cdse), 3) bbox_cube <- sits_bbox(s2_cube_cdse, as_crs = "EPSG:4326") @@ -57,7 +63,13 @@ test_that("Creating S2 cubes from CDSE with tiles", { }, .default = NULL ) - testthat::skip_if(purrr::is_null(s2_cube_cdse), "CDSE is not accessible") + + if (purrr::is_null(s2_cube)) { + .environment_rollback(cdse_env_config) + + testthat::skip("CDSE is not accessible") + } + expect_true(all(sits_bands(s2_cube) %in% c("B05", "CLOUD"))) r <- .raster_open_rast(.tile_path(s2_cube)) expect_equal(s2_cube$xmax[[1]], .raster_xmax(r), tolerance = 1) @@ -65,6 +77,7 @@ test_that("Creating S2 cubes from CDSE with tiles", { r_obj <- .raster_open_rast(s2_cube$file_info[[1]]$path[1]) cube_nrows <- .tile_nrows(s2_cube) expect_true(.raster_nrows(r_obj) == cube_nrows) + expect_true(s2_cube$tile == "20LKP") # Rollback environment changes .environment_rollback(cdse_env_config) }) @@ -85,12 +98,19 @@ test_that("Creating Sentinel-1 RTC cubes from CDSE", { tiles = c("36NWH"), start_date = "2021-07-01", end_date = "2021-09-30", - multicores = 1L + multicores = 1L, + progresss = FALSE ) }, .default = NULL ) - testthat::skip_if(purrr::is_null(cube_s1_rtc), "CDSE is not accessible") + + if (purrr::is_null(cube_s1_rtc)) { + .environment_rollback(cdse_env_config) + + testthat::skip("CDSE is not accessible") + } + bbox <- sits_bbox(cube_s1_rtc[1,]) expect_true(grepl("4326", bbox[["crs"]])) expect_equal(32, bbox[["xmin"]]) diff --git a/tests/testthat/test-cube.R b/tests/testthat/test-cube.R index 6b836aa96..1bb2e26e1 100644 --- a/tests/testthat/test-cube.R +++ b/tests/testthat/test-cube.R @@ -96,6 +96,7 @@ test_that("Reading a raster cube", { expect_true(params_2$ncols == 255) expect_true(params_2$xres >= 231.5) }) + test_that("Creating cubes from BDC - CBERS-WFI-16D", { tiles <- c("007004", "007005") start_date <- "2021-09-01" @@ -442,13 +443,134 @@ 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 LS5-SR cubes from DEA", { + landsat_cube <- sits_cube( + source = "DEAFRICA", + collection = "LS5-SR", + bands = c("B05", "CLOUD"), + roi = c( + lon_min = 33.546, + lon_max = 34.999, + lat_min = 1.427, + lat_max = 3.726 + ), + start_date = "2009-01-01", + end_date = "2010-01-01", + progress = FALSE + ) + + testthat::skip_if(purrr::is_null(landsat_cube), + message = "DEAFRICA is not accessible" + ) + + expect_true(all(sits_bands(landsat_cube) %in% c("B05", "CLOUD"))) + expect_equal(nrow(landsat_cube), 6) + bbox_cube <- sits_bbox(landsat_cube, as_crs = "EPSG:4326") + bbox_cube_1 <- sits_bbox(.tile(landsat_cube), as_crs = "EPSG:4326") + expect_true(bbox_cube["xmax"] >= bbox_cube_1["xmax"]) + expect_true(bbox_cube["ymax"] >= bbox_cube_1["ymax"]) + r_obj <- .raster_open_rast(landsat_cube$file_info[[1]]$path[1]) + cube_nrows <- .tile_nrows(landsat_cube) + expect_true(.raster_nrows(r_obj) == cube_nrows) +}) +test_that("Creating LS7-SR cubes from DEA", { + landsat_cube <- sits_cube( + source = "DEAFRICA", + collection = "LS7-SR", + bands = c("B05", "CLOUD"), + roi = c( + lon_min = 33.546, + lon_max = 34.999, + lat_min = 1.427, + lat_max = 3.726 + ), + start_date = "2009-01-01", + end_date = "2010-01-01", + progress = FALSE + ) + + testthat::skip_if(purrr::is_null(landsat_cube), + message = "DEAFRICA is not accessible" + ) + + expect_true(all(sits_bands(landsat_cube) %in% c("B05", "CLOUD"))) + expect_equal(nrow(landsat_cube), 6) + bbox_cube <- sits_bbox(landsat_cube, as_crs = "EPSG:4326") + bbox_cube_1 <- sits_bbox(.tile(landsat_cube), as_crs = "EPSG:4326") + expect_true(bbox_cube["xmax"] >= bbox_cube_1["xmax"]) + expect_true(bbox_cube["ymax"] >= bbox_cube_1["ymax"]) + r_obj <- .raster_open_rast(landsat_cube$file_info[[1]]$path[1]) + cube_nrows <- .tile_nrows(landsat_cube) + expect_true(.raster_nrows(r_obj) == cube_nrows) +}) +test_that("Creating LS8-SR cubes from DEA", { + landsat_cube <- sits_cube( + source = "DEAFRICA", + collection = "LS8-SR", + bands = c("B05", "CLOUD"), + roi = c( + lon_min = 33.546, + lon_max = 34.999, + lat_min = 1.427, + lat_max = 3.726 + ), + start_date = "2021-01-01", + end_date = "2021-04-29", + progress = FALSE + ) + + testthat::skip_if(purrr::is_null(landsat_cube), + message = "DEAFRICA is not accessible" + ) + + expect_true(all(sits_bands(landsat_cube) %in% c("B05", "CLOUD"))) + expect_equal(nrow(landsat_cube), 6) + bbox_cube <- sits_bbox(landsat_cube, as_crs = "EPSG:4326") + bbox_cube_1 <- sits_bbox(.tile(landsat_cube), as_crs = "EPSG:4326") + expect_true(bbox_cube["xmax"] >= bbox_cube_1["xmax"]) + expect_true(bbox_cube["ymax"] >= bbox_cube_1["ymax"]) + r_obj <- .raster_open_rast(landsat_cube$file_info[[1]]$path[1]) + cube_nrows <- .tile_nrows(landsat_cube) + expect_true(.raster_nrows(r_obj) == cube_nrows) +}) +test_that("Creating LS9-SR cubes from DEA", { + landsat_cube <- sits_cube( + source = "DEAFRICA", + collection = "LS9-SR", + bands = c("B05", "CLOUD"), + roi = c( + lon_min = 33.546, + lon_max = 34.999, + lat_min = 1.427, + lat_max = 3.726 + ), + start_date = "2022-01-01", + end_date = "2022-04-01", + progress = FALSE + ) + + testthat::skip_if(purrr::is_null(landsat_cube), + message = "DEAFRICA is not accessible" + ) + + expect_true(all(sits_bands(landsat_cube) %in% c("B05", "CLOUD"))) + expect_equal(nrow(landsat_cube), 6) + bbox_cube <- sits_bbox(landsat_cube, as_crs = "EPSG:4326") + bbox_cube_1 <- sits_bbox(.tile(landsat_cube), as_crs = "EPSG:4326") + expect_true(bbox_cube["xmax"] >= bbox_cube_1["xmax"]) + expect_true(bbox_cube["ymax"] >= bbox_cube_1["ymax"]) + r_obj <- .raster_open_rast(landsat_cube$file_info[[1]]$path[1]) + cube_nrows <- .tile_nrows(landsat_cube) + expect_true(.raster_nrows(r_obj) == cube_nrows) +}) test_that("Creating S2 cubes from DEA using ROI", { # try to create a DEA cube dea_cube <- .try( { sits_cube( source = "DEAFRICA", - collection = "s2_l2a", + collection = "SENTINEL-2-L2A", bands = c("B01", "B04", "B05"), roi = c( lon_min = 17.379, @@ -463,39 +585,278 @@ test_that("Creating S2 cubes from DEA using ROI", { }, .default = NULL ) + testthat::skip_if(purrr::is_null(dea_cube), message = "DEAFRICA is not accessible" ) + expect_true(all(sits_bands(dea_cube) %in% c("B01", "B04", "B05"))) + expect_equal(nrow(dea_cube), 1) r <- .raster_open_rast(.tile_path(dea_cube)) 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 S2 cubes from DEA - using tiles", { +test_that("Creating S2 cubes from DEA using tiles", { dea_cube <- .try( { sits_cube( - source = "DEAFRICA", - collection = "s2_l2a", - bands = c("B02", "B8A", "B11"), - tiles = c("37MDT","37MET"), - start_date = "2019-01-01", - end_date = "2019-10-28", - progress = FALSE - ) + source = "DEAFRICA", + collection = "SENTINEL-2-L2A", + bands = c("B02", "B8A", "B11"), + tiles = c("37MDT","37MET"), + start_date = "2019-01-01", + end_date = "2019-08-28", + progress = FALSE + ) }, .default = NULL ) + testthat::skip_if(purrr::is_null(dea_cube), message = "DEAFRICA is not accessible" ) + expect_true(all(sits_bands(dea_cube) %in% c("B02", "B8A", "B11"))) + expect_equal(nrow(dea_cube), 2) r <- .raster_open_rast(.tile_path(dea_cube)) expect_equal(dea_cube$xmax[[1]], .raster_xmax(r), tolerance = 1) expect_equal(dea_cube$xmin[[1]], .raster_xmin(r), tolerance = 1) expect_true(all(dea_cube$tile %in% c("37MDT","37MET"))) +}) +test_that("Creating Sentinel-1 RTC cubes from DEA using ROI", { + cube_s1_rtc <- sits_cube( + source = "DEAFRICA", + collection = "SENTINEL-1-RTC", + bands = c("VV"), + orbit = "descending", + roi = c( + lon_min = 17.379, + lat_min = 1.1573, + lon_max = 17.410, + lat_max = 1.1910 + ), + start_date = "2021-07-01", + end_date = "2021-09-30", + progress = FALSE + ) + + testthat::skip_if(purrr::is_null(cube_s1_rtc), + message = "DEAFRICA is not accessible" + ) + + expect_true(sits_bands(cube_s1_rtc) == "VV") + expect_equal(nrow(cube_s1_rtc), 1) + r <- .raster_open_rast(.tile_path(cube_s1_rtc)) + expect_equal(cube_s1_rtc$xmax[[1]], .raster_xmax(r), tolerance = 1) + expect_equal(cube_s1_rtc$xmin[[1]], .raster_xmin(r), tolerance = 1) +}) +test_that("Creating Sentinel-1 RTC cubes from DEA using tiles", { + cube_s1_rtc <- sits_cube( + source = "DEAFRICA", + collection = "SENTINEL-1-RTC", + bands = c("VV"), + orbit = "ascending", + tiles = c("36NWJ"), + start_date = "2022-01-01", + end_date = "2022-02-25", + progress = FALSE + ) + + testthat::skip_if(purrr::is_null(cube_s1_rtc), + message = "DEAFRICA is not accessible" + ) + + bbox <- sits_bbox(cube_s1_rtc) + roi_cube_s1 <- sits_mgrs_to_roi(c("36NWJ")) + + expect_true(bbox[["xmin"]] < roi_cube_s1[["lon_min"]]) + expect_true(bbox[["xmax"]] > roi_cube_s1[["lon_max"]]) + expect_true(bbox[["ymin"]] < roi_cube_s1[["lat_min"]]) + expect_true(bbox[["ymax"]] > roi_cube_s1[["lat_max"]]) + expect_true(all(c("VV") %in% sits_bands(cube_s1_rtc))) + r_obj <- .raster_open_rast(cube_s1_rtc$file_info[[1]]$path[[1]]) + expect_true(terra::nrow(r_obj) == cube_s1_rtc$file_info[[1]]$nrows[[1]]) + + output_dir <- paste0(tempdir(), "/s1-rtc-reg") + if (!dir.exists(output_dir)) { + dir.create(output_dir) + } + + cube_s1_reg <- sits_regularize( + cube = cube_s1_rtc, + period = "P1M", + res = 240, + tiles = c("36NWJ"), + multicores = 1, + output_dir = output_dir, + progress = TRUE + ) + expect_equal(length(sits_timeline(cube_s1_reg)), 2) + expect_true("36NWJ" %in% cube_s1_reg$tile) + expect_true(all("EPSG:32636" %in% cube_s1_reg$crs)) + + bbox <- sits_bbox(cube_s1_reg, as_crs = "EPSG:4326") + roi_cube_s1 <- sits_mgrs_to_roi("36NWJ") + + expect_equal(bbox[["xmin"]], roi_cube_s1[["lon_min"]], tolerance = 0.01) + expect_equal(bbox[["xmax"]], roi_cube_s1[["lon_max"]], tolerance = 0.01) + expect_equal(bbox[["ymin"]], roi_cube_s1[["lat_min"]], tolerance = 0.01) + expect_equal(bbox[["ymax"]], roi_cube_s1[["lat_max"]], tolerance = 0.01) + + expect_true(all(c("VV") %in% sits_bands(cube_s1_reg))) +}) +test_that("Creating ALOS-PALSAR-MOSAIC cubes from DEA", { + cube_alos <- sits_cube( + source = "DEAFRICA", + collection = "ALOS-PALSAR-MOSAIC", + bands = c("HH", "HV", "CLOUD"), + roi = c( + lon_min = 17.379, + lat_min = 1.1573, + lon_max = 17.410, + lat_max = 1.1910 + ), + start_date = "2008-01-01", + end_date = "2009-01-01", + progress = FALSE + ) + + testthat::skip_if(purrr::is_null(cube_alos), + message = "DEAFRICA is not accessible" + ) + + expect_true(all(sits_bands(cube_alos) %in% c("HH", "HV", "CLOUD"))) + expect_equal(nrow(cube_alos), 1) + bbox_cube <- sits_bbox(cube_alos, as_crs = "EPSG:4326") + bbox_cube_1 <- sits_bbox(.tile(cube_alos), as_crs = "EPSG:4326") + expect_true(bbox_cube["xmax"] >= bbox_cube_1["xmax"]) + expect_true(bbox_cube["ymax"] >= bbox_cube_1["ymax"]) + r_obj <- .raster_open_rast(cube_alos$file_info[[1]]$path[1]) + cube_nrows <- .tile_nrows(cube_alos) + expect_true(.raster_nrows(r_obj) == cube_nrows) }) +test_that("Creating NDVI-ANOMALY cubes from DEA", { + cube_ndvi <- sits_cube( + source = "DEAFRICA", + collection = "NDVI-ANOMALY", + bands = c("NDVI-MEAN"), + roi = c( + lon_min = 17.379, + lat_min = 1.1573, + lon_max = 17.410, + lat_max = 1.1910 + ), + start_date = "2018-06-01", + end_date = "2018-12-31", + progress = FALSE + ) + + testthat::skip_if(purrr::is_null(cube_ndvi), + message = "DEAFRICA is not accessible" + ) + + expect_true(sits_bands(cube_ndvi) == "NDVI-MEAN") + expect_equal(nrow(cube_ndvi), 1) + bbox_cube <- sits_bbox(cube_ndvi, as_crs = "EPSG:4326") + bbox_cube_1 <- sits_bbox(.tile(cube_ndvi), as_crs = "EPSG:4326") + expect_true(bbox_cube["xmax"] >= bbox_cube_1["xmax"]) + expect_true(bbox_cube["ymax"] >= bbox_cube_1["ymax"]) + r_obj <- .raster_open_rast(cube_ndvi$file_info[[1]]$path[1]) + cube_nrows <- .tile_nrows(cube_ndvi) + expect_true(.raster_nrows(r_obj) == cube_nrows) +}) +test_that("Creating RAINFALL-CHIRPS-DAILY cubes from DEA", { + cube_chirps <- sits_cube( + source = "DEAFRICA", + collection = "RAINFALL-CHIRPS-DAILY", + bands = c("RAINFALL"), + roi = c( + lon_min = 17.379, + lat_min = 1.1573, + lon_max = 17.410, + lat_max = 1.1910 + ), + start_date = "2018-06-01", + end_date = "2018-08-25", + progress = FALSE + ) + + testthat::skip_if(purrr::is_null(cube_chirps), + message = "DEAFRICA is not accessible" + ) + + expect_true(sits_bands(cube_chirps) == "RAINFALL") + expect_equal(nrow(cube_chirps), 1) + bbox_cube <- sits_bbox(cube_chirps, as_crs = "EPSG:4326") + bbox_cube_1 <- sits_bbox(.tile(cube_chirps), as_crs = "EPSG:4326") + expect_true(bbox_cube["xmax"] >= bbox_cube_1["xmax"]) + expect_true(bbox_cube["ymax"] >= bbox_cube_1["ymax"]) + r_obj <- .raster_open_rast(cube_chirps$file_info[[1]]$path[1]) + cube_nrows <- .tile_nrows(cube_chirps) + expect_true(.raster_nrows(r_obj) == cube_nrows) +}) +test_that("Creating RAINFALL-CHIRPS-MONTHLY cubes from DEA", { + cube_chirps <- sits_cube( + source = "DEAFRICA", + collection = "RAINFALL-CHIRPS-MONTHLY", + bands = c("RAINFALL"), + roi = c( + lon_min = 17.379, + lat_min = 1.1573, + lon_max = 17.410, + lat_max = 1.1910 + ), + start_date = "2018-06-01", + end_date = "2018-08-25", + progress = FALSE + ) + + testthat::skip_if(purrr::is_null(cube_chirps), + message = "DEAFRICA is not accessible" + ) + + expect_true(sits_bands(cube_chirps) == "RAINFALL") + expect_equal(nrow(cube_chirps), 1) + bbox_cube <- sits_bbox(cube_chirps, as_crs = "EPSG:4326") + bbox_cube_1 <- sits_bbox(.tile(cube_chirps), as_crs = "EPSG:4326") + expect_true(bbox_cube["xmax"] >= bbox_cube_1["xmax"]) + expect_true(bbox_cube["ymax"] >= bbox_cube_1["ymax"]) + r_obj <- .raster_open_rast(cube_chirps$file_info[[1]]$path[1]) + cube_nrows <- .tile_nrows(cube_chirps) + expect_true(.raster_nrows(r_obj) == cube_nrows) +}) +test_that("Creating DEM-COP-30 cubes from DEA", { + cube_dem <- sits_cube( + source = "DEAFRICA", + collection = "DEM-COP-30", + bands = c("ELEVATION"), + roi = c( + lon_min = 17.379, + lat_min = 1.1573, + lon_max = 17.410, + lat_max = 1.1910 + ), + start_date = "1899-01-01", + end_date = "1901-01-01", + progress = FALSE + ) + + testthat::skip_if(purrr::is_null(cube_dem), + message = "DEAFRICA is not accessible" + ) + + expect_true(sits_bands(cube_dem) == "ELEVATION") + expect_equal(nrow(cube_dem), 1) + bbox_cube <- sits_bbox(cube_dem, as_crs = "EPSG:4326") + bbox_cube_1 <- sits_bbox(.tile(cube_dem), as_crs = "EPSG:4326") + expect_true(bbox_cube["xmax"] >= bbox_cube_1["xmax"]) + expect_true(bbox_cube["ymax"] >= bbox_cube_1["ymax"]) + r_obj <- .raster_open_rast(cube_dem$file_info[[1]]$path[1]) + cube_nrows <- .tile_nrows(cube_dem) + expect_true(.raster_nrows(r_obj) == cube_nrows) +}) + test_that("Creating S2 cubes from MPC using tiles", { mpc_token <- Sys.getenv("MPC_TOKEN") Sys.setenv("MPC_TOKEN" = "") @@ -671,7 +1032,6 @@ test_that("Creating Sentinel-1 RTC cubes from MPC", { expect_true(all(c("VV") %in% sits_bands(cube_s1_rtc_reg))) }) - test_that("Creating LANDSAT cubes from MPC with ROI", { roi <- c( lon_min = -48.28579, lat_min = -16.05026, @@ -719,6 +1079,7 @@ test_that("Creating LANDSAT cubes from MPC with WRS", { ) ) }) + test_that("Creating Sentinel cubes from AWS", { s2_cube <- .try( { @@ -810,7 +1171,6 @@ test_that("Creating LANDSAT cubes from AWS with ROI", { num_files_2 <- nrow(l8_cube_aws_l8$file_info[[1]]) expect_true(num_files_2 < num_files_1) }) - test_that("Creating LANDSAT cubes from AWS with WRS", { l8_cube_aws_wrs <- .try( { @@ -887,6 +1247,7 @@ test_that("Creating LANDSAT cubes from USGS with WRS", { tile_nrows <- .tile_nrows(l8_cube_223067)[[1]] expect_true(.raster_nrows(r_obj) == tile_nrows) }) + test_that("Creating Harmonized Landsat Sentinel HLSS30 cubes", { roi <- .s2_mgrs_to_roi("20LKP") hls_cube_s2 <- .try( @@ -972,7 +1333,7 @@ test_that("Creating Harmonized Landsat Sentinel HLSS30 cubes", { unlink("./.rcookies") }) -test_that("Creating Harmonized Landsat Sentinel HLSS30 cubes - tiles", { +test_that("Creating Harmonized Landsat Sentinel HLSS30 cubes using tiles", { hls_cube_s2 <- .try( { sits_cube( @@ -1034,6 +1395,7 @@ test_that("Creating Harmonized Landsat Sentinel HLSS30 cubes - tiles", { c(sits_timeline(l8_20LKP), sits_timeline(s2_20LKP)))) }) + test_that("Access to SwissDataCube", { roi <- c( lon_min = 7.54, lat_min = 46.73,