{"id":22940634,"url":"https://github.com/b-cubed-eu/gcube","last_synced_at":"2025-06-24T20:08:07.349Z","repository":{"id":229849662,"uuid":"777812249","full_name":"b-cubed-eu/gcube","owner":"b-cubed-eu","description":"Simulation framework for biodiversity data cubes","archived":false,"fork":false,"pushed_at":"2025-05-12T16:09:25.000Z","size":632809,"stargazers_count":8,"open_issues_count":7,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-14T05:28:29.905Z","etag":null,"topics":["biodiversity-informatics","data-cubes","r","r-package","simulations"],"latest_commit_sha":null,"homepage":"https://b-cubed-eu.github.io/gcube/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/b-cubed-eu.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":".zenodo.json"}},"created_at":"2024-03-26T14:48:59.000Z","updated_at":"2025-05-18T09:44:10.000Z","dependencies_parsed_at":"2024-04-09T10:44:51.209Z","dependency_job_id":"3e3e3db3-3ded-4cec-a153-9e7e9a43155e","html_url":"https://github.com/b-cubed-eu/gcube","commit_stats":null,"previous_names":["b-cubed-eu/simcuber","b-cubed-eu/gcube"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/b-cubed-eu/gcube","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-cubed-eu%2Fgcube","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-cubed-eu%2Fgcube/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-cubed-eu%2Fgcube/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-cubed-eu%2Fgcube/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/b-cubed-eu","download_url":"https://codeload.github.com/b-cubed-eu/gcube/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-cubed-eu%2Fgcube/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260268615,"owners_count":22983601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["biodiversity-informatics","data-cubes","r","r-package","simulations"],"created_at":"2024-12-14T13:29:56.878Z","updated_at":"2025-06-17T00:34:21.104Z","avatar_url":"https://github.com/b-cubed-eu.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\neditor_options: \n  chunk_output_type: console\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = file.path(\"man\", \"figures\", \"readme-\"),\n  out.width = \"80%\",\n  dpi = 300\n)\n```\n\n# gcube \u003ca href=\"https://b-cubed-eu.github.io/gcube/\"\u003e\u003cimg src=\"man/figures/logo.png\" align=\"right\" height=\"139\" alt=\"gcube website\" /\u003e\u003c/a\u003e\n\n\u003c!-- badges: start --\u003e\n\n[![repo status](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n[![Release](https://img.shields.io/github/release/b-cubed-eu/gcube.svg)](https://github.com/b-cubed-eu/gcube/releases)\n[![gcube status badge](https://b-cubed-eu.r-universe.dev/gcube/badges/version)](https://b-cubed-eu.r-universe.dev/gcube)\n[![CRAN status](https://www.r-pkg.org/badges/version/gcube)](https://CRAN.R-project.org/package=gcube)\n[![R-CMD-check](https://github.com/b-cubed-eu/gcube/actions/workflows/check_on_different_r_os.yml/badge.svg)](https://github.com/b-cubed-eu/gcube/actions/workflows/check_on_different_r_os.yml)\n[![codecov](https://codecov.io/gh/b-cubed-eu/gcube/branch/main/graph/badge.svg)](https://app.codecov.io/gh/b-cubed-eu/gcube/)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14038996.svg)](https://doi.org/10.5281/zenodo.14038996)\n[![name status badge](https://b-cubed-eu.r-universe.dev/badges/:name?color=6CDDB4)](https://b-cubed-eu.r-universe.dev/)\n\n\u003c!-- badges: end --\u003e\n\nThe goal of **gcube** is to provide a simulation framework for biodiversity data cubes using the R programming language. This can start from simulating multiple species distributed in a landscape over a temporal scope. In a second phase, the simulation of a variety of observation processes and effort can generate actual occurrence datasets. Based on their (simulated) spatial uncertainty, occurrences can then be designated to a grid to form a data cube.\n\nSimulation studies offer numerous benefits due to their ability to mimic real-world scenarios in controlled and customizable environments. Ecosystems and biodiversity data are very complex and involve a multitude of interacting factors. Simulations allow researchers to model and understand the complexity of ecological systems by varying parameters such as spatial and/or temporal clustering, species prevalence, etc.\n\n## Installation\n\nInstall **gcube** in R:\n\n```r\ninstall.packages(\"gcube\", repos = \"https://b-cubed-eu.r-universe.dev\")\n```\n\nYou can install the development version from [GitHub](https://github.com/) with:\n\n``` r\n# install.packages(\"remotes\")\nremotes::install_github(\"b-cubed-eu/gcube\")\n```\n\n## Package name rationale and origin story\n\nThe name **gcube** stands for \"generate cube\" since it can be used to generate biodiversity data cubes from minimal input.\nIt was first developed during the hackathon \"Hacking Biodiversity Data Cubes for Policy\", where it won the first price in the category \"Visualization and training\".\nYou can read the full story here: \u003chttps://doi.org/10.37044/osf.io/vcyr7\u003e\n\n## Example\n\nThis is a basic example which shows the workflow for simulating a biodiversity data cube.\nIt is divided in three steps or processes:\n\n1.  Occurrence process\n2.  Detection process\n3.  Grid designation process\n\nThe functions are set up such that a single polygon as input is enough to go through this workflow using default arguments.\nThe user can change these arguments to allow for more flexibility.\n\n\n```{r packages, message=FALSE, warning=FALSE}\n# Load packages\nlibrary(gcube)\n\nlibrary(sf)      # working with spatial objects\nlibrary(dplyr)   # data wrangling\nlibrary(ggplot2) # visualisation with ggplot\n```\n\nWe create a polygon as input. It represents the spatial extend of the species.\n\n```{r polygon}\n#| fig.alt: \u003e\n#|   Spatial extend in which we will simulate species occurrences.\n# Create a polygon to simulate occurrences within\npolygon \u003c- st_polygon(list(cbind(c(5, 10, 8, 2, 3, 5), c(2, 1, 7,9, 5, 2))))\n\n# Visualise\nggplot() + \n  geom_sf(data = polygon) +\n  theme_minimal()\n```\n\n### Occurrence process\n\nWe generate occurrence points within the polygon using the `simulate_occurrences()` function.\nIn this function, the user can specify different levels of spatial clustering, and define the trend of number of occurrences over time.\nThe default is a random spatial pattern and a single time point with `rpois(1, 50)` occurrences.\n\n```{r simulate-occurrences}\n#| fig.alt: \u003e\n#|   Spatial distribution of occurrences within the polygon.\n# Simulate occurrences within polygon\noccurrences_df \u003c- simulate_occurrences(\n  species_range = polygon,\n  initial_average_occurrences = 50,\n  spatial_pattern = c(\"random\", \"clustered\"),\n  n_time_points = 1,\n  seed = 123)\n\n# Visualise\nggplot() + \n  geom_sf(data = polygon) +\n  geom_sf(data = occurrences_df) +\n  theme_minimal()\n```\n\n### Detection process\n\nIn the second step we define the sampling process, based on the detection probability of the species and the sampling bias.\nThis is done using the `sample_observations()` function.\nThe default sampling bias is `\"no_bias\"`, but bias can be added using a polygon or a grid as well.\n\n```{r detect-occurrences}\n#| fig.alt: \u003e\n#|   Spatial distribution of occurrences with indication of sampling status.\n# Detect occurrences\ndetections_df_raw \u003c- sample_observations(\n  occurrences = occurrences_df,\n  detection_probability = 0.5,\n  sampling_bias = c(\"no_bias\", \"polygon\", \"manual\"),\n  seed = 123)\n\n# Visualise\nggplot() + \n  geom_sf(data = polygon) +\n  geom_sf(data = detections_df_raw,\n          aes(colour = observed)) +\n  theme_minimal()\n```\n\nWe select the detected occurrences and add an uncertainty to these observations.\nThis can be done using the `filter_observations()` and `add_coordinate_uncertainty()` functions, respectively.\n\n```{r uncertainty-occurrences}\n#| fig.alt: \u003e\n#|   Spatial distribution of detected occurrences with coordinate uncertainty.\n# Select detected occurrences only\ndetections_df \u003c- filter_observations(\n  observations_total = detections_df_raw)\n\n# Add coordinate uncertainty\nset.seed(123)\ncoord_uncertainty_vec \u003c- rgamma(nrow(detections_df), shape = 2, rate = 6)\nobservations_df \u003c- add_coordinate_uncertainty(\n  observations = detections_df,\n  coords_uncertainty_meters = coord_uncertainty_vec)\n\n# Created and sf object with uncertainty circles to visualise\nbuffered_observations \u003c- st_buffer(\n  observations_df,\n  observations_df$coordinateUncertaintyInMeters)\n\n# Visualise\nggplot() + \n  geom_sf(data = polygon) +\n  geom_sf(data = buffered_observations,\n          fill = alpha(\"firebrick\", 0.3)) +\n  geom_sf(data = observations_df, colour = \"firebrick\") +\n  theme_minimal()\n```\n\n### Grid designation process\n\nFinally, observations are designated to a grid with `grid_designation()` to create an occurrence cube.\nWe create a grid over the spatial extend using `sf::st_make_grid()`. \n\n```{r create-grid}\n# Define a grid over spatial extend\ngrid_df \u003c- st_make_grid(\n    buffered_observations,\n    square = TRUE,\n    cellsize = c(1.2, 1.2)\n  ) %\u003e%\n  st_sf() %\u003e%\n  mutate(intersect = as.vector(st_intersects(geometry, polygon,\n                                             sparse = FALSE))) %\u003e%\n  dplyr::filter(intersect == TRUE) %\u003e%\n  dplyr::select(-\"intersect\")\n```\n\nTo create an occurrence cube, `grid_designation()` will randomly take a point within the uncertainty circle around the observations.\nThese points can be extracted by setting the argument `aggregate = FALSE`.\n\n```{r grid-designation}\n#| fig.alt: \u003e\n#|   Distribution of random samples within uncertainty circle.\n# Create occurrence cube\noccurrence_cube_df \u003c- grid_designation(\n  observations = observations_df,\n  grid = grid_df,\n  seed = 123)\n\n# Get sampled points within uncertainty circle\nsampled_points \u003c- grid_designation(\n  observations = observations_df,\n  grid = grid_df,\n  aggregate = FALSE,\n  seed = 123)\n\n# Visualise grid designation\nggplot() +\n  geom_sf(data = occurrence_cube_df, linewidth = 1) +\n  geom_sf_text(data = occurrence_cube_df, aes(label = n)) +\n  geom_sf(data = buffered_observations,\n          fill = alpha(\"firebrick\", 0.3)) +\n  geom_sf(data = sampled_points, colour = \"blue\") +\n  geom_sf(data = observations_df, colour = \"firebrick\") +\n  labs(x = \"\", y = \"\", fill = \"n\") +\n  theme_minimal()\n```\n\nThe output gives the number of observations per grid cell and minimal coordinate uncertainty per grid cell.\n\n```{r visualise-designation}\n#| fig.alt: \u003e\n#|   Distribution of minimal coordinate uncertainty.\n# Visualise minimal coordinate uncertainty\nggplot() +\n  geom_sf(data = occurrence_cube_df, aes(fill = min_coord_uncertainty),\n          alpha = 0.5, linewidth = 1) +\n  geom_sf_text(data = occurrence_cube_df, aes(label = n)) +\n  scale_fill_continuous(type = \"viridis\") +\n  labs(x = \"\", y = \"\") +\n  theme_minimal()\n```\n\n### Cubes for multiple species\n\nEach cube simulation function mentioned earlier has a corresponding mapping function.\nThese mapping functions are designed to handle operations for multiple species simultaneously by using the `purrr::pmap()` function.\nPlease consult the documentation for detailed information on how these mapping functions are implemented.\n\n| single species              | multiple species                |\n|-----------------------------|---------------------------------|\n| simulate_occurrences()      | map_simulate_occurrences()      |\n| sample_observations()       | map_sample_observations()       |\n| filter_observations()       | map_filter_observations()       |\n| add_coordinate_uncertainty()| map_add_coordinate_uncertainty()|\n| grid_designation()          | map_grid_designation()          |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb-cubed-eu%2Fgcube","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fb-cubed-eu%2Fgcube","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb-cubed-eu%2Fgcube/lists"}