diff --git a/.Rbuildignore b/.Rbuildignore index ef3ef81..2459d33 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,5 @@ ^README\.Rmd$ ^LICENSE\.md$ ^\.github$ +^.*\.Rproj$ +^\.Rproj\.user$ diff --git a/DESCRIPTION b/DESCRIPTION index b42b7d0..beda0cc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,3 +15,8 @@ Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 +Imports: + cli, + data.table, + lubridate, + rlang diff --git a/NAMESPACE b/NAMESPACE index 91d046f..8d46268 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,3 +1,5 @@ # Generated by roxygen2: do not edit by hand export(get_key) +export(plot) +importFrom(terra,plot) diff --git a/R/get_key.R b/R/get_key.R index 0b8da18..ba7f441 100644 --- a/R/get_key.R +++ b/R/get_key.R @@ -38,18 +38,18 @@ get_key <- function() { #' @keywords internal #' @noRd #' @return Called for its side-effects, opens a browser window at the TERN -#' weather data API key request form. +#' accounts page. .set_tern_key <- function() { if (interactive()) { - utils::browseURL("https://ternapikeydetails") + utils::browseURL("https://account.tern.org.au/authenticated_user/apikeys") } stop( - "You need to set your TERN API key.\n", - "After getting your key set it as 'DPIRD_API_KEY' in .Renviron.\n", + "You need to create and/or set your TERN API key.\n", + "After getting your key set it as 'TERN_API_KEY' in .Renviron.\n", "TERN_API_KEY='youractualkeynotthisstring'\n", "For that, use `usethis::edit_r_environ()`" ) - invisible("https://ternapikeydetails") + invisible("https://account.tern.org.au/authenticated_user/apikeys") } diff --git a/R/get_smips.R b/R/get_smips.R index 70a3078..07acd0b 100644 --- a/R/get_smips.R +++ b/R/get_smips.R @@ -1,8 +1,59 @@ #' Get Soil Moisture Integration and Prediction System (SMIPS) Data -#' -#' Soil Moisture Integration and Prediction System (\acronym{SMIPS}) +#' +#' Soil Moisture Integration and Prediction System (\acronym{SMIPS}) v1.0. +#' +#' @param collection A character vector of the data collection to be queried, +#' on of: +#' * SMIndex +#' * bucket1 +#' * bucket2 +#' * deepD +#' * runoff +#' * totalbucket +#' Defaults to \dQuote{totalbucket}. +#' @param dates A date to query, _e.g._, `date = 2017-12-31`, both `Character` or +#' `Date` classes are accepted. +#' +#' @return A [terra::rast] object #' @references -get_smips <- function(start_date, end_date) { +get_smips <- function(collection = "totalbucket", + dates, + api_key = get_key()) { + + dates <- lubridate::ymd(dates) + url_dates <- gsub("-", "", dates) + approved_collections <- c("totalbucket", + "SMIndex", + "bucket1", + "bucket2", + "deepD", + "runnoff") + collection <- rlang::arg_match(collection, approved_collections) + + collection_url <- data.table::fcase( + collection == "totalbucket", + paste0("smips_totalbucket_mm_", url_dates, ".tif"), + collection == "SMIndex", + paste0("smips_smi_perc_", url_dates, ".tif"), + collection == "bucket1", + paste0("smips_bucket1_mm_", url_dates, ".tif"), + collection == "bucket2", + paste0("smips_bucket2_mm_", url_dates, ".tif"), + collection == "deepD", + paste0("smips_deepD_mm_", url_dates, ".tif"), + collection == "runoff", + paste0("smips_runoff_mm_", url_dates, ".tif") + ) + + r <- terra::rast(paste0("/vsicurl/https://", + paste0('apikey:', api_key), + "@data.tern.org.au/model-derived/smips/v1_0/", + collection, + "/", + lubridate::year(dates), + "/", + collection_url)) + return(r) +} -} \ No newline at end of file diff --git a/R/reexports.R b/R/reexports.R new file mode 100644 index 0000000..1c045c1 --- /dev/null +++ b/R/reexports.R @@ -0,0 +1,3 @@ +#' @importFrom terra plot +#' @export +terra::plot diff --git a/man/get_smips.Rd b/man/get_smips.Rd index 7f5841d..04f7151 100644 --- a/man/get_smips.Rd +++ b/man/get_smips.Rd @@ -4,10 +4,29 @@ \alias{get_smips} \title{Get Soil Moisture Integration and Prediction System (SMIPS) Data} \usage{ -get_smips(start_date, end_date) +get_smips(collection = "totalbucket", dates, api_key = get_key()) +} +\arguments{ +\item{collection}{A character vector of the data collection to be queried, +on of: +\itemize{ +\item SMIndex +\item bucket1 +\item bucket2 +\item deepD +\item runoff +\item totalbucket +Defaults to \dQuote{totalbucket}. +}} + +\item{dates}{A date to query, \emph{e.g.}, \code{date = 2017-12-31}, both \code{Character} or +\code{Date} classes are accepted.} +} +\value{ +A \link[terra:rast]{terra::rast} object } \description{ -Soil Moisture Integration and Prediction System (\acronym{SMIPS}) +Soil Moisture Integration and Prediction System (\acronym{SMIPS}) v1.0. } \references{ \url{https://portal.tern.org.au/metadata/TERN/d1995ee8-53f0-4a7d-91c2-ad5e4a23e5e0https://geonetwork.tern.org.au/geonetwork/srv/eng/catalog.search#/metadata/d1995ee8-53f0-4a7d-91c2-ad5e4a23e5e0} diff --git a/man/reexports.Rd b/man/reexports.Rd new file mode 100644 index 0000000..d433a64 --- /dev/null +++ b/man/reexports.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/reexports.R +\docType{import} +\name{reexports} +\alias{reexports} +\alias{plot} +\title{Objects exported from other packages} +\keyword{internal} +\description{ +These objects are imported from other packages. Follow the links +below to see their documentation. + +\describe{ + \item{terra}{\code{\link[terra]{plot}}} +}} + diff --git a/nert.Rproj b/nert.Rproj index aaa62a5..766b3b2 100644 --- a/nert.Rproj +++ b/nert.Rproj @@ -5,8 +5,13 @@ SaveWorkspace: No AlwaysSaveHistory: Default EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 Encoding: UTF-8 +RnwWeave: knitr +LaTeX: pdfLaTeX + AutoAppendNewline: Yes StripTrailingWhitespace: Yes LineEndingConversion: Posix