Learn R Programming

mapme.biodiversity

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 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 parallel computing in cloud-infrastructures such as AWS or Microsoft 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. Its development is funded by the German Development Bank KfW.

Installation

The package and its dependencies can be installed from CRAN via:

install.packages("mapme.biodiversity", dependencies = TRUE)

To install the development version, use the following command:

remotes::install_github("https://github.com/mapme-initiative/mapme.biodiversity", dependencies = TRUE)

Available resources and indicators

Below is a list of the resources currently supported by mapme.biodiversity.

namedescriptionlicence
accessibility_2000Accessibility data for the year 2000 from the Global Accessibility Map projectSee JRC data policy: https://joint-research-centre.ec.europa.eu/jrc-mission-statement-work-programme/data-policy_en
acledArmed Conflict Location & Event Data (ACLED)Visit acleddata.com
biodiversity_intactness_indexBiodiversity Intactness IndexCC-BY-4.0
chelsaClimatologies at High resolution for the Earth Land Surface Areas (CHELSA)Unknown - Must cite!
chirpsClimate Hazards Group InfraRed Precipitation with Station data (CHIRPS)CC - unknown
esalandcoverCopernicus Land Monitoring Service (CLMS) 100 meter land cover productCC-BY 4.0
fritz_et_alDrivers of deforestation in the tropicsCC-BY 4.0
gfw_emissionsGlobal Forest Watch - CO2 Emssions caused by forest cover lossCC-BY 4.0
gfw_lossyearGlobal Forest Watch - Year of forest cover loss occurenceCC-BY 4.0
gfw_treecoverGlobal Forest Watch - Percentage of canopy closure in 2000CC-BY 4.0
global_surface_water_changeGlobal Surface Water - Change of water occurrence intensityhttps://www.copernicus.eu/en/access-data
global_surface_water_occurrenceGlobal Surface Water - Percentage of water occurrencehttps://www.copernicus.eu/en/access-data
global_surface_water_recurrenceGlobal Surface Water - Percentage of water recurrencehttps://www.copernicus.eu/en/access-data
global_surface_water_seasonalityGlobal Surface Water - Seasonality of water occurrrencehttps://www.copernicus.eu/en/access-data
global_surface_water_transitionsGlobal Surface Water - Transition classeshttps://www.copernicus.eu/en/access-data
gmwGlobal Mangrove Watch - Vector data of mangrove extentCC BY 4.0
gsw_time_seriesGlobal Surface Water - Yearly Time Serieshttps://global-surface-water.appspot.com/download
humanfootprintTime series on human pressures on natural ecosystems.CC BY 4.0
ipbes_biomesGlobal Assessment Report on Biodiversity and Ecosystem Services division of the earth’s surface into biomes and anthromes.CC 4.0
irr_carbonAmount of carbon irrecoverably lost by a typical land use conversion event until mid-century.CC NC 4.0
iucnIUCN Species Richness Raser Datasethttps://www.iucnredlist.org/terms/terms-of-use
key_biodiversity_areasKey Biodiversity Areashttps://www.keybiodiversityareas.org/termsofservice
man_carbonAmount of carbon that is manageable by humans.CC NC 4.0
mcd64a1MODIS Burned Area Monthly Product (Aqua and Terra)https://lpdaac.usgs.gov/data/data-citation-and-policies/
nasa_graceNASA Gravity Recovery And Climate Experiment (GRACE) - Measurments of Earth’s mass and water changeshttps://nasagrace.unl.edu/About.aspx
nasa_srtmNASA Shuttle Radar Topography Mission (SRTM) Digital Elevation Model (DEM)https://lpdaac.usgs.gov/data/data-citation-and-policies/
nelson_et_alGlobal maps of traveltime to citiesCC-BY 4.0
soilgridsISRIC - Modelled global soil property layersCC-BY 4.0
teowTerrestrial Ecosystems of the World (TEOW) from WWF-USunknown
ucdp_gedUCDP Georeferenced Event Dataset (UCDP GED)CC-BY 4.0
vul_carbonAmount of carbon that is vulnerable to a typical land use conversion event.CC NC 4.0
worldclim_max_temperatureWorldClim - Monthly maximum temperature 1960 - 2021https://www.worldclim.org/about.html
worldclim_min_temperatureWorldClim - Monthly minimum temperature 1960 - 2021https://www.worldclim.org/about.html
worldclim_precipitationWorldClim - Monthly precipitation 1960 - 2021https://www.worldclim.org/about.html
worldpopWorldPop - Unconstrained Global Mosaics 2000 - 2020CC-BY 4.0

