Skip to content

Commit

Permalink
Merge pull request #7 from SABS-R3-Epidemiology/full_functionality
Browse files Browse the repository at this point in the history
Full functionality
  • Loading branch information
Kemuk authored Jan 31, 2025
2 parents 9330149 + c4e9be3 commit ddf1ecf
Show file tree
Hide file tree
Showing 20 changed files with 950 additions and 448 deletions.
89 changes: 89 additions & 0 deletions R/simulation_epigeopop.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
source("R/wrapper.R")
# Example usage:
# Run complete simulation
run_complete_simulation <- function(country="Andorra",

Check warning on line 4 in R/simulation_epigeopop.r

View workflow job for this annotation

GitHub Actions / lint

file=R/simulation_epigeopop.r,line=4,col=44,[infix_spaces_linter] Put spaces around all infix operators.
output_file = "output.csv",
sir_plot_file = "SIR_plot.png",
rt_plot_file = "Rt_plot.png",
si_plot_file = "SerialInterval_plot.png",
simulation_duration = 60,
initial_infected = 100) {

Check warning on line 10 in R/simulation_epigeopop.r

View workflow job for this annotation

GitHub Actions / lint

file=R/simulation_epigeopop.r,line=10,col=62,[trailing_whitespace_linter] Trailing whitespace is superfluous.
output_dir <- paste0("data/", country, "/simulation_outputs")

# Initialize environment
pe <- initialize_simulation_env()

Check warning on line 14 in R/simulation_epigeopop.r

View workflow job for this annotation

GitHub Actions / lint

file=R/simulation_epigeopop.r,line=14,col=9,[object_usage_linter] no visible global function definition for 'initialize_simulation_env'

# User-defined variables
input_dir <- paste0("data/", country, "/inputs")
config_parameters <- paste0("data/", country, "_parameters.json")
seed <- 42

pe <- configure_parameters(pe, input_dir, config_parameters)

Check warning on line 21 in R/simulation_epigeopop.r

View workflow job for this annotation

GitHub Actions / lint

file=R/simulation_epigeopop.r,line=21,col=9,[object_usage_linter] no visible global function definition for 'configure_parameters'

sim_params <- list(
simulation_start_time = as.integer(0),
simulation_end_time = as.integer(simulation_duration),
simulation_seed = TRUE,
initial_infected_number = as.integer(initial_infected),
initial_infect_cell = FALSE,
include_waning = TRUE
)

file_params <- list(
output_file = output_file,
output_dir = output_dir,
spatial_output = TRUE,
age_stratified = TRUE
)

dem_file_params <- list(
output_dir = output_dir,
spatial_output = TRUE,
age_output = TRUE
)

inf_history_params <- list(
output_dir = output_dir,
status_output = TRUE,
infectiousness_output = TRUE,
compress = FALSE,
secondary_infections_output = TRUE,
generation_time_output = TRUE,
serial_interval_output = TRUE
)

Check warning on line 54 in R/simulation_epigeopop.r

View workflow job for this annotation

GitHub Actions / lint

file=R/simulation_epigeopop.r,line=54,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.

# Use Andorra population data
population <- create_epigeopop_population(pe,

Check warning on line 57 in R/simulation_epigeopop.r

View workflow job for this annotation

GitHub Actions / lint

file=R/simulation_epigeopop.r,line=57,col=17,[object_usage_linter] no visible global function definition for 'create_epigeopop_population'

Check warning on line 57 in R/simulation_epigeopop.r

View workflow job for this annotation

GitHub Actions / lint

file=R/simulation_epigeopop.r,line=57,col=48,[trailing_whitespace_linter] Trailing whitespace is superfluous.
paste0("data/", country, "/inputs/", country,

Check warning on line 58 in R/simulation_epigeopop.r

View workflow job for this annotation

GitHub Actions / lint

file=R/simulation_epigeopop.r,line=58,col=2,[indentation_linter] Hanging indent should be 44 spaces but is 2 spaces.

Check warning on line 58 in R/simulation_epigeopop.r

View workflow job for this annotation

GitHub Actions / lint

file=R/simulation_epigeopop.r,line=58,col=48,[trailing_whitespace_linter] Trailing whitespace is superfluous.
"_microcells.csv"))

Check warning on line 59 in R/simulation_epigeopop.r

View workflow job for this annotation

GitHub Actions / lint

file=R/simulation_epigeopop.r,line=59,col=2,[indentation_linter] Hanging indent should be 9 spaces but is 2 spaces.

# Run simulation
sim <- run_geopop_sim(pe, sim_params,
file_params, dem_file_params, population,
inf_history_params, seed)

# Process data
df_long <- process_simulation_data(file.path(output_dir, output_file))

print(colnames(df_long))
print(df_long)

# Generate SIR plot
sir_plot <- create_sir_plot(df_long, display = TRUE)
save_sir_plot(sir_plot, file.path(output_dir, sir_plot_file))

# Generate Rt plot
rt_plot <- plot_rt_curves(file.path(output_dir, "secondary_infections.csv"),
location = file.path(output_dir, rt_plot_file))

# Generate Serial Interval plot
si_plot <- create_serial_interval_plot(file.path(output_dir,
"serial_intervals.csv"), display = TRUE,
location = file.path(output_dir, si_plot_file))

return(list(simulation = sim, data = df_long,
sir_plot = sir_plot, rt_plot = rt_plot, si_plot = si_plot))
}

