diff --git a/.Rbuildignore b/.Rbuildignore index 8cda06d..1693984 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -18,3 +18,5 @@ docs _pkgdown.yml figure$ cache$ +inst/blog +inst/tmp diff --git a/DESCRIPTION b/DESCRIPTION index c29f5df..4d4cfa4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hddtools Title: Hydrological Data Discovery Tools -Version: 0.6 +Version: 0.7 Authors@R: c(person("Claudia", "Vitolo", email = "cvitolodev@gmail.com", role = c("aut", "cre")), person("Wouter", "Buytaert", role = c("ctb"), comment = "This package was developed during Claudia's PhD at Imperial College London and Wouter was the PhD supervisor."), person("Erin", "Le Dell", role = c("ctb"), comment = "Erin reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/73"), diff --git a/NAMESPACE b/NAMESPACE index 3bf5452..1310b85 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,6 @@ # Generated by roxygen2: do not edit by hand export(KGClimateClass) -export(TRMM) export(bboxSpatialPolygon) export(catalogueData60UK) export(catalogueGRDC) diff --git a/NEWS.md b/NEWS.md index 96a0806..bf72bd7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# hddtools 0.7 + +* TRMM function: this function has been temporarily removed from hddtools v0.7 as the ftp at NASA containing the data has been migrated. A new function is under development and will be avalable at the next release (v0.8). + # hddtools 0.6 * TRMM function: set method for download.file to "auto" and added to arguments diff --git a/R/TRMM.R b/R/TRMM.R deleted file mode 100644 index 3d8fb57..0000000 --- a/R/TRMM.R +++ /dev/null @@ -1,171 +0,0 @@ -#' Download and convert TRMM data -#' -#' @author Claudia Vitolo -#' -#' @description The TRMM dataset provide global historical rainfall estimation in a gridded format. -#' -#' @param product this is the code that identifies a product, default is "3B43" -#' @param version this is the version number, default is 7 -#' @param type this is the type of information needed, default is "precipitation.accum". Other types could be "gaugeRelativeWeighting.bin" and "relativeError.bin" -#' @param twindow is a vector of dates and times for which the data should be retrieve -#' @param areaBox OPTIONAL bounding box, a list made of 4 elements: minimum longitude (xmin), minimum latitude (ymin), maximum longitude (xmax), maximum latitude (ymax) -#' @param method method to download, see \code{?download.file} for more info. -#' -#' @return Data is loaded as multilayer GeoTIFF and loaded as a RasterBrick. -#' -#' @details This code is based upon Martin Brandt's blog post: -#' \url{http://matinbrandt.wordpress.com/2013/09/04/automatically-downloading-and-processing-trmm-rainfall-data/} -#' and on the TRMM FAQ: \url{http://disc.sci.gsfc.nasa.gov/additional/faq/precipitation_faq.shtml} -#' -#' @export -#' -#' @examples -#' \dontrun{ -#' # Define a bounding box -#' areaBox <- raster::extent(-10, 5, 48, 62) -#' -#' # Get 3-hourly data -#' twindow <- seq(from = as.POSIXct("2012-1-1 0","%Y-%m-%d %H", tz="UTC"), -#' to = as.POSIXct("2012-1-1 23", "%Y-%m-%d %H", tz="UTC"), -#' by = 3*60*60) -#' TRMMfile <- TRMM(product = "3B42", version = 7, -#' type = "precipitation.bin", -#' twindow = twindow, areaBox = areaBox) -#' raster::plot(TRMMfile) -#' -#' # Get monthly data -#' twindow <- seq(from=as.Date("2012-01-01"), -#' to=as.Date("2012-02-28"), -#' by = "months") -#' TRMMfile <- TRMM(product = "3B43", version = 7, -#' type = "precipitation.accum", -#' twindow = twindow, areaBox = areaBox) -#' raster::plot(TRMMfile) -#' } -#' - -TRMM <- function(product = "3B43", - version = 7, - type = "precipitation.accum", - twindow = NULL, - areaBox = NULL, - method = "auto"){ - - # twindow contains dates and it can be used to identify the files to download - rootURL <- "ftp://disc2.nascom.nasa.gov/data/TRMM/Gridded/" - if (is.null(twindow)){ - stop("Please enter valid twindow") - }else{ - filesURLs <- c() - for (i in seq_along(twindow)){ - mydate <- twindow[i] - if (product == "3B42"){ - myyear <- unique(format(mydate, "%Y")) - mymonth <- format(mydate, "%m") - myday <- format(mydate, "%d") - myhour <- format(mydate, "%H") - filePaths <- paste0(rootURL, product, "_V", version, "/", - myyear, mymonth, "/", - product, ".", - substr(x = myyear, start = 3, stop = 4), - mymonth, myday, ".", myhour, "z", ".", version, ".", - type) - } - if (product == "3B43"){ - myyear <- unique(format(mydate, "%Y")) - mymonth <- format(mydate, "%m") - filePaths <- paste0(rootURL, product, "_V", version, "/", myyear, "/", - product, ".", - substr(x = myyear, start = 3, stop = 4), - mymonth, "01.", version, ".", type) - } - filesURLs <- c(filesURLs, filePaths) - } - } - - # create a temporary directory - td = tempdir() - originalwd <- getwd() - setwd(td) - - failedFiles <- c() - for (j in seq_along(filesURLs)){ - - x <- try(expr = download.file(url = filesURLs[j], - destfile = file.path(td, - basename(filesURLs[j])), - method = method, mode = "wb"), - silent = TRUE) - - if (class(x) == "try-error") { - failedFiles <- c(failedFiles, filesURLs[j]) - } - } - - if (length(failedFiles) > 0) { - message("The following files are currently not available for download: \n") - print(failedFiles) - } - - if (length(failedFiles) < length(filesURLs)){ - - # Now I create a virtual file as the downloaded TRMM data come as binaries. - # The VRT-file contains all the downloaded binary files with the appropriate - # geo-informations. - # To automate the process, there is a template script in inst/trmm.sh that - # generates the VRT-file (TRMM.vrt) for all 2012 data. - # Change "3B43.12" according to your twindow. - fileConn <- file("myTRMM.sh") - shOut <- readLines(system.file(file.path("extdata", "trmm.sh"), - package = "hddtools"), -1) - shOut[4] <- paste("for i in ", product, ".*", sep = "") - writeLines(shOut, fileConn) - close(fileConn) - - # Within R, the script (trmm.sh) is executed and the virtual-file (TRMM.vrt) - # loaded as a rasterbrick. This is flipped in y direction and the files - # written as multilayer Geotiff. - # This Geotiff contains all the layers for 2012 and can - # be opened in any GIS software. - - if (.Platform$OS.type != "unix"){ - message(paste0("Beware this function was tested on a unix machine. ", - "Please report any issues here: \n", - "https://github.com/ropensci/hddtools/issues")) - } - system(paste("sh","myTRMM.sh")) - - b <- raster::brick("TRMM.vrt") - trmm <- raster::flip(b, direction = "y") - # raster::plot(trmm) - - # Check bounding box extent is within original raster extent, - # if not return intersect of the two extents - if (is.null(areaBox)){ - # Use TRMM max extent - areaBox <- raster::extent(-180, +180, -50, +50) - } - - areaBox <- raster::intersect(areaBox, raster::extent(-180, +180, -50, +50)) - bbSP <- bboxSpatialPolygon(areaBox) - - # Crop TRMM raster based on areaBox, if necessary - if ( raster::extent(bbSP) == raster::extent(trmm) ){ - message("Using full spatial extent.") - }else{ - message("Cropping raster to areaBox extent.") - trmm <- raster::crop(trmm, bbSP) - } - - message("Removing temporary files") - file.remove(c("TRMM.vrt", "myTRMM.sh")) - - return(trmm) - - }else{ - message("There are no files available, try a different temporal window.") - } - - on.exit(expr = {setwd(originalwd)}) - -} diff --git a/README.Rmd b/README.Rmd index 8cf50c7..d8c2568 100644 --- a/README.Rmd +++ b/README.Rmd @@ -71,7 +71,7 @@ The package contains functions to interact with the data providers listed below. * [GRDC](http://www.bafg.de/GRDC/EN/Home/homepage_node.html): The Global Runoff Data Centre (GRDC) provides datasets for all the major rivers in the world. -* [TRMM](http://trmm.gsfc.nasa.gov/): The NASA's Tropical Rainfall Measuring Mission records global historical rainfall estimation in a gridded format since 1998 with a daily temporal resolution and a spatial resolution of 0.25 degrees. +* [TRMM](http://trmm.gsfc.nasa.gov/): The NASA's Tropical Rainfall Measuring Mission records global historical rainfall estimation in a gridded format since 1998 with a daily temporal resolution and a spatial resolution of 0.25 degrees. __Please note the TRMM function has been temporarily removed from hddtools v0.7 as the ftp at NASA containing the data has been migrated. A new function is under development and will be avalable at the next release (v0.8).__ * [Data60UK](http://tdwg.catchment.org/datasets.html): The Data60UK initiative collated datasets of areal precipitation and streamflow discharge across 61 gauging sites in England and Wales (UK). diff --git a/README.md b/README.md index 8d86aa7..ce8cd08 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ The package contains functions to interact with the data providers listed below. - [GRDC](http://www.bafg.de/GRDC/EN/Home/homepage_node.html): The Global Runoff Data Centre (GRDC) provides datasets for all the major rivers in the world. -- [TRMM](http://trmm.gsfc.nasa.gov/): The NASA's Tropical Rainfall Measuring Mission records global historical rainfall estimation in a gridded format since 1998 with a daily temporal resolution and a spatial resolution of 0.25 degrees. +- [TRMM](http://trmm.gsfc.nasa.gov/): The NASA's Tropical Rainfall Measuring Mission records global historical rainfall estimation in a gridded format since 1998 with a daily temporal resolution and a spatial resolution of 0.25 degrees. **Please note the TRMM function has been temporarily removed from hddtools v0.7 as the ftp at NASA containing the data has been migrated. A new function is under development and will be avalable at the next release (v0.8).** - [Data60UK](http://tdwg.catchment.org/datasets.html): The Data60UK initiative collated datasets of areal precipitation and streamflow discharge across 61 gauging sites in England and Wales (UK). diff --git a/cran-comments.md b/cran-comments.md index f4b202f..ef7c019 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,14 +1,14 @@ -This is a resubmission after the rOpenSci review. +This is a new release (hddtools v0.7). --------------------------------- ## Release Summary -In this new release, we added the following: +In this new release, we removed the follwoing function because the ftp at NASA containing the data has been migrated: -* a vignette -* Fixed bug with the TRMM function (for Windows users) -* Updated all the links to show the new repository (rOpenSci) +* TRMM() + +A new function is under development and will be avalable at the next release (v0.8). ## Test environment * Ubuntu 14.04, R 3.3.1 diff --git a/man/TRMM.Rd b/man/TRMM.Rd deleted file mode 100644 index 5f4d8ae..0000000 --- a/man/TRMM.Rd +++ /dev/null @@ -1,62 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/TRMM.R -\name{TRMM} -\alias{TRMM} -\title{Download and convert TRMM data} -\usage{ -TRMM(product = "3B43", version = 7, type = "precipitation.accum", - twindow = NULL, areaBox = NULL, method = "auto") -} -\arguments{ -\item{product}{this is the code that identifies a product, default is "3B43"} - -\item{version}{this is the version number, default is 7} - -\item{type}{this is the type of information needed, default is "precipitation.accum". Other types could be "gaugeRelativeWeighting.bin" and "relativeError.bin"} - -\item{twindow}{is a vector of dates and times for which the data should be retrieve} - -\item{areaBox}{OPTIONAL bounding box, a list made of 4 elements: minimum longitude (xmin), minimum latitude (ymin), maximum longitude (xmax), maximum latitude (ymax)} - -\item{method}{method to download, see \code{?download.file} for more info.} -} -\value{ -Data is loaded as multilayer GeoTIFF and loaded as a RasterBrick. -} -\description{ -The TRMM dataset provide global historical rainfall estimation in a gridded format. -} -\details{ -This code is based upon Martin Brandt's blog post: -\url{http://matinbrandt.wordpress.com/2013/09/04/automatically-downloading-and-processing-trmm-rainfall-data/} -and on the TRMM FAQ: \url{http://disc.sci.gsfc.nasa.gov/additional/faq/precipitation_faq.shtml} -} -\examples{ -\dontrun{ - # Define a bounding box - areaBox <- raster::extent(-10, 5, 48, 62) - - # Get 3-hourly data - twindow <- seq(from = as.POSIXct("2012-1-1 0","\%Y-\%m-\%d \%H", tz="UTC"), - to = as.POSIXct("2012-1-1 23", "\%Y-\%m-\%d \%H", tz="UTC"), - by = 3*60*60) - TRMMfile <- TRMM(product = "3B42", version = 7, - type = "precipitation.bin", - twindow = twindow, areaBox = areaBox) - raster::plot(TRMMfile) - - # Get monthly data - twindow <- seq(from=as.Date("2012-01-01"), - to=as.Date("2012-02-28"), - by = "months") - TRMMfile <- TRMM(product = "3B43", version = 7, - type = "precipitation.accum", - twindow = twindow, areaBox = areaBox) - raster::plot(TRMMfile) -} - -} -\author{ -Claudia Vitolo -} - diff --git a/tests/testthat/test-TRMM.R b/tests/testthat/test-TRMM.R deleted file mode 100644 index 41883ed..0000000 --- a/tests/testthat/test-TRMM.R +++ /dev/null @@ -1,68 +0,0 @@ -context("TRMM") - -test_that("Test TRMM function using dates in the past", { - - # Define a bounding box - areaBox <- raster::extent(-4, -3.75, 48, 50) - twindow <- seq(as.Date("2012-01-01"), as.Date("2012-01-31"), by = "months") - - x <- TRMM(product = "3B43", - version = 7, - type = "precipitation.accum", - twindow = twindow, - areaBox = areaBox) - - rasterExtent <- raster::extent(x) - - expect_that(class(x) == "try-error", equals(FALSE)) - - expect_that(rasterExtent@xmin == -4, equals(TRUE)) - expect_that(rasterExtent@xmax == -3.75, equals(TRUE)) - expect_that(rasterExtent@ymin == 48, equals(TRUE)) - expect_that(rasterExtent@ymax == 50, equals(TRUE)) - -}) - -test_that("Test TRMM function using monthly dates in the future", { - - skip_on_cran() - - # Define a bounding box - areaBox <- raster::extent(-4, -3.75, 48, 50) - twindow <- seq(Sys.Date(), Sys.Date() + 32, by = "months") - - x <- TRMM(product = "3B43", - version = 7, - type = "precipitation.accum", - twindow = twindow, - areaBox = areaBox) - - expect_that(class(x) == "NULL", equals(TRUE)) - -}) - -test_that("Test TRMM function using 3-hourly dates in the past", { - - # Define a bounding box - areaBox <- raster::extent(-4, -3.75, 48, 50) - twindow <- seq(from = as.POSIXct("2012-1-1 0","%Y-%m-%d %H", tz="UTC"), - to = as.POSIXct("2012-1-1 23", "%Y-%m-%d %H", tz="UTC"), - by = 3*60*60) - - x <- TRMM(product = "3B42", - version = 7, - type = "precipitation.bin", - twindow = twindow, - areaBox = areaBox) - - rasterExtent <- raster::extent(x) - - expect_that(class(x) == "try-error", equals(FALSE)) - - expect_that(rasterExtent@xmin == -4, equals(TRUE)) - expect_that(rasterExtent@xmax == -3.75, equals(TRUE)) - expect_that(rasterExtent@ymin == 48, equals(TRUE)) - expect_that(rasterExtent@ymax == 50, equals(TRUE)) - -}) - diff --git a/vignettes/hddtools_vignette.Rmd b/vignettes/hddtools_vignette.Rmd index 1318f84..291ba73 100644 --- a/vignettes/hddtools_vignette.Rmd +++ b/vignettes/hddtools_vignette.Rmd @@ -146,7 +146,10 @@ WolfeToneBridge <- tsGRDC(stationID = catalogueGRDC()$grdc_no[7126], ![](tsGRDC.png) -### NASA's Tropical Rainfall Measuring Mission (TRMM, only available for github version) +### NASA's Tropical Rainfall Measuring Mission + +__IMPORTANT NOTE: The TRMM function has been temporarily removed from hddtools v0.7 as the ftp at NASA containing the data has been migrated. A new function is under development and will be avalable at the next release (v0.8).__ + The Tropical Rainfall Measuring Mission (TRMM) is a joint mission between NASA and the Japan Aerospace Exploration Agency (JAXA) that uses a research satellite to measure precipitation within the tropics in order to improve our understanding of climate and its variability. The TRMM satellite records global historical rainfall estimation in a gridded format since 1998 with a daily temporal resolution and a spatial resolution of 0.25 degrees. This information is openly available for educational purposes and downloadable from an FTP server. diff --git a/vignettes/hddtools_vignette.html b/vignettes/hddtools_vignette.html index 77e171d..22fae18 100644 --- a/vignettes/hddtools_vignette.html +++ b/vignettes/hddtools_vignette.html @@ -335,7 +335,9 @@
IMPORTANT NOTE: The TRMM function has been temporarily removed from hddtools v0.7 as the ftp at NASA containing the data has been migrated. A new function is under development and will be avalable at the next release (v0.8).
The Tropical Rainfall Measuring Mission (TRMM) is a joint mission between NASA and the Japan Aerospace Exploration Agency (JAXA) that uses a research satellite to measure precipitation within the tropics in order to improve our understanding of climate and its variability.
diff --git a/vignettes/hddtools_vignette.md b/vignettes/hddtools_vignette.md index d5fea79..c144dd5 100644 --- a/vignettes/hddtools_vignette.md +++ b/vignettes/hddtools_vignette.md @@ -1,6 +1,6 @@ --- author: "Claudia Vitolo" -date: "2017-03-02" +date: "2017-04-02" output: rmarkdown::html_vignette vignette: > %\VignetteEngine{knitr::knitr} @@ -159,7 +159,10 @@ WolfeToneBridge <- tsGRDC(stationID = catalogueGRDC()$grdc_no[7126], ![](tsGRDC.png) -### NASA's Tropical Rainfall Measuring Mission (TRMM, only available for github version) +### NASA's Tropical Rainfall Measuring Mission + +__IMPORTANT NOTE: The TRMM function has been temporarily removed from hddtools v0.7 as the ftp at NASA containing the data has been migrated. A new function is under development and will be avalable at the next release (v0.8).__ + The Tropical Rainfall Measuring Mission (TRMM) is a joint mission between NASA and the Japan Aerospace Exploration Agency (JAXA) that uses a research satellite to measure precipitation within the tropics in order to improve our understanding of climate and its variability. The TRMM satellite records global historical rainfall estimation in a gridded format since 1998 with a daily temporal resolution and a spatial resolution of 0.25 degrees. This information is openly available for educational purposes and downloadable from an FTP server.