Skip to content

Commit

Permalink
reactivate s2 calculations and tests on macos (#131)
Browse files Browse the repository at this point in the history
* CRAN release 0.3.0

* reactivate s2 calculations and tests on macos

* include error and instructions for SSL certificate issue with nasa_srtm

* bump version to 0.3.0

* not manuals for internal functions

* disable gfw examples on cran
  • Loading branch information
goergen95 authored Jan 21, 2023
1 parent c995c04 commit fb17ac4
Show file tree
Hide file tree
Showing 30 changed files with 107 additions and 133 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mapme.biodiversity
Title: Efficient Monitoring of Global Biodiversity Portfolios
Version: 0.2.1.9000
Version: 0.3.0
Authors@R: c(
person("Darius A.", "Görgen", , "[email protected]", role = c("aut", "cre")),
person("Om Prakash", "Bhandari", role = "aut")
Expand Down
33 changes: 25 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
# mapme.biodiversity (development version)
# mapme.biodiversity 0.3.0

## Breaking changes

- on MacOS s2-based calculations are now enabled so users can expect the package
to return numerically equivalent results on any operating system (#131)

- the online source for the `nasa_srtm` resource shows an expired SSL certificate
since November 2022. The get_resources()` function now includes an error and
instructions how to disable SSL certification at a users own risk. The
websites maintainers have been contacted and asked to renew the certification. (#131)

## New features

- GFW resources are now updated to use the latest version allowing analysis for
the additional year of 2021 (#123, @fBedecarrats)

- GFW indicators now accecpt numeric `min_size` argument allowing to specify
- GFW indicators now accept numeric `min_size` argument allowing to specify
fractional covers (#110)

- fire indicators now allow the simultaneous calculation of indicators based on
MODIS and VIIRS. Before users had to chose between one of the instruments for
each analysis (#126)

## Bug fixes

- case when one or multiple assets return NA instead of a tibble is now properly
tested and handled (#101)
tested and handled (#101)

- Rasters are no longer temporary written to disk to omit a bug caused by
applying mask/classify to an already existing raster file (#108, @Jo-Schie)
Expand All @@ -23,14 +35,19 @@ tested and handled (#101)

- both, `treecoverloss_emissions` and `treecover_area_and_emissions` now return
0 instead of NaN for observation years where now forest loss occurred (#120)



## Internal

- `.make_global_grid()` now specifies the CRS when constructing the bounding box
and returns the grid in the specified CRS instead of Lat/Lon (#113)
and returns the grid in the specified CRS instead of Lat/Lon (#113)

- `.calc_active_fire_properties` now uses st_coordinates to retrieve locations
of fires (#119, @DavisVaughan)
of fires (#119, @DavisVaughan)

- tests for MacOS have been re-enabled (#131)

- tests for downloading `nasa_srtm` resource are skipped because the SSL certificate
of the online source has expired (#131)


# mapme.biodiversity 0.2.1
Expand Down
13 changes: 1 addition & 12 deletions R/calc_indicator.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ calc_indicators <- function(x, indicators, ...) {
existing_resources, required_resources,
needed = TRUE
)
# Fix for MacOS CI error with duplicated vertices in vector resources
# Error in s2_geography_from_wkb(x, oriented = oriented, check = check) :
# Evaluation error: Found 1 feature with invalid spherical geometry.
# [1] Loop 0 is not valid: Edge 821 is degenerate (duplicate vertex).
# https://github.com/r-spatial/sf/issues/1762 suggests to deactivate s2,
# proposition of https://github.com/r-spatial/sf/issues/1902 to dissable
# s2 and fix the geometry has failed, thus for now falling back to lwgeom
if (Sys.info()["sysname"] == "Darwin" | grepl("darwin", Sys.info()["sysname"])) {
s2_org <- sf_use_s2()
suppressMessages(sf_use_s2(FALSE))
on.exit(suppressMessages(sf_use_s2(s2_org)))
}
for (indicator in indicators) x <- .get_single_indicator(x, indicator, ...)
x
}
Expand All @@ -59,6 +47,7 @@ calc_indicators <- function(x, indicators, ...) {
#' @param ... Additional arguments required by the requested indicators.
#'
#' @keywords internal
#' @noRd
#' @importFrom dplyr relocate last_col
#' @importFrom tidyr nest
.get_single_indicator <- function(x, indicator, ...) {
Expand Down
2 changes: 2 additions & 0 deletions R/calc_treecover_area.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#' @keywords indicator
#' @format A tibble with a column for years and treecover (in ha)
#' @examples
#' if (Sys.getenv("NOT_CRAN") == "true") {
#' library(sf)
#' library(mapme.biodiversity)
#'
Expand Down Expand Up @@ -47,6 +48,7 @@
#' ) %>%
#' calc_indicators("treecover_area", min_size = 1, min_cover = 30) %>%
#' tidyr::unnest(treecover_area)))
#' }
NULL

#' Calculate tree cover per year based on GFW data sets
Expand Down
2 changes: 2 additions & 0 deletions R/calc_treecover_area_and_emissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#' @keywords indicator
#' @format A tibble with a column for years, treecover (in ha), and emissions (in Mg CO2)
#' @examples
#' if (Sys.getenv("NOT_CRAN") == "true") {
#' library(sf)
#' library(mapme.biodiversity)
#'
Expand Down Expand Up @@ -49,6 +50,7 @@
#' ) %>%
#' calc_indicators("treecover_area_and_emissions", min_size = 1, min_cover = 30) %>%
#' tidyr::unnest(treecover_area_and_emissions)))
#' }
NULL


Expand Down
2 changes: 2 additions & 0 deletions R/calc_treecoverloss_emissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#' @keywords indicator
#' @format A tibble with a column for years and emissions (in Mg)
#' @examples
#' if (Sys.getenv("NOT_CRAN") == "true") {
#' library(sf)
#' library(mapme.biodiversity)
#'
Expand Down Expand Up @@ -49,6 +50,7 @@
#' ) %>%
#' calc_indicators("treecoverloss_emissions", min_size = 1, min_cover = 30) %>%
#' tidyr::unnest(treecoverloss_emissions)))
#' }
NULL

#' Calculate emissions statistics
Expand Down
1 change: 1 addition & 0 deletions R/get_nasa_grace.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ NULL
#'
#' @return A character vector
#' @keywords internal
#' @noRd
.get_nasagrace_url <- function(target_year) {
available_years <- c(2003:2022)
dates <- seq.Date(as.Date("2003/02/03"), as.Date("2022/05/16"), by = "week")
Expand Down
40 changes: 34 additions & 6 deletions R/get_nasa_srtm.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
#' SRTM 30m Digital Elevation Model (DEM) layer
#'
#' This resource is published by Farr et al. (2007) "The Shuttle Radar Topography
#' Mission". The layer represents the 30m global terrestrial digital elevation model
#' This resource is published by Jarvis et al. (2008) "Hole-filled seamless SRTM data V4".
#' The layer represents the 30m global terrestrial digital elevation model
#' from the NASA Shuttle Radar Topographic Mission (SRTM), available for download as
#' 5 degree x 5 degree tiles. It is encoded as meter, representing the elevation
#' at the particular grid cell.
#'
#' **Important Note**:
#'
#' As of January 2023, the SSL certificate of the website where this resource is downloaded
#' from has expired. We include a check and inform users that this resource might not
#' be downloaded without unsetting SSL certification checks on their own risk.
#' The maintainers of the website have been contacted and asked to renew the
#' certificate. Until then, users can decide to disable the SSL certification
#' checks for their preferred downloading method. Using wget as an example, the
#' following options can be set to disable the SSL checks at your own risk:
#'
#' \code{httr::set_config(httr::config(ssl_verifypeer = 0L))}
#' \code{options(download.file.method="wget", download.file.extra="--no-check-certificate")}
#'
#' This assumes that your are *not* using the aria2 downloader.
#'
#' @name nasa_srtm
#' @docType data
#' @keywords resource
#' @format A global tiled raster resource available for all land areas.
#' @references NASA Shuttle Radar Topography Mission (SRTM)(2013). Shuttle Radar
#' Topography Mission (SRTM) Global. Distributed by OpenTopography.
#' https://doi.org/10.5069/G9445JDF. Accessed: 2022-03-17
#' @source \url{https://srtm.csi.cgiar.org/}
#' @references Jarvis A., H.I. Reuter, A. Nelson, E. Guevara, 2008,
#' Hole-filled seamless SRTM data V4, International Centre for Tropical Agriculture (CIAT).
#' @source https://srtm.csi.cgiar.org/
NULL


Expand All @@ -29,6 +43,7 @@ NULL
.get_nasa_srtm <- function(x,
rundir = tempdir(),
verbose = TRUE) {
.warn_about_ssl()
# make the SRTM grid and construct urls for intersecting tiles
grid_srtm <- .make_global_grid(
xmin = -180, xmax = 180, dx = 5,
Expand Down Expand Up @@ -82,3 +97,16 @@ NULL
tileId, ".zip"
)
}

.warn_about_ssl <- function(){
status <- try(httr::http_error("https://srtm.csi.cgiar.org/"), silent = TRUE)
if(inherits(status, "try-error")){
msg <- paste0(
"The data source for 'nasa_srtm' has an expired SSL certificate.\n ",
"You can disable SSL checks if you still want to download the resource.\n ",
"Note, that when disabling SSL certification you understand and accept\n ",
"the associated risks. See `?nasa_srtm` for further information."
)
stop(msg)
}
}
1 change: 1 addition & 0 deletions R/get_resource.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ get_resources <- function(x, resources, ...) {
#' function are matched. If there are missing arguments, the default value is
#' used.
#' @keywords internal
#' @noRd
.get_single_resource <- function(x, resource, ...) {
args <- list(...)
atts <- attributes(x)
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
}

status <- download.file(missing_urls[i], missing_filenames[i],
quiet = TRUE, "libcurl",
quiet = TRUE,
mode = ifelse(Sys.info()["sysname"] == "Windows", "wb", "w")
)
if (status != 0) {
Expand Down
18 changes: 0 additions & 18 deletions man/dot-get_nasagrace_url.Rd

This file was deleted.

21 changes: 0 additions & 21 deletions man/dot-get_single_indicator.Rd

This file was deleted.

29 changes: 0 additions & 29 deletions man/dot-get_single_resource.Rd

This file was deleted.

27 changes: 21 additions & 6 deletions man/nasa_srtm.Rd

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

2 changes: 2 additions & 0 deletions man/treecover_area.Rd

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

2 changes: 2 additions & 0 deletions man/treecover_area_and_emissions.Rd

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

2 changes: 2 additions & 0 deletions man/treecoverloss_emissions.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ library(mapme.biodiversity)
library(pbapply)

pboptions(type = "none")
options(pillar.advice = TRUE)
options(pillar.advice = FALSE)
test_check("mapme.biodiversity")
Loading

0 comments on commit fb17ac4

Please sign in to comment.