Skip to content

Commit c887747

Browse files
committed
Bugfix: read_regnie gave wrong extent
1 parent b01d90f commit c887747

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package: esmisc
22
Type: Package
33
Title: Misc Functions of Eduard Szöcs
44
Version: 0.0.3.9002
5-
Date: 2017-01-10
5+
Date: 2017-03-30
66
Authors@R: c(person("Eduard", "Szöcs", role = c("aut", "cre"),
77
email = "[email protected]"))
88
Maintainer: Eduard Szöcs <[email protected]>

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ MINOR IMPROVEMENTS
1111

1212
BUG FIXES
1313

14+
* read_regnie() gave wrong extent (reported by Tim Haering).
15+
1416
DEPRECATED FUNCTIONS
1517

1618
DEFUNCT FUNCTIONS

R/read_regnie.R

+8-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' \url{https://www.dwd.de/DE/leistungen/regnie/download/regnie_beschreibung_pdf.pdf?__blob=publicationFile&v=2}.
66
#' Data is available here: \url{ftp://ftp-cdc.dwd.de/pub/CDC/grids_germany/daily/regnie/}.
77
#' @import raster readr
8-
#' @param file path to gz archive
8+
#' @param file path to gz archive.
99
#' @return A \code{RasterLayer} object.
1010
#' @export
1111
#' @examples
@@ -18,14 +18,13 @@ read_regnie <- function(file){
1818
n_max = 971,
1919
na = '-999')
2020
r <- raster(as.matrix(cont))
21-
# ymax = (55 + 10 / 120) = 55.083333
22-
# ymin = (55 + 10 / 120) - (971 - 1) / 120 = 47
23-
# xmin = (6 - 10 / 60) = 5.833333
24-
# xmax = (6 - 10 / 60) + (611 - 1) / 60 = 16
25-
extent(r) <- c(6 - 10 / 60,
26-
(6 - 10 / 60) + (611 - 1) / 60,
27-
(55 + 10 / 120) - (971 - 1) / 120,
28-
55 + 10 / 120)
21+
22+
xdelta <- 1/60
23+
ydelta <- 1/120
24+
extent(r) <- c(6 - 10 * xdelta - xdelta / 2,
25+
(6 - 10 * xdelta) + (611 - 1) * xdelta + xdelta / 2,
26+
(55 + 10 * ydelta) - (971 - 1) * ydelta - ydelta / 2,
27+
55 + 10 * ydelta + ydelta / 2)
2928
crs(r) <- "+proj=longlat"
3029
# scale to mm
3130
r <- r/10

tests/testthat.R

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
library('testthat')
22
library('esmisc')
3+
library('raster')
4+
35
test_check("esmisc")

tests/testthat/test-read_regnie.R

+5
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ test_that('read_regnie works', {
99
expect_true(is.na(r[1]))
1010
expect_equivalent(r[438537], 109.1)
1111
expect_equivalent(r[100000], 5.7)
12+
expect_equal(as.matrix(extent(r)),
13+
structure(c(5.825, 46.9958333333333, 16.0083333333333, 55.0875),
14+
.Dim = c(2L, 2L),
15+
.Dimnames = list(c("x", "y"), c("min", "max")))
16+
)
1217
})
1318

0 commit comments

Comments
 (0)