Skip to content

Commit

Permalink
fixing "intermediate" --> "int" directory name
Browse files Browse the repository at this point in the history
  • Loading branch information
annaramji committed Sep 6, 2024
1 parent 060aac8 commit a5a081d
Show file tree
Hide file tree
Showing 2 changed files with 1,194 additions and 64 deletions.
31 changes: 16 additions & 15 deletions globalprep/lsp/v2024/lsp_data_prep.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ output:
number_sections: yes
theme: cerulean
toc: yes
toc_float: true
pdf_document:
toc: yes
word_document:
Expand Down Expand Up @@ -48,7 +49,7 @@ v2021 Using updated February 2021 data

# Data Source

**Reference**: IUCN and UNEP-WCMC (2022), The World Database on Protected Areas (WDPA) [On-line], May 2024. Cambridge, UK: UNEP-WCMC. Available at: www.protectedplanet.net.
**Reference**: IUCN and UNEP-WCMC (2023), The World Database on Protected Areas (WDPA) [On-line], May 2024. Cambridge, UK: UNEP-WCMC. Available at: www.protectedplanet.net.

**Downloaded**: May 24, 2024

Expand Down Expand Up @@ -118,9 +119,9 @@ Comparing the global WDPA raster to the 3 nautical miles offshore and 1 km inlan
```{r lsp_zonal_stats, eval = FALSE}
# list intermedite file paths
zonal_files <- c('zonal_3nm' = file.path(dir_goal, 'intermediate', 'zonal_stats_3nm.csv'),
'zonal_1km' = file.path(dir_goal, 'intermediate', 'zonal_stats_1km.csv'),
'zonal_eez' = file.path(dir_goal, 'intermediate', 'zonal_stats_eez.csv'))
zonal_files <- c('zonal_3nm' = file.path(dir_goal, 'int', 'zonal_stats_3nm.csv'),
'zonal_1km' = file.path(dir_goal, 'int', 'zonal_stats_1km.csv'),
'zonal_eez' = file.path(dir_goal, 'int', 'zonal_stats_eez.csv'))
# load raster created in 1_prep_wdpa_rast.rmd
rast_wdpa <- terra::rast(file.path(dir_goal_anx, 'rast', 'wdpa_2024_moll_500m.tif'))
Expand All @@ -134,7 +135,7 @@ rgn_rast_list <- c(
'zonal_1km' = file.path(dir_zones, 'rgn_inland1km_mol_500mcell.tif'),
'zonal_eez' = file.path(dir_zones, 'rgn_eez_mol_500mcell.tif'))
### Remove all files in `intermediate` if it's the first time working through this data prep for this assessment
### Remove all files in `int` if it's the first time working through this data prep for this assessment
### Filters out finished zonal files: if zonal files don't exist yet, they will be created (comment out to recalculate)
zonal_files_to_run <- zonal_files[!file.exists(zonal_files)]
rgn_rast_list <- rgn_rast_list[!file.exists(zonal_files)]
Expand Down Expand Up @@ -201,7 +202,7 @@ cat('writeRaster elapsed: ', (proc.time() - ptm)[3])
z <- lsp_crosstab(rgn_rast_list[3], rast_values = rast_wdpa) #~51 min minutes to run #eez
cat('writeRaster elapsed: ', (proc.time() - ptm)[3])
## Save these files to the intermediate folder
## Save these files to the int folder
write_csv(x, zonal_files_to_run[1])
write_csv(y, zonal_files_to_run[2])
write_csv(z, zonal_files_to_run[3])
Expand Down Expand Up @@ -306,10 +307,10 @@ prot_1km <- stats_1km %>% calc_areas()
prot_3nm <- stats_3nm %>% calc_areas()
prot_eez <- stats_eez %>% calc_areas()
# write results to intermediate folder as csv
write_csv(prot_3nm, file.path(dir_goal, 'intermediate', 'area_protected_3nm.csv'))
write_csv(prot_1km, file.path(dir_goal, 'intermediate', 'area_protected_1km.csv'))
write_csv(prot_eez, file.path(dir_goal, 'intermediate', 'area_protected_eez.csv'))
# write results to int folder as csv
write_csv(prot_3nm, file.path(dir_goal, 'int', 'area_protected_3nm.csv'))
write_csv(prot_1km, file.path(dir_goal, 'int', 'area_protected_1km.csv'))
write_csv(prot_eez, file.path(dir_goal, 'int', 'area_protected_eez.csv'))
```

------------------------------------------------------------------------
Expand All @@ -323,10 +324,10 @@ From the protected area files, write out the individual layers ready for the Too

```{r write_layers, eval = FALSE}
# read in files and rename
prot_3nm <- read_csv(file.path(dir_goal, 'intermediate', 'area_protected_3nm.csv')) %>%
prot_3nm <- read_csv(file.path(dir_goal, 'int', 'area_protected_3nm.csv')) %>%
rename(area = a_tot_km2,
a_prot_3nm = a_prot_km2)
prot_1km <- read_csv(file.path(dir_goal, 'intermediate', 'area_protected_1km.csv')) %>%
prot_1km <- read_csv(file.path(dir_goal, 'int', 'area_protected_1km.csv')) %>%
rename(area = a_tot_km2,
a_prot_1km = a_prot_km2)
Expand All @@ -353,12 +354,12 @@ Some goals require calculation of resilience nearshore (3nm) or entire EEZ.
area_ref = .30 ### 30% of area protected = reference point
# read in regional data csvs from intermediate
resil_3nm <- read_csv(file.path(dir_goal, 'intermediate', 'area_protected_3nm.csv')) %>%
# read in regional data csvs from int
resil_3nm <- read_csv(file.path(dir_goal, 'int', 'area_protected_3nm.csv')) %>%
mutate(resilience.score = (a_prot_km2 / a_tot_km2) / area_ref,
resilience.score = ifelse(resilience.score > 1, 1, resilience.score))
resil_eez <- read_csv(file.path(dir_goal, 'intermediate', 'area_protected_eez.csv')) %>%
resil_eez <- read_csv(file.path(dir_goal, 'int', 'area_protected_eez.csv')) %>%
mutate(resilience.score = (a_prot_km2 / a_tot_km2) / area_ref,
resilience.score = ifelse(resilience.score > 1, 1, resilience.score))
# ask Mel about using file.path versus here function
Expand Down
1,227 changes: 1,178 additions & 49 deletions globalprep/lsp/v2024/lsp_data_prep.html

Large diffs are not rendered by default.

0 comments on commit a5a081d

Please sign in to comment.