|
|
|
|
|
|
| library(data.table)
|
|
|
| cat("
|
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| β ClimateAndMSP INPUT VALIDATION REPORT β
|
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
| ")
|
|
|
|
|
| check_file <- function(path, description, required = TRUE) {
|
| exists <- file.exists(path)
|
| status <- if (exists) "β FOUND" else "β MISSING"
|
| severity <- if (required) "[REQUIRED]" else "[OPTIONAL]"
|
| cat(sprintf("%s %s: %s\n", status, severity, description))
|
| return(exists)
|
| }
|
|
|
|
|
| check_dir <- function(path, description, required = TRUE) {
|
| exists <- dir.exists(path)
|
| status <- if (exists) "β EXISTS" else "β MISSING"
|
| severity <- if (required) "[REQUIRED]" else "[OPTIONAL]"
|
| cat(sprintf("%s %s: %s\n", status, severity, description))
|
| return(exists)
|
| }
|
|
|
|
|
|
|
|
|
| cat("\n[1] DIRECTORIES\n")
|
| cat("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
|
| dirs_ok <- c(
|
| check_dir("code/", "code/ (scripts)"),
|
| check_dir("data/", "data/ (static data)"),
|
| check_dir("output/", "output/ (results)"),
|
| check_dir("dataDL/", "dataDL/ (downloaded data)")
|
| )
|
|
|
|
|
|
|
|
|
| cat("\n[2] OUTPUT FILES (Pre-computed, mostly available)\n")
|
| cat("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
|
| output_files <- c(
|
| "output/climatology.csv.gz",
|
| "output/fishery_spps.csv",
|
| "output/landgridpts_northamerica.csv",
|
| "output/region_grid.csv.gz",
|
| "output/wdpa_cov_by_grid0.05.csv.gz",
|
| "output/grid0.05_cov_by_wdpa.csv.gz",
|
| "output/turnover_by_CMSPgrid.csv",
|
| "output/randMPAs_byBT.csv",
|
| "output/wind_npv.csv.gz",
|
| "output/wave_npv.csv.gz",
|
| "output/goalsmetbymod_hist_all.csv",
|
| "output/goalsmetbymod_2per_all.csv",
|
| "output/goalsmetbyensemble_hist_all.csv",
|
| "output/goalsmetbyensemble_2per_all.csv"
|
| )
|
|
|
| output_ok <- sapply(output_files, function(f) {
|
| exists <- file.exists(f)
|
| status <- if (exists) "β" else "β"
|
| cat(sprintf(" %s %s\n", status, f))
|
| return(exists)
|
| })
|
|
|
|
|
|
|
|
|
| cat("\n[3] MORLEY ET AL. SPECIES PROJECTIONS (dataDL/morley/)\n")
|
| cat("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
|
| morley_dir <- "dataDL/morley"
|
| if (dir.exists(morley_dir)) {
|
| morley_files <- list.files(morley_dir, recursive = TRUE)
|
| if (length(morley_files) > 0) {
|
| cat(sprintf(" β Found %d Morley projection files\n", length(morley_files)))
|
| for (f in head(morley_files, 5)) {
|
| cat(sprintf(" - %s\n", f))
|
| }
|
| if (length(morley_files) > 5) cat(sprintf(" ... and %d more\n", length(morley_files) - 5))
|
| } else {
|
| cat(" β Directory exists but is empty\n")
|
| }
|
| } else {
|
| cat(" β MISSING: dataDL/morley/\n")
|
| cat(" Required: Morley et al. 2018 species projection RData files\n")
|
| cat(" Source: BCO-DMO (dataset ID 753124)\n")
|
| cat(" URL: https://www.bco-dmo.org/dataset/753124\n")
|
| }
|
|
|
|
|
|
|
|
|
| cat("\n[4] WDPA (WORLD DATABASE OF PROTECTED AREAS)\n")
|
| cat("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
|
| wdpa_dirs <- c(
|
| "dataDL/WDPA/",
|
| "dataDL/WDPA_marine/",
|
| "dataDL/wdpa/"
|
| )
|
| wdpa_found <- FALSE
|
| for (d in wdpa_dirs) {
|
| if (dir.exists(d)) {
|
| shp_files <- list.files(d, pattern = "\\.shp$", recursive = TRUE)
|
| if (length(shp_files) > 0) {
|
| cat(sprintf(" β Found WDPA shapefile in: %s\n", d))
|
| wdpa_found <- TRUE
|
| }
|
| }
|
| }
|
| if (!wdpa_found) {
|
| cat(" β MISSING: WDPA marine protected areas shapefile\n")
|
| cat(" Required: WDPA_Aug2019_marine-shapefile or similar\n")
|
| cat(" Source: Protected Planet (https://www.protectedplanet.net/)\n")
|
| cat(" Action: Download 'WDPA_marine' shapefile and extract to dataDL/WDPA/\n")
|
| }
|
|
|
|
|
|
|
|
|
| cat("\n[5] OCEANADAPT DATA (dataDL/oceanadapt/)\n")
|
| cat("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
|
| oa_file <- "dataDL/oceanadapt/all-regions-full.rds"
|
| if (file.exists(oa_file)) {
|
| cat(" β all-regions-full.rds exists\n")
|
| } else {
|
| cat(" β MISSING: all-regions-full.rds\n")
|
| cat(" Source: Zenodo (https://zenodo.org/record/3890214)\n")
|
| cat(" Status: OPTIONAL (needed for 1.4_compare_WDPA_projections_data.r)\n")
|
| }
|
|
|
|
|
|
|
|
|
| cat("\n[6] TEMPORARY FILES (Generated during pipeline execution)\n")
|
| cat("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
|
| temp_files <- c(
|
| "temp/SPsf2.rds" = "Species projection grid",
|
| "temp/wdpa_by_grid0.05_intersect.rds" = "WDPA-grid intersection",
|
| "temp/presmap_Atl_rcp26_2007-2020.csv.gz" = "Atlantic presence/absence map",
|
| "temp/presmap_Pac_rcp26_2007-2020.csv.gz" = "Pacific presence/absence map",
|
| "temp/biomassmap_Atl_rcp26_2007-2020.csv.gz" = "Atlantic biomass map",
|
| "temp/biomassmap_Pac_rcp26_2007-2020.csv.gz" = "Pacific biomass map",
|
| "temp/wdpaturnbyMPAbymod.csv.gz" = "MPA turnover by model",
|
| "temp/wdpaturnbynetbymod.csv.gz" = "Network turnover by model"
|
| )
|
|
|
| temp_dir_exists <- dir.exists("temp")
|
| cat(sprintf(" temp/ directory: %s\n", if (temp_dir_exists) "β EXISTS" else "β MISSING"))
|
|
|
| for (file in names(temp_files)) {
|
| exists <- file.exists(file)
|
| status <- if (exists) "β" else "β"
|
| cat(sprintf(" %s %s (%s)\n", status, file, temp_files[file]))
|
| }
|
|
|
|
|
|
|
|
|
| cat("\n[7] NATCAP / INVEST OUTPUTS\n")
|
| cat("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
|
| natcap_regions <- c("westcoastwind", "eastcoastwind", "gulfwind", "alaskawind",
|
| "westcoastwave", "eastcoastwave", "gulfwave")
|
| natcap_found <- 0
|
| for (region in natcap_regions) {
|
| tif_pattern <- file.path("NatCap_temp", region, "output", "*.tif")
|
| tif_files <- list.files(file.path("NatCap_temp", region, "output"),
|
| pattern = "\\.tif$", full.names = TRUE)
|
| if (length(tif_files) > 0) {
|
| cat(sprintf(" β %s: found %d .tif files\n", region, length(tif_files)))
|
| natcap_found <- natcap_found + length(tif_files)
|
| } else {
|
| cat(sprintf(" β %s: (awaiting InVEST computation)\n", region))
|
| }
|
| }
|
|
|
| cat(sprintf("\nTotal NatCap files found: %d\n", natcap_found))
|
|
|
|
|
|
|
|
|
| cat("\n[8] STATIC DATA (data/ directory)\n")
|
| cat("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
|
| data_files <- list.files("data/", recursive = TRUE)
|
| if (length(data_files) > 0) {
|
| cat(sprintf(" β Found %d files in data/ directory:\n", length(data_files)))
|
| for (f in data_files) {
|
| cat(sprintf(" - %s\n", f))
|
| }
|
| } else {
|
| cat(" β data/ directory is empty (may not be needed)\n")
|
| }
|
|
|
|
|
|
|
|
|
| cat("\n")
|
| cat("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
|
| cat("β SUMMARY & NEXT STEPS β\n")
|
| cat("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n\n")
|
|
|
| missing_critical <- 0
|
| if (!dir.exists("dataDL/morley")) {
|
| cat("β CRITICAL: Morley et al. projections missing\n")
|
| missing_critical <- missing_critical + 1
|
| }
|
| if (!check_file("dataDL/WDPA/WDPA_Aug2019_marine-shapefile/WDPA_Aug2019_marine-shapefile-polygons.shp",
|
| "WDPA shapefile", required = FALSE)) {
|
| cat("β CRITICAL: WDPA shapefile missing\n")
|
| missing_critical <- missing_critical + 1
|
| }
|
|
|
| cat("\n")
|
| if (missing_critical == 0) {
|
| cat("β
All CRITICAL inputs are available!\n\n")
|
| cat("Recommended next steps:\n")
|
| cat(" 1. Run: Rscript code/1.0_processWDPA.r\n")
|
| cat(" 2. Then: Rscript code/plot_figures.r (to generate visualizations)\n")
|
| } else {
|
| cat(sprintf("β οΈ %d critical input(s) are missing\n\n", missing_critical))
|
| cat("To run the full pipeline, you need:\n")
|
| cat(" 1. Morley et al. species projection files (from BCO-DMO)\n")
|
| cat(" 2. WDPA marine shapefile (from ProtectedPlanet)\n")
|
| cat("\nOptional (for extended analysis):\n")
|
| cat(" 3. OceanAdapt RDS file (from Zenodo)\n")
|
| cat(" 4. InVEST output .tif files (requires separate NatCap computation)\n")
|
| }
|
|
|
| cat("\n")
|
| cat("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
|
|
|