Skip to content

Commit 1d3a1ea

Browse files
committed
Fix Road processing
1 parent 1d06632 commit 1d3a1ea

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

R/DWF_EASIN_process.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,18 @@ EASIN_process <- function(
247247
dplyr::distinct() %>%
248248
# Extract species name (exclude authors)
249249
dplyr::mutate(species_name = stringr::word(taxon_name, 1, 2)) %>%
250-
dplyr::rename(EASIN_Name = Name)
250+
dplyr::rename(EASIN_name = Name)
251251

252252
ecokit::cat_time("Check EASIN taxa not in the list", level = 1L)
253253
# EASIN taxa not in the reference list
254-
new_EASIN_taxa <- setdiff(EASIN_taxa$EASIN_Name, EASIN_ref$Name)
254+
new_EASIN_taxa <- setdiff(EASIN_taxa$EASIN_name, EASIN_ref$Name)
255255
if (length(new_EASIN_taxa) > 0) {
256256
tibble::tibble(NewTaxa = new_EASIN_taxa) %>%
257257
readr::write_tsv(
258258
file = fs::path(path_EASIN, "new_EASIN_taxa.txt"),
259259
progress = FALSE)
260260
}
261+
261262
## Save EASIN taxa - RData ----
262263
ecokit::cat_time("Save EASIN taxa - RData", level = 1L)
263264
save(EASIN_taxa, file = path_EASIN_taxa)
@@ -320,6 +321,7 @@ EASIN_process <- function(
320321
break
321322
}
322323

324+
# not_processedID
323325
data_download <- try(
324326
future.apply::future_lapply(
325327
X = not_processed, FUN = IASDT.R::EASIN_download, env_file = env_file,

R/DWF_road_intensity.R

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ road_intensity <- function(env_file = ".env") {
214214
extract_road_summary <- function(road_type, road_name, Function = "length") {
215215
summary_map <- list.files(
216216
path = path_road, full.names = TRUE,
217-
pattern = paste0("^road_sf_", road_type, "_.+RData")) %>%
217+
pattern = paste0("^road_sf_", road_type, "_.+qs2")) %>%
218218
ecokit::load_as(unwrap_r = TRUE) %>%
219219
terra::rasterizeGeom(y = grid_ref, fun = Function, unit = "km") %>%
220220
terra::mask(mask = grid_ref) %>%
@@ -224,18 +224,23 @@ road_intensity <- function(env_file = ".env") {
224224

225225
ecokit::cat_time("1 - Highways", level = 2L)
226226
grip_1 <- extract_road_summary(road_type = 1, road_name = "Highways")
227+
invisible(gc())
227228

228229
ecokit::cat_time("2 - Primary", level = 2L)
229230
grip_2 <- extract_road_summary(road_type = 2, road_name = "Primary")
231+
invisible(gc())
230232

231233
ecokit::cat_time("3 - Secondary", level = 2L)
232234
grip_3 <- extract_road_summary(road_type = 3, road_name = "Secondary")
235+
invisible(gc())
233236

234237
ecokit::cat_time("4 - Tertiary", level = 2L)
235238
grip_4 <- extract_road_summary(road_type = 4, road_name = "Tertiary")
239+
invisible(gc())
236240

237241
ecokit::cat_time("5 - Local", level = 2L)
238242
grip_5 <- extract_road_summary(road_type = 5, road_name = "Local")
243+
invisible(gc())
239244

240245
ecokit::cat_time("All roads", level = 2L)
241246
road_length <- (grip_1 + grip_2 + grip_3 + grip_4 + grip_5) %>%
@@ -274,8 +279,8 @@ road_intensity <- function(env_file = ".env") {
274279
.x = as.list(road_length),
275280
.f = ~ {
276281
ecokit::cat_time(names(.x), level = 2L)
277-
Road_Points <- terra::as.points(terra::classify(.x, cbind(0, NA)))
278-
terra::distance(x = .x, y = Road_Points, unit = "km") %>%
282+
road_points <- terra::as.points(terra::classify(.x, cbind(0, NA)))
283+
terra::distance(x = .x, y = road_points, unit = "km") %>%
279284
terra::mask(grid_ref) %>%
280285
stats::setNames(paste0("road_distance_", names(.x))) %>%
281286
# Ensure that values are read from memory
@@ -339,8 +344,8 @@ road_intensity <- function(env_file = ".env") {
339344
plots_length <- purrr::map(
340345
.x = terra::as.list(road_length),
341346
.f = ~ {
342-
Road <- log10(terra::classify(.x, cbind(0, NA)))
343-
Title <- names(.x) %>%
347+
road_to_plot <- log10(terra::classify(.x, cbind(0, NA)))
348+
plot_title <- names(.x) %>%
344349
stringr::str_remove("road_distance_") %>%
345350
stringr::str_replace("_", " - ") %>%
346351
paste(" roads")
@@ -350,7 +355,7 @@ road_intensity <- function(env_file = ".env") {
350355
EU_boundaries,
351356
mapping = ggplot2::aes(), color = "grey75",
352357
linewidth = 0.075, fill = "grey98") +
353-
tidyterra::geom_spatraster(data = Road, maxcell = Inf) +
358+
tidyterra::geom_spatraster(data = road_to_plot, maxcell = Inf) +
354359
ggplot2::geom_sf(
355360
EU_boundaries,
356361
mapping = ggplot2::aes(), color = "grey30",
@@ -363,10 +368,9 @@ road_intensity <- function(env_file = ".env") {
363368
ggplot2::scale_y_continuous(
364369
expand = ggplot2::expansion(mult = c(0, 0)),
365370
limits = c(1450000, 5420000)) +
366-
ggplot2::labs(title = Title, fill = "log10") +
371+
ggplot2::labs(title = plot_title, fill = "log10") +
367372
plot_theme
368-
}
369-
)
373+
})
370374

371375
plots_length <- patchwork::wrap_plots(plots_length, ncol = 3, nrow = 2) +
372376
patchwork::plot_annotation(
@@ -412,8 +416,7 @@ road_intensity <- function(env_file = ".env") {
412416
limits = c(1450000, 5420000)) +
413417
ggplot2::labs(title = paste0(names(.x), " roads"), fill = "km") +
414418
plot_theme
415-
}
416-
)
419+
})
417420

418421
plots_distance <- patchwork::wrap_plots(plots_distance, ncol = 3, nrow = 2) +
419422
patchwork::plot_annotation(

0 commit comments

Comments
 (0)