Skip to content

Commit

Permalink
Fix bug repeated tiles (#100)
Browse files Browse the repository at this point in the history
* fix bug returning repeated tiles

* update NEWS

* included tests for tile bug

* removed warning from README

* added spellcheck
  • Loading branch information
goergen95 authored Sep 9, 2022
1 parent 72ae9fa commit d67b487
Show file tree
Hide file tree
Showing 47 changed files with 322 additions and 89 deletions.
3 changes: 2 additions & 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.0.9000
Version: 0.2.1
Authors@R: c(
person("Darius A.", "Görgen", , "darius2402@web.de", role = c("aut", "cre")),
person("Om Prakash", "Bhandari", role = "aut")
Expand Down Expand Up @@ -54,3 +54,4 @@ Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
SystemRequirements: GDAL (>= 3.0.0), PROJ (>= 4.8.0)
Language: en-GB
11 changes: 10 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# mapme.biodiversity (development version)

# mapme.biodiversity 0.2.1

## Bug fixes
- fixes a serious bug that occurred for tiled resources when multiple assets are within
the same tile resulting in returning the same tile multiple times

## Internal
- tests to catch above mentioned bug have been introduced for tiled resources

# mapme.biodiversity 0.2.0

## Breaking changes
Expand Down Expand Up @@ -132,5 +141,5 @@ only writing to the temporal directory (#22).
## Internal

* Introduced absolute URLS in userguide.Rmd pointing to the online documentation (#59)
* \value tags added to all exported functions explaining what is the output/sideffect (#59)
* \value tags added to all exported functions explaining what is the output/side effect (#59)
* using requireNamespace() instead of installed.packages() to check if packages listed in SUGGEST are loadable (#58)
2 changes: 1 addition & 1 deletion R/calc_active_fire_counts.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Calculate active fire counts based on NASA FIRMS polygons
#'
#' This function allows to efficiently calculate the number of fire
#' events occured in the region of interest from the NASA FIRMS active
#' events occurred in the region of interest from the NASA FIRMS active
#' fire polygon datasets. For each polygon, the fire event counts for
#' the desired year is returned.
#' The required resources for this indicator are:
Expand Down
2 changes: 1 addition & 1 deletion R/calc_active_fire_properties.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Calculate active fire properties based on NASA FIRMS polygons
#'
#' This function allows to efficiently extract the properties of fire
#' events occured in the region of interest from the NASA FIRMS active
#' events occurred in the region of interest from the NASA FIRMS active
#' fire polygon datasets. For each polygon, the fire events properties
#' like fire pixel brightness temperature, and fire radiative power (frp)
#' along with fire hotspots for the desired year is returned.
Expand Down
4 changes: 2 additions & 2 deletions R/calc_indicator.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Compute specific indicators
#'
#' With \code{calc_indicators()} specific biodiversity indicators
#' can be calculated. A requirment is that the ressources that
#' can be calculated. A requirement is that the resources that
#' are mandatory inputs for the requested indicators are available
#' locally. Multiple indicators and their respective additional
#' arguments can be supplied. You can check available indicators and
Expand Down Expand Up @@ -54,7 +54,7 @@ calc_indicators <- function(x, indicators, ...) {
#' This functions let's users calculate on or more biodiversity indicators for
#' a portfolio.
#' @param x A sf object returned by init_portfolio().
#' @param indicator A variable length charcter vector with the indicators to
#' @param indicator A variable length character vector with the indicators to
#' calculate.
#' @param ... Additional arguments required by the requested indicators.
#'
Expand Down
8 changes: 4 additions & 4 deletions R/calc_soilproperties.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#' Calculate Zonal Soil Properties
#'
#' This indicator allows the extraction of zonal statistics for resource layers
#' previously downloaded from soilgrids, thus in total supporting the calculation
#' previously downloaded from SoilGrids, thus in total supporting the calculation
#' of zonal statistics for 10 different soil properties at 6 different depths for
#' a total of 4 different model outputs (stat). Zonal statistics will be calculated
#' for all soilgrid layers that have been previously made available vie \code{get_resources()}.
#' for all SoilGrid layers that have been previously made available vie \code{get_resources()}.
#' The required resource for this indicator is:
#' - [soilgrids]
#'
Expand All @@ -20,8 +20,8 @@
#' @name soilproperties
#' @docType data
#' @keywords indicator
#' @format A tibble with a column for the soilgrid layer, the depth and the model
#' output statistic as well as additionall columns for all zonal statistics
#' @format A tibble with a column for the SoilGrid layer, the depth and the model
#' output statistic as well as additional columns for all zonal statistics
#' specified via \code{stats_soil}
#' @examples
#' library(sf)
Expand Down
4 changes: 2 additions & 2 deletions R/calc_treecover_area.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#'
#' This functions allows to efficiently calculate treecover statistics for
#' polygons. For each year in the analysis timeframe, the forest losses in
#' preceeding and the current years are substracted from the treecover in the
#' preceding and the current years are subtracted from the treecover in the
#' year 2000 and actual treecover figures within the polygon are returned.
#' The required resources for this indicator are:
#' - [gfw_treecover]
#' - [gfw_lossyear]
#'
#' The following arguments can be set:
#' \describe{
#' \item{min_size}{The minum size of a forest patch to be considered as forest in ha.}
#' \item{min_size}{The minimum size of a forest patch to be considered as forest in ha.}
#' \item{min_cover}{The minimum cover percentage per pixel to be considered as forest.}
#' }
#'
Expand Down
2 changes: 1 addition & 1 deletion R/calc_treecover_area_and_emissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#'
#' The following arguments can be set:
#' \describe{
#' \item{min_size}{The minum size of a forest patch to be considered as forest in ha.}
#' \item{min_size}{The minimum size of a forest patch to be considered as forest in ha.}
#' \item{min_cover}{The minimum cover percentage per pixel to be considered as forest.}
#' }
#'
Expand Down
2 changes: 1 addition & 1 deletion R/calc_treecoverloss_emissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#'
#' The following arguments can be set:
#' \describe{
#' \item{min_size}{The minum size of a forest patch to be considered as forest in ha.}
#' \item{min_size}{The minimum size of a forest patch to be considered as forest in ha.}
#' \item{min_cover}{The minimum cover percentage per pixel to be considered as forest.}
#' }
#'
Expand Down
2 changes: 1 addition & 1 deletion R/calc_tri.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Calculate Terrain Ruggedness Index (TRI) statistics
#'
#' Terrain Ruggedness Index is a measurement developed by Riley, et al. (1999).
#' The elevation difference between the center pixel and its eight immediate
#' The elevation difference between the centre pixel and its eight immediate
#' pixels are squared and then averaged and its square root is taken to get
#' the TRI value. This function allows to efficiently calculate terrain ruggedness
#' index (tri) statistics for polygons. For each polygon, the desired statistic/s
Expand Down
2 changes: 1 addition & 1 deletion R/get_chirps.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' of +30 years, anomaly detection and long-term average analysis is also possible.
#' The routine will download the complete archive in order to support long-term
#' average and anomaly calculations with respect to the 1981 - 2010 climate normal
#' period. Thus no additionall arguments need to be specified.
#' period. Thus no additional arguments need to be specified.
#'
#'
#' @name chirps
Expand Down
2 changes: 1 addition & 1 deletion R/get_esalandcover.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ NULL
xmin = -180, xmax = 180, dx = 20,
ymin = -60, ymax = 80, dy = 20
)
tile_ids <- unlist(st_intersects(x, grid_esa))
tile_ids <- unique(unlist(st_intersects(x, grid_esa)))
if (length(tile_ids) == 0) {
stop(paste("The extent of the portfolio does not ",
"intersect with the Land Cover grid.",
Expand Down
4 changes: 2 additions & 2 deletions R/get_gfw_emissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' "Global maps of twenty-first century forest carbon fluxes.". It
#' represents "the greenhouse gas
#' emissions arising from stand-replacing forest disturbances that occurred in
#' each modeled year (megagrams CO2 emissions/ha, between 2001 and 2020).
#' each modelled year (megagrams CO2 emissions/ha, between 2001 and 2020).
#' Emissions include all relevant ecosystem carbon pools (aboveground biomass,
#' belowground biomass, dead wood, litter, soil) and greenhouse gases (CO2, CH4,
#' N2O)." The area unit that is downloaded here corresponds to the
Expand Down Expand Up @@ -41,7 +41,7 @@ NULL

index_file <- system.file("extdata", "greenhouse_index.geosjon", package = "mapme.biodiversity")
spatialindex <- st_read(index_file, quiet = TRUE)
tile_ids <- unlist(st_intersects(x, spatialindex))
tile_ids <- unique(unlist(st_intersects(x, spatialindex)))
tile_ids <- spatialindex$tile_id[tile_ids]
urls <- as.character(
spatialindex$Mg_CO2e_px_download[spatialindex$tile_id %in% tile_ids]
Expand Down
4 changes: 2 additions & 2 deletions R/get_gfw_lossyear.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Year of forest loss occurence
#' Year of forest loss occurrence
#'
#' This resource is part of the publication by Hansen et al. (2013)
#' "High-Resolution Global Maps of 21st-Century Forest Cover Change". It
Expand Down Expand Up @@ -65,7 +65,7 @@ NULL
xmin = -180, xmax = 170, dx = 10,
ymin = -50, ymax = 80, dy = 10
)
tile_ids <- unlist(st_intersects(x, grid_gfc))
tile_ids <- unique(unlist(st_intersects(x, grid_gfc)))
if (length(tile_ids) == 0) {
stop("The extent of the portfolio does not intersect with the GFW grid.",
call. = FALSE
Expand Down
2 changes: 1 addition & 1 deletion R/get_gfw_treecover.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ NULL
xmin = -180, xmax = 170, dx = 10,
ymin = -50, ymax = 80, dy = 10
)
tile_ids <- unlist(st_intersects(x, grid_gfc))
tile_ids <- unique(unlist(st_intersects(x, grid_gfc)))
if (length(tile_ids) == 0) {
stop("The extent of the portfolio does not intersect with the GFW grid.",
call. = FALSE
Expand Down
2 changes: 1 addition & 1 deletion R/get_nasa_grace.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ NULL
}


#' Helper function to construct GRACE urls
#' Helper function to construct GRACE URLs
#'
#' @param target_year
#'
Expand Down
3 changes: 2 additions & 1 deletion R/get_nasa_srtm.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ NULL
xmin = -180, xmax = 180, dx = 5,
ymin = -60, ymax = 60, dy = 5
)
tile_ids <- unlist(st_intersects(x, grid_srtm))
tile_ids <- unique(unlist(st_intersects(x, grid_srtm)))
if (length(tile_ids) == 0) {
stop("The extent of the portfolio does not intersect with the SRTM grid.")
}
urls <- unlist(sapply(tile_ids, function(tile) .get_srtm_url(tile)))

if (attr(x, "testing")) {
return(basename(urls))
}
Expand Down
2 changes: 1 addition & 1 deletion R/get_resource.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ get_resources <- function(x, resources, ...) {
if (selected_resource[[1]]$type == "raster") {
tindex_file <- file.path(rundir, paste0("tileindex_", resource, ".gpkg"))
if (file.exists(tindex_file)) file.remove(tindex_file)
footprints <- lapply(downloaded_files, function(file) {
footprints <- lapply(unique(downloaded_files), function(file) {
tmp <- rast(file)
footprint <- st_as_sf(st_as_sfc(st_bbox(tmp)))
st_geometry(footprint) <- "geom"
Expand Down
12 changes: 6 additions & 6 deletions R/get_soilgrids.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Soildgrids data layers
#' SoilGrids data layers
#'
#' Soilgrids is a project combining global observation data with
#' SoilGrids is a project combining global observation data with
#' machine learning to map the spatial distribution of soil properties across
#' the globe. It is produced at a spatial resolution of 250 meters and each
#' parameters is mapped at different depths. In order to be able to assess
Expand All @@ -23,9 +23,9 @@
#'
#' Users can specify the following arguments:
#' \describe{
#' \item{layer}{The soil parameter as a single charachter}
#' \item{depth}{The requested depth as a single chrachter}
#' \item{stat}{The predicted statistic as a single charachter}
#' \item{layer}{The soil parameter as a single character}
#' \item{depth}{The requested depth as a single character}
#' \item{stat}{The predicted statistic as a single character}
#' }
#'
#' Except for \code{ocs}, which is only available for a depth of \code{"0-30cm"},
Expand Down Expand Up @@ -67,7 +67,7 @@ NULL
#' @param x A sf portfolio object
#' @param layers A charchter vector indicating the layers to download from
#' soilgrids
#' @param depths A charachter vector indicating the depths to download
#' @param depths A character vector indicating the depths to download
#' @param stats A chrachter vector indicating the statistics to download.
#' @param rundir The directory where temporary and final results are written to.
#' @param verbose A logical controlling the verbosity.
Expand Down
4 changes: 1 addition & 3 deletions R/get_worldclim.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' temperature, maximum temperature, and mean precipitation layers. The layers are
#' available to download for the period 2000 - 2018 on monthly basis from WorldClim.
#'
#' Enlisted different resources can be reqested with their dedicated functions:
#' Enlisted different resources can be requested with their dedicated functions:
#' \describe{
#' \item{tmin}{Encoded as (°C), representing the minimum temperature per output grid cell.}
#' \item{tmax}{Encoded as (°C), representing the maximum temperature per output grid cell.}
Expand Down Expand Up @@ -42,8 +42,6 @@ NULL
}




#' Downloads WorldClim Maximum Temperature layer
#'
#' This resource represents the maximum temperature, layers available to
Expand Down
2 changes: 1 addition & 1 deletion R/portfolio.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#' added to the portfolio. Defaults to TRUE. Setting it to FALSE can be of use
#' e.g. if a previous download has terminated unexpectedly in order to resume.
#' @return The sf portfolio object `x` with amended attributes controlling the
#' processing behavior further down the processing chain.
#' processing behaviour further down the processing chain.
#' @keywords function
#' @export
init_portfolio <- function(x,
Expand Down
8 changes: 2 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ output: github_document

## About

Biodiversity areas, especially primary forests, provide multiple ecosystem services for the local population and the planet as a whole. The rapid expansion of human landuse into natural ecosystems and the impacts of the global climate crisis put natural ecosystems and the global biodiversity under threat.
Biodiversity areas, especially primary forests, provide multiple ecosystem services for the local population and the planet as a whole. The rapid expansion of human land use into natural ecosystems and the impacts of the global climate crisis put natural ecosystems and the global biodiversity under threat.

The mapme.biodiversity package helps to analyse a number of biodiversity related indicators and biodiversity threats based on freely available geodata-sources such as the Global Forest Watch. It supports computational efficient routines and heavy parallelization in cloud-infrastructures such as AWS or AZURE using in the statistical programming language R. The package allows for the analysis of global biodiversity portfolios with a thousand or millions of AOIs which is normally only possible on dedicated platforms such as the Google Earth Engine. It provides the possibility to e.g. analyze the World Database of Protected Areas (WDPA) for a number of relevant indicators. The primary use case of this package is to support scientific analysis and data science for individuals and organizations who seek to preserve the planet biodiversity. It's development is funded by the German Development Bank KfW.
The mapme.biodiversity package helps to analyse a number of biodiversity related indicators and biodiversity threats based on freely available geodata-sources such as the Global Forest Watch. It supports computational efficient routines and heavy parallelization in cloud-infrastructures such as AWS or AZURE using in the statistical programming language R. The package allows for the analysis of global biodiversity portfolios with a thousand or millions of AOIs which is normally only possible on dedicated platforms such as the Google Earth Engine. It provides the possibility to e.g. analyse the World Database of Protected Areas (WDPA) for a number of relevant indicators. The primary use case of this package is to support scientific analysis and data science for individuals and organizations who seek to preserve the planet biodiversity. It's development is funded by the German Development Bank KfW.


## Installation
Expand Down Expand Up @@ -80,7 +80,3 @@ list column to the original object.

Head over to the [online documentation](https://mapme-initiative.github.io/mapme.biodiversity/index.html)
find more detailed information about the package.

## Important note for global scale analysis

In the current version on CRAN (0.1.2) there is a bug that may cause issue when downloading tiled data (Global Forest Watch, ESA Landcover, SRTM) for global portfolios. It is described [here](https://github.com/mapme-initiative/mapme.biodiversity/issues/84). It is fixed in the current version on Github which you can download as described above.
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cloud-infrastructures such as AWS or AZURE using in the statistical
programming language R. The package allows for the analysis of global
biodiversity portfolios with a thousand or millions of AOIs which is
normally only possible on dedicated platforms such as the Google Earth
Engine. It provides the possibility to e.g. analyze the World Database
Engine. It provides the possibility to e.g. analyse the World Database
of Protected Areas (WDPA) for a number of relevant indicators. The
primary use case of this package is to support scientific analysis and
data science for individuals and organizations who seek to preserve the
Expand Down Expand Up @@ -151,17 +151,7 @@ object.
## 1 478140 Sierra de Neiba National Park DOM 1 2016 2832 2357.
## 2 478140 Sierra de Neiba National Park DOM 1 2017 3468 2345.
## # … with 1 more variable: geom <POLYGON [°]>
## # ℹ Use `colnames()` to see all variable names

Head over to the [online
documentation](https://mapme-initiative.github.io/mapme.biodiversity/index.html)
find more detailed information about the package.

## Important note for global scale analysis

In the current version on CRAN (0.1.2) there is a bug that may cause
issue when downloading tiled data (Global Forest Watch, ESA Landcover,
SRTM) for global portfolios. It is described
[here](https://github.com/mapme-initiative/mapme.biodiversity/issues/84).
It is fixed in the current version on Github which you can download as
described above.
Loading

0 comments on commit d67b487

Please sign in to comment.