Skip to content

Commit

Permalink
Returns a single (or multiple) station in get_station_metadata() (#51)
Browse files Browse the repository at this point in the history
* Clarity in docs

* Adds functionality to filter metadata results by station code or name.

* Update WORDLIST

* Update codemeta.json

* Fix cross-ref to data.table

* Tidy up references to data.table
  • Loading branch information
Adam H. Sparks committed Dec 6, 2023
1 parent 435648d commit 8166c92
Show file tree
Hide file tree
Showing 44 changed files with 185 additions and 56 deletions.
4 changes: 2 additions & 2 deletions R/find_forecast_towns.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#' # find forecast towns near Esperance, WA
#' find_forecast_towns(longitude = 121.8913, latitude = -33.8614)
#'
#' @return A [data.table::data.table] of all forecast towns (in this package)
#' sorted by distance from \var{latitude} and \var{longitude}, ascending.
#' @return A [data.table] of all forecast towns (in this package) sorted by
#' distance from \var{latitude} and \var{longitude}, ascending.
#' @author Hugh Parsonage, \email{hugh.parsonage@@gmail.com}, and James Goldie,
#' \email{me@@jamesgoldie.dev}, and Adam H. Sparks,
#' \email{adam.sparks@@dpird.wa.gov.au}
Expand Down
2 changes: 1 addition & 1 deletion R/find_nearby_stations.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#' stations in the \acronym{DPIRD} network should be included in the results.
#' Defaults to `FALSE` with closed stations not included.
#'
#' @return A [data.table::data.table] with `station_code`, `station_name`,
#' @return A [data.table] with `station_code`, `station_name`,
#' `latitude`, `longitude`, `elev_m`, `state`, `owner`, and `distance`.
#' Data are sorted by increasing distance from station or location of
#' interest.
Expand Down
4 changes: 2 additions & 2 deletions R/get_ag_bulletin.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#'
#' @return
#' A data frame as a `weatherOz_tbl` object (inherits and is fully compatible
#' with [data.table::data.table]) of Australia \acronym{BOM} agricultural
#' bulletin information.
#' with [data.table]) of Australia \acronym{BOM} agricultural bulletin
#' information.
#'
#' @note Data and Information Use
#' Please note the copyright notice and disclaimer,
Expand Down
5 changes: 4 additions & 1 deletion R/get_bom_metadata.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#' Fetch and Clean BOM Metadata for SILO Stations
#'
#' This function caches the file during a user's session for faster responses.
#' Starting a new \R session will delete this file.
#'
#' @return a \CRANpkg{data.table} of BOM station metadata.
#' @keywords internal
#' @keywords Internal
#' @noRd

.get_bom_metadata <- function() {
Expand Down
2 changes: 1 addition & 1 deletion R/get_coastal_forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' }
#'
#' @return
#' A [data.table::data.table] of an Australia \acronym{BOM} Coastal Waters
#' A [data.table] of an Australia \acronym{BOM} Coastal Waters
#' Forecast.
#'
#' @examplesIf interactive()
Expand Down
2 changes: 1 addition & 1 deletion R/get_data_drill.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
#' observations for that day of year}
#' }
#'
#' @return a [data.table::data.table] with the weather data queried with the
#' @return a [data.table] with the weather data queried with the
#' weather variables in alphabetical order. The first eight columns will
#' always be:
#'
Expand Down
2 changes: 1 addition & 1 deletion R/get_dpird_availability.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#' * availabilityYearToDateSince12AM, and
#' * availabilityYearToDateTo9AM
#'
#' @return a [data.table::data.table] with `station_code` and the requested
#' @return a [data.table] with `station_code` and the requested
#' metadata.
#'
#' @family DPIRD
Expand Down
2 changes: 1 addition & 1 deletion R/get_dpird_extremes.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
#' * heatConditionYearToDateMinutes, and
#' * heatConditionYearToDateStartTime
#'
#' @return a [data.table::data.table] of one row with `station_code`,
#' @return a [data.table] of one row with `station_code`,
#' `station_name`, `latitude`, `longitude`, `date_time` of the query and the
#' extreme weather information according to the value(s) selected.
#'
Expand Down
2 changes: 1 addition & 1 deletion R/get_dpird_minute.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#' Universal Time \sQuote{UTC} returned by the \acronym{API} to Australian
#' Western Standard Time \sQuote{AWST}.
#'
#' @return a [data.table::data.table] with `station_code` and the date interval
#' @return a [data.table] with `station_code` and the date interval
#' queried together with the requested weather variables.
#'
#' @examples
Expand Down
2 changes: 1 addition & 1 deletion R/get_dpird_summaries.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
#' * windAvgSpeed, and
#' * windMaxSpeed
#'
#' @return a [data.table::data.table] with `station_code` and the date interval
#' @return a [data.table] with `station_code` and the date interval
#' queried together with the requested weather variables in alphabetical
#' order. The first ten columns will always be:
#'
Expand Down
2 changes: 1 addition & 1 deletion R/get_patched_point.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
#' observations for that day of year.}
#' }
#'
#' @return a [data.table::data.table] with the weather data queried with the
#' @return a [data.table] with the weather data queried with the
#' weather variables in alphabetical order. The first eight columns will
#' always be:
#'
Expand Down
2 changes: 1 addition & 1 deletion R/get_precis_forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' }
#'
#' @return
#' A [data.table::data.table] of an Australia \acronym{BOM} précis seven day
#' A [data.table] of an Australia \acronym{BOM} précis seven day
#' forecasts for \acronym{BOM} selected towns.
#'
#' @examplesIf interactive()
Expand Down
2 changes: 1 addition & 1 deletion R/get_radar_imagery.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @details Valid \acronym{BOM} \acronym{radar} ID for each location required.
#'
#' @return
#' A [data.table::data.table] of all selected \acronym{radar} locations with
#' A [data.table] of all selected \acronym{radar} locations with
#' location information and \var{product_ids}.
#'
#' @references
Expand Down
51 changes: 43 additions & 8 deletions R/get_station_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@
#' that exist in \acronym{SILO}, but lack metadata from \acronym{BOM}, the
#' rows will exist to indicate that the station is in the \acronym{SILO} data
#' set, but there is no corresponding \acronym{BOM} metadata available.
#'
#' @param station_code An optional value that should be provided as a single
#' `string` value or character `vector` of station codes for which to return
#' metadata. If this or `station_name` are not provided, all station metadata
#' is returned by default. If this and `station_name` are both provided, this
#' takes precedence and values corresponding to this input will be returned.
#' @param station_name An optional value that should be provided as either a
#' single `string` or character `vector` of station names for which to return
#' metadata. Fuzzy matching is used, \emph{e.g.}, using
#' `c("brisbane", "melbourne")` will return rows for \dQuote{Brisbane},
#' \dQuote{Brisbane Aero}, \dQuote{Mt Brisbane},
#' \dQuote{City of Melbourne Bay}, \dQuote{Selbourne Kirnbrae},
#' \dQuote{Maroondah Weir Melbourne Water}, \dQuote{Melbourne Airport} and
#' \dQuote{Melbourne Botanical Gardens} `station_name` values. If this or
#' `station_code` are not provided, all station metadata is returned by
#' default. Using `station_code` will always override this argument if both
#' are provided.
#' @param which_api A `string` value that indicates which \acronym{API} to use.
#' Valid values are `all`, for both \acronym{SILO} (\acronym{BOM} data) and
#' \acronym{DPIRD} \acronym{API}s; `silo` for only stations from the
Expand Down Expand Up @@ -49,7 +64,7 @@
#' get_station_metadata(api_key = "your_api_key")
#' }
#'
#' @return a [data.table::data.table] of \acronym{BOM} weather stations'
#' @return A [data.table] of \acronym{BOM} weather stations'
#' metadata for stations available from \acronym{SILO} and weather stations'
#' metadata for stations available from \acronym{DPIRD}'s Weather 2.0
#' \acronym{API} with the following columns sorted by `state` and
Expand Down Expand Up @@ -93,7 +108,9 @@
#' @export

get_station_metadata <-
function(which_api = "all",
function(station_code = NULL,
station_name = NULL,
which_api = "all",
api_key,
include_closed = FALSE,
rich = FALSE) {
Expand Down Expand Up @@ -155,12 +172,30 @@ get_station_metadata <-
"wmo"
))

# lastly, if user wants all stations return them, else return only open ones
if (isTRUE(include_closed)) {
return(out[])
} else {
return(subset(out, status == "open")[])
# if user wants all stations return them, else return only open ones
if (isFALSE(include_closed)) {
out <- out[status == "open", ]
}

# filter for `station_code` and call it good if that's specified, else
# search for station names, otherwise just return everything (default)
# Here, new vectors are created to allow for subsetting since the data frame
# has cols with these respective names already and therefore it will not
# subset until you rename the user-provided vector of values.
if (!is.null(station_code)) {
station_code_user <- station_code
return(out[station_code %in% station_code_user, ][])
} else if (!is.null(station_name)) {
station_name_user <- station_name
indices <-
unlist(lapply(
X = station_name_user,
FUN = agrep,
x = out$station_name
))
return(out[indices, ][])
}
return(out[])
}


Expand Down
2 changes: 1 addition & 1 deletion R/parse_ag_bulletin.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#' Australia in the same fashion as [get_precis_forecast()], provided that the
#' files are all present in the directory.
#'
#' @return A [data.table::data.table] of Australia \acronym{BOM} agricultural
#' @return A [data.table] of Australia \acronym{BOM} agricultural
#' bulletin information.
#'
#' @examplesIf interactive()
Expand Down
2 changes: 1 addition & 1 deletion R/parse_coastal_forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#' the files are all present in the directory.
#'
#' @return
#' A [data.table::data.table] of an Australia \acronym{BOM} Coastal Waters
#' A [data.table] of an Australia \acronym{BOM} Coastal Waters
#' Forecast.
#'
#' @examplesIf interactive()
Expand Down
2 changes: 1 addition & 1 deletion R/parse_precis_forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#' files are all present in the directory.
#'
#' @return
#' A [data.table::data.table] of Australia \acronym{BOM} précis seven-day
#' A [data.table] of Australia \acronym{BOM} précis seven-day
#' forecasts for \acronym{BOM} selected towns.
#'
#' @examplesIf interactive()
Expand Down
4 changes: 2 additions & 2 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "R",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 4.3.1 (2023-06-16)",
"runtimePlatform": "R version 4.3.2 (2023-10-31)",
"author": [
{
"@type": "Person",
Expand Down Expand Up @@ -530,7 +530,7 @@
"applicationCategory": "Tools",
"isPartOf": "https://www.agric.wa.gov.au/",
"keywords": ["dpird", "bom", "meteorological-data", "weather-forecast", "australia", "weather", "weather-data", "meteorology", "western-australia", "australia-bureau-of-meteorology", "western-australia-agriculture", "rstats", "climate", "api-client", "data", "weather-api", "rainfall", "r"],
"fileSize": "11300.674KB",
"fileSize": "12670.8KB",
"releaseNotes": "https://github.com/DPIRD-FSI/weatherOz/blob/master/NEWS.md",
"readme": "https://github.com/DPIRD-FSI/weatherOz/blob/main/README.md",
"contIntegration": ["https://github.com/DPIRD-FSI/weatherOz/actions", "https://app.codecov.io/gh/DPIRD-FSI/weatherOz?branch=main"],
Expand Down
4 changes: 4 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ASCE
ASCE’s
AUS
AWST
Aero
BOM
BOM's
Beswick
Expand Down Expand Up @@ -34,8 +35,10 @@ GeoTIFF
Indooroopilly
JSON
Kaushal
Kirnbrae
Licence
Lifecycle
Maroondah
Modelling
Moodie
NSW
Expand All @@ -54,6 +57,7 @@ Rayner
Renviron
SHTML
SILO's
Selbourne
Siddique
Southwood
SpatRaster
Expand Down
4 changes: 2 additions & 2 deletions man/find_forecast_towns.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/find_nearby_stations.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/get_ag_bulletin.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/get_available_radar.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/get_coastal_forecast.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/get_data_drill.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/get_dpird_availability.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/get_dpird_extremes.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/get_dpird_minute.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/get_dpird_summaries.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/get_patched_point.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/get_precis_forecast.Rd

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

0 comments on commit 8166c92

Please sign in to comment.