Skip to content

Commit d7185c9

Browse files
committed
fix pp
1 parent 381daf4 commit d7185c9

File tree

8 files changed

+23
-28
lines changed

8 files changed

+23
-28
lines changed

.lintr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ exclusions: list(
101101
"R/dwf_river_length.R" = list(line_length_linter = Inf),
102102
"R/mod_prepare_knots.R" = list(unnecessary_nesting_linter = 70:80),
103103
"R/mod_prepare_hpc.R" = list(line_length_linter = Inf),
104-
"R/mod_potprocess.R" = list(line_length_linter = 1011:1062),
104+
"R/mod_postprocess.R" = list(line_length_linter = 1011:1062),
105105
"R/dwf_wetness_index.R" = list(line_length_linter = Inf),
106106
"R/dwf_soil.R" = list(line_length_linter = Inf)
107107
)

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Package: IASDT.R
33
Title: Modelling the distribution of invasive alien plant species in
44
Europe
55
Version: 0.1.09
6-
Date: 2025-09-21
6+
Date: 2025-09-23
77
Authors@R:
88
person("Ahmed", "El-Gabbas", , "ahmed.el-gabbas@ufz.de", role = c("aut", "cre"),
99
comment = c(ORCID = "0000-0003-2225-088X"))
@@ -25,7 +25,7 @@ Imports:
2525
fs (>= 1.6.4),
2626
future (>= 1.34.0),
2727
future.apply (>= 1.11.3),
28-
ggplot2 (>= 3.5.1),
28+
ggplot2 (<= 3.5.2),
2929
Hmsc,
3030
Rcpp (>= 1.0.13),
3131
rlang (>= 1.1.4),
@@ -140,4 +140,4 @@ Encoding: UTF-8
140140
Language: en-GB
141141
LazyData: true
142142
Roxygen: list(markdown = TRUE)
143-
RoxygenNote: 7.3.2
143+
RoxygenNote: 7.3.3

