Skip to content

Commit 50c4fcf

Browse files
committed
Fix model data
1 parent 9f3c89d commit 50c4fcf

File tree

2 files changed

+34
-36
lines changed

2 files changed

+34
-36
lines changed

R/mod_prepare_data.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ mod_prepare_data <- function(
159159
data_sp <- ecokit::load_as(data_sp) %>%
160160
dplyr::arrange(ias_id) %>%
161161
dplyr::mutate(
162-
ias_id = stringr::str_pad(ias_id, pad = "0", width = 4),
163-
ias_id = paste0("sp_", ias_id))
162+
ias_id = stringr::str_pad(ias_id, pad = "0", width = 4))
164163

165164
if (hab_abb == "0") {
166165
hab_column <- NULL

R/mod_prepare_hpc.R

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,39 @@ mod_prepare_hpc <- function(
564564
fs::path(path_model, "model_data.RData"), overwrite = TRUE)
565565

566566
}
567+
## # ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
568+
569+
# # |||||||||||||||||||||||||||||||||||
570+
# # Exclude grid cells with low number of presences -----
571+
# # |||||||||||||||||||||||||||||||||||
572+
573+
ecokit::cat_time(
574+
"Exclude grid cells with low number of presences",
575+
verbose = verbose_progress)
576+
577+
if (n_species_per_grid == 0) {
578+
ecokit::cat_time(
579+
paste0(
580+
"All grid cells, irrespective of number of species ",
581+
"presence, will be considered"),
582+
level = 1L, cat_timestamp = FALSE, verbose = verbose_progress)
583+
} else {
584+
empty_grids_id <- dplyr::select(
585+
data_all, tidyselect::starts_with("sp_")) %>%
586+
rowSums() %>%
587+
magrittr::is_less_than(as.integer(n_species_per_grid)) %>%
588+
which() %>%
589+
magrittr::multiply_by(-1)
590+
591+
if (length(empty_grids_id) > 0) {
592+
ecokit::cat_time(
593+
paste0(
594+
"Excluding grid cells with < ", n_species_per_grid,
595+
" species presence"),
596+
level = 1L, verbose = verbose_progress)
597+
data_all <- dplyr::slice(data_all, empty_grids_id)
598+
}
599+
}
567600

568601
# # ..................................................................... ###
569602

@@ -709,40 +742,6 @@ mod_prepare_hpc <- function(
709742

710743
## # ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
711744

712-
# # |||||||||||||||||||||||||||||||||||
713-
# # Exclude grid cells with low number of presences -----
714-
# # |||||||||||||||||||||||||||||||||||
715-
716-
ecokit::cat_time(
717-
"Exclude grid cells with low number of presences",
718-
verbose = verbose_progress)
719-
720-
if (n_species_per_grid == 0) {
721-
ecokit::cat_time(
722-
paste0(
723-
"All grid cells, irrespective of number of species ",
724-
"presence, will be considered"),
725-
level = 1L, cat_timestamp = FALSE, verbose = verbose_progress)
726-
} else {
727-
empty_grids_id <- dplyr::select(
728-
data_all, tidyselect::starts_with("sp_")) %>%
729-
rowSums() %>%
730-
magrittr::is_less_than(as.integer(n_species_per_grid)) %>%
731-
which() %>%
732-
magrittr::multiply_by(-1)
733-
734-
if (length(empty_grids_id) > 0) {
735-
ecokit::cat_time(
736-
paste0(
737-
"Excluding grid cells with < ", n_species_per_grid,
738-
" species presence"),
739-
level = 1L, verbose = verbose_progress)
740-
data_all <- dplyr::slice(data_all, empty_grids_id)
741-
}
742-
}
743-
744-
## # ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
745-
746745
# # |||||||||||||||||||||||||||||||||||
747746
# # Cross-validation ----
748747
# # |||||||||||||||||||||||||||||||||||

0 commit comments

Comments
 (0)