Next, is a list of supported indicators.

namedescription
biodiversity_intactness_indexAveraged biodiversity intactness index.
biomeAreal statistics of biomes from TEOW
burned_areaMonthly burned area detected by MODIS satellites
deforestation_driversAreal statistics of deforestation drivers
drought_indicatorRelative wetness statistics based on NASA GRACE
ecoregionAreal statstics of ecoregions based on TEOW
elevationStatistics of elevation based on NASA SRTM
exposed_population_acledNumber of people exposed to conflicts based on ACLED
exposed_population_ucdpNumber of people exposed to conflicts based on UCDP GED
fatalities_acledNumber of fatalities by event type based on ACLED.
fatalities_ucdpNumber of fatalities by group of conflict based on UCDP GED
gsw_changeStatistics of the surface water change layer by JRC
gsw_occurrenceAreal statistic of surface water based on occurrence threshold
gsw_recurrenceAreal statistic of surface water based on reccurence threshold
gsw_seasonalityAreal statistic of surface water by seasonality
gsw_time_seriesGlobal Surface Water - Yearly Time Series area estimation of water classes.
gsw_transitionsAreal statistics of surface water grouped by transition class
humanfootprintStatistics of the human footprint data set per polygon.
ipbes_biomesArea distibution of IBPES biomes within a polygon.
irr_carbonStatistics of irrecoverable carbon per polygon.
key_biodiversity_areasArea estimation of intersection with key biodiversity areas.
landcoverAreal statistics grouped by landcover class
man_carbonStatistics of manageable carbon per polygon.
mangroves_areaArea covered by mangroves
population_countStatistic of population counts
precipitation_chelsaStatistics of CHELSA precipitation layer
precipitation_chirpsStatistics of CHIRPS precipitation layer
precipitation_wcStatistics of WorldClim precipitation layer
slopeStatistics of slope based on NASA SRTM
soilpropertiesStatistics of SoilGrids layers
species_richnessSpecies richness statistics based on user-specified raster files.
temperature_max_wcStatistics of WorldClim maximum temperature layer
temperature_min_wcStatistics of WorldClim minimum temperature layer
traveltimeStatistics of traveltime to the clostes city grouped by city category
traveltime_2000Statistics of traveltime to the clostest city in 2000
treecover_areaArea of forest cover by year
treecover_area_and_emissionsArea of forest cover and greenhouse gas emssions caused by forest loss by year
treecoverloss_emissionsGreenouse gas emissions cause by forest loss by year
triStatistics of terrain rudgedness index based on NASA SRTM DEM
vul_carbonStatistics of vulnerable carbon per polygon.

Usage example

{mapme.biodiversity} works by constructing a portfolio from an sf object. Specific raster and vector resource matching the spatio-temporal extent of the portfolio are made available locally. Once all required resources are available, indicators can be calculated individually for each asset in the portfolio.

library(mapme.biodiversity)
library(sf)
## Linking to GEOS 3.13.0, GDAL 3.9.2, PROJ 9.5.0; sf_use_s2() is TRUE

Once you have decided on an indicator you are interested in, you can start by making the required resource available for your portfolio. Using mapme_options() you can set an output directory, control the maximum size of polygons before they are chunked into smaller parts, and control the verbosity of the package.

A portfolio is represented by an sf-object. It is required for the object to only contain geometries of type POLYGON and MULTIPOLYGON as assets. We can request the download of a resource for the spatial extent of our portfolio by using the get_resources() function. We simply supply our portfolio and one or more resource functions. Once the resources were made available, we can query the calculation of an indicator by using the calc_indicators() function. This function also expects the portfolio as input and one or more indicator functions. Once the indicator has been calculated for all assets in a portfolio, the data is returned as a nested list column to the original portfolio object. The output of each indicator is standardized to common format, consisting of a tibble with columns datetime, variable, unit, and value. We can transform the the data to long format by using portfolio_long().

mapme_options(
  outdir = system.file("res", package = "mapme.biodiversity"),
  chunk_size = 1e6, # in ha
  verbose = FALSE
)

aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>%
  sf::read_sf() %>%
  get_resources(
    get_gfw_treecover(version = "GFC-2023-v1.11"),
    get_gfw_lossyear(version = "GFC-2023-v1.11"),
    get_gfw_emissions()
  ) %>%
  calc_indicators(calc_treecover_area_and_emissions(years = 2016:2017, min_size = 1, min_cover = 30)) %>%
  portfolio_long()

aoi
## Simple feature collection with 4 features and 8 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -71.80933 ymin: 18.57668 xmax: -71.33201 ymax: 18.69931
## Geodetic CRS:  WGS 84
## # A tibble: 4 × 9
##   WDPAID ISO3  assetid indicator        datetime            variable unit  value
##    <dbl> <chr>   <int> <chr>            <dttm>              <chr>    <chr> <dbl>
## 1 478140 DOM         1 treecover_area_… 2016-01-01 00:00:00 emissio… Mg    4296.
## 2 478140 DOM         1 treecover_area_… 2016-01-01 00:00:00 treecov… ha    2370.
## 3 478140 DOM         1 treecover_area_… 2017-01-01 00:00:00 emissio… Mg    4970.
## 4 478140 DOM         1 treecover_area_… 2017-01-01 00:00:00 treecov… ha    2358.
## # ℹ 1 more variable: geom <POLYGON [°]>

Using cloud storages

{mapme.biodiversity} leverages GDAL’s capabilities for data I/O. For users of this package, that means that integrating a cloud storage is as easy as setting up a configuration file and changing the outdir argument in mapme_options(). While you could also decide to use environment variables, we recommend to set up a GDAL config file. You can find GDAL’s documentation on this topic here.

Suppose that we want to use an AWS S3 bucket that we control to write resource data to. Let’s assume this bucket is already set up and we wish to refer to it in our R code as mapme-data. The GDAL configuration file should look something like this:

[credentials]

[.mapme-data]
path=/vsis3/mapme-data
AWS_SECRET_ACCESS_KEY=<your-access-key>
AWS_ACCESS_KEY_ID=<your-access-id>

The connection will be handled based on GDAL’s virtual file system. You can find documentation on specific options for your cloud provider here.

Ideally, you would also set the following in the .Renviron file in your user’s home directory to ensure that GDAL is aware of this configuration when an R session is started:

GDAL_CONFIG_FILE = "<path-to-your-config-file>"

Then, in your scripts set the outdir option to the value specified with the path variable in the configuration file:

mapme_options(outdir = "/vsis3/mapme-data")

A note on parallel computing

{mapme.biodiversity} follows the parallel computing paradigm of the {future} package. That means that you as a user are in the control if and how you would like to set up parallel processing. Since {mapme.biodiversity} v0.9, we apply pre-chunking to all assets in the portfolio. That means that assets are split up into components of roughly the size of chunk_size. These components can than be iterated over in parallel to speed up processing. Indicator values will be aggregated automatically.

library(future)
plan(cluster, workers = 6)

As another example, with the code below one would apply parallel processing of 2 assets, with each having 4 workers available to process chunks, thus requiring a total of 8 available cores on the host machine. Be sure to not request more workers than available on your machine.

library(progressr)

plan(cluster, workers = 2)

with_progress({
  aoi <- calc_indicators(
    aoi,
    calc_treecover_area_and_emissions(
      min_size = 1,
      min_cover = 30
    )
  )
})

plan(sequential) # close child processes

Head over to the online documentation find more detailed information about the package.

Copy Link

Version

Install

install.packages('mapme.biodiversity')

Monthly Downloads

413

Version

0.9.3

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Darius A. Görgen

Last Published

October 21st, 2024

Functions in mapme.biodiversity (0.9.3)

gfw_treecover

Treecover for the year 2000
gfw_lossyear

Year of forest loss occurrence
chelsa

Climatologies at High resolution for the Earth Land Surface Areas (CHELSA)
gfw_emissions

Forest greenhouse gas emissions
fatalities_ucpd

Calculate number of fatalities of violent conflict from UCDP GED
fatalities_acled

Calculate number of fatalities of conflict events from ACLED
fritz_et_al

Drivers of deforestation for tropical forests
global_surface_water_transitions

Global Surface Water Transitions
gsw_transitions

Calculate Global Surface Water (GSW) Transitions
gmw

Global Mangrove Extent Polygon
global_surface_water_seasonality

