File size: 12,252 Bytes
e618ab8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/env Rscript
# Validate and report on required inputs for ClimateAndMSP project

library(data.table)

cat("

╔══════════════════════════════════════════════════════════════════════════════╗

β•‘                    ClimateAndMSP INPUT VALIDATION REPORT                     β•‘

β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•



")

# Function to check file existence
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)
}

# Function to check directory
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)
}

# ============================================================================
# Section 1: Base infrastructure
# ============================================================================
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)")
)

# ============================================================================
# Section 2: Data in output/ (usually pre-computed)
# ============================================================================
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)
})

# ============================================================================
# Section 3: Morley et al. species projections (CRITICAL)
# ============================================================================
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")
}

# ============================================================================
# Section 4: WDPA marine protected areas (CRITICAL)
# ============================================================================
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")
}

# ============================================================================
# Section 5: OceanAdapt species data (OPTIONAL)
# ============================================================================
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")
}

# ============================================================================
# Section 6: Temporary files (generated during pipeline)
# ============================================================================
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 "β—‹"  # circle = will be generated
  cat(sprintf("    %s %s (%s)\n", status, file, temp_files[file]))
}

# ============================================================================
# Section 7: NatCap data (InVEST outputs)
# ============================================================================
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))

# ============================================================================
# Section 8: Data in data/ directory
# ============================================================================
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")
}

# ============================================================================
# Summary & Recommendations
# ============================================================================
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")