Skip to content

Commit

Permalink
- missing namespaces required by R 3.3 added
Browse files Browse the repository at this point in the history
- tests for S2_query_images() and S2_download() provided
- Travis and Coveralls integrariong added
  • Loading branch information
zozlak committed Nov 9, 2016
1 parent 5bf5420 commit 2a562b2
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 8 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.travis.yml$
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# http://docs.travis-ci.com/user/languages/r/
language: r

cache: packages

r:
- release
- devel

after_success:
- Rscript -e 'covr::coveralls(function_exclusions = c("\\.onLoad"))'

notifications:
email:
- [email protected]
- [email protected]
6 changes: 6 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ Imports:
curl,
httr,
jsonlite,
methods,
raster,
sp
Suggests:
testthat,
knitr,
rmarkdown
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 5.0.1
VignetteBuilder: knitr
4 changes: 4 additions & 0 deletions R/S2_do_query.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
S2_do_query <- function(query, path){
user <- getOption("S2user")
password <- getOption("S2password")

filter <- sapply(query, is.logical)
query[filter] <- as.numeric(query[filter])

rtrn <- httr::GET('https://s2.boku.eodc.eu',
config = httr::authenticate(user, password),
path = path,
Expand Down
2 changes: 1 addition & 1 deletion R/S2_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ S2_download <- function(url, destfile, zip = TRUE){

curl::curl_download(url = url, destfile = destfile, quiet = TRUE)

if (isTRUE(zip)) unzip(zipfile = destfile, exdir = dirname(destfile))
if (isTRUE(zip)) utils::unzip(zipfile = destfile, exdir = dirname(destfile))

return(invisible(NULL))
}
Expand Down
4 changes: 2 additions & 2 deletions R/S2_generate_RGB.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ S2_generate_RGB <- function(granuleId,
user <- getOption("S2user")
password <- getOption("S2password")
rtrn <- httr::modify_url('https://s2.boku.eodc.eu',
username = URLencode(user, reserved = TRUE),
password = URLencode(password, reserved = TRUE),
username = utils::URLencode(user, reserved = TRUE),
password = utils::URLencode(password, reserved = TRUE),
path = "rgb",
query = query)

Expand Down
2 changes: 1 addition & 1 deletion R/S2_initialize_user.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @param password character password for 'https://s2.boku.eodc.eu'
#' @export

S2_initialize_user <- function(user = "[email protected]", password = "default"){
S2_initialize_user <- function(user = "[email protected]", password = "test"){
options("S2user" = user)
options("S2password" = password)
}
2 changes: 1 addition & 1 deletion R/jgeom_to_SpatialPolygons.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jgeom_to_SpatialPolygons <- function(x){
y <- strsplit(y, split = ",")
y <- do.call(rbind, y)
y <- apply(y, 2, as.numeric)
hull <- chull(y)
hull <- grDevices::chull(y)
y <- y[c(hull, hull[1]), ]
y <- sp::Polygon(y)
y <- sp::Polygons(list(y), ID=1)
Expand Down
2 changes: 1 addition & 1 deletion R/roi_to_jgeom.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ roi_to_jgeom <- function(roi, round = Inf){
})
}

if ("Spatial" %in% is(roi)){
if ("Spatial" %in% methods::is(roi)){
if (!raster::isLonLat(roi)){
roi <- sp::spTransform(roi, CRSobj = raster::crs(raster::raster()))
}
Expand Down
2 changes: 1 addition & 1 deletion R/spat_to_jgeom.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spat_to_jgeom <- function(spat, round = Inf){

poi_xy <- raster::geom(spat[i, ])[, c("x", "y"), drop = FALSE]

if (nrow(poi_xy) == 1 && "SpatialPoints" %in% is(spat)){
if (nrow(poi_xy) == 1 && "SpatialPoints" %in% methods::is(spat)){

poi_xy <- data.frame(round(poi_xy, round))
g_type <- "Point"
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# sentinel2

Accessing https://s2.boku.eodc.eu Sentinel-2 API made easy.

## Installation

* If you do not have the `devtools` package, install it with `install.packages('devtools')`.
* Run `devtools::install_github('IVFL-BOKU/sentinel2')

2 changes: 1 addition & 1 deletion man/S2_initialize_user.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/run-all.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://github.com/hadley/devtools/wiki/Testing
library(testthat)
test_check('sentinel2')
39 changes: 39 additions & 0 deletions tests/testthat/test-S2_query.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
context('S2_query')
S2_initialize_user()

test_that('S2_query_image() works', {
data = S2_query_image(
atmCorr = FALSE,
band = 'B10',
cloudCovMin = 80,
dateMin = '2016-06-01',
dateMax = '2016-08-31',
utm = '33UXP'
)
expect_is(data, 'data.frame')
expect_gt(nrow(data), 0)
cols = c("imageId", "productId", "granuleId", "product", "granule", "utm", "orbit", "band", "resolution", "cloudCov", "atmCorr", "date", "format", "processDate", "url")
expect_equal(intersect(names(data), cols), cols)
expect_true(all(as.numeric(data$atmCorr) == 0))
expect_true(all(data$band == 'B10'))
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')
}
on.exit({
if (file.exists('test.jp2')) {
unlink('test.jp2')
}
})

data = S2_query_image(imageId = 29392766)
S2_download(data$url, 'test.jp2', FALSE)
expect_true(file.exists('test.jp2'))
expect_true(file.info('test.jp2')$size == 3190469)
})

0 comments on commit 2a562b2

Please sign in to comment.