Created
September 24, 2019 12:57
-
-
Save lbusett/fbffb683e79e338c21f346843a983811 to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ref_dir <- system.file("extdata/example_files/out_ref", package = "sen2r") | |
testthat::test_that( | |
"Tests on custom mask on TOA with smoothing and buffering, with save binary mask", { | |
outdir_6 <- file.path(tempdir(), "out_test6") | |
dir.create(dirname(outdir_6), showWarnings = FALSE) | |
exp_outpath_6 <- file.path(outdir_6, "TOA", "S2A1C_20170703_022_Barbellino_TOA_10.tif") | |
exp_outpath_msk <- file.path(outdir_6, "MSK", "S2A1C_20170703_022_Barbellino_MSK_10.tif") | |
unlink(exp_outpath_6) | |
s2_mask( | |
infiles = file.path(ref_dir, "S2A1C_20170703_022_Barbellino_TOA_10.tif"), | |
maskfiles = file.path(ref_dir, "S2A2A_20170703_022_Barbellino_SCL_10.tif"), | |
mask_type = "clear_sky", | |
outdir = outdir_6, | |
subdirs = TRUE, | |
smooth = 20, | |
buffer = 20, | |
save_binary_mask = TRUE | |
) | |
expect_true(file.exists(exp_outpath_6)) | |
expect_true(file.exists(exp_outpath_msk)) | |
# test on raster metadata | |
exp_meta_r <- raster_metadata(exp_outpath_6, format = "list")[[1]] | |
testthat::expect_equal(exp_meta_r$size, c("x"=24, "y"=42)) | |
testthat::expect_equal(exp_meta_r$res, c("x"=10, "y"=10)) | |
testthat::expect_equal(exp_meta_r$nbands, 12) | |
testthat::expect_equal( | |
exp_meta_r$bbox, | |
sf::st_bbox( | |
c("xmin" = 580560, "ymin" = 5101700, "xmax" = 580800, "ymax" = 5102120), | |
crs = sf::st_crs(32632) | |
) | |
) | |
testthat::expect_equal(exp_meta_r$type, "UInt16") | |
testthat::expect_equal(exp_meta_r$outformat, "GTiff") | |
# test on raster values | |
testthat::expect_equal(raster::cellStats(r, "mean"), 1435.579, tolerance = 1e-3) | |
testthat::expect_equal(raster::cellStats(r, "countNA"), 360) | |
exp_meta_msk <- raster_metadata(exp_outpath_msk, format = "list")[[1]] | |
testthat::expect_equal(exp_meta_msk$size, c("x" = 12, "y" = 21)) | |
r <- raster::raster(exp_outpath_msk) | |
testthat::expect_equal(raster::cellStats(r, "max"), 1, tolerance = 1e-3) | |
testthat::expect_equal(raster::cellStats(r, "min"), 0, tolerance = 1e-3) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment