-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from nmfs-ost/test-convert-output
Add SS3 integration tests for testing convert_output()
- Loading branch information
Showing
21 changed files
with
226,978 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Download SS3 models and place them in the specified directory | ||
ss3_models <- r4ss::download_models( | ||
dir = test_path("fixtures", "ss3_models") | ||
) | ||
|
||
# Get the SS3 executable for running the models | ||
ss3_exe <- r4ss::get_ss3_exe( | ||
dir = test_path("fixtures", "ss3_models") | ||
) | ||
|
||
# Function to run a specific SS3 model | ||
run_ss3_models <- function(model_id, model_dir, exe_dir){ | ||
# Define the working directory for the model | ||
working_dir <- model_dir[model_id] | ||
|
||
# Copy the SS3 executable to the model's working directory | ||
file.copy(Sys.which(file.path(exe_dir, "ss3")), working_dir) | ||
|
||
# Run SS3 model | ||
r4ss::run(dir = working_dir) | ||
} | ||
|
||
# List all the model directories to be processed | ||
all_models <- list.dirs( | ||
file.path(test_path("fixtures", "ss3_models"), "models"), | ||
full.names = TRUE, | ||
recursive = FALSE | ||
) | ||
|
||
# Detect the number of available CPU cores, leaving one free | ||
core_num <- parallel::detectCores() - 1 | ||
|
||
# Initialize snowfall for parallel processing, using the detected core count | ||
snowfall::sfInit(parallel = TRUE, cpus = core_num) | ||
|
||
# Run the SS3 models in parallel using the snowfall library | ||
snowfall::sfLapply( | ||
1:length(all_models), | ||
run_ss3_models, | ||
all_models, | ||
test_path("fixtures", "ss3_models") | ||
) | ||
|
||
# Stop the snowfall parallel session | ||
snowfall::sfStop() | ||
|
||
# Remove the SS3 files except Report.sso from the working directory after the run is complete | ||
all_files <- list.files( | ||
test_path("fixtures", "ss3_models", "models"), | ||
full.names = TRUE, | ||
recursive = TRUE | ||
) | ||
report_files <- file.path(all_models, "Report.sso") | ||
|
||
report_id <- match(report_files, all_files) | ||
files_to_delete <- all_files[-report_id] | ||
file.remove(files_to_delete) | ||
|
||
# Clean up by removing the SS3 executable from the main directory after running all models | ||
file.remove(Sys.which(test_path("fixtures", "ss3_models", "ss3"))) |
Oops, something went wrong.