Skip to content

Commit

Permalink
locdir: now used in all examples. Should Fix #31
Browse files Browse the repository at this point in the history
  • Loading branch information
brry committed Jun 8, 2021
1 parent 486ec71 commit cee30f4
Show file tree
Hide file tree
Showing 20 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rdwd
Title: Select and Download Climate Data from 'DWD' (German Weather Service)
Version: 1.5.8
Version: 1.5.9
Date: 2021-06-09
Depends: R(>= 2.10)
Imports: berryFunctions (>= 1.18.19), pbapply
Expand Down
2 changes: 1 addition & 1 deletion R/checkIndex.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ checkIndex <- function(
excludefp=TRUE,
fast=FALSE,
warn=!quiet,
logfile=localtestdir(".", "misc/ExampleTests/warnings.txt"),
logfile=berryFunctions::packagePath(file="misc/ExampleTests/warnings.txt"),
quiet=rdwdquiet()
)
{
Expand Down
4 changes: 2 additions & 2 deletions R/dataDWD.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' # find FTP files for a given station name and file path:
#' link <- selectDWD("Fuerstenzell", res="hourly", var="wind", per="recent")
#' # download file:
#' fname <- dataDWD(link, dir=tempdir(), read=FALSE) ; fname
#' fname <- dataDWD(link, dir=locdir(), read=FALSE) ; fname
#' # dir="DWDdata" is the default directory to store files
#' # unless force=TRUE, already obtained files will not be downloaded again
#'
Expand All @@ -52,7 +52,7 @@
#'
#' # current and historical files:
#' link <- selectDWD("Potsdam", res="daily", var="kl", per="hr"); link
#' potsdam <- dataDWD(link, dir=tempdir())
#' potsdam <- dataDWD(link, dir=locdir())
#' potsdam <- do.call(rbind, potsdam) # this will partly overlap in time
#' plot(TMK~MESS_DATUM, data=tail(potsdam,1500), type="l")
#' # The straight line marks the jump back in time
Expand Down
4 changes: 2 additions & 2 deletions R/plotRadar.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' # See homepage in the section 'See Also'
#' \dontrun{ ## Excluded from CRAN checks: requires internet connection
#' link <- "seasonal/air_temperature_mean/16_DJF/grids_germany_seasonal_air_temp_mean_188216.asc.gz"
#' rad <- dataDWD(link, base=gridbase, joinbf=TRUE, dir=tempdir())
#' rad <- dataDWD(link, base=gridbase, joinbf=TRUE, dir=locdir())
#' radp <- plotRadar(rad, proj="seasonal", extent=rad@extent, main="plotRadar ex")
#' plotRadar(radp, ylim=c(52,54), project=FALSE) # reuses main
#'
Expand All @@ -27,7 +27,7 @@
#'
#' # several layers
#' url <- "daily/Project_TRY/pressure/PRED_199606_daymean.nc.gz" # 5 MB
#' nc <- dataDWD(url, base=gridbase, joinbf=TRUE, dir=localtestdir())
#' nc <- dataDWD(url, base=gridbase, joinbf=TRUE, dir=locdir())
#'
#' ncp3 <- plotRadar(nc, main=paste(nc@title, nc@z[[1]]), layer=1:3,
#' col=terrain.colors(100), proj="nc", extent="nc")
Expand Down
18 changes: 9 additions & 9 deletions R/readDWD.R
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ return(dat)
#' durl <- selectDWD(res="multi_annual", var="mean_81-10", per="")[9]
#' murl <- selectDWD(res="multi_annual", var="mean_81-10", per="", meta=TRUE)[9]
#'
#' ma_temp <- dataDWD(durl, dir=localtestdir())
#' ma_meta <- dataDWD(murl, dir=localtestdir())
#' ma_temp <- dataDWD(durl, dir=locdir())
#' ma_meta <- dataDWD(murl, dir=locdir())
#'
#' head(ma_temp)
#' head(ma_meta)
Expand Down Expand Up @@ -388,7 +388,7 @@ out
#' \dontrun{ # Excluded from CRAN checks, but run in localtests
#'
#' link <- selectDWD(id=10381, res="subdaily", var="standard_format", per="r")
#' file <- dataDWD(link, dir=localtestdir(), read=FALSE)
#' file <- dataDWD(link, dir=locdir(), read=FALSE)
#' sf <- readDWD(file)
#'
#' sf2 <- readDWD(file, fast=FALSE) # 20 secs!
Expand Down Expand Up @@ -499,7 +499,7 @@ return(sf)
#' if(length(link)!=1) stop("length of link should be 1, but is ", length(link),
#' ":\n", berryFunctions::truncMessage(link,prefix="",sep="\n"))
#'
#' file <- dataDWD(link, dir=localtestdir(), read=FALSE)
#' file <- dataDWD(link, dir=locdir(), read=FALSE)
#' meta <- readDWD(file)
#' head(meta)
#'
Expand Down Expand Up @@ -584,7 +584,7 @@ stats
#'
#' SF_link <- "/daily/radolan/historical/bin/2017/SF201712.tar.gz"
#' SF_file <- dataDWD(url=SF_link, base=gridbase, joinbf=TRUE, # 204 MB
#' dir=localtestdir(), read=FALSE)
#' dir=locdir(), read=FALSE)
#' # exdir radardir set to speed up my tests:
#' SF_exdir <- "C:/Users/berry/Desktop/DWDbinarySF"
#' if(!file.exists(SF_exdir)) SF_exdir <- tempdir()
Expand All @@ -599,7 +599,7 @@ stats
#'
#' RW_link <- "hourly/radolan/reproc/2017_002/bin/2017/RW2017.002_201712.tar.gz"
#' RW_file <- dataDWD(url=RW_link, base=gridbase, joinbf=TRUE, # 25 MB
#' dir=localtestdir(), read=FALSE)
#' dir=locdir(), read=FALSE)
#' RW_exdir <- "C:/Users/berry/Desktop/DWDbinaryRW"
#' if(!file.exists(RW_exdir)) RW_exdir <- tempdir()
#' RW_rad <- readDWD(RW_file, selection=1:10, exdir=RW_exdir)
Expand Down Expand Up @@ -702,7 +702,7 @@ return(invisible(list(dat=rbmat, meta=rbmeta)))
#' rasterbase <- paste0(gridbase,"/seasonal/air_temperature_mean")
#' ftp.files <- indexFTP("/16_DJF", base=rasterbase, dir=tempdir())
#' localfiles <- dataDWD(ftp.files[1:2], base=rasterbase, joinbf=TRUE,
#' dir=localtestdir(), read=FALSE)
#' dir=locdir(), read=FALSE)
#' rf <- readDWD(localfiles[1])
#' rf <- readDWD(localfiles[1]) # runs faster at second time due to skip=TRUE
#' raster::plot(rf)
Expand Down Expand Up @@ -767,7 +767,7 @@ return(invisible(r))
#'
#' url <- "daily/Project_TRY/pressure/PRED_199606_daymean.nc.gz" # 5 MB
#' url <- "daily/Project_TRY/humidity/RH_199509_daymean.nc.gz" # 25 MB
#' file <- dataDWD(url, base=gridbase, joinbf=TRUE, dir=localtestdir(), read=FALSE)
#' file <- dataDWD(url, base=gridbase, joinbf=TRUE, dir=locdir(), read=FALSE)
#' nc <- readDWD(file)
#' ncp <- plotRadar(nc, main=paste(nc@title, nc@z[[1]]), layer=1:3,
#' col=seqPal(), proj="nc", extent="nc")
Expand Down Expand Up @@ -934,7 +934,7 @@ return(invisible(rf))
#' \dontrun{ # Excluded from CRAN checks, but run in localtests
#'
#' # File selection and download:
#' datadir <- localtestdir()
#' datadir <- locdir()
#' radbase <- paste0(gridbase,"/hourly/radolan/historical/asc/")
#' radfile <- "2018/RW-201809.tar" # 25 MB to download
#' file <- dataDWD(radfile, base=radbase, joinbf=TRUE, dir=datadir,
Expand Down
12 changes: 6 additions & 6 deletions R/runLocalTests.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
#' data downloads, these tests are not run automatically on CRAN.
#' @return Time taken to run tests in minutes
#' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Apr-Oct 2019
#' @seealso [localtestdir()]
#' @seealso [locdir()]
#' @keywords debugging
#' @importFrom grDevices dev.off pdf
#' @importFrom graphics par title
#' @importFrom utils tail
#' @export
#'
#' @param dir_data Reusable data location. Preferably not under version control.
#' DEFAULT: [localtestdir()]
#' @param dir_exmpl Reusable example location. DEFAULT: localtestdir(folder="misc/ExampleTests")
#' DEFAULT: [locdir()]
#' @param dir_exmpl Reusable example location. DEFAULT: local directory
#' @param fast Exclude many tests? DEFAULT: FALSE
#' @param devcheck Run `devtools::check()`? DEFAULT: !fast
#' @param radar Test reading radar example files. DEFAULT: !fast
Expand All @@ -25,8 +25,8 @@
#' @param quiet Suppress progress messages? DEFAULT: FALSE through [rdwdquiet()]
#'
runLocalTests <- function(
dir_data=localtestdir(),
dir_exmpl=localtestdir(folder="misc/ExampleTests"),
dir_data=locdir(),
dir_exmpl=berryFunctions::packagePath(file="misc/ExampleTests"),
fast=FALSE, # ca 0.1 minutes (always, even if fast=T)
devcheck=!fast, # ca 1.0 minutes
radar=!fast, # ca 0.3 minutes
Expand Down Expand Up @@ -112,7 +112,7 @@ testthat::test_that("readRadarFile works", {
trr <- function(file, ext="radolan", readdwd=FALSE) # trr: test reading radar data
{
main <- deparse(substitute(file))
file2 <- localtestdir(folder="misc", file=file)
file2 <- berryFunctions::packagePath(file=paste0("misc/",file))
rrf <- if(readdwd) readDWD(file2, toraster=FALSE) else dwdradar::readRadarFile(file2)
rrr <- raster::raster(rrf$dat)
rrp <- projectRasterDWD(rrr, extent=ext)
Expand Down
2 changes: 1 addition & 1 deletion R/updateIndexes.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ tools::resaveRdaFiles( "data/formatIndex.rda", version=2)
messaget("Checking readVars parameter abbreviations...")
urls <- selectDWD("Potsdam","","","", quiet=TRUE, mindex=metaIndex, findex=fileIndex)
urls <- urls[! (grepl("1*_minute", urls) & !grepl("meta_data", urls)) ]
files <- dataDWD(urls, dir=localtestdir(), read=F)
files <- dataDWD(urls, dir=locdir(), read=F)
rv <- readVars(files, quiet=TRUE) # quiet, message through nkurzmissing
#str(rv, max.level=1)
k <- unlist(lapply(rv, function(x)x$Kurz))
Expand Down
2 changes: 1 addition & 1 deletion man/checkIndex.Rd

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

4 changes: 2 additions & 2 deletions man/dataDWD.Rd

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

6 changes: 3 additions & 3 deletions man/locdir.Rd

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

4 changes: 2 additions & 2 deletions man/plotRadar.Rd

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

2 changes: 1 addition & 1 deletion man/readDWD.asc.Rd

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

4 changes: 2 additions & 2 deletions man/readDWD.binary.Rd

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

2 changes: 1 addition & 1 deletion man/readDWD.meta.Rd

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

4 changes: 2 additions & 2 deletions man/readDWD.multia.Rd

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

2 changes: 1 addition & 1 deletion man/readDWD.nc.Rd

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

2 changes: 1 addition & 1 deletion man/readDWD.raster.Rd

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

2 changes: 1 addition & 1 deletion man/readDWD.stand.Rd

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

10 changes: 5 additions & 5 deletions man/runLocalTests.Rd

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

10 changes: 5 additions & 5 deletions misc/vign/index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ there's yet more data at <https://opendata.dwd.de/weather>.
A helper function to reduce code duplication:

```{r readDWD_gridded}
ddir <- localtestdir()
ddir <- locdir()
tdir <- tempdir()
project_and_plot <- function(x, main1, main2, main3=NULL, ...)
{
Expand Down Expand Up @@ -537,7 +537,7 @@ Since Version 1.4.18 (2021-04-08), the default is `dbin=TRUE`. Report errors [he
If you do not use this, your plots may look partially shifted like this and have the wrong units (image from 2020-06-16 21:30 CEST):
```{r wrong_binary, eval=FALSE}
url <- "ftp://opendata.dwd.de/weather/radar/radolan/rw/raa01-rw_10000-latest-dwd---bin"
rw_file <- dataDWD(url, dir=tempdir(), read=FALSE, dbin=FALSE)
rw_file <- dataDWD(url, dir=locdir(), read=FALSE, dbin=FALSE)
rw_orig <- dwdradar::readRadarFile(rw_file)
raster::plot(raster::raster(rw_orig$dat))
```
Expand Down Expand Up @@ -646,15 +646,15 @@ Obtain time series of values at a selected location in gridded data.
```{r grid_loc_val_index}
library(rdwd)
# select data
index <- indexFTP(folder="annual/air_temperature_max", base=gridbase, dir=localtestdir())
index <- indexFTP(folder="annual/air_temperature_max", base=gridbase, dir=locdir())
index <- index[-(1:2)] # exclude description files
index <- index[as.numeric(substr(index,62,65))>=2013] # after year 2013
index
```

```{r grid_loc_val_downloadread}
# download & read data:
tempmax <- dataDWD(index, base=gridbase, joinbf=TRUE, dir=localtestdir())
tempmax <- dataDWD(index, base=gridbase, joinbf=TRUE, dir=locdir())
names(tempmax) <- substr(names(tempmax), 62, 65)
```

Expand Down Expand Up @@ -1033,7 +1033,7 @@ phenocrop_base <- paste0(sub("climate$", "phenology", dwdbase),
# pheno_urls <- indexFTP("", base=phenocrop_base, dir="Pheno")
kohl_url <- "PH_Jahresmelder_Landwirtschaft_Kulturpflanze_Weisskohl_1951_1990_hist.txt"# 9 MB
kohl_file <- dataDWD(base=phenocrop_base, url=kohl_url, joinbf=TRUE,
dir=localtestdir(), read=FALSE)
dir=locdir(), read=FALSE)
kohl <- read.table(kohl_file, sep=";", header=TRUE)
summary(kohl)
```
Expand Down

0 comments on commit cee30f4

Please sign in to comment.