Global Surface Water Seasonality
global_surface_water_recurrence

Global Surface Water Recurrence
gsw_recurrence

Calculate Global Surface Water (GSW) Recurrence
gsw_change

Calculate Global Surface Water (GSW) Change
global_surface_water_change

Global Surface Water Change
gsw_seasonality

Calculate Global Surface Water (GSW) Seasonality
global_surface_water_occurrence

Global Surface Water Occurrence
humanfootprint_indicator

Calculate human footprint statistics
key_biodiversity_areas_resource

Key Biodiversity Areas
gsw_occurrence

Calculate Global Surface Water (GSW) Occurrence
indicators

Register or list indicators in mapme.biodiversity
ipbes_biome_stats

Calculate areal statistics for IBPES Biomes
make_footprints

Create footprints for vector or raster data sets
humanfootprint_resource

Terrestrial Human Foootprint
precipitation_chelsa

Calculate precipitation average based on CHELSA
gsw_time_series_indicator

Calculate Global Surface Water Time Series
gsw_time_series_resource

Helper function to download Global Surface Water (GSW) yearly time series data
make_global_grid

Helper to create a grid of regular resolution and CRS
key_biodiversity_areas_indicator

Calculate Key Biodiversity Areas
mcd64a1

MODIS Burned Area Monthly (MCD64A1)
nelson_et_al

Accessibility to Cities layer
iucn

IUCN Red List of Threatened Species
nasa_grace

NASA GRACE-based Drought Indicator layer
nasa_srtm

NASADEM HGT v001
mangroves_area

Calculate mangrove extent based on Global Mangrove Watch (GMW)
precipitation_chirps

Calculate precipitation sums based on CHIRPS
teow

Terrestrial Ecoregions of the World (TEOW) Polygon
temperature_min_wc

Calculate minimum temperature statistics based on WorldClim
landcover

Calculate area of different landcover classes
treecover_area

Calculate treecover statistics
species_richness

Species richness based on IUCN raster data
traveltime

Calculate accessibility statistics
temperature_max_wc

Calculate maximum temperature statistics
traveltime_2000

Calculate accessibility statistics for the year 2000
worldclim_precipitation

Downloads WorldClim Mean Precipitation layer
worldclim_min_temperature

Downloads WorldClim Minimum Temperature layer
treecover_area_and_emissions

Calculate treeloss statistics
slope

Calculate slope statistics
mapme

Portfolio methods for mapme.biodiversity
soilgrids

SoilGrids data layers
portfolio

Portfolio methods
resources

Register or list resources in mapme.biodiversity
treecoverloss_emissions

Calculate emission statistics
precipitation_wc

Calculate precipitation statistics
tri

Calculate Terrain Ruggedness Index (TRI) statistics
population_count

Calculate population count statistics
ipbes_biomes

Terrestrial and Aquatic Biomes
soilproperties

Calculate Zonal Soil Properties
spds_exists

Check if a spatial data sets exists
worldclim_max_temperature

Downloads WorldClim Maximum Temperature layer
worldpop

Population Count layer for year 2000-2020
ucdp_ged

UCDP Georeferenced Event Dataset (UCDP GED)
burned_area

Calculate Monthly Burned Area based on MODIS (MCD64A1)
engine

Function to select processing engines
carbon_indicators

Calculate carbon statistics
exposed_population_ucdp

Calculate population exposed to violent conflict from UCDP GED
calc_exposed_population_acled

Calculate population exposed to violent conflict from ACLED
accessibility_2000

Accessibility to Cities in 2000
deforestation_drivers

Calculate deforestation drivers
carbon_resources

Carbon Layers
esalandcover

ESA Copernicus Global Land Cover layer
biodiversity_intactness_index_indicator

Calculate Biodiversity Intactness Index
biodiversity_intactness_index_resource

Biodiversity Intactness Index
check_namespace

Checks if namespace is available
chirps

Climate Hazards Group InfraRed Precipitation with Station data (CHIRPS)
check_available_years

Helper to check yearly availability
biome

Calculate biomes statistics (TEOW) based on WWF
acled

Armed Conflict Location & Event Data (ACLED)
elevation

Calculate elevation statistics
drought_indicator

Calculate drought indicator statistics
ecoregion

Calculate terrestrial ecoregions statistics (TEOW) based on WWF