Skip to content

Commit

Permalink
Handle getting info for multi band coverages. Resolves #20
Browse files Browse the repository at this point in the history
  • Loading branch information
annakrystalli committed Sep 29, 2022
1 parent b533295 commit 4445187
Show file tree
Hide file tree
Showing 14 changed files with 496 additions and 419 deletions.
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: EMODnetWCS
Title: Access EMODnet Web Coverage Service data through R
Version: 0.0.0.9010
Version: 0.0.0.9011
Authors@R: c(
person("Anna", "Krystalli", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-2378-4915")),
Expand All @@ -16,6 +16,7 @@ Imports:
checkmate,
cli,
curl,
geometa,
glue,
httr,
memoise,
Expand All @@ -36,14 +37,15 @@ Suggests:
withr
Config/testthat/edition: 3
Remotes:
eblondel/ows4R
eblondel/ows4R,
eblondel/geometa
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.0
RoxygenNote: 7.2.1
URL: https://github.com/EMODnet/EMODnetWCS,
https://emodnet.github.io/EMODnetWCS/
BugReports: https://github.com/EMODnet/EMODnetWCS/issues
Depends:
R (>= 4.1), ows4R (>= 0.3-1)
R (>= 4.1), ows4R (>= 0.3-2)
LazyData: true
VignetteBuilder: knitr
16 changes: 10 additions & 6 deletions R/info.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@
#' - **`service_name`:** the EMODnet WCS service name.
#' - **`service_url`:** the EMODnet WCS service URL.
#' - **`coverage_ids`:** the coverage ID.
#' - **`band_description`:** the description of the data contained in the band of the coverage.
#' - **`band_uom`:** the unit of measurement of the data contained in the band of the coverage.
#' - **`constraint`:** the range of values of the data contained in the band of the coverage.
#' - **`band_description`:** the description of the data contained each band of the coverage.
#' - **`band_uom`:** the unit of measurement of the data contained each band of the coverage.
#' If all bands share the same unit of measurement, the single shared uom is shown.
#' - **`constraint`:** the range of values of the data contained in each band of the coverage.
#' If all bands share the same constraint, the single shared constraint range is shown.
#' - **`nil_value`:** the nil value of the data contained in the band of the coverage.
#' - **`grid_size`:** the spatial size of the coverage grid (ncol x nrow).
#' - **`resolution`:** the spatial resolution (pixel size) of the coverage grid
Expand Down Expand Up @@ -189,10 +191,12 @@ emdn_get_wcs_info_all <- memoise::memoise(.emdn_get_wcs_info_all)
service_name = wcs$getUrl(),
service_url = get_service_name(wcs$getUrl()),
coverage_id = purrr::map_chr(summaries, ~ error_wrap(.x$getId())),
band_description = purrr::map_chr(summaries, ~ error_wrap(emdn_get_band_name(.x))),
band_uom = purrr::map_chr(summaries, ~ error_wrap(emdn_get_uom(.x))),
band_description = purrr::map_chr(summaries, ~ error_wrap(emdn_get_band_name(.x) |>
paste(collapse = ", "))),
band_uom = purrr::map_chr(summaries, ~ error_wrap(emdn_get_uom(.x) |>
conc_band_uom())),
constraint = purrr::map_chr(summaries, ~ error_wrap(emdn_get_constraint(.x) |>
paste(collapse = ", "))),
conc_constraint())),
nil_value = purrr::map_dbl(summaries, ~ error_wrap(emdn_get_nil_value(.x))),
dim_n = purrr::map_int(summaries, ~ error_wrap(length(.x$getDimensions()))),
dim_names = purrr::map_chr(summaries, ~ error_wrap(emdn_get_dimensions_info(.x, format = "character"))),
Expand Down
58 changes: 51 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ emdn_get_coverage_dim_coefs <- function(wcs,
#' in a coverage.
#' - `emdn_get_band_name` a character vector of band names.
#' - `emdn_get_uom` a character vector of band units of measurement.
#' - `emdn_get_constraint` a numeric vector of length 2 indicating the min and max
#' of the data contained in the bands of the coverage.
#' - `emdn_get_constraint` a list of numeric vectors of length 2 indicating the min and max
#' values of the data contained in each bands of the coverage.
#' - `emdn_get_grid_size` a numeric vector of length 2 giving the spatial size in
#' grid cells (pixels) of the coverage grid (ncol x nrow)
#' - `emdn_get_resolution` a numeric vector of length 2 giving the spatial resolution
Expand Down Expand Up @@ -256,23 +256,46 @@ emdn_get_nil_value <- function(summary) {
#' @describeIn emdn_get_bbox Get the band names of a coverage.
#' @export
emdn_get_band_name <- function(summary) {
summary$getDescription()$rangeType$DataRecord$field$Quantity$description$value
fields <- summary$getDescription()$rangeType$field
band_names <- fields |>
purrr::map_chr(~.x$description)

attr(band_names, "uom") <- fields |>
purrr::map_chr(~.x$uom$attrs$code)

return(band_names)
}

#' @describeIn emdn_get_bbox Get the units of measurement of the data contained in
#' the bands values of a coverage.
#' @export
emdn_get_uom <- function(summary) {
summary$getDescription()$rangeType$DataRecord$field$Quantity$uom$attrs$code
fields <- summary$getDescription()$rangeType$field
uom <- fields |>
purrr::map_chr(~.x$uom$attrs$code)

names(uom) <- fields |>
purrr::map_chr(~.x$description)

return(uom)
}

#' @describeIn emdn_get_bbox Get the range of values of the data contained in
#' the bands of the coverage.
#' @export
emdn_get_constraint <- function(summary) {
summary$getDescription()$rangeType$DataRecord$field$Quantity$constraint$
AllowedValues$interval$value |> strsplit(" ") |> unlist() |>
as.numeric()
fields <- summary$getDescription()$rangeType$field
constraints <- fields |>
purrr::map(
~.x$constraint |>
strsplit(" ") |>
unlist() |>
as.numeric()
)
names(constraints) <- fields |>
purrr::map_chr(~.x$description)

return(constraints)

}

Expand Down Expand Up @@ -509,3 +532,24 @@ get_service_name <- function(service_url) {
get_capabilities <- function(wcs) {
wcs$getCapabilities()
}

conc_band_uom <- function(x) {

if(length(unique(x)) == 1L) {
return(unique(x))
}

return(paste(x, collapse = ", "))
}

conc_constraint <- function(x) {

x <- purrr::map_chr(x,
~paste(.x, collapse = "-"))

if(length(unique(x)) == 1L) {
return(unique(x))
}

return(paste(x, collapse = ", "))
}
36 changes: 18 additions & 18 deletions man/emdn_get_bbox.Rd

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

12 changes: 6 additions & 6 deletions man/emdn_get_coverage_summaries.Rd

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

16 changes: 9 additions & 7 deletions man/emdn_get_wcs_info.Rd

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

Loading

0 comments on commit 4445187

Please sign in to comment.