From 4f5a6ece08a9643e567d34dc5c146ee8dc3ed7a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=BB=C3=B3=C5=82tak?= Date: Thu, 25 Oct 2018 10:42:35 +0200 Subject: [PATCH] Dates checks fixed --- R/S2_put_ROI.R | 6 +++--- R/S2_query_angle.R | 2 +- R/S2_query_image.R | 2 +- R/S2_query_job.R | 2 +- R/S2_query_product.R | 6 ++++-- R/S2_query_qiData.R | 7 ++++--- R/S2_query_roi.R | 8 +++++--- tests/testthat/test-S2_query.R | 18 +++++++++++++++++- 8 files changed, 36 insertions(+), 15 deletions(-) diff --git a/R/S2_put_ROI.R b/R/S2_put_ROI.R index b485f21..f9c01de 100644 --- a/R/S2_put_ROI.R +++ b/R/S2_put_ROI.R @@ -23,15 +23,15 @@ S2_put_ROI <- function(geometry, dateMax = NULL, srid = 4326){ - if (is.null(dateMin) || is.null(dateMax)){ + if (is.null(dateMin) || is.null(dateMax)) { stop("Please supply 'dateMin' and 'dateMax' in format 'YYYY-MM-DD") } - if(check_date(dateMin) > check_date(dateMax)){ + if (check_date(dateMin) > check_date(dateMax)) { stop("'dateMin' (", dateMin, ") larger than 'dateMax' (", dateMax, ")") } - if (is.null(regionId)){ + if (is.null(regionId)) { stop("'regionId' not specified!", "\n-> If you want to update an existing 'roi', please supply valid 'regionId'", "\n-> If you like to create a new 'regionId' enter desired name") diff --git a/R/S2_query_angle.R b/R/S2_query_angle.R index e3e3b8f..def8e56 100644 --- a/R/S2_query_angle.R +++ b/R/S2_query_angle.R @@ -46,7 +46,7 @@ S2_query_angle <- function(angleType = NULL, dateSingle <- NULL } - if (check_date(dateMin) > check_date(dateMax)) { + if (!is.null(dateMin) && !is.null(dateMax) && check_date(dateMin) > check_date(dateMax)) { stop("'dateMin' (", dateMin, ") larger than 'dateMax' (", dateMax, ")") } diff --git a/R/S2_query_image.R b/R/S2_query_image.R index 09e7c9d..ffde9aa 100644 --- a/R/S2_query_image.R +++ b/R/S2_query_image.R @@ -76,7 +76,7 @@ S2_query_image <- function(atmCorr = NULL, dateSingle <- NULL } - if (check_date(dateMin) > check_date(dateMax)) { + if (!is.null(dateMin) && !is.null(dateMax) && check_date(dateMin) > check_date(dateMax)) { stop("'dateMin' (", dateMin, ") larger than 'dateMax' (", dateMax, ")") } diff --git a/R/S2_query_job.R b/R/S2_query_job.R index 0822122..ece222d 100644 --- a/R/S2_query_job.R +++ b/R/S2_query_job.R @@ -48,7 +48,7 @@ S2_query_job <- function(dateMax = NULL, dateSingle <- NULL } - if (check_date(dateMin) > check_date(dateMax)) { + if (!is.null(dateMin) && !is.null(dateMax) && check_date(dateMin) > check_date(dateMax)) { stop("'dateMin' (", dateMin, ") larger than 'dateMax' (", dateMax, ")") } diff --git a/R/S2_query_product.R b/R/S2_query_product.R index b82f923..3abf18d 100644 --- a/R/S2_query_product.R +++ b/R/S2_query_product.R @@ -47,12 +47,14 @@ S2_query_product <- function(atmCorr = NULL, dateSingle <- NULL } - if (check_date(dateMin) > check_date(dateMax)){ + if (!is.null(dateMin) && !is.null(dateMax) && check_date(dateMin) > check_date(dateMax)) { stop("'dateMin' (", dateMin, ") larger than 'dateMax' (", dateMax, ")") } # prepare json geometry ------------------------------------------------------ - if (!is.null(geometry)) geometry <- roi_to_jgeom(geometry) + if (!is.null(geometry)) { + geometry <- roi_to_jgeom(geometry) + } # make named query list ------------------------------------------------------ query <- c(as.list(environment()), list(...)) diff --git a/R/S2_query_qiData.R b/R/S2_query_qiData.R index d6f143f..7bae4a1 100644 --- a/R/S2_query_qiData.R +++ b/R/S2_query_qiData.R @@ -60,12 +60,14 @@ S2_query_qiData <- function(atmCorr = NULL, dateSingle <- NULL } - if (check_date(dateMin) > check_date(dateMax)) { + if (!is.null(dateMin) && !is.null(dateMax) && check_date(dateMin) > check_date(dateMax)) { stop("'dateMin' (", dateMin, ") larger than 'dateMax' (", dateMax, ")") } # prepare json geometry ------------------------------------------------------ - if (!is.null(geometry)) geometry <- roi_to_jgeom(geometry) + if (!is.null(geometry)) { + geometry <- roi_to_jgeom(geometry) + } # make named query list ------------------------------------------------------ query <- c(as.list(environment()), list(...)) @@ -75,4 +77,3 @@ S2_query_qiData <- function(atmCorr = NULL, rtrn <- S2_do_query(query = query, path = 'qiData') return(rtrn) } - diff --git a/R/S2_query_roi.R b/R/S2_query_roi.R index 9574bfc..e43f531 100644 --- a/R/S2_query_roi.R +++ b/R/S2_query_roi.R @@ -25,19 +25,21 @@ S2_query_roi <- function(dateMax = Sys.Date(), ...){ # check inputs --------------------------------------------------------------- - if (!is.null(dateSingle)){ + if (!is.null(dateSingle)) { check_date(dateSingle) dateMin <- dateSingle dateMax <- dateSingle dateSingle <- NULL } - if(check_date(dateMin) > check_date(dateMax)){ + if (!is.null(dateMin) && !is.null(dateMax) && check_date(dateMin) > check_date(dateMax)) { stop("'dateMin' (", dateMin, ") larger than 'dateMax' (", dateMax, ")") } # prepare json geometry ------------------------------------------------------ - if (!is.null(geometry)) geometry <- roi_to_jgeom(geometry) + if (!is.null(geometry)) { + geometry <- roi_to_jgeom(geometry) + } # make named query list ------------------------------------------------------ query <- c(as.list(environment()), list(...)) diff --git a/tests/testthat/test-S2_query.R b/tests/testthat/test-S2_query.R index 2581b2e..ffcf40b 100644 --- a/tests/testthat/test-S2_query.R +++ b/tests/testthat/test-S2_query.R @@ -1,6 +1,5 @@ context('S2_query') S2_initialize_user() -apiUrl = 'https://test%40s2.boku.eodc.eu:test@s2.boku.eodc.eu/' test_that('S2_query_image() works', { data = S2_query_image( @@ -23,6 +22,23 @@ test_that('S2_query_image() works', { expect_true(all(data$utm == '33UXP')) }) +test_that('S2_query_granule() works', { + data = S2_query_granule( + cloudCovMin = 80, + dateMin = '2016-06-01', + dateMax = '2016-08-31', + utm = '33UXP' + ) + expect_is(data, 'data.frame') + expect_gt(nrow(data), 0) + cols = c("granuleId", "productId", "product", "granule", "date", "processDate", "utm", "orbit", "cloudCov", "atmCorr", "broken", "url") + expect_equal(intersect(names(data), cols), cols) + expect_true(all(data$cloudCov >= 80)) + expect_true(all(data$date >= '2016-06-01')) + expect_true(all(data$date <= '2016-08-31')) + expect_true(all(data$utm == '33UXP')) +}) + test_that('S2 downloads images', { if (file.exists('test.jp2')) { unlink('test.jp2')