results <- run_complete_simulation()
157 changes: 0 additions & 157 deletions R/simulation_flow_check.R

This file was deleted.

97 changes: 97 additions & 0 deletions R/simulation_toy.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
source("R/wrapper.R")
# Example usage:
# Run complete simulation
run_complete_simulation <- function(output_dir="data/toy/simulation_outputs",
output_file = "output.csv",
sir_plot_file = "SIR_plot.png",
rt_plot_file = "Rt_plot.png",
si_plot_file = "SerialInterval_plot.png",
use_toy_example = TRUE,
simulation_duration = 60,
initial_infected = 10) {
# Initialize environment
pe <- initialize_simulation_env()

# User-defined variables
input_dir <- ""
config_parameters <- "data/toy/simple_parameters.json"
seed <- 42

pe <- configure_parameters(pe, input_dir, config_parameters)

# Create all parameter sets
pop_params <- list(
population_size = as.integer(100),
cell_number = as.integer(2),
microcell_number = as.integer(2),
household_number = as.integer(5),
place_number = as.integer(2)
)

sim_params <- list(
simulation_start_time = as.integer(0),
simulation_end_time = as.integer(simulation_duration),
simulation_seed = TRUE,
initial_infected_number = as.integer(initial_infected),
initial_infect_cell = TRUE,
include_waning = TRUE
)

file_params <- list(
output_file = output_file,
output_dir = output_dir,
spatial_output = FALSE,
age_stratified = FALSE
)

dem_file_params <- list(
output_dir = output_dir,
spatial_output = FALSE,
age_output = FALSE
)

inf_history_params <- list(
output_dir = output_dir,
status_output = TRUE,
infectiousness_output = TRUE,
compress = FALSE,
secondary_infections_output = TRUE,
generation_time_output = TRUE,
serial_interval_output = TRUE
)

# Select population creation function
population_creation_function <- if (use_toy_example) create_toy_population else create_epigeopop_population
# nolint: line_length_linter.
population <- population_creation_function(pe, if (use_toy_example) pop_params else "data/epigeopop.csv")

# Run simulation
sim <- run_simulation(pe, sim_params, file_params,
dem_file_params, population, inf_history_params, seed)

# Process data
df_long <- process_simulation_data(file.path(output_dir, output_file))

print(colnames(df_long))
print(df_long)

# Generate SIR plot
sir_plot <- create_sir_plot(df_long, display = TRUE)
save_sir_plot(sir_plot, file.path(output_dir, sir_plot_file))


# Generate Rt plot
rt_plot <- plot_rt_curves(file.path(output_dir,
"secondary_infections.csv"),
location = file.path(output_dir, rt_plot_file))

# Generate Serial Interval plot
si_plot <- create_serial_interval_plot(file.path(output_dir,
"serial_intervals.csv"), display = TRUE,
location = file.path(output_dir, si_plot_file))

return(list(simulation = sim, data = df_long,
sir_plot = sir_plot, rt_plot = "", si_plot = ""))
}

results <- run_complete_simulation()
Loading

0 comments on commit ddf1ecf

Please sign in to comment.