Skip to content

Commit

Permalink
Dates checks fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
zozlak committed Oct 25, 2018
1 parent adababd commit 4f5a6ec
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 15 deletions.
6 changes: 3 additions & 3 deletions R/S2_put_ROI.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion R/S2_query_angle.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ")")
}

Expand Down
2 changes: 1 addition & 1 deletion R/S2_query_image.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ")")
}

Expand Down
2 changes: 1 addition & 1 deletion R/S2_query_job.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ")")
}

Expand Down
6 changes: 4 additions & 2 deletions R/S2_query_product.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(...))
Expand Down
7 changes: 4 additions & 3 deletions R/S2_query_qiData.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(...))
Expand All @@ -75,4 +77,3 @@ S2_query_qiData <- function(atmCorr = NULL,
rtrn <- S2_do_query(query = query, path = 'qiData')
return(rtrn)
}

8 changes: 5 additions & 3 deletions R/S2_query_roi.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(...))
Expand Down
18 changes: 17 additions & 1 deletion tests/testthat/test-S2_query.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
context('S2_query')
S2_initialize_user()
apiUrl = 'https://test%40s2.boku.eodc.eu:[email protected]/'

test_that('S2_query_image() works', {
data = S2_query_image(
Expand All @@ -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')
Expand Down

0 comments on commit 4f5a6ec

Please sign in to comment.