R/mod_cv_evaluate.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ mod_cv_evaluate <- function(model_dir = NULL, cv_type = "cv_dist") {
6464

6565
# Model predictions -----
6666
model_predictions <- fs::path(
67-
model_dir, "model_prediction", "no_clamp", "prediction_current_R.qs2")
67+
model_dir, "model_prediction", "no_clamp", "prediction_current_r.qs2")
6868
if (!ecokit::check_data(model_predictions)) {
6969
ecokit::stop_ctx(
7070
"Model prediction file does not exist",

R/mod_predict_hmsc.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,19 +526,19 @@ predict_hmsc <- function(
526526
ecokit::cat_time(
527527
"Save ppEta / post as small chunks", level = 1L, verbose = verbose)
528528
chunk_size <- 25
529-
chunkIDs <- ceiling(seq_along(post) / chunk_size)
529+
chunk_ids <- ceiling(seq_along(post) / chunk_size)
530530
chunks <- purrr::map_chr(
531-
.x = seq_len(max(chunkIDs)),
531+
.x = seq_len(max(chunk_ids)),
532532
.f = ~ {
533-
IDs <- which(chunkIDs == .x)
533+
IDs <- which(chunk_ids == .x)
534534
Ch <- list(ppEta = ppEta[IDs], post = post[IDs])
535535
chunk_file <- fs::path(
536536
temp_dir, paste0(model_name, "_preds_ch", .x, ".qs2"))
537537
ecokit::save_as(object = Ch, out_path = chunk_file)
538538
return(chunk_file)
539539
})
540540

541-
rm(chunkIDs, post, ppEta, envir = environment())
541+
rm(chunk_ids, post, ppEta, envir = environment())
542542
invisible(gc())
543543

544544
seeds <- sample.int(.Machine$integer.max, predN)
@@ -866,7 +866,6 @@ get1prediction <- function(
866866

867867
updateZ <- updateEta <- NULL
868868

869-
870869
if (!is.null(seed)) {
871870
set.seed(seed)
872871
}

R/mod_predict_maps.R

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ predict_maps <- function(
259259
## Species information -----
260260

261261
species_info <- IASDT.R::get_species_name(env_file = env_file) %>%
262-
janitor::clean_names() %>%
263262
dplyr::select(ias_id, taxon_name, species_name, class, order, family)
264263

265264
# # |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| #
@@ -418,7 +417,9 @@ predict_maps <- function(
418417
# Models are trained and predictions are made only at grid cells with > 0 %
419418
# coverage. Mask layer to exclude grid cells with zero % coverage from
420419
# predictions.
421-
r_hab_mask <- terra::classify(r_hab, cbind(0, NA), others = 1)
420+
# r_hab_mask <- terra::classify(r_hab, cbind(0, NA), others = 1)
421+
# Update 2025_09: make predictions at the full study area, and if needed
422+
# predictions at 0% coverage could be masked
422423

423424
r_hab <- stats::setNames(log10(r_hab + 0.1), "habitat_log")
424425

@@ -759,13 +760,8 @@ predict_maps <- function(
759760
## Merge static predictors -----
760761
ecokit::cat_time("Merge static predictors", level = 1L)
761762

762-
static_predictors <- terra::rast(static_predictors)
763-
764-
# If Habitat predictor is used, grid cells with zero % coverage are
765-
# excluded from predictions
766-
if (hab_predictor) {
767-
static_predictors <- terra::mask(static_predictors, r_hab_mask)
768-
}
763+
static_predictors <- terra::rast(static_predictors) %>%
764+
terra::mask(ecokit::load_as(path_grid_r, unwrap_r = TRUE))
769765

770766
# # ..................................................................... ###
771767
# # ..................................................................... ###
@@ -871,7 +867,7 @@ predict_maps <- function(
871867
do_clamp <- prediction_options$clamp[[id]]
872868

873869
# Name of the current option
874-
option_name <- prediction_options$climate_name[[id]]
870+
option_name <- prediction_options$name[[id]]
875871

876872
# Name of the current model
877873
model_name <- paste0(
@@ -929,7 +925,7 @@ predict_maps <- function(
929925
path_prediction_sf <- fs::path(
930926
path_prediction, paste0("prediction_", option_name, "_sf.qs2"))
931927
path_prediction_r <- fs::path(
932-
path_prediction, paste0("prediction_", option_name, "_R.qs2"))
928+
path_prediction, paste0("prediction_", option_name, "_r.qs2"))
933929
path_prediction_summary <- fs::path(
934930
path_prediction, paste0("prediction_", option_name, "_summary.RData"))
935931

@@ -1140,7 +1136,7 @@ predict_maps <- function(
11401136
# use relevant folder containing the current predictions. This is
11411137
# determined by `path_prediction`, which is not the same whether
11421138
# clamping is used or not
1143-
path = path_prediction, pattern = "prediction_current.*_R.qs2",
1139+
path = path_prediction, pattern = "prediction_current.*_r.qs2",
11441140
full.names = TRUE) %>%
11451141
ecokit::load_as(unwrap_r = TRUE) %>%
11461142
terra::subset(mean_names)
@@ -1326,7 +1322,7 @@ predict_maps <- function(
13261322
current_mean <- list.files(
13271323
path = dplyr::if_else(
13281324
clamp_pred, path_prediction_clamp, path_prediction_no_clamp),
1329-
pattern = "prediction_current.*_R.qs2", full.names = TRUE)
1325+
pattern = "prediction_current.*_r.qs2", full.names = TRUE)
13301326

13311327
# --------------------------------------------------------- #
13321328

@@ -1429,7 +1425,7 @@ predict_maps <- function(
14291425
clamp_pred, path_prediction_clamp, path_prediction_no_clamp),
14301426
paste0(
14311427
"prediction_", stringr::str_replace(time_period, "-", "_"), "_",
1432-
climate_scenario, "_ensemble_R.qs2"))) %>%
1428+
climate_scenario, "_ensemble_r.qs2"))) %>%
14331429
dplyr::select(tidyselect::all_of(vars_to_select)) %>%
14341430
tidyr::nest(data = -ensemble_file)
14351431

@@ -1525,7 +1521,7 @@ predict_maps <- function(
15251521
climate_scenario, "_ensemble"),
15261522
file_pred_sf = NA_character_,
15271523
file_pred_r = stringr::str_replace(
1528-
file_pred_summary, "_summary.RData", "_R.qs2")) %>%
1524+
file_pred_summary, "_summary.RData", "_r.qs2")) %>%
15291525
dplyr::distinct()
15301526
}
15311527
# # ..................................................................... ###

R/mod_predict_maps_cv.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ predict_maps_cv <- function(
120120
path_prediction, paste0("prediction_", model_name, ".qs2"))
121121
path_eval_file <- fs::path(path_eval, paste0("eval_", model_name, ".qs2"))
122122
path_preds_r <- fs::path(
123-
path_prediction, paste0("prediction_", model_name, "_R.qs2"))
123+
path_prediction, paste0("prediction_", model_name, "_r.qs2"))
124124
path_preds_summary <- fs::path(
125125
path_prediction, paste0("prediction_", model_name, "_summary.RData"))
126126

R/mod_slurm_refit.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mod_slurm_refit <- function(
4040
# # ..................................................................... ###
4141

4242
if (is.null(job_name)) {
43-
job_name <- paste0(basename(model_dir), "_RF")
43+
job_name <- paste0(basename(model_dir), "_refit")
4444
}
4545

4646
# # ..................................................................... ###

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ If you use the `IASDT.R` package, please cite it as:
8181
> <a href="https://biodt.eu" target="_blank">https://biodt.eu</a>.
8282
8383
<span style=" color: grey !important;">Last update:
84-
2025-09-21</span>
84+
2025-09-23</span>

0 commit comments

Comments
 (0)