├── figs ├── hex_logo.png ├── map_sites.png └── workflow.png ├── code ├── w_code-leaflet.R ├── 00_functions │ ├── render_rmd.R │ ├── convert_coords.R │ ├── ncrmp_converter.R │ ├── convert_classification.R │ ├── mermaid_converter_sampleevents.R │ ├── mermaid_converter_observations.R │ ├── reefcloud_converter.R │ ├── graphical_par.R │ ├── data_descriptors.R │ └── mermaid_converter_sampleunits.R ├── 05_control-standardization.R ├── 04_standardization │ ├── 0255.R │ ├── 0259.R │ ├── 0221.R │ ├── 0222.R │ ├── 0223.R │ ├── 0224.R │ ├── 0225.R │ ├── 0227.R │ ├── 0249.R │ ├── 0036.R │ ├── 0239.R │ ├── 0084.R │ ├── 0171.R │ ├── 0028.R │ ├── 0268.R │ ├── 0178.R │ ├── 0180.R │ ├── 0181.R │ ├── 0102.R │ ├── 0103.R │ ├── 0104.R │ ├── 0186.R │ ├── 0101.R │ ├── 0172.R │ ├── 0188.R │ ├── 0121.R │ ├── 0126.R │ ├── 0129.R │ ├── 0189.R │ ├── 0190.R │ ├── 0191.R │ ├── 0123.R │ ├── 0127.R │ ├── 0192.R │ ├── 0122.R │ ├── 0193.R │ ├── 0124.R │ ├── 0128.R │ ├── 0125.R │ ├── 0095.R │ ├── 0202.R │ ├── 0187.R │ ├── 0198.R │ ├── 0195.R │ ├── 0200.R │ ├── 0254.R │ ├── 0201.R │ ├── 0208.R │ ├── 0167.R │ ├── 0179.R │ ├── 0204.R │ ├── 0205.R │ ├── 0207.R │ ├── 0215.R │ ├── 0258.R │ ├── 0206.R │ ├── 0226.R │ ├── 0100.R │ ├── 0105.R │ ├── 0119.R │ ├── 0120.R │ ├── 0137.R │ ├── 0144.R │ ├── 0260.R │ ├── 0056.R │ ├── 0058.R │ ├── 0059.R │ ├── 0063.R │ ├── 0064.R │ ├── 0065.R │ ├── 0068.R │ ├── 0069.R │ ├── 0151.R │ ├── 0045.R │ ├── 0046.R │ ├── 0010.R │ ├── 0025.R │ ├── 0026.R │ ├── 0027.R │ ├── 0030.R │ ├── 0031.R │ ├── 0032.R │ ├── 0033.R │ ├── 0034.R │ ├── 0035.R │ ├── 0158.R │ ├── 0159.R │ ├── 0160.R │ ├── 0161.R │ ├── 0162.R │ ├── 0229.R │ ├── 0196.R │ ├── 0077.R │ ├── 0243.R │ ├── 0252.R │ ├── 0156.R │ ├── 0040.R │ ├── 0272.R │ ├── 0016.R │ ├── 0244.R │ ├── 0261.R │ ├── 0078.R │ ├── 0037.R │ ├── 0039.R │ ├── 0240.R │ ├── 0135.R │ ├── 0253.R │ ├── 0216.R │ ├── 0234.R │ ├── 0169.R │ ├── 0265.R │ ├── 0269.R │ ├── 0230.R │ ├── 0174.R │ ├── 0245.R │ ├── 0004.R │ ├── 0157.R │ ├── 0117.R │ ├── 0241.R │ ├── 0237.R │ ├── 0238.R │ ├── 0001.R │ ├── 0251.R │ ├── 0210.R │ ├── 0047.R │ ├── 0113.R │ ├── 0142.R │ ├── 0118.R │ ├── 0211.R │ ├── 0132.R │ ├── 0143.R │ ├── 0007.R │ ├── 0197.R │ ├── 0002.R │ ├── 0049.R │ ├── 0022.R │ ├── 0052.R │ ├── 0217.R │ ├── 0218.R │ ├── 0152.R │ ├── 0212.R │ ├── 0250.R │ ├── 0136.R │ ├── 0054.R │ ├── 0154.R │ ├── 0005.R │ ├── 0214.R │ ├── 0012.R │ └── 0013.R ├── w_test-duplicated.R ├── w_mermaid-projects.R └── 01_clean-reefs.R ├── .gitignore └── gcrmndb_benthos.Rproj /figs/hex_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GCRMN/gcrmndb_benthos/HEAD/figs/hex_logo.png -------------------------------------------------------------------------------- /figs/map_sites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GCRMN/gcrmndb_benthos/HEAD/figs/map_sites.png -------------------------------------------------------------------------------- /figs/workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GCRMN/gcrmndb_benthos/HEAD/figs/workflow.png -------------------------------------------------------------------------------- /code/w_code-leaflet.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | 3 | leaflet(data = A) %>% 4 | addTiles() %>% 5 | addMarkers(~decimalLongitude, ~decimalLatitude, label = ~locality) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Base # 2 | ######## 3 | .Rproj.user 4 | .Rproj 5 | .Rhistory 6 | .RData 7 | .Rprofile 8 | .Ruserdata 9 | *.html 10 | # folder # 11 | ########## 12 | misc/ 13 | output/ 14 | data/* 15 | !*data/03_tax-recategorisation.csv 16 | figs/hex_logo.svg 17 | figs/workflow.svg 18 | .httr-oauth 19 | -------------------------------------------------------------------------------- /gcrmndb_benthos.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: c89fd89a-967a-48c4-9a0a-0af611c650c2 3 | 4 | RestoreWorkspace: Default 5 | SaveWorkspace: Default 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | -------------------------------------------------------------------------------- /code/00_functions/render_rmd.R: -------------------------------------------------------------------------------- 1 | render_rmd <- function(i){ 2 | 3 | if(file.exists(paste0("../output/dataset_", i, ".html")) == FALSE){ 4 | 5 | render("../code/00_functions/individual_checks.Rmd", 6 | output_file = paste0("dataset_", i), 7 | output_dir = "../output", 8 | quiet = TRUE) 9 | 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /code/05_control-standardization.R: -------------------------------------------------------------------------------- 1 | # 1. Load packages ---- 2 | 3 | library(tidyverse) 4 | 5 | # 2. List of individual data standardization scripts ---- 6 | 7 | list_path <- list.files("code/01_standardization/", full.names = TRUE, pattern = ".R") 8 | 9 | # 3. Run all scripts ---- 10 | 11 | walk(list_path, ~source(.)) # walk() is from the map family (purrr) 12 | -------------------------------------------------------------------------------- /code/04_standardization/0255.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0250" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | A <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., sheet = 1, na = c("", "NA", "na")) -------------------------------------------------------------------------------- /code/04_standardization/0259.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0259" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | A <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., sheet = 1, na = c("", "NA", "na")) -------------------------------------------------------------------------------- /code/00_functions/convert_coords.R: -------------------------------------------------------------------------------- 1 | convert_coords <- base::Vectorize(function(x){ 2 | 3 | require(tidyverse) 4 | 5 | x <- str_squish(x) 6 | 7 | degree <- as.numeric(str_split_fixed(x, "°|’|'|”|\"", 4)[,1]) 8 | minute <- as.numeric(str_replace(str_split_fixed(x, "°|’|'|”|\"", 4)[,2], ",", ".")) 9 | second <- as.numeric(str_replace(str_split_fixed(x, "°|’|'|”|\"", 4)[,3], ",", ".")) 10 | 11 | if(is.na(second)){ 12 | 13 | result <- degree + (minute/60) 14 | 15 | }else{ 16 | 17 | result <- degree + (minute/60) + (second/3600) 18 | 19 | } 20 | 21 | return(result) 22 | 23 | }) -------------------------------------------------------------------------------- /code/04_standardization/0221.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | source("code/00_functions/reefcloud_converter.R") 6 | 7 | dataset <- "0221" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "main") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read.csv() %>% 16 | reefcloud_converter(data = ., pivot_nb = 15) %>% 17 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 18 | -------------------------------------------------------------------------------- /code/04_standardization/0222.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | source("code/00_functions/reefcloud_converter.R") 6 | 7 | dataset <- "0222" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "main") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read.csv() %>% 16 | reefcloud_converter(data = ., pivot_nb = 15) %>% 17 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 18 | -------------------------------------------------------------------------------- /code/04_standardization/0223.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | source("code/00_functions/reefcloud_converter.R") 6 | 7 | dataset <- "0223" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "main") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read.csv() %>% 16 | reefcloud_converter(data = ., pivot_nb = 15) %>% 17 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 18 | -------------------------------------------------------------------------------- /code/04_standardization/0224.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | source("code/00_functions/reefcloud_converter.R") 6 | 7 | dataset <- "0224" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "main") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read.csv() %>% 16 | reefcloud_converter(data = ., pivot_nb = 15) %>% 17 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 18 | -------------------------------------------------------------------------------- /code/04_standardization/0225.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | source("code/00_functions/reefcloud_converter.R") 6 | 7 | dataset <- "0225" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "main") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read.csv() %>% 16 | reefcloud_converter(data = ., pivot_nb = 15) %>% 17 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 18 | -------------------------------------------------------------------------------- /code/04_standardization/0227.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | source("code/00_functions/reefcloud_converter.R") 6 | 7 | dataset <- "0227" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "main") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read.csv() %>% 16 | reefcloud_converter(data = ., pivot_nb = 15) %>% 17 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 18 | -------------------------------------------------------------------------------- /code/04_standardization/0249.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | source("code/00_functions/reefcloud_converter.R") 5 | 6 | dataset <- "0249" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read.csv() %>% 15 | reefcloud_converter() %>% 16 | filter(measurementValue != 0) %>% 17 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 18 | -------------------------------------------------------------------------------- /code/04_standardization/0036.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | source("code/00_functions/reefcloud_converter.R") 5 | 6 | dataset <- "0036" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | # Read the file 15 | read_csv(.) %>% 16 | # Convert from ReefCloud format to gcrmndb_benthos format 17 | reefcloud_converter(.) %>% 18 | # Export the data 19 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 20 | -------------------------------------------------------------------------------- /code/w_test-duplicated.R: -------------------------------------------------------------------------------- 1 | load("data/09_gcrmndb_benthos.RData") 2 | 3 | library(tidyverse) 4 | 5 | test <- synthetic_data %>% 6 | select(-datasetID) %>% 7 | group_by(across(everything())) %>% 8 | count() %>% 9 | ungroup() %>% 10 | filter(n > 1) %>% 11 | mutate(dupl = row_number()) 12 | 13 | 14 | testdeu <- left_join(test, synthetic_data) 15 | 16 | testtroi <- testdeu %>% 17 | select(dupl, datasetID, n) 18 | 19 | 20 | B <- tibble(dataset_a = c("0012", "0013", "0025"), 21 | dataset_b = c("0013", "0025", "0012"), 22 | n = c(12, 2, 6)) 23 | 24 | 25 | ggplot(data = B, aes(x = dataset_a, y = dataset_b, fill = n, label = n)) + 26 | geom_tile() + 27 | geom_text(color = "white", size = 5) 28 | -------------------------------------------------------------------------------- /code/04_standardization/0239.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | source("code/00_functions/reefcloud_converter.R") 5 | 6 | dataset <- "0239" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read.csv() %>% 15 | reefcloud_converter() %>% 16 | # Remove year before 2018 (already included in datasetID 0040) 17 | filter(year > 2018) %>% 18 | filter(measurementValue != 0) %>% 19 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 20 | -------------------------------------------------------------------------------- /code/00_functions/ncrmp_converter.R: -------------------------------------------------------------------------------- 1 | ncrmp_converter <- function(data_path){ 2 | 3 | data <- read_csv(as.character(data_path)) %>% 4 | rename(year = YEAR, month = MONTH, day = DAY, decimalLatitude = LAT_DEGREES, decimalLongitude = LON_DEGREES, 5 | organismID = COVER_CAT_NAME, locality = PRIMARY_SAMPLE_UNIT) %>% 6 | mutate(locality = paste0("S", locality), 7 | eventDate = as.Date(paste0(year, "-", month, "-", day)), 8 | verbatimDepth = (MIN_DEPTH+MAX_DEPTH/2), 9 | measurementValue = HARDBOTTOM_P+SOFTBOTTOM_P+RUBBLE_P) %>% 10 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, year, 11 | month, day, eventDate, organismID, measurementValue) 12 | 13 | return(data) 14 | 15 | } 16 | -------------------------------------------------------------------------------- /code/w_mermaid-projects.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | 6 | mermaid_projects <- mermaid_get_projects() 7 | 8 | included_datasets_paths <- read_csv("data/01_raw-data/benthic-cover_paths.csv") 9 | 10 | pacific_mermaid_projects <- mermaid_projects %>% 11 | filter(if_any(.cols = c(name, countries), 12 | .fns = ~str_detect(., pattern = "Fiji|Papua New Guinea|Vanuatu|Micronesia, Federated States of| 13 | Solomon Islands|Samoa|Tonga"))) %>% 14 | # Remove already integrated datasets 15 | filter(!(id %in% unique(included_datasets_paths$project_id))) %>% 16 | arrange(-num_sites) 17 | 18 | -------------------------------------------------------------------------------- /code/01_clean-reefs.R: -------------------------------------------------------------------------------- 1 | # 1. Load packages ---- 2 | 3 | library(tidyverse) 4 | library(sf) 5 | sf_use_s2(FALSE) 6 | 7 | # 2. Correct ETP coral reef sites (shared by Andrea Arriaga-Madrigual) ---- 8 | 9 | read.csv("data/08_quality-checks-buffer/2025-10_regional_reef_type_data.csv") %>% 10 | filter(decimalLatitude >= -90 & decimalLatitude <= 90) %>% 11 | filter(decimalLongitude < -74) %>% 12 | drop_na(decimalLatitude, decimalLongitude) %>% 13 | drop_na(reef_habitat_type) %>% 14 | filter(reef_habitat_type != "rocky_reef") %>% 15 | select(decimalLatitude, decimalLongitude, reef_habitat_type) %>% 16 | distinct() %>% 17 | st_as_sf(coords = c("decimalLongitude", "decimalLatitude"), crs = 4326) %>% 18 | st_write(., "data/08_quality-checks-buffer/gcrmndb-benthos_etp-reef-sites.shp", append = FALSE) 19 | -------------------------------------------------------------------------------- /code/04_standardization/0084.R: -------------------------------------------------------------------------------- 1 | # 1. Packages ---- 2 | 3 | library(tidyverse) 4 | library(readxl) 5 | 6 | dataset <- "0084" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = 1) %>% 15 | pivot_longer("Coral":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 16 | mutate(datasetID = dataset, 17 | month = month(Year), 18 | year = year(Year)) %>% 19 | rename(locality = Site_Code, 20 | decimalLatitude = Lat, 21 | decimalLongitude = Long) %>% 22 | select(-Year) %>% 23 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 24 | -------------------------------------------------------------------------------- /code/04_standardization/0171.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0171" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx() %>% 15 | select(-Source) %>% 16 | rename(locality = Site, eventDate = Date, measurementValue = `%CoralCover`, 17 | decimalLatitude = Lat, decimalLongitude = Lon) %>% 18 | mutate(organismID = "Hard coral", 19 | datasetID = dataset, 20 | year = year(eventDate), 21 | month = month(eventDate), 22 | day = day(eventDate)) %>% 23 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 24 | -------------------------------------------------------------------------------- /code/04_standardization/0028.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | source("code/00_functions/reefcloud_converter.R") 5 | 6 | dataset <- "0028" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | # Read the file 15 | read_csv(.) %>% 16 | # Convert from ReefCloud format to gcrmndb_benthos format 17 | reefcloud_converter(.) %>% 18 | mutate(decimalLatitude = ifelse(locality == "Cooks Rock", -19.546029, decimalLatitude), 19 | decimalLongitude = ifelse(locality == "Cooks Rock", 169.499078, decimalLongitude)) %>% 20 | # Export the data 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0268.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | source("code/00_functions/reefcloud_converter.R") 5 | 6 | dataset <- "0268" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read.csv() %>% 15 | reefcloud_converter() %>% 16 | filter(measurementValue != 0) %>% 17 | # Correct error for date 18 | mutate(eventDate = case_when(eventDate == "2002-02-16" ~ as.Date("2022-02-16"), 19 | TRUE ~ eventDate), 20 | year = case_when(year == 2002 ~ 2022, 21 | TRUE ~ year)) %>% 22 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 23 | -------------------------------------------------------------------------------- /code/04_standardization/0178.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0178" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx() %>% 15 | rename(decimalLatitude = Lat, decimalLongitude = Long, 16 | locality = SiteName, samplingProtocol = Method, year = Year) %>% 17 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, CoralCover, AlgaeCover) %>% 18 | pivot_longer("CoralCover":"AlgaeCover", names_to = "organismID", values_to = "measurementValue") %>% 19 | mutate(datasetID = dataset) %>% 20 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 21 | -------------------------------------------------------------------------------- /code/04_standardization/0180.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0180" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx() %>% 15 | rename(decimalLatitude = Lat, decimalLongitude = Long, verbatimDepth = Depth.m, 16 | locality = SiteName, samplingProtocol = Method, year = Year, measurementValue = CoralCover) %>% 17 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, verbatimDepth, measurementValue) %>% 18 | mutate(organismID = "Hard coral", 19 | datasetID = dataset) %>% 20 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 21 | -------------------------------------------------------------------------------- /code/00_functions/convert_classification.R: -------------------------------------------------------------------------------- 1 | convert_classification <- function(data, i){ 2 | 3 | result <- data[[i]] 4 | 5 | if(length(result) == 1){ 6 | 7 | result <- tibble(organismID = names(data)[i], 8 | category = NA, 9 | subcategory = NA, 10 | condition = NA) 11 | 12 | }else{ 13 | 14 | result <- result %>% 15 | as_tibble() %>% 16 | mutate(rank = str_replace_all(rank, c("Phylum \\(Division\\)" = "Phylum")), 17 | rank = str_to_lower(rank)) %>% 18 | filter(rank %in% c("phylum", "class", "subclass", "order", "family", "genus", "species")) %>% 19 | pivot_wider(names_from = "rank", values_from = "name") %>% 20 | mutate(organismID = names(data)[i], .before = "phylum") %>% 21 | mutate(category = NA, subcategory = NA, condition = NA, .after = organismID) 22 | 23 | } 24 | 25 | return(result) 26 | 27 | } 28 | -------------------------------------------------------------------------------- /code/04_standardization/0181.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0181" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx() %>% 15 | rename(decimalLatitude = Lat, decimalLongitude = Long, verbatimDepth = Depth.m, 16 | locality = SiteName, samplingProtocol = Method, year = Year) %>% 17 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, verbatimDepth, CoralCover, AlgaeCover) %>% 18 | pivot_longer("CoralCover":"AlgaeCover", names_to = "organismID", values_to = "measurementValue") %>% 19 | mutate(datasetID = dataset) %>% 20 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 21 | -------------------------------------------------------------------------------- /code/04_standardization/0102.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | source("code/00_functions/ncrmp_converter.R") 5 | 6 | dataset <- "0102" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 List of files to combine ---- 11 | 12 | data_paths <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "main") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | list.files(path = ., full.names = TRUE) 17 | 18 | ## 2.2 Combine files ---- 19 | 20 | map_dfr(data_paths, ~ncrmp_converter(data_path = .)) %>% 21 | mutate(datasetID = dataset, 22 | samplingProtocol = "Point intersect transect, 15 m transect length, every 15 cm") %>% 23 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 24 | 25 | # 3. Remove useless objects ---- 26 | 27 | rm(data_paths, ncrmp_converter) 28 | -------------------------------------------------------------------------------- /code/04_standardization/0103.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | source("code/00_functions/ncrmp_converter.R") 5 | 6 | dataset <- "0103" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 List of files to combine ---- 11 | 12 | data_paths <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "main") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | list.files(path = ., full.names = TRUE) 17 | 18 | ## 2.2 Combine files ---- 19 | 20 | map_dfr(data_paths, ~ncrmp_converter(data_path = .)) %>% 21 | mutate(datasetID = dataset, 22 | samplingProtocol = "Point intersect transect, 15 m transect length, every 15 cm") %>% 23 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 24 | 25 | # 3. Remove useless objects ---- 26 | 27 | rm(data_paths, ncrmp_converter) 28 | -------------------------------------------------------------------------------- /code/04_standardization/0104.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | source("code/00_functions/ncrmp_converter.R") 5 | 6 | dataset <- "0104" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 List of files to combine ---- 11 | 12 | data_paths <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "main") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | list.files(path = ., full.names = TRUE) 17 | 18 | ## 2.2 Combine files ---- 19 | 20 | map_dfr(data_paths, ~ncrmp_converter(data_path = .)) %>% 21 | mutate(datasetID = dataset, 22 | samplingProtocol = "Point intersect transect, 15 m transect length, every 15 cm") %>% 23 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 24 | 25 | # 3. Remove useless objects ---- 26 | 27 | rm(data_paths, ncrmp_converter) 28 | -------------------------------------------------------------------------------- /code/04_standardization/0186.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0186" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 16 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 17 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 18 | mutate(samplingProtocol = "Photo-quadrat", 19 | datasetID = dataset) %>% 20 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 21 | -------------------------------------------------------------------------------- /code/04_standardization/0101.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | source("code/00_functions/ncrmp_converter.R") 5 | 6 | dataset <- "0101" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 List of files to combine ---- 11 | 12 | data_paths <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "main") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | list.files(path = ., full.names = TRUE, pattern = ".csv") 17 | 18 | ## 2.2 Combine files ---- 19 | 20 | map_dfr(data_paths, ~ncrmp_converter(data_path = .)) %>% 21 | mutate(datasetID = dataset, 22 | samplingProtocol = "Point intersect transect, 15 m transect length, every 15 cm") %>% 23 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 24 | 25 | # 3. Remove useless objects ---- 26 | 27 | rm(data_paths, ncrmp_converter) 28 | -------------------------------------------------------------------------------- /code/04_standardization/0172.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | source("code/00_functions/convert_coords.R") 6 | 7 | dataset <- "0172" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "main") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read_xlsx() %>% 16 | select(-Source) %>% 17 | rename(locality = Site, year = Year, measurementValue = `%CoralCover`, 18 | decimalLatitude = Lat, decimalLongitude = Lon, verbatimDepth = Depth) %>% 19 | mutate(organismID = "Hard coral", 20 | datasetID = dataset, 21 | across(c(decimalLatitude, decimalLongitude), ~convert_coords(.x))) %>% 22 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 23 | 24 | # 3. Remove useless objects ---- 25 | 26 | rm(convert_coords) 27 | -------------------------------------------------------------------------------- /code/04_standardization/0188.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0188" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "IMS") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0121.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0121" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "CORDIO") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0126.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0126" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "Dahari") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0129.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0129" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "CORDIO") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0189.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0189" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "CORDIO") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0190.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0190" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "CHICOP") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0191.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0191" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "SUZA") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0123.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0123" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "REEFolution") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0127.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0127" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_replicate") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "Moheli MPA") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0192.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0192" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "Eylem_Elma") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0122.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0122" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "A_Rocha_Kenya") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0193.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0193" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "Under_the_Wave") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/00_functions/mermaid_converter_sampleevents.R: -------------------------------------------------------------------------------- 1 | mermaid_converter_sampleevents <- function(data, dataset, method){ 2 | 3 | result <- data %>% 4 | pivot_longer("percent_cover_benthic_category_avg_sand":"percent_cover_benthic_category_avg_crustose_coralline_algae", 5 | names_to = "organismID", values_to = "measurementValue") %>% 6 | mutate(organismID = str_remove_all(organismID, "percent_cover_benthic_category_avg_")) %>% 7 | select(site, latitude, longitude, sample_date, depth_avg, organismID, measurementValue) %>% 8 | rename(decimalLatitude = latitude, decimalLongitude = longitude, eventDate = sample_date, 9 | verbatimDepth = depth_avg, locality = site) %>% 10 | mutate(eventDate = as_date(eventDate), 11 | year = year(eventDate), 12 | month = month(eventDate), 13 | day = day(eventDate), 14 | datasetID = dataset, 15 | samplingProtocol = method, 16 | organismID = str_to_sentence(str_replace_all(organismID, "_", " "))) 17 | 18 | return(result) 19 | 20 | } -------------------------------------------------------------------------------- /code/04_standardization/0124.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0124" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization %in% c("KMFRI_A_Rocha_Kenya", "KMFRI")) %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0128.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0128" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization %in% c("Sarah_Freed_and_AIDE", "AIDE")) %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/04_standardization/0125.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0125" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization %in% c("CORDIO_WWF_KWS, WRTI", "KWS, WRTI")) %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset) %>% 21 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 22 | -------------------------------------------------------------------------------- /code/00_functions/mermaid_converter_observations.R: -------------------------------------------------------------------------------- 1 | mermaid_converter_observations <- function(data, dataset, method){ 2 | 3 | result <- data %>% 4 | rename(locality = site, decimalLatitude = latitude, decimalLongitude = longitude, habitat = reef_type, 5 | verbatimDepth = depth, parentEventID = transect_number, organismID = benthic_attribute, eventDate = sample_date) %>% 6 | select(locality, decimalLatitude, decimalLongitude, habitat, verbatimDepth, parentEventID, eventDate, organismID) %>% 7 | group_by(pick(everything())) %>% 8 | summarise(measurementValue = n()) %>% 9 | ungroup() %>% 10 | group_by(across(-c(organismID, measurementValue))) %>% 11 | mutate(total = sum(measurementValue)) %>% 12 | ungroup() %>% 13 | mutate(measurementValue = (measurementValue*100)/total, 14 | datasetID = dataset, 15 | year = year(eventDate), 16 | month = month(eventDate), 17 | day = day(eventDate), 18 | samplingProtocol = method) %>% 19 | select(-total) 20 | 21 | return(result) 22 | 23 | } 24 | -------------------------------------------------------------------------------- /code/04_standardization/0095.R: -------------------------------------------------------------------------------- 1 | # 1. Packages ---- 2 | 3 | library(tidyverse) 4 | library(readxl) 5 | 6 | dataset <- "0095" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(.) %>% 15 | rename(locality = dives_code, parentEventID = transect_code, 16 | measurementValue = cover, organismID = taxa, 17 | decimalLatitude = lat, decimalLongitude = long, 18 | eventDate = date, verbatimDepth = max_depth) %>% 19 | select(-sites_code, -protec, -group, -group2) %>% 20 | mutate(parentEventID = as.numeric(str_sub(parentEventID, -1)), 21 | datasetID = dataset, 22 | year = year(eventDate), 23 | month = month(eventDate), 24 | day = day(eventDate), 25 | samplingProtocol = "Photo-quadrat, 10 m transect length") %>% 26 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 27 | -------------------------------------------------------------------------------- /code/04_standardization/0202.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0202" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "KORAÏ") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset, 21 | across(c("decimalLatitude", "decimalLongitude"), ~as.numeric(.x))) %>% 22 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 23 | -------------------------------------------------------------------------------- /code/00_functions/reefcloud_converter.R: -------------------------------------------------------------------------------- 1 | reefcloud_converter <- function(data, datasetID = dataset, pivot_nb = 15){ 2 | 3 | result <- data %>% 4 | pivot_longer(as.numeric(pivot_nb):ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 5 | rename(eventDate = date..UTC., verbatimDepth = depth_m, decimalLongitude = site_longitude, 6 | decimalLatitude = site_latitude, eventID = unique_id, parentEventID = transect, 7 | locality = site) %>% 8 | mutate(eventDate = as.Date(str_sub(eventDate, 1, 10)), 9 | year = year(eventDate), 10 | month = month(eventDate), 11 | day = day(eventDate), 12 | datasetID = datasetID, 13 | samplingProtocol = "Photo-quadrat") %>% 14 | select(datasetID, locality, parentEventID, eventID, decimalLatitude, decimalLongitude, 15 | verbatimDepth, year, month, day, eventDate, samplingProtocol, organismID, measurementValue) %>% 16 | group_by(eventDate, locality, parentEventID, verbatimDepth) %>% 17 | mutate(eventID = as.numeric(as.factor(eventID))) %>% 18 | ungroup() 19 | 20 | return(result) 21 | 22 | } -------------------------------------------------------------------------------- /code/00_functions/graphical_par.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | require(extrafont) # For fonts 4 | 5 | # 2. Set the default font family ---- 6 | 7 | windowsFonts("Open Sans" = windowsFont("Open Sans")) 8 | 9 | font_choose_graph <- "Open Sans" 10 | font_choose_map <- "Open Sans" 11 | 12 | # 3. Set the colors ---- 13 | 14 | col_fill_graph <- "#89C4F4" 15 | col_color_graph <- "#446CB3" 16 | col_fill_map <- "#f2caae" 17 | col_color_map <- "#6c7a89" 18 | col_background_map <- "#e4f1fe" 19 | col_facet <- "#ECF0F1" 20 | 21 | col_fill_bleaching <- "#d64541" 22 | col_fill_ts <- "#2abb9b" 23 | 24 | # 4. Number of facets by plot ---- 25 | 26 | facets_by_plot <- 20 27 | 28 | # 5. Variable names ---- 29 | 30 | var_names <- c("datasetID", "higherGeography", "country", "territory", "locality", 31 | "habitat", "parentEventID", "eventID", "decimalLatitude", "decimalLongitude", 32 | "verbatimDepth", "year", "month", "day", "eventDate", "samplingProtocol", 33 | "recordedBy", "category", "subcategory", "condition", "phylum", "class", 34 | "order", "family", "genus", "scientificName", "measurementValue") 35 | -------------------------------------------------------------------------------- /code/04_standardization/0187.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0187" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read.csv() %>% 15 | select("date":"rubble") %>% 16 | pivot_longer("coral":"rubble", names_to = "organismID", values_to = "measurementValue") %>% 17 | rename(eventDate = date, locality = site, decimalLatitude = latitude, decimalLongitude = longitude, 18 | verbatimDepth = depth, parentEventID = transect) %>% 19 | mutate(measurementValue = measurementValue*100, 20 | eventDate = as.Date(eventDate, format = "%d/%m/%Y"), 21 | year = year(eventDate), 22 | month = month(eventDate), 23 | day = day(eventDate), 24 | datasetID = dataset) %>% 25 | drop_na(measurementValue) %>% 26 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 27 | 28 | -------------------------------------------------------------------------------- /code/04_standardization/0198.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0198" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "YSO") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset, 21 | decimalLatitude = as.numeric(decimalLatitude), 22 | decimalLongitude = as.numeric(decimalLongitude)) %>% 23 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 24 | -------------------------------------------------------------------------------- /code/04_standardization/0195.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0195" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "CNRO") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset, 21 | decimalLatitude = as.numeric(decimalLatitude), 22 | decimalLongitude = as.numeric(decimalLongitude)) %>% 23 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 24 | -------------------------------------------------------------------------------- /code/04_standardization/0200.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0200" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "WWF MDCO") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset, 21 | decimalLatitude = as.numeric(decimalLatitude), 22 | decimalLongitude = as.numeric(decimalLongitude)) %>% 23 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 24 | -------------------------------------------------------------------------------- /code/04_standardization/0254.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0254" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., sheet = 1, skip = 1, na = c("", "NA", "na")) %>% 15 | pivot_longer("Hardcoral_percent":"Other_percent", names_to = "organismID", values_to = "measurementValue") %>% 16 | rename(locality = Location, decimalLatitude = Latitude, decimalLongitude = Longitude, 17 | verbatimDepth = Depth, year = Year, month = Month, samplingProtocol = Method, 18 | parentEventID = Replicate) %>% 19 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, year, month, 20 | parentEventID, organismID, measurementValue) %>% 21 | mutate(datasetID = dataset, 22 | organismID = str_remove_all(organismID, "_percent")) %>% 23 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 24 | -------------------------------------------------------------------------------- /code/04_standardization/0201.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0201" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "CORDIO_WWF MDCO_IHSM") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset, 21 | decimalLatitude = as.numeric(decimalLatitude), 22 | decimalLongitude = as.numeric(decimalLongitude)) %>% 23 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 24 | -------------------------------------------------------------------------------- /code/04_standardization/0208.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0208" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx() %>% 15 | rename(locality = SiteID, decimalLatitude = Latitude, decimalLongitude = Longitude, 16 | verbatimDepth = Depth, eventDate = Date, samplingProtocol = Method, parentEventID = TransectoID) %>% 17 | pivot_longer("Hard Coral":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 18 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, eventDate, 19 | parentEventID, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset, 21 | year = year(eventDate), 22 | month = month(eventDate), 23 | day = day(eventDate), 24 | samplingProtocol = "Point intercept transect") %>% 25 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 26 | -------------------------------------------------------------------------------- /code/04_standardization/0167.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0167" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, method = "benthicpqt", data = "sampleevents") 19 | 20 | # 4. Save raw data ---- 21 | 22 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 23 | row.names = FALSE) 24 | 25 | # 5. Standardize data ---- 26 | 27 | mermaid_converter_sampleevents(data, dataset, method = "Photo-quadrat") %>% 28 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 29 | 30 | # 6. Remove useless objects ---- 31 | 32 | rm(data, project_id, mermaid_converter_sampleevents) 33 | -------------------------------------------------------------------------------- /code/04_standardization/0179.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0179" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx() %>% 15 | rename(decimalLatitude = Lat, decimalLongitude = Long, verbatimDepth = Depth.m, 16 | locality = SiteName, samplingProtocol = Method, year = Year, measurementValue = CoralCover) %>% 17 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, verbatimDepth, measurementValue) %>% 18 | mutate(organismID = "Hard coral", 19 | datasetID = dataset, 20 | # Slightly change coordinates of one site to avoid same coordinates than the other one 21 | decimalLatitude = ifelse(locality == "East Flower Garden 26", 27.91671, decimalLatitude), 22 | decimalLongitude = ifelse(locality =="East Flower Garden 26", -93.60001, decimalLongitude)) %>% 23 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 24 | -------------------------------------------------------------------------------- /code/04_standardization/0204.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0204" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, method = "benthicpqt", data = "observations") 19 | 20 | # 4. Save raw data ---- 21 | 22 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 23 | row.names = FALSE) 24 | 25 | # 5. Standardize data ---- 26 | 27 | mermaid_converter_observations(data = data, method = "Photo-quadrat", dataset = dataset) %>% 28 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 29 | 30 | # 6. Remove useless objects ---- 31 | 32 | rm(data, project_id, mermaid_converter_observations) 33 | -------------------------------------------------------------------------------- /code/04_standardization/0205.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0205" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, method = "benthicpqt", data = "observations") 19 | 20 | # 4. Save raw data ---- 21 | 22 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 23 | row.names = FALSE) 24 | 25 | # 5. Standardize data ---- 26 | 27 | mermaid_converter_observations(data = data, method = "Photo-quadrat", dataset = dataset) %>% 28 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 29 | 30 | # 6. Remove useless objects ---- 31 | 32 | rm(data, project_id, mermaid_converter_observations) 33 | -------------------------------------------------------------------------------- /code/04_standardization/0207.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0207" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, method = "benthicpqt", data = "observations") 19 | 20 | # 4. Save raw data ---- 21 | 22 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 23 | row.names = FALSE) 24 | 25 | # 5. Standardize data ---- 26 | 27 | mermaid_converter_observations(data = data, method = "Photo-quadrat", dataset = dataset) %>% 28 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 29 | 30 | # 6. Remove useless objects ---- 31 | 32 | rm(data, project_id, mermaid_converter_observations) 33 | -------------------------------------------------------------------------------- /code/04_standardization/0215.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0215" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, method = "benthicpqt", data = "observations") 19 | 20 | # 4. Save raw data ---- 21 | 22 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 23 | row.names = FALSE) 24 | 25 | # 5. Standardize data ---- 26 | 27 | mermaid_converter_observations(data = data, method = "Photo-quadrat", dataset = dataset) %>% 28 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 29 | 30 | # 6. Remove useless objects ---- 31 | 32 | rm(data, project_id, mermaid_converter_observations) 33 | -------------------------------------------------------------------------------- /code/04_standardization/0258.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0258" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., skip = 1, sheet = 1, na = c("", "NA", "na")) %>% 15 | pivot_longer("Hardcoral_percent":"Other_percent", names_to = "organismID", values_to = "measurementValue") %>% 16 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, 17 | verbatimDepth = Depth, year = Year, month = Month, parentEventID = Replicate, 18 | samplingProtocol = Method) %>% 19 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, year, month, 20 | parentEventID, samplingProtocol, organismID, measurementValue) %>% 21 | mutate(organismID = str_remove_all(organismID, "_percent"), 22 | datasetID = dataset, 23 | samplingProtocol = "Line Intercept Transect") %>% 24 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 25 | -------------------------------------------------------------------------------- /code/04_standardization/0206.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0206" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, method = "benthicpit", data = "observations") 19 | 20 | # 4. Save raw data ---- 21 | 22 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 23 | row.names = FALSE) 24 | 25 | # 5. Standardize data ---- 26 | 27 | mermaid_converter_observations(data = data, method = "Point Intercept Transect", dataset = dataset) %>% 28 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 29 | 30 | # 6. Remove useless objects ---- 31 | 32 | rm(data, project_id, mermaid_converter_observations) 33 | -------------------------------------------------------------------------------- /code/04_standardization/0226.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0226" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, method = "benthiclit", data = "observations") 19 | 20 | # 4. Save raw data ---- 21 | 22 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 23 | row.names = FALSE) 24 | 25 | # 5. Standardize data ---- 26 | 27 | mermaid_converter_observations(data = data, method = "Line intercept transect", dataset = dataset) %>% 28 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 29 | 30 | # 6. Remove useless objects ---- 31 | 32 | rm(data, project_id, mermaid_converter_observations) 33 | -------------------------------------------------------------------------------- /code/04_standardization/0100.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0100" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "sampleevents") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0105.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0105" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "sampleevents") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0119.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0119" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "sampleevents") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0120.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0120" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "sampleevents") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0137.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0137" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "sampleevents") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0144.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0144" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "sampleevents") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0260.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0260" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read.csv() %>% 15 | pivot_longer("HardcoralPercent":"OtherPercent", 16 | names_to = "organismID", values_to = "measurementValue") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, 18 | verbatimDepth = Depth, year = Year, month = Month, parentEventID = Replicate, 19 | samplingProtocol = Method) %>% 20 | select(locality, decimalLatitude, decimalLongitude, parentEventID, 21 | verbatimDepth, year, month, samplingProtocol, organismID, measurementValue) %>% 22 | mutate(samplingProtocol = "Line Intercept Transect", 23 | organismID = str_remove_all(organismID, "Percent"), 24 | measurementValue = measurementValue*100, 25 | datasetID = dataset) %>% 26 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 27 | -------------------------------------------------------------------------------- /code/00_functions/data_descriptors.R: -------------------------------------------------------------------------------- 1 | data_descriptors <- function(data){ 2 | 3 | # Number of sites 4 | 5 | nb_sites <- data %>% 6 | select(decimalLongitude, decimalLatitude) %>% 7 | distinct() %>% 8 | count(name = "nb_sites") 9 | 10 | # Number of surveys 11 | 12 | nb_surveys <- data %>% 13 | select(decimalLongitude, decimalLatitude, year, month, eventDate) %>% 14 | distinct() %>% 15 | count(name = "nb_surveys") 16 | 17 | # Number of individual datasets 18 | 19 | nb_datasets <- data %>% 20 | select(datasetID) %>% 21 | distinct() %>% 22 | count(name = "nb_datasets") 23 | 24 | # First and last year with data 25 | 26 | first_last_year <- data %>% 27 | mutate(first_year = min(year), 28 | last_year = max(year)) %>% 29 | select(first_year, last_year) %>% 30 | distinct() 31 | 32 | # Return the results 33 | 34 | if (is.grouped_df(data) == TRUE) { 35 | 36 | result <- nb_sites %>% 37 | left_join(., nb_surveys) %>% 38 | left_join(., nb_datasets) %>% 39 | left_join(., first_last_year) 40 | 41 | }else{ 42 | 43 | result <- bind_cols(nb_sites, nb_surveys, nb_datasets, first_last_year) 44 | 45 | } 46 | 47 | return(result) 48 | 49 | } -------------------------------------------------------------------------------- /code/04_standardization/0056.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0056" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "observations") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_observations(data, dataset = dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_observations) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0058.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0058" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "observations") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_observations(data, dataset = dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_observations) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0059.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0059" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "observations") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_observations(data, dataset = dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_observations) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0063.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0063" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "observations") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_observations(data, dataset = dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_observations) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0064.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0064" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "observations") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_observations(data, dataset = dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_observations) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0065.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0065" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "observations") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_observations(data, dataset = dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_observations) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0068.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0068" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "observations") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_observations(data, dataset = dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_observations) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0069.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0069" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpqt", data = "observations") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_observations(data, dataset = dataset, method = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_observations) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0151.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | 5 | dataset <- "0151" # Define the dataset_id 6 | 7 | # 2. Import, standardize and export the data ---- 8 | 9 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 10 | filter(datasetID == dataset & data_type == "main") %>% 11 | select(data_path) %>% 12 | pull() %>% 13 | read.csv() %>% 14 | drop_na(TOT_BIOTIC_COVER) %>% 15 | rename(locality = STATION_CODE, decimalLatitude = LAT_DEGREES, decimalLongitude = LON_DEGREES, 16 | eventDate = DATE, organismID = SCIENTIFIC_NAME, measurementValue = TOT_BIOTIC_COVER, year = YEAR) %>% 17 | select(locality, decimalLatitude, decimalLongitude, eventDate, organismID, measurementValue, year) %>% 18 | mutate(datasetID = dataset, 19 | eventDate = as.Date(eventDate, format = "%d/%m/%Y"), 20 | year = ifelse(is.na(eventDate), year, year(eventDate)), 21 | month = month(eventDate), 22 | day = day(eventDate), 23 | organismID = str_remove_all(organismID, " spp"), 24 | organismID = ifelse(organismID == "Turbinaria", "Algae - Turbinaria", organismID)) %>% 25 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 26 | -------------------------------------------------------------------------------- /code/04_standardization/0045.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0045" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, data = "observations", method = "benthicpit") 19 | 20 | # 4. Save raw data ---- 21 | 22 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", 23 | project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_observations(data, dataset = dataset, method = "Point intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_observations) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0046.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0046" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, data = "observations", method = "benthicpit") 19 | 20 | # 4. Save raw data ---- 21 | 22 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", 23 | project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_observations(data, dataset = dataset, method = "Point intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_observations) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0010.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0010" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Point intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0025.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0025" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Point intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0026.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0026" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Point intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0027.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0027" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Point intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0030.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0030" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Point intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0031.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0031" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Point intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0032.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0032" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, method = "benthicpit", 19 | data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Point intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0033.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0033" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Point intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0034.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0034" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Point intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0035.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0035" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Point intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0158.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0158" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthiclit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Line intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0159.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0159" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthiclit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Line intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0160.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0160" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthiclit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Line intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0161.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0161" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthiclit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Line intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0162.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_sampleevents.R") 6 | 7 | dataset <- "0162" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthiclit", data = "sampleevents", token = NULL) 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_sampleevents(data, dataset, method = "Line intersect transect") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | # 6. Remove useless objects ---- 32 | 33 | rm(data, project_id, mermaid_converter_sampleevents) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0229.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0229" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx() %>% 15 | group_by(`Site Id`, Lat, Lon, date) %>% 16 | mutate(Transect = as.numeric(as.factor(Transect))) %>% 17 | ungroup() %>% 18 | rename(decimalLatitude = Lat, decimalLongitude = Lon, verbatimDepth = `Depth (m)`, 19 | eventDate = date, locality = `Site Id`, parentEventID = Transect) %>% 20 | select(-`Reef Name`, -Facies, -Status, -`No Take (yes or No)`, -`Visibility M`, -year, 21 | -month, -`Rugosity (m)`, -`image#`, -`point#`) %>% 22 | pivot_longer("Abiotic":ncol(.), values_to = "measurementValue", names_to = "organismID") %>% 23 | mutate(locality = paste0("S", locality), 24 | datasetID = dataset, 25 | year = year(eventDate), 26 | month = month(eventDate), 27 | day = day(eventDate), 28 | samplingProtocol = "Photo-quadrat") %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | -------------------------------------------------------------------------------- /code/00_functions/mermaid_converter_sampleunits.R: -------------------------------------------------------------------------------- 1 | mermaid_converter_sampleunits <- function(data){ 2 | 3 | split_benthic_categories <- function(data){ 4 | 5 | result <- str_split_fixed(data$percent_cover_by_benthic_category_avg, ",", n = Inf) 6 | 7 | result <- tibble(raw = as.vector(result)) %>% 8 | mutate(organismID = str_squish(str_split_fixed(raw, ": ", 2)[,1]), 9 | measurementValue = str_split_fixed(raw, ": ", 2)[,2]) %>% 10 | mutate_all(., ~str_replace_all(.x, "\\{|\\'|\\}", "")) %>% 11 | mutate(measurementValue = as.numeric(measurementValue)) %>% 12 | select(-raw) 13 | 14 | return(result) 15 | 16 | } 17 | 18 | mermaid_reformat <- function(data){ 19 | 20 | result <- bind_cols(data, split_benthic_categories(data)) 21 | 22 | return(result) 23 | 24 | } 25 | 26 | mermaid_reformat(data) %>% 27 | select(project_id, site_name, latitude, longitude, sample_date_year, 28 | sample_date_month, sample_date_day, depth_avg, organismID, measurementValue) %>% 29 | rename(decimalLatitude = latitude, decimalLongitude = longitude, year = sample_date_year, 30 | month = sample_date_month, day = sample_date_day, verbatimDepth = depth_avg, locality = site_name) %>% 31 | mutate(eventDate = as_date(paste(year, month, day, sep = "-"))) 32 | 33 | } -------------------------------------------------------------------------------- /code/04_standardization/0196.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0196" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "Blue Ventures") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset, 21 | decimalLatitude = as.numeric(decimalLatitude), 22 | decimalLatitude = ifelse(locality == "Bevato_Permanent_Reserve", NA, decimalLatitude), 23 | decimalLongitude = as.numeric(decimalLongitude), 24 | decimalLongitude = ifelse(locality == "Bevato_Permanent_Reserve", NA, decimalLongitude)) %>% 25 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 26 | -------------------------------------------------------------------------------- /code/04_standardization/0077.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(mermaidr) # API to mermaid data. To install -> remotes::install_github("data-mermaid/mermaidr") 5 | source("code/00_functions/mermaid_converter_observations.R") 6 | 7 | dataset <- "0077" # Define the dataset_id 8 | 9 | # 2. Get the MERMAID project ID ---- 10 | 11 | project_id <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset) %>% 13 | select(project_id) %>% 14 | pull() 15 | 16 | # 3. Get data from the mermaidr API ---- 17 | 18 | data <- mermaid_get_project_data(project = project_id, 19 | method = "benthicpit", data = "observations") 20 | 21 | # 4. Save raw data ---- 22 | 23 | write.csv(data, file = paste0("data/01_raw-data/", dataset, "/mermaid_", project_id, "_", lubridate::date(Sys.time()), ".csv"), 24 | row.names = FALSE) 25 | 26 | # 5. Standardize data ---- 27 | 28 | mermaid_converter_observations(data, dataset = dataset, method = "Point intersect transect") %>% 29 | # Remove artificial reef sites 30 | filter(!(locality %in% c("PAN_P3", "PAN_P1"))) %>% 31 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 32 | 33 | # 6. Remove useless objects ---- 34 | 35 | rm(data, project_id, mermaid_converter_observations) 36 | -------------------------------------------------------------------------------- /code/04_standardization/0243.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0243" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., sheet = 1, skip = 1, na = c("", "NA", "na")) %>% 15 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, 16 | verbatimDepth = Depth, year = Year, month = Month, samplingProtocol = Method, 17 | parentEventID = Replicate) %>% 18 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, year, month, 19 | samplingProtocol, parentEventID, Hardcoral_percent, Softcoral_percent, 20 | Reckilledcoral_percent, Macroalgae_percent, Turfalgae_percent, 21 | Corallinealgae_percent, Other_percent) %>% 22 | pivot_longer("Hardcoral_percent":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 23 | mutate(organismID = str_remove_all(organismID, "_percent"), 24 | samplingProtocol = "Photo-quadrat", 25 | datasetID = dataset) %>% 26 | drop_na(measurementValue) %>% 27 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 28 | -------------------------------------------------------------------------------- /code/04_standardization/0252.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0252" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., sheet = 1, skip = 1, na = c("", "NA", "na")) %>% 15 | pivot_longer("Hardcoral_percent":"Other_percent", names_to = "organismID", values_to = "measurementValue") %>% 16 | rename(locality = Location, decimalLatitude = Latitude, decimalLongitude = Longitude, 17 | verbatimDepth = Depth, year = Year, month = Month, samplingProtocol = Method, 18 | parentEventID = Replicate) %>% 19 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, year, month, 20 | samplingProtocol, parentEventID, organismID, measurementValue) %>% 21 | mutate(verbatimDepth = as.numeric(verbatimDepth), 22 | datasetID = dataset, 23 | organismID = str_remove_all(organismID, "_percent"), 24 | samplingProtocol = str_replace_all(samplingProtocol, 25 | c("Point_intercept_transect" = "Point intercept transect"))) %>% 26 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 27 | -------------------------------------------------------------------------------- /code/04_standardization/0156.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0156" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 Path of files to combine ---- 11 | 12 | data_paths <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "main") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | excel_sheets() 17 | 18 | ## 2.2 Function to combine the files ---- 19 | 20 | convert_data_156 <- function(sheet_i){ 21 | 22 | data <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 23 | filter(datasetID == dataset & data_type == "main") %>% 24 | select(data_path) %>% 25 | pull() %>% 26 | read_xlsx(path = ., sheet = sheet_i) %>% 27 | mutate(locality = sheet_i) 28 | 29 | return(data) 30 | 31 | } 32 | 33 | ## 2.3 Map over the function ---- 34 | 35 | map_dfr(data_paths, ~convert_data_156(.x)) %>% 36 | rename(decimalLatitude = Lat, 37 | decimalLongitude = Lon, 38 | year = Year, 39 | measurementValue = CoralCover) %>% 40 | mutate(organismID = "Hard coral", 41 | datasetID = dataset) %>% 42 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 43 | 44 | # 3. Remove useless objects ---- 45 | 46 | rm(data_paths, convert_data_156) 47 | -------------------------------------------------------------------------------- /code/04_standardization/0040.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) # To read excel files 5 | 6 | dataset <- "0040" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | # 2.1 Code data -- 11 | 12 | data_code <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "code") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | # Read the file 17 | read.csv2(file = .) 18 | 19 | # 2.2 Main data -- 20 | 21 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 22 | filter(datasetID == dataset & data_type == "main") %>% 23 | select(data_path) %>% 24 | pull() %>% 25 | # Read the file 26 | read_xlsx(., sheet = 1) %>% 27 | select(Depth, Surveyor, Lat, Long, Year, Site, Transect, "Acr_br":"Turf") %>% 28 | rename(locality = Site, parentEventID = Transect, decimalLatitude = Lat, 29 | decimalLongitude = Long, verbatimDepth = Depth, year = Year, recordedBy = Surveyor) %>% 30 | pivot_longer("Acr_br":"Turf", names_to = "code", values_to = "measurementValue") %>% 31 | drop_na(measurementValue) %>% 32 | mutate(datasetID = dataset) %>% 33 | left_join(., data_code) %>% 34 | select(-code) %>% 35 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 36 | 37 | # 3. Remove useless objects ---- 38 | 39 | rm(data_code) -------------------------------------------------------------------------------- /code/04_standardization/0272.R: -------------------------------------------------------------------------------- 1 | # 1. Packages ---- 2 | 3 | library(tidyverse) 4 | library(readxl) 5 | 6 | dataset <- "0272" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 Lord Howe Island data ---- 11 | 12 | data_lordhowe <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "main") %>% 14 | filter(row_number() == 1) %>% 15 | select(data_path) %>% 16 | pull() %>% 17 | read.csv() 18 | 19 | ## 2.2 Norfolfk Island data ---- 20 | 21 | data_norfolk <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 22 | filter(datasetID == dataset & data_type == "main") %>% 23 | filter(row_number() == 2) %>% 24 | select(data_path) %>% 25 | pull() %>% 26 | read.csv() 27 | 28 | ## 2.3 Combine data ---- 29 | 30 | bind_rows(data_lordhowe, data_norfolk) %>% 31 | select(-se, -CI_95_lower_bound, -CI_95_upper_bound) %>% 32 | rename(locality = site, measurementValue = cover, organismID = response_variable, 33 | decimalLatitude = latitude, decimalLongitude = longitude) %>% 34 | mutate(month = as.numeric(str_replace_all(month, c("March" = "3"))), 35 | measurementValue = measurementValue*100, 36 | datasetID = dataset) %>% 37 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 38 | 39 | # 3. Remove useless objects ---- 40 | 41 | rm(data_norfolk, data_lordhowe) 42 | -------------------------------------------------------------------------------- /code/04_standardization/0016.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) # To read excel files 5 | 6 | dataset <- "0016" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | # Read the file 15 | read_xlsx(., sheet = "Data", skip = 1) %>% 16 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, verbatimDepth = Depth_m, 17 | habitat = Zone, year = Year, month = Month, parentEventID = Replicate, recordedBy = Surveyor) %>% 18 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, habitat, year, month, parentEventID, 19 | recordedBy, "Hardcoral_percent":"Other_percent") %>% 20 | pivot_longer("Hardcoral_percent":"Other_percent", names_to = "organismID", values_to = "measurementValue") %>% 21 | mutate(datasetID = dataset, 22 | samplingProtocol = "Photo-quadrat, 20 m transect length", 23 | organismID = str_remove_all(organismID, "_percent"), 24 | verbatimDepth = (as.numeric(str_split_fixed(verbatimDepth, "-", 2)[,1]) + 25 | as.numeric(str_split_fixed(verbatimDepth, "-", 2)[,2]))/2) %>% 26 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 27 | -------------------------------------------------------------------------------- /code/04_standardization/0244.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0244" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., sheet = 1, skip = 1, na = c("", "NA", "na")) %>% 15 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, 16 | verbatimDepth = Depth, year = Year, month = Month, samplingProtocol = Method, 17 | parentEventID = Replicate) %>% 18 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, year, month, 19 | samplingProtocol, parentEventID, Hardcoral_percent, Softcoral_percent, 20 | Reckilledcoral_percent, Macroalgae_percent, Turfalgae_percent, 21 | Corallinealgae_percent, Other_percent) %>% 22 | pivot_longer("Hardcoral_percent":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 23 | mutate(organismID = str_remove_all(organismID, "_percent"), 24 | samplingProtocol = str_replace_all(samplingProtocol, "Line_intercept_transect", "Line intercept transect"), 25 | datasetID = dataset) %>% 26 | drop_na(measurementValue) %>% 27 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 28 | -------------------------------------------------------------------------------- /code/04_standardization/0261.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0261" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., skip = 1, sheet = 1, na = c("", "NA", "na")) %>% 15 | pivot_longer("Hardcoral_percent":"Other_percent", 16 | names_to = "organismID", values_to = "measurementValue") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, 18 | verbatimDepth = Depth, year = Year, month = Month, parentEventID = Replicate, 19 | samplingProtocol = Method) %>% 20 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, year, month, 21 | parentEventID, samplingProtocol, organismID, measurementValue) %>% 22 | mutate(organismID = str_remove_all(organismID, "_percent"), 23 | across(c("decimalLatitude", "decimalLongitude", "verbatimDepth"), ~as.numeric(.x)), 24 | samplingProtocol = str_replace_all(samplingProtocol, 25 | "Line_intercept_belt-transect", "Line Intercept Transect"), 26 | datasetID = dataset) %>% 27 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 28 | -------------------------------------------------------------------------------- /code/04_standardization/0078.R: -------------------------------------------------------------------------------- 1 | # 1. Packages ---- 2 | 3 | library(tidyverse) 4 | library(readxl) 5 | 6 | dataset <- "0078" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(.) %>% 15 | mutate(across(c(Latitud, Longitud), ~round(.x, 4))) %>% # Correct issue of slightly different coordinates 16 | rename(locality = Site, decimalLatitude = Latitud, decimalLongitude = Longitud, 17 | verbatimDepth = 'Average Depth (m)', day = Day, month = Month, year = Year, 18 | parentEventID = Transect, eventID = Image, organismID = 'spp Name', 19 | measurementValue = 'Cov% per species') %>% 20 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, day, month, year, 21 | parentEventID, eventID, organismID, measurementValue) %>% 22 | mutate(eventDate = date(paste(year, month, day, sep = "-")), 23 | datasetID = dataset, 24 | samplingProtocol = "Photo-quadrat") %>% 25 | group_by(locality, decimalLatitude, decimalLongitude, parentEventID, eventDate) %>% 26 | mutate(eventID = as.numeric(as.factor(eventID)), 27 | organismID = ifelse(organismID == "Turbinaria sp.", "Algae - Turbinaria sp.", organismID)) %>% 28 | ungroup() %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | -------------------------------------------------------------------------------- /code/04_standardization/0037.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) # To read excel files 5 | library(lubridate) 6 | 7 | dataset <- "0037" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | # 2.1 Site data -- 12 | 13 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 14 | filter(datasetID == dataset & data_type == "main") %>% 15 | select(data_path) %>% 16 | pull() %>% 17 | # Read the file 18 | read_xlsx(., sheet = 2) 19 | 20 | # 2.2 Main data -- 21 | 22 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 23 | filter(datasetID == dataset & data_type == "main") %>% 24 | select(data_path) %>% 25 | pull() %>% 26 | # Read the file 27 | read_xlsx(., sheet = 1) %>% 28 | pivot_longer("Hard corals":"Other", names_to = "organismID", values_to = "measurementValue") %>% 29 | left_join(., data_site) %>% 30 | rename(locality = Site, eventDate = Date, habitat = Habitat, 31 | decimalLatitude = Latitude, decimalLongitude = Longitude, verbatimDepth = "Depth (m)") %>% 32 | mutate(year = year(eventDate), 33 | month = month(eventDate), 34 | day = day(eventDate), 35 | datasetID = dataset, 36 | samplingProtocol = "Photo-quadrat, 50 m transect length, every 5 m") %>% 37 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 38 | 39 | # 3. Remove useless objects ---- 40 | 41 | rm(data_site) 42 | -------------------------------------------------------------------------------- /code/04_standardization/0039.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) # To read excel files 5 | 6 | dataset <- "0039" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | # Read the file 15 | read_xlsx(., sheet = 1) %>% 16 | select(-Sum, -Station, -"Photo Name", -"Island", -"No. Points") %>% 17 | pivot_longer("Hard Coral":"TWS", values_to = "measurementValue", names_to = "organismID") %>% 18 | drop_na(measurementValue) %>% 19 | # Remove Tapes, wands and shadow as not included in the sum (see metadata) 20 | filter(!(organismID %in% c("Cyanobacteria", "TWS"))) %>% 21 | rename(year = Year, decimalLatitude = Latitude, decimalLongitude = Longitude, 22 | locality = Site, eventID = Replicate, habitat = Habitat) %>% 23 | mutate(datasetID = dataset, 24 | verbatimDepth = 10, # See metadata 25 | habitat = str_replace_all(habitat, c("ORT" = "Fore reef", 26 | "FT" = "Fringing reef", 27 | "TOKA" = "Patch reef", 28 | "KAOA" = "Patch reef")), 29 | samplingProtocol = "Photo-quadrat") %>% 30 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 31 | -------------------------------------------------------------------------------- /code/04_standardization/0240.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0240" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., sheet = 1, skip = 1, na = c("", "NA", "na")) %>% 15 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, 16 | verbatimDepth = Depth, year = Year, month = Month, samplingProtocol = Method, 17 | parentEventID = Replicate) %>% 18 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, year, month, 19 | samplingProtocol, parentEventID, Hardcoral_percent, Softcoral_percent, 20 | Reckilledcoral_percent, Macroalgae_percent, Turfalgae_percent, 21 | Corallinealgae_percent, Other_percent) %>% 22 | pivot_longer("Hardcoral_percent":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 23 | mutate(measurementValue = measurementValue*100, 24 | organismID = str_remove_all(organismID, "_percent"), 25 | samplingProtocol = str_replace_all(samplingProtocol, "Line_intercept_transect", "Line intercept transect"), 26 | datasetID = dataset) %>% 27 | drop_na(measurementValue) %>% 28 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 29 | -------------------------------------------------------------------------------- /code/04_standardization/0135.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(sf) 5 | 6 | dataset <- "0135" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 Code data ---- 11 | 12 | data_code <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "code") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | read.csv2() 17 | 18 | ## 2.2 Main data ---- 19 | 20 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 21 | filter(datasetID == dataset & data_type == "main") %>% 22 | select(data_path) %>% 23 | pull() %>% 24 | read.csv() %>% 25 | pivot_longer("AAGA":ncol(.), names_to = "code", values_to = "measurementValue") %>% 26 | rename(locality = Site, decimalLatitude = x, decimalLongitude = y, verbatimDepth = Depth) %>% 27 | mutate(year = 2022, 28 | samplingProtocol = "Photo-quadrat", 29 | datasetID = dataset) %>% 30 | filter(code != "LC") %>% 31 | st_as_sf(coords = c("decimalLatitude", "decimalLongitude"), crs = "EPSG:32616") %>% 32 | st_transform(crs = 4326) %>% 33 | mutate(decimalLatitude = st_coordinates(.)[,2], 34 | decimalLongitude = st_coordinates(.)[,1]) %>% 35 | st_drop_geometry() %>% 36 | left_join(., data_code) %>% 37 | select(-code) %>% 38 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 39 | 40 | # 3. Remove useless objects ---- 41 | 42 | rm(data_code) 43 | -------------------------------------------------------------------------------- /code/04_standardization/0253.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0253" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., sheet = 1, skip = 1, na = c("", "NA", "na")) %>% 15 | pivot_longer("Hardcoral_percent":"Other_percent", names_to = "organismID", values_to = "measurementValue") %>% 16 | rename(locality = Location, decimalLatitude = Latitude, decimalLongitude = Longitude, 17 | verbatimDepth = Depth, year = Year, month = Month, samplingProtocol = Method, 18 | parentEventID = Replicate) %>% 19 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, year, month, 20 | samplingProtocol, parentEventID, organismID, measurementValue) %>% 21 | mutate(across(c("decimalLatitude", "decimalLongitude", "year", "month", "verbatimDepth"), ~as.numeric(.x)), 22 | measurementValue = measurementValue*100, 23 | datasetID = dataset, 24 | organismID = str_remove_all(organismID, "_percent"), 25 | samplingProtocol = str_replace_all(samplingProtocol, 26 | c("Point_intercept_transect" = "Point intercept transect"))) %>% 27 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 28 | -------------------------------------------------------------------------------- /code/04_standardization/0216.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0216" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx() %>% 15 | select(-SUM, -`Site code`) %>% 16 | rename(decimalLatitude = Lat, decimalLongitude = Long, locality = Site, year = Year) %>% 17 | pivot_longer("HC":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 18 | mutate(datasetID = dataset, 19 | organismID = str_replace_all(organismID, c("HC" = "Hard coral", 20 | "SC" = "Soft coral", 21 | "RKC" = "Recently killed coral", 22 | "NIA" = "Algae", 23 | "SP" = "Sponges", 24 | "RC" = "Rock", 25 | "RB" = "Rubble", 26 | "SD" = "Sand", 27 | "SI" = "Silt", 28 | "OT" = "Other"))) %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | -------------------------------------------------------------------------------- /code/04_standardization/0234.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0234" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 Site coordinates ---- 11 | 12 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "site") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | read.csv() %>% 17 | rename(locality = Station, decimalLatitude = Latitude, decimalLongitude = Longitude) %>% 18 | select(locality, decimalLatitude, decimalLongitude) %>% 19 | mutate(locality = str_replace_all(locality, "_", " "), 20 | locality = str_remove_all(locality, "\\.")) %>% 21 | distinct() 22 | 23 | ## 2.2 Main data ---- 24 | 25 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 26 | filter(datasetID == dataset & data_type == "main") %>% 27 | select(data_path) %>% 28 | pull() %>% 29 | read_xlsx(., sheet = "Plan view", na = c("NA", "na", " ", "")) %>% 30 | select(-"total Coral", -"total", -"struc complexity") %>% 31 | pivot_longer("sand":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 32 | rename(locality = location, parentEventID = count, verbatimDepth = depth) %>% 33 | left_join(., data_site) %>% 34 | mutate(datasetID = dataset) %>% 35 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 36 | 37 | # 3. Remove useless objects ---- 38 | 39 | rm(data_site) 40 | -------------------------------------------------------------------------------- /code/04_standardization/0169.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | 5 | dataset <- "0169" # Define the dataset_id 6 | 7 | # 2. Import, standardize and export the data ---- 8 | 9 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 10 | filter(datasetID == dataset & data_type == "main") %>% 11 | select(data_path) %>% 12 | pull() %>% 13 | read.csv() %>% 14 | pivot_longer("Actinaria..Anemone.":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 15 | select(-locality) %>% 16 | rename(eventDate = date..UTC., locality = site, decimalLatitude = site_latitude, 17 | decimalLongitude = site_longitude, verbatimDepth = depth_m, parentEventID = transect, 18 | recordedBy = observer, eventID = image_name) %>% 19 | select(locality, decimalLatitude, decimalLongitude, parentEventID, eventID, verbatimDepth, 20 | recordedBy, eventDate, organismID, measurementValue) %>% 21 | group_by(locality, decimalLatitude, decimalLongitude, parentEventID, verbatimDepth, eventDate) %>% 22 | mutate(eventID = as.numeric(as.factor(eventID))) %>% 23 | ungroup() %>% 24 | mutate(datasetID = dataset, 25 | samplingProtocol = "Photo-quadrat, 50 m transect length", 26 | eventDate = as.Date(eventDate), 27 | parentEventID = as.numeric(parentEventID), 28 | year = year(eventDate), 29 | month = month(eventDate), 30 | day = day(eventDate)) %>% 31 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 32 | -------------------------------------------------------------------------------- /code/04_standardization/0265.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0265" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., sheet = 1, na = c("", "NA", "na")) %>% 15 | pivot_longer("Hardcoral":"Other", names_to = "organismID", values_to = "measurementValue") %>% 16 | rename(locality = Site, year = Year, month = Month, parentEventID = Replicate, 17 | decimalLongitude = Longitude, decimalLatitude = Latitude, 18 | verbatimDepth = Depth) %>% 19 | select(locality, decimalLatitude, decimalLongitude, parentEventID, year, month, 20 | verbatimDepth, organismID, measurementValue) %>% 21 | mutate(verbatimDepth = ifelse(verbatimDepth > 20, NA, verbatimDepth), 22 | decimalLatitude2 = ifelse(decimalLatitude > 50, decimalLatitude, NA), 23 | decimalLongitude2 = ifelse(decimalLongitude < 50, decimalLongitude, NA), 24 | decimalLatitude = ifelse(is.na(decimalLatitude2) == TRUE, decimalLatitude, decimalLongitude2), 25 | decimalLongitude = ifelse(is.na(decimalLongitude2) == TRUE, decimalLongitude, decimalLatitude2), 26 | datasetID = dataset) %>% 27 | select(-decimalLatitude2, -decimalLongitude2) %>% 28 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 29 | -------------------------------------------------------------------------------- /code/04_standardization/0269.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0269" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., skip = 1, na = c("NA", "na")) %>% 15 | filter(Year >= 2018) %>% # Remove data before 2018, which are included in datasetID 0263 16 | pivot_longer("Hardcoral_percent":"Other_percent", names_to = "organismID", values_to = "measurementValue") %>% 17 | select(Site, Latitude, Longitude, Depth, Year, Month, Method, organismID, measurementValue) %>% 18 | drop_na(measurementValue) %>% 19 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, 20 | verbatimDepth = Depth, year = Year, month = Month, samplingProtocol = Method) %>% 21 | mutate(verbatimDepth = as.numeric(verbatimDepth), 22 | datasetID = dataset, 23 | organismID = str_remove_all(organismID, "_percent"), 24 | samplingProtocol = case_when(str_detect(samplingProtocol, "timed swim") == TRUE ~ "Timed swim", 25 | samplingProtocol == "Line_intercept_transect" ~ "Line Intercept Transect", 26 | samplingProtocol == "quadrat" ~ "Photo-quadrat")) %>% 27 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 28 | -------------------------------------------------------------------------------- /code/04_standardization/0230.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(sf) 5 | 6 | dataset <- "0230" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read.csv2(, skip = 1) %>% 15 | rename(eventDate = Date, decimalLatitude = Lat, decimalLongitude = Long, 16 | locality = Station_new) %>% 17 | select(eventDate, decimalLatitude, decimalLongitude, locality, X._Rec_coral, X._algal) %>% 18 | pivot_longer(5:ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 19 | mutate(organismID = str_replace_all(organismID, c("X._algal" = "Algae", 20 | "X._Rec_coral" = "Hard coral")), 21 | eventDate = as.Date(eventDate, format = "%d/%m/%y"), 22 | year = year(eventDate), 23 | month = month(eventDate), 24 | day = day(eventDate), 25 | datasetID = dataset, 26 | samplingProtocol = "Visual estimate, circulate plot of 5.6 m radius") %>% 27 | st_as_sf(coords = c("decimalLongitude", "decimalLatitude"), crs = "EPSG:2975") %>% 28 | st_transform(crs = 4326) %>% 29 | mutate(decimalLatitude = st_coordinates(.)[,2], 30 | decimalLongitude = st_coordinates(.)[,1]) %>% 31 | st_drop_geometry() %>% 32 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 33 | -------------------------------------------------------------------------------- /code/04_standardization/0174.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0174" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(, skip = 1) %>% 15 | rename(decimalLatitude = Approx_Lat, 16 | decimalLongitude = Approx_Long, 17 | eventDate = "Date_of_Observation/Survey", 18 | samplingProtocol = Method, 19 | locality = Reef, 20 | verbatimDepth = Approx_Depth_of_Bleaching, 21 | `Partially Live Coral` = "Partially Live") %>% 22 | select(locality, decimalLatitude, decimalLongitude, samplingProtocol, 23 | eventDate, verbatimDepth, "Live Coral", "Bleached Coral", "Dead Coral", 24 | "Partially Live Coral", "macroalgae", "turf algae", "crustose coralline algae") %>% 25 | mutate(across(c("Live Coral", "Bleached Coral", "Dead Coral", 26 | "Partially Live Coral"), ~.x*100)) %>% 27 | pivot_longer(7:ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 28 | mutate(verbatimDepth = as.numeric(str_replace_all(verbatimDepth, "Reef Flat", "0.5")), 29 | year = year(eventDate), 30 | month = month(eventDate), 31 | day = day(eventDate), 32 | datasetID = dataset) %>% 33 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0245.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0245" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., sheet = 1, na = c("", "NA", "na")) %>% 15 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, 16 | verbatimDepth = Depth, year = Year, month = Month, samplingProtocol = Method, 17 | parentEventID = Replicate) %>% 18 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, year, month, 19 | samplingProtocol, parentEventID, Hardcoral_percent, Softcoral_percent, 20 | Reckilledcoral_percent, Macroalgae_percent, Turfalgae_percent, 21 | Corallinealgae_percent, Other_percent) %>% 22 | pivot_longer("Hardcoral_percent":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 23 | mutate(organismID = str_remove_all(organismID, "_percent"), 24 | samplingProtocol = str_replace_all(samplingProtocol, "LIT", "Line intercept transect"), 25 | measurementValue = measurementValue*100, 26 | month = as.numeric(month), 27 | verbatimDepth = as.numeric(verbatimDepth), 28 | datasetID = dataset) %>% 29 | drop_na(measurementValue) %>% 30 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 31 | -------------------------------------------------------------------------------- /code/04_standardization/0004.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) # To read excel files 5 | 6 | dataset <- "0004" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | # 2.1 Site data -- 11 | 12 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "site") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | # Read the file 17 | read.csv2(file = .) %>% 18 | mutate(habitat = str_to_sentence(habitat)) 19 | 20 | # 2.2 Main data -- 21 | 22 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 23 | filter(datasetID == dataset & data_type == "main") %>% 24 | select(data_path) %>% 25 | pull() %>% 26 | # Read the file 27 | read_xlsx(path = ., sheet = 4) %>% 28 | select(-Campaign, -Season, -observations, -Year) %>% 29 | rename(eventDate = Date, locality = "Marine Area", habitat = Habitat, recordedBy = Observer, 30 | parentEventID = Transect, organismID = Substrate, measurementValue = proportion) %>% 31 | left_join(., data_site) %>% 32 | mutate(datasetID = dataset, 33 | year = year(eventDate), 34 | month = month(eventDate), 35 | day = day(eventDate), 36 | measurementValue = measurementValue*100, 37 | samplingProtocol = "Point intersect transect, 25 m transect length, every 50 cm") %>% 38 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 39 | 40 | # 3. Remove useless objects ---- 41 | 42 | rm(data_site) 43 | -------------------------------------------------------------------------------- /code/04_standardization/0157.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | source("code/00_functions/convert_coords.R") 7 | 8 | dataset <- "0157" # Define the dataset_id 9 | 10 | # 2. Import, standardize and export the data ---- 11 | 12 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "main") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | read_xlsx() %>% 17 | pivot_longer(6:ncol(.), names_to = "eventDate", values_to = "measurementValue") %>% 18 | drop_na(measurementValue) %>% 19 | select(-Transect, -Area) %>% 20 | rename(locality = Reef, decimalLatitude = Lat, decimalLongitude = Lon) %>% 21 | mutate(organismID = "Hard coral", 22 | year = case_when(eventDate == 33786 ~ 1992, 23 | eventDate == 34029 ~ 1993, 24 | eventDate == 34121 ~ 1993), 25 | month = case_when(eventDate == 33786 ~ 7, 26 | eventDate == 34029 ~ 2, 27 | eventDate == 34121 ~ 5), 28 | datasetID = dataset, 29 | across(c(decimalLatitude, decimalLongitude), ~str_replace_all(.x, c("′" = "'", 30 | "″" = "''"))), 31 | across(c(decimalLatitude, decimalLongitude), ~convert_coords(.x))) %>% 32 | select(-eventDate) %>% 33 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 34 | 35 | # 3. Remove useless objects ---- 36 | 37 | rm(convert_coords) 38 | -------------------------------------------------------------------------------- /code/04_standardization/0117.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0117" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 Site data ---- 11 | 12 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "site") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | read_xlsx(., range = "O9:P29", col_names = c("code", "locality")) 17 | 18 | ## 2.2 Main data ---- 19 | 20 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 21 | filter(datasetID == dataset & data_type == "main") %>% 22 | select(data_path) %>% 23 | pull() %>% 24 | read_xlsx(.) %>% 25 | rename(code = Reef, decimalLatitude = Latitude, decimalLongitude = Longitud, eventDate = Date) %>% 26 | select(code, decimalLatitude, decimalLongitude, eventDate, CoralC, AlgaeC) %>% 27 | pivot_longer("CoralC":"AlgaeC", names_to = "organismID", values_to = "measurementValue") %>% 28 | mutate(decimalLongitude = -decimalLongitude, 29 | organismID = str_replace_all(organismID, c("CoralC" = "Hard coral", 30 | "AlgaeC" = "Algae")), 31 | year = year(eventDate), 32 | month = month(eventDate), 33 | day = day(eventDate), 34 | datasetID = dataset) %>% 35 | left_join(., data_site) %>% 36 | select(-code) %>% 37 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 38 | 39 | # 3. Remove useless objects ---- 40 | 41 | rm(data_site) 42 | -------------------------------------------------------------------------------- /code/04_standardization/0241.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0241" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., sheet = 1, skip = 1, na = c("", "NA", "na")) %>% 15 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, 16 | verbatimDepth = Depth, eventDate = Year, samplingProtocol = Method, 17 | parentEventID = Replicate) %>% 18 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, eventDate, 19 | samplingProtocol, parentEventID, Hardcoral_percent, Softcoral_percent, 20 | Reckilledcoral_percent, Macroalgae_percent, Turfalgae_percent, 21 | Corallinealgae_percent, Other_percent) %>% 22 | pivot_longer("Hardcoral_percent":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 23 | mutate(year = year(eventDate), 24 | month = month(eventDate), 25 | day = day(eventDate), 26 | verbatimDepth = as.numeric(verbatimDepth), 27 | organismID = str_remove_all(organismID, "_percent"), 28 | samplingProtocol = str_replace_all(samplingProtocol, "Point_intercept_transect", "Point intercept transect"), 29 | datasetID = dataset) %>% 30 | drop_na(measurementValue) %>% 31 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 32 | -------------------------------------------------------------------------------- /code/04_standardization/0237.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | 5 | dataset <- "0237" # Define the dataset_id 6 | 7 | # 2. Import, standardize and export the data ---- 8 | 9 | ## 2.1 Site data ---- 10 | 11 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "site") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read.csv() 16 | 17 | ## 2.2 Main data ---- 18 | 19 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 20 | filter(datasetID == dataset & data_type == "main") %>% 21 | select(data_path) %>% 22 | pull() %>% 23 | read.csv() %>% 24 | left_join(., data_site) %>% 25 | select(-locality) %>% 26 | rename(decimalLatitude = latitude, decimalLongitude = longitude, verbatimDepth = depth_m, 27 | measurementValue = pct_cover, eventDate = date, locality = ps_site_id, 28 | samplingProtocol = method, organismID = morphotaxon) %>% 29 | select(locality, decimalLatitude, decimalLongitude, habitat, verbatimDepth, 30 | eventDate, organismID, measurementValue, samplingProtocol) %>% 31 | mutate(samplingProtocol = str_replace_all(samplingProtocol, "uvs", "Underwater Visual Sensus"), 32 | habitat = str_replace_all(habitat, "fore_reef", "Fore Reef"), 33 | year = year(eventDate), 34 | month = month(eventDate), 35 | day = day(eventDate), 36 | datasetID = dataset) %>% 37 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 38 | 39 | # 3. Remove useless objects ---- 40 | 41 | rm(data_site) 42 | -------------------------------------------------------------------------------- /code/04_standardization/0238.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | 5 | dataset <- "0238" # Define the dataset_id 6 | 7 | # 2. Import, standardize and export the data ---- 8 | 9 | ## 2.1 Site data ---- 10 | 11 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "site") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read.csv() 16 | 17 | ## 2.2 Main data ---- 18 | 19 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 20 | filter(datasetID == dataset & data_type == "main") %>% 21 | select(data_path) %>% 22 | pull() %>% 23 | read.csv() %>% 24 | left_join(., data_site) %>% 25 | select(-locality) %>% 26 | rename(decimalLatitude = latitude, decimalLongitude = longitude, verbatimDepth = depth_m, 27 | measurementValue = pct_cover, eventDate = date, locality = ps_site_id, 28 | samplingProtocol = method, organismID = morphotaxon) %>% 29 | select(locality, decimalLatitude, decimalLongitude, habitat, verbatimDepth, 30 | eventDate, organismID, measurementValue, samplingProtocol) %>% 31 | mutate(samplingProtocol = str_replace_all(samplingProtocol, "uvs", "Underwater Visual Sensus"), 32 | habitat = str_replace_all(habitat, "fore_reef", "Fore Reef"), 33 | year = year(eventDate), 34 | month = month(eventDate), 35 | day = day(eventDate), 36 | datasetID = dataset) %>% 37 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 38 | 39 | # 3. Remove useless objects ---- 40 | 41 | rm(data_site) 42 | -------------------------------------------------------------------------------- /code/04_standardization/0001.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) # To read excel files 5 | 6 | dataset <- "0001" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | # Read the file 15 | read_csv(file = ., na = c("nd", "", "NA", " ")) %>% 16 | select(-percentCover_CTB) %>% # CTB combine categories of CCA, Turf and bare, non recategorisable 17 | pivot_longer(percentCover_allCoral:percentCover_macroalgae, names_to = "organismID", values_to = "measurementValue") %>% 18 | rename(parentEventID = transect, eventID = quadrat, eventDate = Date, locality = site) %>% 19 | mutate(datasetID = dataset, 20 | year = year(eventDate), 21 | month = month(eventDate), 22 | day = day(eventDate), 23 | eventID = as.numeric(str_split_fixed(eventID, "Q", 2)[,2]), 24 | # Manually add metadata from file "edi.291.2.txt" 25 | verbatimDepth = case_when(locality == "Tektite" ~ 14, 26 | locality == "Yawzi" ~ 9), 27 | decimalLatitude = case_when(locality == "Tektite" ~ 18.30996508, 28 | locality == "Yawzi" ~ 18.31506678), 29 | decimalLongitude = case_when(locality == "Tektite" ~ -64.72321746, 30 | locality == "Yawzi" ~ -64.72551007)) %>% 31 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 32 | -------------------------------------------------------------------------------- /code/04_standardization/0251.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0251" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(path = ., sheet = 1, skip = 1, na = c("", "NA", "na")) %>% 15 | rename(locality = Location, decimalLatitude = Latitude, decimalLongitude = Longitude, 16 | verbatimDepth = Depth, year = Year, month = Month, samplingProtocol = Method, 17 | parentEventID = Replicate, measurementValue = Hardcoral_percent) %>% 18 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, year, month, 19 | samplingProtocol, parentEventID, measurementValue) %>% 20 | mutate(organismID = "Hard coral", 21 | datasetID = dataset, 22 | samplingProtocol = str_replace_all(samplingProtocol, c("Point_intercept_transect" = "Point intercept transect", 23 | "Belt_transect" = "Belt transect")), 24 | verbatimDepth = str_replace_all(verbatimDepth, c("3 to 5" = "4", 25 | "1 to 4" = "2.5")), 26 | verbatimDepth = as.numeric(verbatimDepth), 27 | month = str_replace_all(month, c("Nov" = "11", 28 | "Jun-Oct" = NA)), 29 | month = as.numeric(month)) %>% 30 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 31 | -------------------------------------------------------------------------------- /code/04_standardization/0210.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0210" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 Site data ---- 11 | 12 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "site") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | read_xlsx(., sheet = "sites") %>% 17 | rename(locality = Name, decimalLatitude = Latitude, decimalLongitude = Longitude) %>% 18 | select(locality, decimalLatitude, decimalLongitude) 19 | 20 | ## 2.2 Main data ---- 21 | 22 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 23 | filter(datasetID == dataset & data_type == "main") %>% 24 | select(data_path) %>% 25 | pull() %>% 26 | read_xlsx(., na = c("NA")) %>% 27 | select(-Aspect, -relative_depth) %>% 28 | rename(year = Year, locality = Site, verbatimDepth = depth, 29 | day = Day, month = Month, parentEventID = transect, eventID = quadrat, 30 | organismID = benthic_attribute, measurementValue = percent) %>% 31 | left_join(., data_site) %>% 32 | mutate(datasetID = dataset, 33 | eventDate = case_when(!(is.na(year)) & !(is.na(month)) & !(is.na(day)) ~ 34 | paste0(year, "-", str_pad(month, 2, pad = "0"), "-", str_pad(day, 2, pad = "0")), 35 | TRUE ~ NA), 36 | eventDate = as.Date(eventDate)) %>% 37 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 38 | 39 | # 3. Remove useless objects ---- 40 | 41 | rm(data_site) 42 | -------------------------------------------------------------------------------- /code/04_standardization/0047.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) # To read excel files 5 | 6 | dataset <- "0047" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | # Read the file 15 | read_xlsx(path = ., sheet = 1, col_types = c("text", "numeric", "numeric", "numeric", 16 | "date", "numeric", "text", "guess", "guess")) %>% 17 | drop_na(Site) %>% 18 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, 19 | verbatimDepth = Depth, eventDate = Date, parentEventID = Transect, organismID = Substrate) %>% 20 | select(1:7) %>% 21 | mutate(datasetID = dataset, 22 | year = year(eventDate), 23 | month = month(eventDate), 24 | day = day(eventDate), 25 | samplingProtocol = "Point intersect transect, 10 m transect length, every 20 cm") %>% 26 | # Correction on longitude and depth 27 | mutate(decimalLongitude = if_else(decimalLongitude > 0, -decimalLongitude, decimalLongitude), 28 | verbatimDepth = if_else(verbatimDepth == 45047.0, 1.5, verbatimDepth)) %>% 29 | group_by(across(-organismID)) %>% 30 | mutate(total = n()) %>% 31 | ungroup() %>% 32 | group_by_all() %>% 33 | count() %>% 34 | ungroup() %>% 35 | mutate(measurementValue = (n*100)/total) %>% 36 | select(-n, -total) %>% 37 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 38 | -------------------------------------------------------------------------------- /code/04_standardization/0113.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0113" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "DATA_V2", skip = 1, na = c("NA", "(blank)")) %>% 15 | # Remove HRI data since they are included within AGRRA data 16 | filter(`Organization that produced the data` != "The Healthy Reefs Initiative ") %>% 17 | select(-`...54`) %>% 18 | pivot_longer("Acropora":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 19 | rename(locality = Nombre_sitio, day = Día, month = Mes, year = Anio, 20 | decimalLatitude = Latitud, decimalLongitude = longitud, verbatimDepth = `Depth (m)`, 21 | parentEventID = Transecto, samplingProtocol = Metodo) %>% 22 | select(locality, day, month, year, decimalLatitude, decimalLongitude, 23 | verbatimDepth, parentEventID, samplingProtocol, organismID, measurementValue) %>% 24 | mutate(eventDate = paste0(year, "-", str_pad(month, width = 2, pad = "0"), 25 | "-", str_pad(day, width = 2, pad = "0")), 26 | datasetID = dataset) %>% 27 | group_by(locality, decimalLatitude, decimalLongitude, eventDate) %>% 28 | mutate(parentEventID = as.numeric(as.factor(parentEventID))) %>% 29 | ungroup() %>% 30 | drop_na(decimalLatitude) %>% # remove one empty row 31 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 32 | -------------------------------------------------------------------------------- /code/04_standardization/0142.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0142" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 Site data ---- 11 | 12 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "main") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | read_xlsx(., sheet = "site_metadata") 17 | 18 | ## 2.2 Main data ---- 19 | 20 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 21 | filter(datasetID == dataset & data_type == "main") %>% 22 | select(data_path) %>% 23 | pull() %>% 24 | read_xlsx(., sheet = "long_format") %>% 25 | left_join(., data_site) %>% 26 | rename(locality = "Site.Name", year = Year, month = Month, day = Day, parentEventID = Transect, 27 | verbatimDepth = "Depth.m", measurementValue = "Absolute.percent.cover", decimalLatitude = Latitude, 28 | decimalLongitude = Longitude) %>% 29 | mutate(eventDate = as.Date(paste(year, month, day, sep = "-")), 30 | organismID = case_when(Genus.or.group == "Turbinaria" ~ paste(Broad.group, Genus.or.group, sep = " - "), 31 | TRUE ~ Genus.or.group), 32 | datasetID = dataset, 33 | samplingProtocol = "Point intersect transect, 30 m transect length, every 50 cm") %>% 34 | select(datasetID, locality, decimalLatitude, decimalLongitude, verbatimDepth, parentEventID, eventDate, 35 | samplingProtocol, year, month, day, organismID, measurementValue) %>% 36 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 37 | 38 | # 3. Remove useless objects ---- 39 | 40 | rm(data_site) 41 | -------------------------------------------------------------------------------- /code/04_standardization/0118.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | 5 | dataset <- "0118" # Define the dataset_id 6 | 7 | # 2. Import, standardize and export the data ---- 8 | 9 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 10 | filter(datasetID == dataset & data_type == "main") %>% 11 | select(data_path) %>% 12 | pull() %>% 13 | read.csv() %>% 14 | pivot_longer("Sand":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 15 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, 16 | parentEventID = Replicate, eventID = Individual.Quadrat.ID, 17 | verbatimDepth = Depth_Below_Chart_Datum..m., recordedBy = Person.in.charge.of.observation) %>% 18 | mutate(locality = paste0("S", locality), 19 | samplingProtocol = "Photo-quadrat", 20 | year = case_when(Sampling.time == "February/March, 2016" ~ 2016, 21 | Sampling.time == "January, 2018" ~ 2018, 22 | Sampling.time == "January, 2020" ~ 2020, 23 | Sampling.time == "January/February, 2021" ~ 2021, 24 | Sampling.time == "October, 2016" ~ 2016), 25 | month = case_when(Sampling.time == "February/March, 2016" ~ 3, 26 | Sampling.time == "January, 2018" ~ 1, 27 | Sampling.time == "January, 2020" ~ 1, 28 | Sampling.time == "January/February, 2021" ~ 2, 29 | Sampling.time == "October, 2016" ~ 10), 30 | datasetID = dataset) %>% 31 | select(-Country, -Region, -Location, -Habitat, -Exposure, -Method, -Zone, -Sampling.time) %>% 32 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 33 | -------------------------------------------------------------------------------- /code/04_standardization/0211.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0211" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 Site data ---- 11 | 12 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "site") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | read_xlsx(., sheet = "sites") %>% 17 | rename(locality = Name, decimalLatitude = Latitude, decimalLongitude = Longitude) %>% 18 | select(locality, decimalLatitude, decimalLongitude) 19 | 20 | ## 2.2 Main data ---- 21 | 22 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 23 | filter(datasetID == dataset & data_type == "main") %>% 24 | select(data_path) %>% 25 | pull() %>% 26 | read_xlsx(., na = c("NA")) %>% 27 | rename(year = "Sample date: Year *", month = "Sample date: Month *", day = "Sample date: Day *", 28 | locality = "Site *", verbatimDepth = "Depth *", parentEventID = "Transect number *", 29 | eventID = "Quadrat *", organismID = "Benthic attribute *", measurementValue = "Percent") %>% 30 | select(year, month, day, locality, verbatimDepth, parentEventID, eventID, organismID, measurementValue) %>% 31 | left_join(., data_site) %>% 32 | mutate(datasetID = dataset, 33 | eventDate = case_when(!(is.na(year)) & !(is.na(month)) & !(is.na(day)) ~ 34 | paste0(year, "-", str_pad(month, 2, pad = "0"), "-", str_pad(day, 2, pad = "0")), 35 | TRUE ~ NA), 36 | eventDate = as.Date(eventDate)) %>% 37 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 38 | 39 | # 3. Remove useless objects ---- 40 | 41 | rm(data_site) 42 | -------------------------------------------------------------------------------- /code/04_standardization/0132.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | 5 | dataset <- "0132" # Define the dataset_id 6 | 7 | # 2. Import, standardize and export the data ---- 8 | 9 | ## 2.1 Site data ---- 10 | 11 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "site") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read.csv(.) %>% 16 | select(survey_id, site_latitude, site_longitude) %>% 17 | distinct() 18 | 19 | ## 2.2 Main data ---- 20 | 21 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 22 | filter(datasetID == dataset & data_type == "main") %>% 23 | select(data_path) %>% 24 | pull() %>% 25 | read.csv(.) %>% 26 | pivot_longer(13:ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 27 | left_join(., data_site) %>% 28 | rename(locality = site, eventDate = date..UTC., parentEventID = transect, 29 | eventID = image_name, verbatimDepth = depth_m, decimalLatitude = site_latitude, 30 | decimalLongitude = site_longitude) %>% 31 | select(locality, parentEventID, eventID, verbatimDepth, decimalLatitude, decimalLongitude, 32 | eventDate, organismID, measurementValue) %>% 33 | mutate(eventDate = as.Date(eventDate), 34 | year = year(eventDate), 35 | month = month(eventDate), 36 | day = day(eventDate), 37 | datasetID = dataset, 38 | samplingProtocol = "Photo-quadrat") %>% 39 | group_by(locality, parentEventID, eventDate, decimalLatitude, decimalLongitude, verbatimDepth) %>% 40 | mutate(eventID = as.numeric(as.factor(eventID))) %>% 41 | ungroup() %>% 42 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 43 | 44 | # 3. Remove useless objects ---- 45 | 46 | rm(data_site) 47 | -------------------------------------------------------------------------------- /code/04_standardization/0143.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0143" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 Site data ---- 11 | 12 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "main") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | read_xlsx(., sheet = "site_metadata") %>% 17 | rename(Site.name = Site.Name) 18 | 19 | ## 2.2 Main data ---- 20 | 21 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 22 | filter(datasetID == dataset & data_type == "main") %>% 23 | select(data_path) %>% 24 | pull() %>% 25 | read_xlsx(., sheet = "data_wide") %>% 26 | pivot_longer("Pavement":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 27 | left_join(., data_site) %>% 28 | rename(locality = "Site.name", year = Year, month = Month, day = Day, parentEventID = Transect, 29 | verbatimDepth = "Depth..m.", decimalLatitude = Latitude, 30 | decimalLongitude = Longitude) %>% 31 | mutate(eventDate = as.Date(paste(year, month, day, sep = "-")), 32 | organismID = case_when(organismID == "Turbinaria" ~ paste("Hard coral", organismID, sep = " - "), 33 | TRUE ~ organismID), 34 | datasetID = dataset, 35 | samplingProtocol = "Point intersect transect, 50 m transect length, every 50 cm") %>% 36 | select(datasetID, locality, decimalLatitude, decimalLongitude, verbatimDepth, parentEventID, eventDate, 37 | samplingProtocol, year, month, day, organismID, measurementValue) %>% 38 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 39 | 40 | # 3. Remove useless objects ---- 41 | 42 | rm(data_site) 43 | -------------------------------------------------------------------------------- /code/04_standardization/0007.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) # To read excel files 5 | 6 | dataset <- "0007" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | # 2.1 Code data -- 11 | 12 | data_code <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "code") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | # Read the file 17 | read.csv2(file = .) 18 | 19 | # 2.2 Main data -- 20 | 21 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 22 | filter(datasetID == dataset & data_type == "main") %>% 23 | select(data_path) %>% 24 | pull() %>% 25 | # Read the file 26 | read_xlsx(path = ., sheet = 3) %>% 27 | select(-Date, -Observations) %>% 28 | rename(year = Year, recordedBy = Observer, habitat = Habitat, 29 | parentEventID = Station, code = Substrate) %>% 30 | left_join(., data_code) %>% # Merge main data with substrates codes 31 | select(-code) %>% # Delete useless variables 32 | group_by(year, recordedBy, habitat, parentEventID, organismID) %>% 33 | count(name = "measurementValue") %>% 34 | ungroup() %>% 35 | group_by(year, recordedBy, habitat, parentEventID) %>% 36 | mutate(total = sum(measurementValue)) %>% 37 | ungroup() %>% 38 | mutate(datasetID = dataset, 39 | measurementValue = (measurementValue/total)*100, 40 | decimalLongitude = -149.901167, 41 | decimalLatitude = -17.470833, 42 | parentEventID = str_extract(parentEventID, "[1-9]"), 43 | samplingProtocol = "Point intersect transect, 50 m transect length, every 50 cm") %>% 44 | select(-total) %>% 45 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 46 | 47 | # 3. Remove useless objects ---- 48 | 49 | rm(data_code) -------------------------------------------------------------------------------- /code/04_standardization/0197.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0197" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xlsx(., sheet = "data_with_summary") %>% 15 | # Select the organization since multiple datasetID in a single Excel sheet 16 | filter(Organization == "PRÎSM") %>% 17 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, year = Year, 18 | samplingProtocol = Method, organismID = `Benthic category`, measurementValue = mean_cover) %>% 19 | select(locality, decimalLatitude, decimalLongitude, year, samplingProtocol, organismID, measurementValue) %>% 20 | mutate(datasetID = dataset, 21 | decimalLatitude = paste0(str_sub(decimalLatitude, 1, 3), ".", 22 | str_sub(decimalLatitude, 4, str_length(decimalLatitude))), 23 | decimalLatitude = str_replace_all(decimalLatitude, "\\.\\.", "\\."), 24 | decimalLatitude = as.numeric(decimalLatitude), 25 | decimalLongitude = paste0(str_sub(decimalLongitude, 1, 2), ".", 26 | str_sub(decimalLongitude, 3, str_length(decimalLongitude))), 27 | decimalLongitude = str_replace_all(decimalLongitude, "\\.\\.", "\\."), 28 | decimalLongitude = as.numeric(decimalLongitude)) %>% 29 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 30 | 31 | 32 | 33 | library(leaflet) 34 | 35 | 36 | leaflet(A) %>% 37 | addTiles() %>% 38 | addMarkers(~decimalLongitude, ~decimalLatitude, label = ~locality) 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /code/04_standardization/0002.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) # To read excel files 5 | 6 | dataset <- "0002" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | # 2.1 Site data -- 11 | 12 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "site") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | # Read the file 17 | read.csv2(file = .) 18 | 19 | # 2.2 Main data -- 20 | 21 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 22 | filter(datasetID == dataset & data_type == "main") %>% 23 | select(data_path) %>% 24 | pull() %>% 25 | # Read the file 26 | read_csv(file = ., na = c("NA", "", "nd", "999", "unk")) %>% 27 | select(-percentCover_all, -percentCover_CTB) %>% # CTB combine categories of CCA, Turf and bare, non recategorisable 28 | pivot_longer(percentCover_macroalgae:Millepora, names_to = "organismID", values_to = "measurementValue") %>% 29 | rename(locality = site, eventID = quadrat) %>% 30 | # Convert photoquadrat image name to quadrat number (for some of the rows) 31 | group_by(locality, year) %>% 32 | mutate(eventID = as.numeric(as.factor(eventID))) %>% 33 | ungroup() %>% 34 | mutate(datasetID = dataset, 35 | # Manually add metadata from file "edi.291.2.txt" 36 | verbatimDepth = 8, # between 7-9 m, mean chosen 37 | samplingProtocol = "Photo-quadrat, na, na, area of 0.5 x 0.5 m") %>% 38 | left_join(., data_site) %>% 39 | # Fix the issue of missing date 40 | mutate(year = case_when(year %in% c("7_2017", "11_2017") ~ "2017", 41 | TRUE ~ year)) %>% 42 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 43 | 44 | # 3. Remove useless objects ---- 45 | 46 | rm(data_site) 47 | -------------------------------------------------------------------------------- /code/04_standardization/0049.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) # To read excel files 5 | 6 | dataset <- "0049" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | # Read the file 15 | read_xlsx(path = ., sheet = 1, na = c("", "NA")) %>% 16 | select(1:9) %>% 17 | mutate(year = as.numeric(str_split_fixed(Date, "\\.", 2)[,1]), 18 | month = as.numeric(str_split_fixed(Date, "\\.", 2)[,2]), 19 | parentEventID = if_else(Sampling == "LIT.10m", Transect.Quadrat, NA), 20 | eventID = if_else(Sampling == "Quadrat.1m2", Transect.Quadrat, NA), 21 | datasetID = dataset) %>% 22 | select(-Date, -Transect.Quadrat) %>% 23 | rename(locality = Site, decimalLatitude = Latitude, decimalLongitude = Longitude, 24 | verbatimDepth = Depth, samplingProtocol = Sampling, organismID = Substrate, 25 | measurementValue = "%cover") %>% 26 | mutate(samplingProtocol = case_when(samplingProtocol == "LIT.10m" ~ 27 | "Line intersect transect, 10 m transect length", 28 | samplingProtocol == "Quadrat.1m2" ~ 29 | "Photo-quadrat, 10 m transect length, every 1 m, area of 1 m2, image analyzed by 91 point count"), 30 | organismID = str_replace_all(organismID, "Sand&Rubble", "Sand and rubble"), 31 | measurementValue = measurementValue*100) %>% 32 | mutate(across(c(decimalLatitude, decimalLongitude), ~ 33 | -(abs(as.numeric(str_split_fixed(.x, "°", 2)[,1])) + 34 | (as.numeric(str_split_fixed(.x, "°", 2)[,2])/60)))) %>% 35 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 36 | -------------------------------------------------------------------------------- /code/04_standardization/0022.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | 5 | dataset <- "0022" # Define the dataset_id 6 | 7 | # 2. Import, standardize and export the data ---- 8 | 9 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 10 | filter(datasetID == dataset & data_type == "main") %>% 11 | select(data_path) %>% 12 | pull() %>% 13 | # Read the file 14 | read.csv(.) %>% 15 | rename(decimalLatitude = x, decimalLongitude = y, verbatimDepth = depth, locality = site_code, habitat = reeftype) %>% 16 | pivot_longer("BRANCHING.CORALLINE.ALGAE":"TURF.ALGAE", values_to = "measurementValue", names_to = "organismID") %>% 17 | mutate(datasetID = dataset, 18 | year = str_split_fixed(event_date, "/", 3)[,3], 19 | month = str_split_fixed(event_date, "/", 3)[,1], 20 | day = str_split_fixed(event_date, "/", 3)[,2], 21 | eventDate = as_date(paste(year, month, day, sep = "-")), 22 | verbatimDepth = str_replace_all(verbatimDepth, c("8m" = "8", 23 | "3-5m" = "4", 24 | "3m" = "3")), 25 | verbatimDepth = as.numeric(verbatimDepth), 26 | transect_length = str_replace_all(transect_length, c("50m" = "50", 27 | "50 m" = "50", 28 | "25m" = "25", 29 | "50" = "50")), 30 | transect_length = as.numeric(transect_length), 31 | samplingProtocol = paste0("Photo-quadrat, ", transect_length," m transect length, every 1 m")) %>% 32 | select(-event_date, -"date.site", -transect_length, -subregion_name) %>% 33 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 34 | 35 | -------------------------------------------------------------------------------- /code/04_standardization/0052.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | 5 | dataset <- "0052" # Define the dataset_id 6 | 7 | # 2. Import, standardize and export the data ---- 8 | 9 | # 2.1 Site data -- 10 | 11 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "site") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | # Read the file 16 | read.csv(., na = c("NA", "na")) %>% 17 | rename(eventDate = date, locality = site, decimalLatitude = Latitude, 18 | decimalLongitude = Longitude, verbatimDepth = Depth_Stratum) %>% 19 | select(locality, eventDate, verbatimDepth, decimalLongitude, decimalLatitude) %>% 20 | mutate(eventDate = as.Date(eventDate), 21 | year = year(eventDate), 22 | month = month(eventDate), 23 | day = day(eventDate)) 24 | 25 | # 2.2 Main data -- 26 | 27 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 28 | filter(datasetID == dataset & data_type == "main") %>% 29 | select(data_path) %>% 30 | pull() %>% 31 | # Read the file 32 | read.csv() %>% 33 | pivot_longer("Acropora":ncol(.), values_to = "measurementValue", names_to = "organismID") %>% 34 | select(-Habitat, -Locality, -Island, -File) %>% 35 | rename(locality = Site, parentEventID = Transect, eventID = Quadrat) %>% 36 | left_join(., data_site) %>% 37 | group_by(locality) %>% 38 | mutate(parentEventID = as.numeric(as.factor(parentEventID))) %>% 39 | ungroup() %>% 40 | group_by(locality, parentEventID) %>% 41 | mutate(eventID = as.numeric(as.factor(eventID))) %>% 42 | ungroup() %>% 43 | mutate(samplingProtocol = "Photo-quadrat", 44 | datasetID = dataset) %>% 45 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 46 | 47 | # 3. Remove useless objects ---- 48 | 49 | rm(data_site) 50 | -------------------------------------------------------------------------------- /code/04_standardization/0217.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | source("code/00_functions/convert_coords.R") 6 | 7 | dataset <- "0217" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "main") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read_xlsx() %>% 16 | rename(decimalLatitude = Lat, decimalLongitude = Long, locality = Site, year = Year) %>% 17 | select(-SUM) %>% 18 | pivot_longer("HC":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 19 | mutate(datasetID = dataset, 20 | measurementValue = measurementValue*100, 21 | organismID = str_replace_all(organismID, c("HC" = "Hard coral", 22 | "SC" = "Soft coral", 23 | "RKC" = "Recently killed coral", 24 | "NIA" = "Algae", 25 | "SP" = "Sponges", 26 | "RC" = "Rock", 27 | "RB" = "Rubble", 28 | "SD" = "Sand", 29 | "SI" = "Silt", 30 | "OT" = "Other")), 31 | decimalLatitude = str_remove_all(decimalLatitude, "N"), 32 | decimalLongitude = str_remove_all(decimalLongitude, "E"), 33 | across(c("decimalLatitude", "decimalLongitude"), ~str_replace_all(.x, "º", "°")), 34 | across(c("decimalLatitude", "decimalLongitude"), ~convert_coords(.x))) %>% 35 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 36 | -------------------------------------------------------------------------------- /code/04_standardization/0218.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | source("code/00_functions/convert_coords.R") 6 | 7 | dataset <- "0218" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "main") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read_xlsx() %>% 16 | rename(decimalLatitude = Lat, decimalLongitude = Long, locality = Site, year = Year) %>% 17 | select(-SUM) %>% 18 | pivot_longer("HC":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 19 | mutate(datasetID = dataset, 20 | measurementValue = measurementValue*100, 21 | organismID = str_replace_all(organismID, c("HC" = "Hard coral", 22 | "SC" = "Soft coral", 23 | "RKC" = "Recently killed coral", 24 | "NIA" = "Algae", 25 | "SP" = "Sponges", 26 | "RC" = "Rock", 27 | "RB" = "Rubble", 28 | "SD" = "Sand", 29 | "SI" = "Silt", 30 | "OT" = "Other")), 31 | decimalLatitude = str_remove_all(decimalLatitude, "N"), 32 | decimalLongitude = str_remove_all(decimalLongitude, "E"), 33 | across(c("decimalLatitude", "decimalLongitude"), ~str_replace_all(.x, "º", "°")), 34 | across(c("decimalLatitude", "decimalLongitude"), ~convert_coords(.x))) %>% 35 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 36 | -------------------------------------------------------------------------------- /code/04_standardization/0152.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | 5 | source("code/00_functions/convert_coords.R") 6 | 7 | dataset <- "0152" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | ## 2.1 Site data ---- 12 | 13 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 14 | filter(datasetID == dataset & data_type == "site") %>% 15 | select(data_path) %>% 16 | pull() %>% 17 | read.csv() %>% 18 | rename(Site = ReefSite, decimalLatitude = Latitude..N., decimalLongitude = Longitude..W.) %>% 19 | mutate(across(c("decimalLatitude", "decimalLongitude"), ~convert_coords(.x)), 20 | decimalLongitude = -decimalLongitude) 21 | 22 | ## 2.2 Code data ---- 23 | 24 | data_code <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 25 | filter(datasetID == dataset & data_type == "code") %>% 26 | select(data_path) %>% 27 | pull() %>% 28 | read.csv() 29 | 30 | ## 2.3 Main data ---- 31 | 32 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 33 | filter(datasetID == dataset & data_type == "main") %>% 34 | select(data_path) %>% 35 | pull() %>% 36 | read.csv() %>% 37 | pivot_longer("acce_cover":ncol(.), names_to = "benthic_cover_code", values_to = "measurementValue") %>% 38 | left_join(., data_code) %>% 39 | left_join(., data_site) %>% 40 | rename(locality = Site, year = Year, organismID = Description, 41 | verbatimDepth = MedianDepth) %>% 42 | select(locality, verbatimDepth, year, decimalLatitude, decimalLongitude, organismID, measurementValue) %>% 43 | mutate(samplingProtocol = "Point intersect transect, 30 m transect length, every 25 cm", 44 | datasetID = dataset) %>% 45 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 46 | 47 | # 3. Remove useless objects ---- 48 | 49 | rm(data_site, data_code, convert_coords) 50 | -------------------------------------------------------------------------------- /code/04_standardization/0212.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0212" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 Site data ---- 11 | 12 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "site") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | read_xlsx(., sheet = "Coordinates") %>% 17 | rename(locality = Site, decimalLatitude = Lat, decimalLongitude = Long) %>% 18 | select(locality, decimalLatitude, decimalLongitude) 19 | 20 | ## 2.2 Main data ---- 21 | 22 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 23 | filter(datasetID == dataset & data_type == "main") %>% 24 | select(data_path) %>% 25 | pull() %>% 26 | read_xlsx(., na = c("NA")) %>% 27 | rename(eventDate = Date, locality = Site, parentEventID = Transect, eventID = Quadrat, 28 | organismID = Benthic_category, measurementValue = Percent, verbatimDepth = Relative_depth) %>% 29 | select(eventDate, locality, parentEventID, eventID, verbatimDepth, organismID, measurementValue) %>% 30 | left_join(., data_site) %>% 31 | mutate(year = year(eventDate), 32 | month = month(eventDate), 33 | day = day(eventDate), 34 | datasetID = dataset, 35 | verbatimDepth = case_when(verbatimDepth == "deep" ~ 14.5, 36 | verbatimDepth == "shallow" ~ 8), 37 | organismID = case_when(organismID == "DC" ~ "Dead coral", 38 | organismID == "CCA_DC" ~ "CCA on dead coral", 39 | TRUE ~ organismID), 40 | parentEventID = parse_number(parentEventID)) %>% 41 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 42 | 43 | # 3. Remove useless objects ---- 44 | 45 | rm(data_site) 46 | -------------------------------------------------------------------------------- /code/04_standardization/0250.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | source("code/00_functions/convert_coords.R") 6 | 7 | dataset <- "0250" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "main") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | read_xlsx(path = ., sheet = 1, na = c("", "NA", "na"), range = "A1:AD277") %>% 16 | pivot_longer("CORAL (LHC)":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 17 | drop_na(measurementValue) %>% 18 | rename(year = Year, month = Month, parentEventID = "Transect No.", locality = "Site*\r\nSee full name below") %>% 19 | mutate(decimalLatitude = str_split_fixed(Coordinates, "N ", 2)[,1], 20 | decimalLongitude = str_split_fixed(Coordinates, "N ", 2)[,2], 21 | across(c("decimalLatitude", "decimalLongitude"), ~convert_coords(.x))) %>% 22 | select(locality, parentEventID, decimalLatitude, decimalLongitude, month, year, organismID, measurementValue) %>% 23 | mutate(organismID = str_split_fixed(organismID, " \\(", 2)[,1], 24 | parentEventID = as.numeric(as.factor(parentEventID)), 25 | month = str_replace_all(month, c("May" = "5", 26 | "Dec" = "12", 27 | "Jan" = "1", 28 | "Aug" = "8", 29 | "Sep" = "9", 30 | "Jul-Sept" = NA, 31 | "Oct" = "10", 32 | "Nov" = "11")), 33 | month = as.numeric(month), 34 | datasetID = dataset) %>% 35 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 36 | -------------------------------------------------------------------------------- /code/04_standardization/0136.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0136" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | ## 2.1 Site data ---- 11 | 12 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "site") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | read_xlsx(path = ., sheet = 3) %>% 17 | rename(locality = Site, decimalLatitude = `GPS (south)`, 18 | decimalLongitude = `GPS (east)`, eventDate = Date) %>% 19 | select(locality, decimalLatitude, decimalLongitude, eventDate) %>% 20 | mutate(decimalLatitude = -decimalLatitude, 21 | eventDate = as.Date(eventDate)) 22 | 23 | ## 2.2 Main data ---- 24 | 25 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 26 | filter(datasetID == dataset & data_type == "main") %>% 27 | select(data_path) %>% 28 | pull() %>% 29 | read_xlsx(path = .) %>% 30 | pivot_longer("Acropora - Tabular":"Pavement", values_to = "measurementValue", names_to = "organismID") %>% 31 | drop_na(measurementValue) %>% 32 | rename(eventDate = Date, locality = Site, parentEventID = Transect, verbatimDepth = Depth) %>% 33 | select(eventDate, locality, parentEventID, verbatimDepth, organismID, measurementValue) %>% 34 | mutate(eventDate = as.Date(eventDate), 35 | parentEventID = as.numeric(parentEventID), 36 | datasetID = dataset, 37 | year = year(eventDate), 38 | month = month(eventDate), 39 | day = day(eventDate), 40 | samplingProtocol = "Point intersect transect, 50 m transect length, every 50 cm") %>% 41 | distinct() %>% 42 | left_join(., data_site) %>% 43 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 44 | 45 | # 3. Remove useless objects ---- 46 | 47 | rm(data_site) 48 | -------------------------------------------------------------------------------- /code/04_standardization/0054.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | 5 | dataset <- "0054" # Define the dataset_id 6 | 7 | # 2. Import, standardize and export the data ---- 8 | 9 | # 2.1 Site data -- 10 | 11 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 12 | filter(datasetID == dataset & data_type == "site") %>% 13 | select(data_path) %>% 14 | pull() %>% 15 | # Read the file 16 | read.csv(., na = c("NA", "na")) %>% 17 | rename(locality = site, eventDate = date, verbatimDepth = Depth_Stratum, 18 | decimalLatitude = Latitude, decimalLongitude = Longitude) %>% 19 | select(locality, eventDate, verbatimDepth, decimalLatitude, decimalLongitude) %>% 20 | mutate(eventDate = as.Date(eventDate, format = "%m/%d/%Y"), 21 | year = year(eventDate), 22 | month = month(eventDate), 23 | day = day(eventDate)) 24 | 25 | # 2.2 Main data -- 26 | 27 | # 2.3.1 Extract paths - 28 | 29 | data_main <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 30 | filter(datasetID == dataset & data_type == "main") %>% 31 | select(data_path) 32 | 33 | # 2.3.2 Combine and transform data - 34 | 35 | map_dfr(data_main$data_path, ~read_csv(file = .x)) %>% 36 | select(-Expedition_ID, -Island_Code, -Date, -Sum, -Calcifying, -"Non Calcifying") %>% 37 | rename(locality = Station_ID) %>% 38 | pivot_longer("Acropora":ncol(.), values_to = "measurementValue", names_to = "organismID") %>% 39 | left_join(., data_site) %>% 40 | mutate(parentEventID = as.numeric(str_extract(str_split_fixed(PicName, "_", 5)[,4], "[1-9]")), 41 | eventID = as.numeric(str_split_fixed(PicName, "_", 5)[,5]), 42 | samplingProtocol = "Photo-quadrat", 43 | datasetID = dataset) %>% 44 | select(-PicName) %>% 45 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 46 | 47 | # 3. Remove useless objects ---- 48 | 49 | rm(data_site) 50 | -------------------------------------------------------------------------------- /code/04_standardization/0154.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | 6 | dataset <- "0154" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 11 | filter(datasetID == dataset & data_type == "main") %>% 12 | select(data_path) %>% 13 | pull() %>% 14 | read_xls() %>% 15 | drop_na(Recordkey) %>% 16 | select(-c("PercentTotalCoral Includes Millepora?", "PercentTotalCoral", "TotalAlgalCover", 17 | "TotalAlgalCover SD", "TotalMacroalgalCover SD", "Macroalgae - Fleshy", "Percent Other Living", 18 | "SD...85", "TotalMacroalgae includes Lobophora?", "Macroalgae - Erect Calcareous", 19 | "SD...88", "TotalMacroalgae Includes Erect Calcareous?", "SD...91", "SD...93", 20 | "SD...95", "SD...97", "SD...99", "SD...101", "SD...103", "SD...105", "SD...107")) %>% 21 | pivot_longer("Acropora cervicornis":ncol(.), names_to = "organismID", values_to = "measurementValue") %>% 22 | rename(decimalLatitude = "Latitude (N)", decimalLongitude = "Longitude (W)", parentEventID = TransectID, 23 | locality = "ReefSite", year = "StartDate (MM/DD/YY)", verbatimDepth = "MedianDepth") %>% 24 | select(locality, decimalLatitude, decimalLongitude, verbatimDepth, parentEventID, 25 | year, organismID, measurementValue) %>% 26 | mutate(decimalLatitude = as.numeric(str_split_fixed(decimalLatitude, " ", 2)[,1]) + 27 | as.numeric(str_split_fixed(decimalLatitude, " ", 2)[,2])/60, 28 | decimalLongitude = as.numeric(str_split_fixed(decimalLongitude, " ", 2)[,1]) + 29 | as.numeric(str_split_fixed(decimalLongitude, " ", 2)[,2])/60, 30 | decimalLongitude = -decimalLongitude) %>% 31 | mutate(samplingProtocol = "Video transect, 25 m transect length", 32 | datasetID = dataset) %>% 33 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 34 | -------------------------------------------------------------------------------- /code/04_standardization/0005.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) # To read excel files 5 | 6 | dataset <- "0005" # Define the dataset_id 7 | 8 | # 2. Import, standardize and export the data ---- 9 | 10 | # 2.1 Site data -- 11 | 12 | data_site <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 13 | filter(datasetID == dataset & data_type == "site") %>% 14 | select(data_path) %>% 15 | pull() %>% 16 | # Read the file 17 | read.csv2(file = ., na.strings = c("", "NA")) %>% 18 | select(locality, decimalLatitude, decimalLongitude) 19 | 20 | # 2.2 Main data -- 21 | 22 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 23 | filter(datasetID == dataset & data_type == "main") %>% 24 | select(data_path) %>% 25 | pull() %>% 26 | # Read the file 27 | read_xlsx(path = ., 28 | sheet = 1, 29 | col_types = c("date", "numeric", "text", "text", "text", "text", "numeric", "text", 30 | "numeric", "text", "text", "text", "text", "text", "text")) %>% 31 | rename(eventDate = "date", locality = "île x site", recordedBy = "identificateur", eventID = "n° quadrat", 32 | organismID = "genre", measurementValue = "recouvrement %") %>% 33 | select(eventDate, locality, recordedBy, eventID, organismID, measurementValue) %>% 34 | mutate(datasetID = dataset, 35 | eventDate = as.Date(eventDate), 36 | year = year(eventDate), 37 | month = month(eventDate), 38 | day = day(eventDate), 39 | habitat = "Outer slope", # cf website SNO Corail 40 | verbatimDepth = 10, # Depth between 7 and 13 meters (cf website SNO Corail) 41 | samplingProtocol = "Photo-quadrat, 20 m transect length, every 1 m, area of 1 x 1 m, image analyzed by 81 point count") %>% 42 | left_join(., data_site) %>% 43 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 44 | 45 | # 3. Remove useless objects ---- 46 | 47 | rm(data_site) 48 | -------------------------------------------------------------------------------- /code/04_standardization/0214.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | library(readxl) 5 | source("code/00_functions/convert_coords.R") 6 | 7 | dataset <- "0214" # Define the dataset_id 8 | 9 | # 2. Import, standardize and export the data ---- 10 | 11 | ## 2.1 Path of files to combine ---- 12 | 13 | list_files <- read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 14 | filter(datasetID == dataset & data_type == "main") %>% 15 | select(data_path) %>% 16 | pull() %>% 17 | read_xlsx() %>% 18 | mutate(across(c(decimalLatitude, decimalLongitude), ~as.numeric(.x)), 19 | decimalLatitude = -abs(decimalLatitude)) 20 | 21 | ## 2.2 Function to combine the files ---- 22 | 23 | convert_data_214 <- function(row_i){ 24 | 25 | data <- read_xlsx(path = as.character(list_files[row_i, "path"]), 26 | range = as.character(list_files[row_i, "range"]), 27 | sheet = as.character(list_files[row_i, "sheet"])) %>% 28 | filter(row_number() > 16) %>% 29 | drop_na(2) %>% 30 | pivot_longer(2:ncol(.), names_to = "parentEventID", values_to = "measurementValue") %>% 31 | rename(organismID = 1) %>% 32 | mutate(parentEventID = parse_number(parentEventID), 33 | locality = as.character(list_files[row_i, "locality"]), 34 | decimalLatitude = as.numeric(list_files[row_i, "decimalLatitude"]), 35 | decimalLongitude = as.numeric(list_files[row_i, "decimalLongitude"]), 36 | year = as.numeric(list_files[row_i, "year"])) 37 | 38 | return(data) 39 | 40 | } 41 | 42 | ## 2.3 Map over the function ---- 43 | 44 | map(1:nrow(list_files), ~convert_data_214(row_i = .x)) %>% 45 | list_rbind() %>% 46 | mutate(datasetID = dataset, 47 | organismID = gsub("\\s*\\([^\\)]+\\)", "", organismID)) %>% 48 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 49 | 50 | # 3. Remove useless objects ---- 51 | 52 | rm(list_files, convert_data_214) 53 | -------------------------------------------------------------------------------- /code/04_standardization/0012.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | 5 | dataset <- "0012" # Define the dataset_id 6 | 7 | # 2. Import, standardize and export the data ---- 8 | 9 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 10 | filter(datasetID == dataset & data_type == "main") %>% 11 | select(data_path) %>% 12 | pull() %>% 13 | # Read the file 14 | read_csv(., na = c("", "NA", "NaN")) %>% 15 | slice(-1) %>% 16 | mutate(verbatimDepth = (as.numeric(min_depth) + as.numeric(max_depth))/2, 17 | verbatimDepth = round(verbatimDepth*0.3048, 1), # Convert depth from feet to meters 18 | datasetID = dataset, 19 | longitude = as.numeric(longitude), 20 | latitude = as.numeric(latitude), 21 | date_ = as.Date(date_), 22 | rep = as.numeric(as.factor(rep)), 23 | organismID = coalesce(genera_name, subcategory_name, category_name)) %>% 24 | rename(locality = site, parentEventID = rep, eventID = photoid, habitat = reef_zone, 25 | decimalLatitude = latitude, decimalLongitude = longitude, eventDate = date_, 26 | recordedBy = analyst) %>% 27 | select(datasetID, eventDate, locality, habitat, decimalLatitude, decimalLongitude, parentEventID, 28 | eventID, organismID, verbatimDepth) %>% 29 | mutate(year = year(eventDate), 30 | month = month(eventDate), 31 | day = day(eventDate), 32 | samplingProtocol = "Photo-quadrat") %>% 33 | # Calculate the number of points per image 34 | group_by(across(c(-organismID))) %>% 35 | mutate(total_points = n()) %>% 36 | ungroup() %>% 37 | # Calculate the number of points per benthic categories within image 38 | group_by_all() %>% 39 | summarise(n_points = n()) %>% 40 | ungroup() %>% 41 | # Calculate percentage cover 42 | mutate(measurementValue = (n_points*100)/total_points) %>% 43 | select(-total_points, -n_points) %>% 44 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 45 | -------------------------------------------------------------------------------- /code/04_standardization/0013.R: -------------------------------------------------------------------------------- 1 | # 1. Required packages ---- 2 | 3 | library(tidyverse) # Core tidyverse packages 4 | 5 | dataset <- "0013" # Define the dataset_id 6 | 7 | # 2. Import, standardize and export the data ---- 8 | 9 | read_csv("data/01_raw-data/benthic-cover_paths.csv") %>% 10 | filter(datasetID == dataset & data_type == "main") %>% 11 | select(data_path) %>% 12 | pull() %>% 13 | # Read the file 14 | read_csv(., na = c("", "NA", "NaN")) %>% 15 | slice(-1) %>% 16 | mutate(verbatimDepth = (as.numeric(min_depth) + as.numeric(max_depth))/2, 17 | verbatimDepth = round(verbatimDepth*0.3048, 1), # Convert depth from feet to meters 18 | datasetID = dataset, 19 | longitude = as.numeric(longitude), 20 | latitude = as.numeric(latitude), 21 | date_ = as.Date(date_), 22 | rep = as.numeric(as.factor(rep)), 23 | organismID = coalesce(genera_name, subcategory_name, category_name)) %>% 24 | rename(locality = site, parentEventID = rep, eventID = photoid, habitat = reef_zone, 25 | decimalLatitude = latitude, decimalLongitude = longitude, eventDate = date_, 26 | recordedBy = analyst) %>% 27 | select(datasetID, eventDate, locality, habitat, decimalLatitude, decimalLongitude, parentEventID, 28 | eventID, organismID, verbatimDepth) %>% 29 | mutate(year = year(eventDate), 30 | month = month(eventDate), 31 | day = day(eventDate), 32 | samplingProtocol = "Photo-quadrat") %>% 33 | # Calculate the number of points per image 34 | group_by(across(c(-organismID))) %>% 35 | mutate(total_points = n()) %>% 36 | ungroup() %>% 37 | # Calculate the number of points per benthic categories within image 38 | group_by_all() %>% 39 | summarise(n_points = n()) %>% 40 | ungroup() %>% 41 | # Calculate percentage cover 42 | mutate(measurementValue = (n_points*100)/total_points) %>% 43 | select(-total_points, -n_points) %>% 44 | write.csv(., file = paste0("data/02_standardized-data/", dataset, ".csv"), row.names = FALSE) 45 | --------------------------------------------------------------------------------