Skip to content

Instantly share code, notes, and snippets.

View damianooldoni's full-sized avatar
🚴‍♂️

Damiano Oldoni damianooldoni

🚴‍♂️
View GitHub Profile
@damianooldoni
damianooldoni / prototype_leaflet.html
Created June 6, 2024 10:27
Prototype of a stand-alone html page containing a a leaflet map.
<!-- Sources:
https://leafletjs.com/examples/quick-start/
https://www.sitepoint.com/leaflet-create-map-beginner-guide/
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
@damianooldoni
damianooldoni / download_data_rgbif_example.R
Last active January 24, 2024 15:15
Options to download GBIF occ data with rgbif. Some attention is also given to get back the species not present in the data.
library(rgbif)
library(tidyverse)
# Create list of taxa we are interested to.
taxa <- tibble(
species_name = c("Amelanchier lamarckii",
"Mareca sibilatrix",
"Ursus maritimus"
)
)
@damianooldoni
damianooldoni / gbif_occurrences_analysis_ladybirds.R
Created September 7, 2023 11:49
Retrieve a GBIF checklist, download related GBIF occurrences and calculate first/last year. Similar to https://gist.github.com/damianooldoni/e70aded982934ca22ecdab62e20a9f0e
library(rgbif)
library(dplyr)
library(purrr)
library(readr)
# Get dataset
doi <- "2c38cf8a-f981-4dfb-bc9d-dd2b6fc792ed"
taxa <- rgbif::name_usage(datasetKey = doi, limit = 99999)
taxa <- taxa$data
@damianooldoni
damianooldoni / gbif_occurrences_basic_analysis.R
Last active March 20, 2023 13:01
How to read an occurrence.txt GBIF download and do a basic analysis at species level (n occs, min/max eventDate). Data used in example have been retrieved via https://gist.github.com/damianooldoni/b16608eef989aa17a296adcaa71537e5. GBIF download: https://www.gbif.org/occurrence/download/0104018-230224095556074
library(readr)
library(dplyr)
library(purrr)
# specify your path
occs <- read_tsv("../../0104018-230224095556074_eu_ias_occs.txt",
guess_max = 100000,
na = ""
)
@damianooldoni
damianooldoni / download_eu_ias_brussels.R
Last active March 20, 2023 12:59
How to trigger a download of occurrences at regional level (Brussels) for EU IAS derived list via rgbif (3.7.5).
library(rgbif)
# specify keys of interest
taxon_key_key <- "taxonKey"
taxon_key_value <- c(2978552, # EU - IAS list
2489005,
3190653,
2498252,
3084923,
2340977,
@damianooldoni
damianooldoni / check_changes_gbif_usage_keys.R
Created February 20, 2023 13:45
Basic R script to check changes in matching taxa to GBIF Backbone via `name_backbone()`
## Example from prius project
# Load packages
library(rgbif)
library(tidyverse)
# Read checklist
checklist <- readr::read_csv("https://raw.githubusercontent.com/inbo/prius/main/data/input/prius_species_list.csv",
na = "",
locale = locale(encoding = "ISO-8859-1")
@damianooldoni
damianooldoni / observations-table-schema_improved.json
Last active December 16, 2022 16:11
Improved table schema for observations: `speed`, `radius` and `angle` added
{
"name": "observations",
"title": "Observations",
"description": "Table with observations based on the media files. Associated with deployments (`deploymentID`), sequences (`sequenceID`) and optionally individual media files (`mediaID`). Observations can mark non-animal events (camera setup, human, blank) or one or more animal observations (`observationType` = `animal`) of a certain taxon, count, life stage, sex, behaviour and/or individual.",
"fields": [
{
"name": "observationID",
"type": "string",
"format": "default",
"description": "Unique identifier (within a project) of the observation.",
@damianooldoni
damianooldoni / get_scientific_names_from_vernacular_names.R
Created January 18, 2021 12:59
Snippet to show how to retrieve and add scientific names to a dataframe containing a list of non unique vernacular names based on GBIF Backbone. The most likely match only is returned. If the vernacular name cannot be matched, NA is returned
#' load packages
library(rgbif)
library(tidyverse)
#' example input
vernacular_names_df <- tibble(
id = c(1,2,3,4,5,6,7,8),
vernacular_name = c("Beenvissen",
"Bruine beer",
"Bont zandoogje",
@damianooldoni
damianooldoni / get_gbif_full_name.R
Last active January 18, 2021 08:28
Given a vector of scientific names, retrieve the full scientific name with authority from GBIF Backbone. Used for checking taxa in official annexes of BIM.
library(rgbif)
library(inborutils)
library(tidyverse)
# names list example
names_bim <- c("Asplenium hemionitis L.",
"Dracaena draco (L.) L.",
"Viola rupestris subsp. relicta Jalas")
# make a df of it
@damianooldoni
damianooldoni / get_and_join_data_on_protected_areas.R
Created June 3, 2020 15:00
This code allows to download and join data and metadata about species occurrence in protected areas
library(inborutils) # To download data from zenodo (not needed for manual download)
library(readr) # To read data
library(dplyr) # To do datascience
library(tidylog) # # To provide feedback on dplyr functions (not essential, but nice to have)
library(here) # To find files
# Files we need
files <- c("protected_areas_species_occurrence.csv",
"protected_areas_species_info.csv",
"protected_areas_metadata.csv")