Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ appveyor.yml
inst/extdata/grdc
inst/experimental/*
^\.github$
^cran-comments\.md$
57 changes: 38 additions & 19 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
Package: hddtools
Title: Hydrological Data Discovery Tools
Version: 0.9.5
Authors@R: c(person(given = "Claudia", family = "Vitolo",
role = c("aut"), email = "[email protected]",
comment = c(ORCID = "0000-0002-4252-1176")),
person(given = "Wouter", family = "Buytaert", role = c("ctb"),
comment = "Supervisor"),
person(given = "Erin", family = "Le Dell", role = c("ctb"),
comment = "Erin reviewed the package for rOpenSci, see https://github.com/ropensci/software-review/issues/73"),
person(given = "Michael", family = "Sumner", role = c("ctb"),
comment = "Michael reviewed the package for rOpenSci, see https://github.com/ropensci/software-review/issues/73"),
person(given = "Dorothea", family = "Hug Peter", role = c("aut", "cre"), email = "[email protected]"))
Authors@R: c(
person("Claudia", "Vitolo", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-4252-1176")),
person("Wouter", "Buytaert", role = "ctb",
comment = "Supervisor"),
person("Erin", "Le Dell", role = "ctb",
comment = "Erin reviewed the package for rOpenSci, see https://github.com/ropensci/software-review/issues/73"),
person("Michael", "Sumner", role = "ctb",
comment = "Michael reviewed the package for rOpenSci, see https://github.com/ropensci/software-review/issues/73"),
person("Dorothea", "Hug Peter", , "[email protected]", role = c("aut", "cre"))
)
Maintainer: Dorothea Hug Peter <[email protected]>
URL: https://docs.ropensci.org/hddtools/, https://github.com/ropensci/hddtools
BugReports: https://github.com/ropensci/hddtools/issues
Description: Tools to discover hydrological data, accessing catalogues and databases from various data providers. The package is described in Vitolo (2017) "hddtools: Hydrological Data Discovery Tools" <doi:10.21105/joss.00056>.
Depends: R (>= 3.5.0)
Imports: zoo, curl, XML, terra, readxl, tidyr, sf
Suggests: testthat, leaflet, rmarkdown, knitr, dplyr
VignetteBuilder: knitr
Description: Tools to discover hydrological data, accessing catalogues and
databases from various data providers. The package is described in
Vitolo (2017) "hddtools: Hydrological Data Discovery Tools"
<doi:10.21105/joss.00056>.
License: GPL-3
Repository: CRAN
RoxygenNote: 7.2.0
URL: https://docs.ropensci.org/hddtools/,
https://github.com/ropensci/hddtools
BugReports: https://github.com/ropensci/hddtools/issues
Depends:
R (>= 3.5.0)
Imports:
curl,
readxl,
sf,
terra,
tidyr,
XML,
zoo
Suggests:
dplyr,
knitr,
leaflet,
rmarkdown,
testthat
VignetteBuilder:
knitr
Encoding: UTF-8
Repository: CRAN
RoxygenNote: 7.2.3
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# hddtools 0.9.5

*Removed dependency fom rgdal and raster packages
*Removed dependency from rgdal and raster packages

# hddtools 0.9.4

Expand Down
40 changes: 18 additions & 22 deletions R/Data60UK.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@
#'
#' @examples
#' \dontrun{
#' # Retrieve the whole catalogue
#' Data60UK_catalogue_all <- catalogueData60UK()
#' # Retrieve the whole catalogue
#' Data60UK_catalogue_all <- catalogueData60UK()
#'
#' # Filter the catalogue based on a bounding box
#' areaBox <- terra::ext(-4, -2, +52, +53)
#' Data60UK_catalogue_bbox <- catalogueData60UK(areaBox)
#' # Filter the catalogue based on a bounding box
#' areaBox <- terra::ext(-4, -2, +52, +53)
#' Data60UK_catalogue_bbox <- catalogueData60UK(areaBox)
#' }
#'

catalogueData60UK <- function(areaBox = NULL){

catalogueData60UK <- function(areaBox = NULL) {
file_url <- "http://nrfaapps.ceh.ac.uk/datauk60/data.html"

tables <- XML::readHTMLTable(file_url)
Expand All @@ -55,28 +53,29 @@ catalogueData60UK <- function(areaBox = NULL){
Data60UKcatalogue$Longitude <- temp$longitude

# Latitude is the Y axis, longitude is the X axis.
if (!is.null(areaBox)){
if (!is.null(areaBox)) {
lonMin <- areaBox$xmin
lonMax <- areaBox$xmax
latMin <- areaBox$ymin
latMax <- areaBox$ymax
}else{
} else {
lonMin <- -180
lonMax <- +180
latMin <- -90
latMax <- +90
}

Data60UKcatalogue <- subset(Data60UKcatalogue,
(Data60UKcatalogue$Latitude <= latMax &
Data60UKcatalogue$Latitude >= latMin &
Data60UKcatalogue$Longitude <= lonMax &
Data60UKcatalogue$Longitude >= lonMin))
Data60UKcatalogue <- subset(
Data60UKcatalogue,
(Data60UKcatalogue$Latitude <= latMax &
Data60UKcatalogue$Latitude >= latMin &
Data60UKcatalogue$Longitude <= lonMax &
Data60UKcatalogue$Longitude >= lonMin)
)

row.names(Data60UKcatalogue) <- NULL

return(Data60UKcatalogue)

}

#' Interface for the Data60UK database of Daily Time Series
Expand All @@ -93,12 +92,10 @@ catalogueData60UK <- function(areaBox = NULL){
#'
#' @examples
#' \dontrun{
#' Morwick <- tsData60UK(id = "22001")
#' Morwick <- tsData60UK(id = "22001")
#' }
#'

tsData60UK <- function(id){

tsData60UK <- function(id) {
file_url <- paste0("http://nrfaapps.ceh.ac.uk/datauk60/data/rq", id, ".txt")

temp <- utils::read.table(file_url)
Expand All @@ -111,8 +108,7 @@ tsData60UK <- function(id){
P <- zoo::zoo(temp$P, order.by = datetime) # measured in mm
Q <- zoo::zoo(temp$Q, order.by = datetime) # measured in m3/s

myTS <- zoo::merge.zoo(P,Q)
myTS <- zoo::merge.zoo(P, Q)

return(myTS)

}
53 changes: 31 additions & 22 deletions R/GRDC.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,47 +38,56 @@
#'
#' @examples
#' \dontrun{
#' # Retrieve the catalogue
#' GRDC_catalogue_all <- catalogueGRDC()
#' # Retrieve the catalogue
#' GRDC_catalogue_all <- catalogueGRDC()
#' }
#'

catalogueGRDC <- function() {

file_url <- "ftp://ftp.bafg.de/pub/REFERATE/GRDC/catalogue/grdc_stations.zip"

# Create a temporary directory
td <- tempdir()
# Create the placeholder file
tf <- tempfile(tmpdir = td, fileext = ".zip")

# Retrieve the catalogue into the placeholder file
x <- curl::curl_download(url = file_url, destfile = tf)

# Unzip the file to the temporary directory
utils::unzip(tf, exdir = td, overwrite = TRUE)

# Read
GRDCcatalogue <- readxl::read_xlsx(path = file.path(td, "GRDC_Stations.xlsx"),
sheet = "station_catalogue")

GRDCcatalogue <- readxl::read_xlsx(
path = file.path(td, "GRDC_Stations.xlsx"),
sheet = "station_catalogue"
)

# Cleanup
GRDCcatalogue <- data.frame(lapply(GRDCcatalogue,
function(x) {gsub("n.a.|-999.0", NA, x)}),
stringsAsFactors = FALSE)

GRDCcatalogue <- data.frame(
lapply(
GRDCcatalogue,
function(x) {
gsub("n.a.|-999.0", NA, x)
}
),
stringsAsFactors = FALSE
)

# Convert to numeric some of the columns
colx <- c("wmo_reg", "sub_reg",
"d_start", "d_end", "d_yrs",
"m_start", "m_end", "m_yrs",
"t_start", "t_end", "t_yrs")
colx <- c(
"wmo_reg", "sub_reg",
"d_start", "d_end", "d_yrs",
"m_start", "m_end", "m_yrs",
"t_start", "t_end", "t_yrs"
)
GRDCcatalogue[, colx] <- lapply(GRDCcatalogue[, colx], as.integer)

# Convert to integers some of the columns
colx <- c("lat", "long", "area", "altitude", "d_miss", "m_miss",
"lta_discharge", "r_volume_yr", "r_height_yr")
colx <- c(
"lat", "long", "area", "altitude", "d_miss", "m_miss",
"lta_discharge", "r_volume_yr", "r_height_yr"
)
GRDCcatalogue[, colx] <- lapply(GRDCcatalogue[, colx], as.numeric)

return(GRDCcatalogue)

}
Loading