From 8055f7a331d83ec14acbffcc3d92b3c59bcf0bcc Mon Sep 17 00:00:00 2001 From: "Adam H. Sparks" Date: Wed, 6 Nov 2024 16:42:31 +0800 Subject: [PATCH 1/4] line lengths --- R/read_cog.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/R/read_cog.R b/R/read_cog.R index 45f2eb1..e6a47e6 100644 --- a/R/read_cog.R +++ b/R/read_cog.R @@ -90,7 +90,8 @@ read_cog <- function(data = "smips", }, error = function(e) { if (attempt < max_tries) { delay <- initial_delay * 2 ^ (attempt - 1) - cli::cli_alert("Download failed on attempt { attempt }. Retrying in { delay } seconds...") + cli::cli_alert("Download failed on attempt { attempt }. + Retrying in { delay } seconds...") Sys.sleep(delay) attempt <- attempt + 1 } else { @@ -120,7 +121,8 @@ read_cog <- function(data = "smips", "Ymd", "dmY", "mdY", "BdY", "Bdy", "bdY", "bdy" ), tz = Sys.timezone()), warning = function(c) { - cli::cli_abort("{ x } is not in a valid date format. Please enter a valid date format.") + cli::cli_abort("{ x } is not in a valid date format. + Please enter a valid date format.") } ) return(x) @@ -168,7 +170,8 @@ read_cog <- function(data = "smips", if (.collection == "totalbucket" && .url_year < 2005 || .day > .last_week) { - cli::cli_abort("The data are not available before 2005 and past { .last_week }") + cli::cli_abort("The data are not available before 2005 and roughly + much past { .last_week }") } } From 63efdfd662c5b64fdbee662f6b654008f5e9277c Mon Sep 17 00:00:00 2001 From: "Adam H. Sparks" Date: Wed, 6 Nov 2024 16:55:35 +0800 Subject: [PATCH 2/4] Add spelling check --- codemeta.json | 2 +- inst/WORDLIST | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 inst/WORDLIST diff --git a/codemeta.json b/codemeta.json index 8c526b9..1d0534c 100644 --- a/codemeta.json +++ b/codemeta.json @@ -124,7 +124,7 @@ }, "SystemRequirements": null }, - "fileSize": "174.876KB", + "fileSize": "175.09KB", "codeRepository": "https://github.com/AAGI-AUS/nert", "readme": "https://github.com/AAGI-AUS/nert/blob/main/README.md", "contIntegration": ["https://github.com/AAGI-AUS/nert/actions/workflows/R-CMD-check.yaml", "https://app.codecov.io/gh/AAGI-AUS/nert"] diff --git a/inst/WORDLIST b/inst/WORDLIST new file mode 100644 index 0000000..d2ff5be --- /dev/null +++ b/inst/WORDLIST @@ -0,0 +1,18 @@ +CMD +COGs +Codecov +Geotiff +ORCID +Optimised +Renviron +Rprofile +SMIPS +SMindex +bashrc +config +currenly +deepD +smips +totalbucket +visualise +zshrc From 3f12ae6b89f8e3f2cb896597a53635022d8bf216 Mon Sep 17 00:00:00 2001 From: "Adam H. Sparks" Date: Thu, 7 Nov 2024 13:52:38 +0800 Subject: [PATCH 3/4] Add example extract to README, remove read_cog_dt, add Max --- DESCRIPTION | 20 +++++++------ NAMESPACE | 1 - R/read_cog.R | 6 ++-- R/read_cog_dt.R | 40 ------------------------- README.Rmd | 21 +++++++++---- README.md | 40 ++++++++++++------------- codemeta.json | 13 ++++++-- man/nert-package.Rd | 7 ++++- man/read_cog.Rd | 8 ++--- man/read_cog_dt.Rd | 73 --------------------------------------------- 10 files changed, 68 insertions(+), 161 deletions(-) delete mode 100644 R/read_cog_dt.R delete mode 100644 man/read_cog_dt.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 4088e8a..a524847 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,19 +4,13 @@ Version: 0.0.0.9000 Authors@R: c( person("Adam H.", "Sparks", , "adamhsparks@gmail.com", role = "cre", comment = c(ORCID = "0000-0002-0061-8359")), - person("Russell", "Edson", , "russell.edson@adelaide.edu.au", role = "aut") + person("Russell", "Edson", , "russell.edson@adelaide.edu.au", role = "aut", + comment = c(ORCID = "0000-0002-4607-5396")), + person("Max", "Moldovan", , "max.moldovan@adelaide.edu.au", role = "ctb") ) Description: Provides access to Australia's TERN (Terrestrial Ecosystem Research Network) data through the API, . License: MIT + file LICENSE -Suggests: - roxyglobals, - testthat (>= 3.0.0) -Config/testthat/edition: 3 -Encoding: UTF-8 -Roxygen: list(markdown = TRUE, roclets = c("collate", "namespace", "rd", - "roxyglobals::global_roclet")) -RoxygenNote: 7.3.2 Imports: cli, data.table, @@ -24,5 +18,13 @@ Imports: rlang, terra, utils +Suggests: + roxyglobals, + testthat (>= 3.0.0) Config/roxyglobals/filename: globals.R Config/roxyglobals/unique: FALSE +Config/testthat/edition: 3 +Encoding: UTF-8 +Roxygen: list(markdown = TRUE, roclets = c("collate", "namespace", "rd", + "roxyglobals::global_roclet")) +RoxygenNote: 7.3.2 diff --git a/NAMESPACE b/NAMESPACE index 8edadce..f32b112 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,5 +3,4 @@ export(get_key) export(plot) export(read_cog) -export(read_cog_dt) importFrom(terra,plot) diff --git a/R/read_cog.R b/R/read_cog.R index e6a47e6..354c717 100644 --- a/R/read_cog.R +++ b/R/read_cog.R @@ -7,7 +7,7 @@ #' Currently only Soil Moisture Integration and Prediction System #' (\acronym{SMIPS}) v1.0 is supported. #' -#' @param data A character vector of the data source to be queried, currently +#' @param dataset A character vector of the data source to be queried, currently #' only \dQuote{smips}. #' @param collection A character vector of the data collection to be queried, #' currenly only \dQuote{smips} is supported with the following collections: @@ -51,7 +51,7 @@ #' @references #' @export -read_cog <- function(data = "smips", +read_cog <- function(dataset = "smips", collection = "totalbucket", day, api_key = get_key(), @@ -66,7 +66,7 @@ read_cog <- function(data = "smips", day <- .check_date(day) url_year <- lubridate::year(day) - if (data == "smips") { + if (dataset == "smips") { collection_url <- .make_smips_url(.collection = collection, .day = day) while (attempt <= max_tries && !success) diff --git a/R/read_cog_dt.R b/R/read_cog_dt.R deleted file mode 100644 index 24f2333..0000000 --- a/R/read_cog_dt.R +++ /dev/null @@ -1,40 +0,0 @@ -#' Read COGs from TERN -#' -#' Read Cloud Optimised Geotiff (\acronym{COG}) files from \acronym{TERN} in -#' your active \R session as a \CRANpkg{data.table} object. -#' -#' @note -#' Currently only Soil Moisture Integration and Prediction System -#' (\acronym{SMIPS}) v1.0 is supported. -#' -#' @inherit read_cog -#' -#' @family COGs -#' @author Adam H. Sparks \email{adamhsparks@@curtin.edu.au} -#' @examplesIf interactive() -#' -#' r <- read_cog_dt(day = "2024-01-01", api_key = "your_api_key") -#' -#' r -#' -#' @return A [data.table::data.table] object -#' @autoglobal -#' @references -#' @export - -read_cog_dt <- function(data = "smips", - collection = "totalbucket", - day, - api_key = get_key()) { - r <- data.table::setDT(terra::as.data.frame( - read_cog( - data = data, - collection = collection, - day = day, - api_key = api_key - ), xy = TRUE - )) - - data.table::setnames(r, old = c("x", "y"), new = c("lon", "lat")) - return(r) -} diff --git a/README.Rmd b/README.Rmd index ec4acaa..d008be6 100644 --- a/README.Rmd +++ b/README.Rmd @@ -45,13 +45,22 @@ r <- read_cog(day = "2024-01-01") plot(r) ``` -## Example reading a COG as a data.table +## Extract Values Given Lat/Lon Values -This is a basic example which shows you how you can fetch one day's data from the SMIPS data as a data.table: +Extract Soil Moisture for Corrigin and Merriden, WA and Tamworth, NSW given latitude and longitude values for each. -```{r example_dt} -library(nert) -r <- read_cog_dt(day = "2024-01-01") +```{r} +df <- structure(list( + location = c("Corrigin", "Merredin", "Tamworth"), + x = c(117.87, 118.28, 150.84), + y = c(-32.33, -31.48, -31.07) +), +row.names = c(NA, -3L), +class = "data.frame") + +cog_df <- terra::extract(x = r, y = df[, c("x", "y")], xy = TRUE) -r +cog_df <- cbind(df$location, cog_df) +names(cog_df) <- c("location", "ID", "smips_totalbucket_mm_20240101", "x", "y") +cog_df ``` diff --git a/README.md b/README.md index 74d908f..38ceb45 100644 --- a/README.md +++ b/README.md @@ -49,27 +49,27 @@ plot(r) -## Example reading a COG as a data.table +## Extract Values Given Lat/Lon Values -This is a basic example which shows you how you can fetch one day’s data -from the SMIPS data as a data.table: +Extract Soil Moisture for Corrigin and Merriden, WA and Tamworth, NSW +given latitude and longitude values for each. ``` r -library(nert) -r <- read_cog_dt(day = "2024-01-01") - -r -#> lon lat smips_totalbucket_mm_20240101 -#> -#> 1: 142.5328 -10.69951 38.68500 -#> 2: 142.5228 -10.70951 43.40917 -#> 3: 142.5328 -10.70951 41.99442 -#> 4: 142.4428 -10.71951 38.94186 -#> 5: 142.4928 -10.71951 43.28778 -#> --- -#> 6873516: 146.8517 -43.62003 40.96997 -#> 6873517: 146.8617 -43.62003 38.49732 -#> 6873518: 146.8717 -43.62003 48.08897 -#> 6873519: 146.8517 -43.63003 33.92958 -#> 6873520: 146.8617 -43.63003 32.85794 +df <- structure(list( + location = c("Corrigin", "Merredin", "Tamworth"), + x = c(117.87, 118.28, 150.84), + y = c(-32.33, -31.48, -31.07) +), +row.names = c(NA, -3L), +class = "data.frame") + +cog_df <- terra::extract(x = r, y = df[, c("x", "y")], xy = TRUE) + +cog_df <- cbind(df$location, cog_df) +names(cog_df) <- c("location", "ID", "smips_totalbucket_mm_20240101", "x", "y") +cog_df +#> location ID smips_totalbucket_mm_20240101 x y +#> 1 Corrigin 1 0.06715473 117.8688 -32.33328 +#> 2 Merredin 2 0.22716530 118.2787 -31.48353 +#> 3 Tamworth 3 93.44989014 150.8408 -31.07365 ``` diff --git a/codemeta.json b/codemeta.json index 1d0534c..f7a66f8 100644 --- a/codemeta.json +++ b/codemeta.json @@ -17,7 +17,16 @@ "@type": "Person", "givenName": "Russell", "familyName": "Edson", - "email": "russell.edson@adelaide.edu.au" + "email": "russell.edson@adelaide.edu.au", + "@id": "https://orcid.org/0000-0002-4607-5396" + } + ], + "contributor": [ + { + "@type": "Person", + "givenName": "Max", + "familyName": "Moldovan", + "email": "max.moldovan@adelaide.edu.au" } ], "maintainer": [ @@ -124,7 +133,7 @@ }, "SystemRequirements": null }, - "fileSize": "175.09KB", + "fileSize": "171.514KB", "codeRepository": "https://github.com/AAGI-AUS/nert", "readme": "https://github.com/AAGI-AUS/nert/blob/main/README.md", "contIntegration": ["https://github.com/AAGI-AUS/nert/actions/workflows/R-CMD-check.yaml", "https://app.codecov.io/gh/AAGI-AUS/nert"] diff --git a/man/nert-package.Rd b/man/nert-package.Rd index 9f2f5dd..60e0cf9 100644 --- a/man/nert-package.Rd +++ b/man/nert-package.Rd @@ -13,7 +13,12 @@ Provides access to Australia's TERN (Terrestrial Ecosystem Research Network) dat Authors: \itemize{ - \item Russell Edson \email{russell.edson@adelaide.edu.au} + \item Russell Edson \email{russell.edson@adelaide.edu.au} (\href{https://orcid.org/0000-0002-4607-5396}{ORCID}) +} + +Other contributors: +\itemize{ + \item Max Moldovan \email{max.moldovan@adelaide.edu.au} [contributor] } } diff --git a/man/read_cog.Rd b/man/read_cog.Rd index d744f31..d436dcc 100644 --- a/man/read_cog.Rd +++ b/man/read_cog.Rd @@ -5,7 +5,7 @@ \title{Read COGs from TERN} \usage{ read_cog( - data = "smips", + dataset = "smips", collection = "totalbucket", day, api_key = get_key(), @@ -14,7 +14,7 @@ read_cog( ) } \arguments{ -\item{data}{A character vector of the data source to be queried, currently +\item{dataset}{A character vector of the data source to be queried, currently only \dQuote{smips}.} \item{collection}{A character vector of the data collection to be queried, @@ -73,8 +73,4 @@ plot(r) \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} } -\seealso{ -Other COGs: -\code{\link{read_cog_dt}()} -} \concept{COGs} diff --git a/man/read_cog_dt.Rd b/man/read_cog_dt.Rd deleted file mode 100644 index 6eecad3..0000000 --- a/man/read_cog_dt.Rd +++ /dev/null @@ -1,73 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/read_cog_dt.R -\name{read_cog_dt} -\alias{read_cog_dt} -\title{Read COGs from TERN} -\usage{ -read_cog_dt( - data = "smips", - collection = "totalbucket", - day, - api_key = get_key() -) -} -\arguments{ -\item{data}{A character vector of the data source to be queried, currently -only \dQuote{smips}.} - -\item{collection}{A character vector of the data collection to be queried, -currenly only \dQuote{smips} is supported with the following collections: -\itemize{ -\item SMindex -\item bucket1 -\item bucket2 -\item deepD -\item runoff -\item totalbucket -Defaults to \dQuote{totalbucket}. Multiple \code{collections} are supported, -\emph{e.g.}, \code{collection = c("SMindex", "totalbucket")}. -}} - -\item{day}{A vector of date(s) to query, \emph{e.g.}, \code{day = "2017-12-31"} or -\code{day = seq.Date(as.Date("2017-12-01"), as.Date("2017-12-31"), "days")}, both -\code{Character} and \code{Date} classes are accepted.} - -\item{api_key}{A \code{character} string containing your \acronym{API} key, -a random string provided to you by \acronym{TERN}, for the request. -Defaults to automatically detecting your key from your local .Renviron, -.Rprofile or similar. Alternatively, you may directly provide your key as -a string here or use functionality like that from \CRANpkg{keyring}. If -nothing is provided, you will be prompted on how to set up your \R session -so that it is auto-detected and a browser window will open at the -\acronym{TERN} website for you to request a key.} -} -\value{ -A \link[data.table:data.table]{data.table::data.table} object -} -\description{ -Read Cloud Optimised Geotiff (\acronym{COG}) files from \acronym{TERN} in -your active \R session as a \CRANpkg{data.table} object. -} -\note{ -Currently only Soil Moisture Integration and Prediction System -(\acronym{SMIPS}) v1.0 is supported. -} -\examples{ -\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} - -r <- read_cog_dt(day = "2024-01-01", api_key = "your_api_key") - -r -\dontshow{\}) # examplesIf} -} -\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} -} -\seealso{ -Other COGs: -\code{\link{read_cog}()} -} -\author{ -Adam H. Sparks \email{adamhsparks@curtin.edu.au} -} -\concept{COGs} From 88242027184d4a1fb1d20afa89de5f314c532377 Mon Sep 17 00:00:00 2001 From: "Adam H. Sparks" Date: Thu, 7 Nov 2024 13:58:34 +0800 Subject: [PATCH 4/4] Update WORDLIST --- codemeta.json | 2 +- inst/WORDLIST | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/codemeta.json b/codemeta.json index f7a66f8..59806c2 100644 --- a/codemeta.json +++ b/codemeta.json @@ -133,7 +133,7 @@ }, "SystemRequirements": null }, - "fileSize": "171.514KB", + "fileSize": "171.536KB", "codeRepository": "https://github.com/AAGI-AUS/nert", "readme": "https://github.com/AAGI-AUS/nert/blob/main/README.md", "contIntegration": ["https://github.com/AAGI-AUS/nert/actions/workflows/R-CMD-check.yaml", "https://app.codecov.io/gh/AAGI-AUS/nert"] diff --git a/inst/WORDLIST b/inst/WORDLIST index d2ff5be..b1d7154 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,7 +1,10 @@ CMD COGs Codecov +Corrigin Geotiff +Merriden +NSW ORCID Optimised Renviron