|
| 1 | +test_that("Creating S2 cubes from CDSE with ROI", { |
| 2 | + # Configure environment |
| 3 | + cdse_env_config <- .environment_cdse() |
| 4 | + # Patch environment variables |
| 5 | + .environment_patch(cdse_env_config) |
| 6 | + # Test |
| 7 | + roi <- c( |
| 8 | + lon_min = -48.28579, lat_min = -16.05026, |
| 9 | + lon_max = -47.30839, lat_max = -15.50026 |
| 10 | + ) |
| 11 | + s2_cube_cdse <- .try( |
| 12 | + { |
| 13 | + sits_cube( |
| 14 | + source = "CDSE", |
| 15 | + collection = "SENTINEL-2-L2A", |
| 16 | + roi = roi, |
| 17 | + bands = c("B05", "CLOUD"), |
| 18 | + start_date = as.Date("2018-07-18"), |
| 19 | + end_date = as.Date("2018-08-23"), |
| 20 | + progress = FALSE, |
| 21 | + multicores = 1L |
| 22 | + ) |
| 23 | + }, |
| 24 | + .default = NULL |
| 25 | + ) |
| 26 | + testthat::skip_if(purrr::is_null(s2_cube_cdse), "CDSE is not accessible") |
| 27 | + expect_true(all(sits_bands(s2_cube_cdse) %in% c("B05", "CLOUD"))) |
| 28 | + expect_equal(nrow(s2_cube_cdse), 3) |
| 29 | + bbox_cube <- sits_bbox(s2_cube_cdse, as_crs = "EPSG:4326") |
| 30 | + bbox_cube_1 <- sits_bbox(.tile(s2_cube_cdse), as_crs = "EPSG:4326") |
| 31 | + expect_true(bbox_cube["xmax"] >= bbox_cube_1["xmax"]) |
| 32 | + expect_true(bbox_cube["ymax"] >= bbox_cube_1["ymax"]) |
| 33 | + r_obj <- .raster_open_rast(s2_cube_cdse$file_info[[1]]$path[1]) |
| 34 | + cube_nrows <- .tile_nrows(s2_cube_cdse) |
| 35 | + expect_true(.raster_nrows(r_obj) == cube_nrows) |
| 36 | + # Rollback environment changes |
| 37 | + .environment_rollback(cdse_env_config) |
| 38 | +}) |
| 39 | +test_that("Creating S2 cubes from CDSE with tiles", { |
| 40 | + # Configure environment |
| 41 | + cdse_env_config <- .environment_cdse() |
| 42 | + # Patch environment variables |
| 43 | + .environment_patch(cdse_env_config) |
| 44 | + # Test |
| 45 | + s2_cube <- .try( |
| 46 | + { |
| 47 | + sits_cube( |
| 48 | + source = "CDSE", |
| 49 | + collection = "SENTINEL-2-L2A", |
| 50 | + tiles = "20LKP", |
| 51 | + bands = c("B05", "CLOUD"), |
| 52 | + start_date = as.Date("2018-07-18"), |
| 53 | + end_date = as.Date("2018-08-23"), |
| 54 | + progress = FALSE, |
| 55 | + multicores = 1L |
| 56 | + ) |
| 57 | + }, |
| 58 | + .default = NULL |
| 59 | + ) |
| 60 | + expect_true(all(sits_bands(s2_cube) %in% c("B05", "CLOUD"))) |
| 61 | + r <- .raster_open_rast(.tile_path(s2_cube)) |
| 62 | + expect_equal(s2_cube$xmax[[1]], .raster_xmax(r), tolerance = 1) |
| 63 | + expect_equal(s2_cube$xmin[[1]], .raster_xmin(r), tolerance = 1) |
| 64 | + r_obj <- .raster_open_rast(s2_cube$file_info[[1]]$path[1]) |
| 65 | + cube_nrows <- .tile_nrows(s2_cube) |
| 66 | + expect_true(.raster_nrows(r_obj) == cube_nrows) |
| 67 | + # Rollback environment changes |
| 68 | + .environment_rollback(cdse_env_config) |
| 69 | +}) |
| 70 | + |
| 71 | +test_that("Creating Sentinel-1 RTC cubes from CDSE", { |
| 72 | + # Configure environment |
| 73 | + cdse_env_config <- .environment_cdse() |
| 74 | + # Patch environment variables |
| 75 | + .environment_patch(cdse_env_config) |
| 76 | + # Test |
| 77 | + cube_s1_rtc <- sits_cube( |
| 78 | + source = "CDSE", |
| 79 | + collection = "SENTINEL-1-RTC", |
| 80 | + bands = c("VV"), |
| 81 | + orbit = "descending", |
| 82 | + tiles = c("36NWH"), |
| 83 | + start_date = "2021-07-01", |
| 84 | + end_date = "2021-09-30", |
| 85 | + multicores = 1L |
| 86 | + ) |
| 87 | + bbox <- sits_bbox(cube_s1_rtc[1,]) |
| 88 | + expect_true(grepl("4326", bbox[["crs"]])) |
| 89 | + expect_equal(32, bbox[["xmin"]]) |
| 90 | + expect_equal(34, bbox[["xmax"]]) |
| 91 | + expect_equal(nrow(cube_s1_rtc$file_info[[1]]), 68) |
| 92 | + |
| 93 | + output_dir <- paste0(tempdir(), "/s1rtcreg") |
| 94 | + if (!dir.exists(output_dir)) { |
| 95 | + dir.create(output_dir) |
| 96 | + } |
| 97 | + |
| 98 | + cube_s1_rtc_reg <- sits_regularize( |
| 99 | + cube = cube_s1_rtc, |
| 100 | + period = "P1M", |
| 101 | + res = 240, |
| 102 | + tiles = c("36NXG", "36NVG"), |
| 103 | + multicores = 1, |
| 104 | + output_dir = output_dir, |
| 105 | + progress = TRUE |
| 106 | + ) |
| 107 | + expect_equal(length(sits_timeline(cube_s1_rtc_reg)), 3) |
| 108 | + expect_true(all(c("36NXG", "36NVG") %in% |
| 109 | + cube_s1_rtc_reg$tile)) |
| 110 | + expect_true("EPSG:32636" %in% cube_s1_rtc_reg$crs) |
| 111 | + |
| 112 | + bbox <- sits_bbox(cube_s1_rtc_reg, as_crs = "EPSG:4326") |
| 113 | + roi_cube_s1 <- sits_mgrs_to_roi(c("36NXG", "36NVG")) |
| 114 | + |
| 115 | + expect_equal(bbox[["xmin"]], roi_cube_s1[["lon_min"]], tolerance = 0.01) |
| 116 | + expect_equal(bbox[["xmax"]], roi_cube_s1[["lon_max"]], tolerance = 0.03) |
| 117 | + expect_equal(bbox[["ymin"]], roi_cube_s1[["lat_min"]], tolerance = 0.25) |
| 118 | + expect_equal(bbox[["ymax"]], roi_cube_s1[["lat_max"]], tolerance = 0.01) |
| 119 | + expect_true(all(c("VV") %in% sits_bands(cube_s1_rtc_reg))) |
| 120 | + |
| 121 | + # Rollback environment changes |
| 122 | + .environment_rollback(cdse_env_config) |
| 123 | +}) |
0 commit comments