Last active
January 27, 2025 14:53
-
-
Save PietrH/805b87c3b3b989f8d1d7c0c968ef3668 to your computer and use it in GitHub Desktop.
Get a number of stats for a few ETN projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
# Ensure ETN API-beta version | |
remotes::install_github("inbo/[email protected]") | |
library(etn) | |
# Get number of detections, species and animals for lifewatch presentation | |
project_codes_to_investigate <- c( | |
"2010_PHD_REUBENS", | |
"2011_RIVIERPRIK", | |
"2012_LEOPOLDKANAAL", | |
"2013_ALBERTKANAAL", | |
"2014_DEMER", | |
"2015_DIJLE", | |
"2015_HOMARUS", | |
"2015_PHD_VERHELST_COD", | |
"2015_PHD_VERHELST_EEL" | |
) | |
# Open data is available except for HOMARUS: | |
# https://github.com/inbo/etn-occurrences?tab=readme-ov-file#datasets | |
# number of detections ---------------------------------------------------- | |
requested_numbers <- | |
tibble::tibble(animal_project_code = project_codes_to_investigate) %>% | |
dplyr::mutate( # count the number of detections based on `detection_id` | |
n_detections = purrr::map_int( | |
animal_project_code, | |
~ { | |
get_acoustic_detections( | |
animal_project_code = .x, | |
api = FALSE | |
) %>% | |
dplyr::pull(detection_id) %>% | |
dplyr::n_distinct() | |
} | |
) | |
) %>% # Fetch the animal data | |
dplyr::mutate(animal_data = purrr::map( | |
animal_project_code, | |
~ etn::get_animals(animal_project_code = .x) | |
)) %>% # Extract the number of animals | |
dplyr::mutate( | |
n_animals = | |
purrr::map_int( | |
animal_data, | |
~ dplyr::n_distinct(dplyr::pull(.x, animal_id)) | |
), # extract the number of species | |
n_species = | |
purrr::map_int( | |
animal_data, | |
~ dplyr::n_distinct(dplyr::pull(.x, scientific_name)) | |
) | |
) | |
# write out --------------------------------------------------------------- | |
requested_numbers %>% | |
dplyr::select(-animal_data) %>% | |
readr::write_csv("20250127-requested_etn_proj_numbers.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment