From 6008a8a894c5364f44c322dd2caf2508e9fab2fa Mon Sep 17 00:00:00 2001 From: Hillary Topazian <80535782+htopazian@users.noreply.github.com> Date: Tue, 21 May 2024 14:23:32 +0100 Subject: [PATCH 1/5] adding in n_spray output - adding spraying to mortality processes - renaming process from RTS,S to PEV --- R/mortality_processes.R | 5 ++++- R/processes.R | 16 ++++++++-------- R/vector_control.R | 4 +++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/R/mortality_processes.R b/R/mortality_processes.R index 37792f6c..1e7446d9 100644 --- a/R/mortality_processes.R +++ b/R/mortality_processes.R @@ -111,9 +111,12 @@ reset_target <- function(variables, events, target, state, parameters, timestep) variables$pev_profile$queue_update(-1, target) variables$tbv_vaccinated$queue_update(-1, target) + # spraying + variables$spray_time$queue_update(-1, target) + # onwards infectiousness variables$infectivity$queue_update(0, target) - + # treated compartment residence time: if(!is.null(variables$dt)) { variables$dt$queue_update(parameters$dt, target) diff --git a/R/processes.R b/R/processes.R index 12f8c3db..1a7b2ebb 100644 --- a/R/processes.R +++ b/R/processes.R @@ -30,7 +30,7 @@ create_processes <- function( correlations, lagged_eir, lagged_infectivity, - timesteps, + timesteps, mixing = 1, mixing_index = 1 ) { @@ -105,22 +105,22 @@ create_processes <- function( 0 ) ) - + # ======================= # Antimalarial Resistance # ======================= # Add an a new process which governs the transition from Tr to S when # antimalarial resistance is simulated. The rate of transition switches # from a parameter to a variable when antimalarial resistance == TRUE. - + # Assign the dt input to a separate object with the default single parameter value: dt_input <- parameters$dt - - # If antimalarial resistance is switched on, assign dt variable values to the + + # If antimalarial resistance is switched on, assign dt variable values to the if(parameters$antimalarial_resistance) { dt_input <- variables$dt } - + # Create the progression process for Tr --> S specifying dt_input as the rate: processes <- c( processes, @@ -143,7 +143,7 @@ create_processes <- function( ) # ========= - # RTS,S EPI + # PEV EPI # ========= if (!is.null(parameters$pev_epi_coverage)) { processes <- c( @@ -250,7 +250,7 @@ create_processes <- function( if (parameters$spraying) { processes <- c( processes, - indoor_spraying(variables$spray_time, parameters, correlations) + indoor_spraying(variables$spray_time, renderer, parameters, correlations) ) } diff --git a/R/vector_control.R b/R/vector_control.R index 29c92d35..10d90c90 100644 --- a/R/vector_control.R +++ b/R/vector_control.R @@ -105,7 +105,8 @@ prob_bitten <- function( #' @param parameters the model parameters #' @param correlations correlation parameters #' @noRd -indoor_spraying <- function(spray_time, parameters, correlations) { +indoor_spraying <- function(spray_time, render, parameters, correlations) { + renderer$set_default('n_spray', 0) function(timestep) { matches <- timestep == parameters$spraying_timesteps if (any(matches)) { @@ -116,6 +117,7 @@ indoor_spraying <- function(spray_time, parameters, correlations) { correlations )) spray_time$queue_update(timestep, target) + renderer$render('n_spray', length(target), timestep) } } } From b0ef327debee530c2f29f97b0192a12d66db9c2a Mon Sep 17 00:00:00 2001 From: Hillary Topazian <80535782+htopazian@users.noreply.github.com> Date: Tue, 21 May 2024 19:22:04 +0100 Subject: [PATCH 2/5] fix typo renderer Co-authored-by: Giovanni --- R/vector_control.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/vector_control.R b/R/vector_control.R index 10d90c90..64405972 100644 --- a/R/vector_control.R +++ b/R/vector_control.R @@ -105,7 +105,7 @@ prob_bitten <- function( #' @param parameters the model parameters #' @param correlations correlation parameters #' @noRd -indoor_spraying <- function(spray_time, render, parameters, correlations) { +indoor_spraying <- function(spray_time, renderer, parameters, correlations) { renderer$set_default('n_spray', 0) function(timestep) { matches <- timestep == parameters$spraying_timesteps From 7a9966b852be93eb87ea4c7f80b82b3b85c784e5 Mon Sep 17 00:00:00 2001 From: Hillary Topazian <80535782+htopazian@users.noreply.github.com> Date: Tue, 21 May 2024 19:22:16 +0100 Subject: [PATCH 3/5] update documentation Co-authored-by: Giovanni --- R/vector_control.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/vector_control.R b/R/vector_control.R index 64405972..74ea0edb 100644 --- a/R/vector_control.R +++ b/R/vector_control.R @@ -102,6 +102,7 @@ prob_bitten <- function( #' `get_correlation_parameters` #' #' @param spray_time the variable for the time of spraying +#' @param renderer model rendering object #' @param parameters the model parameters #' @param correlations correlation parameters #' @noRd From f1eb68cc00b80515198b8b59cad37e340aecae0c Mon Sep 17 00:00:00 2001 From: Hillary Topazian <80535782+htopazian@users.noreply.github.com> Date: Tue, 21 May 2024 21:18:20 +0100 Subject: [PATCH 4/5] Update test-vector-control.R --- tests/testthat/test-vector-control.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/testthat/test-vector-control.R b/tests/testthat/test-vector-control.R index 8c2e2d49..3950ac87 100644 --- a/tests/testthat/test-vector-control.R +++ b/tests/testthat/test-vector-control.R @@ -201,9 +201,11 @@ test_that('indoor_spraying process sets spray_time correctly', { ms_gamma = matrix(c(-0.009, -0.009), nrow=2, ncol=1) ) spray_time <- mock_double(rep(0, 4)) + renderer <- list(render = mockery::mock()) correlations <- get_correlation_parameters(parameters) process <- indoor_spraying( spray_time, + renderer, parameters, correlations ) @@ -216,6 +218,7 @@ test_that('indoor_spraying process sets spray_time correctly', { mockery::expect_args(target_mock, 1, seq(4), 'spraying', .9, correlations) mockery::expect_args( spray_time$queue_update_mock(), + renderer$render, 1, 50, c(3, 4) From 7c5232c8b82e3dd6673a38af5339dc50cd4382ea Mon Sep 17 00:00:00 2001 From: Hillary Topazian <80535782+htopazian@users.noreply.github.com> Date: Tue, 21 May 2024 21:20:39 +0100 Subject: [PATCH 5/5] add whitespace back in --- R/mortality_processes.R | 2 +- R/processes.R | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/mortality_processes.R b/R/mortality_processes.R index 1e7446d9..71306c49 100644 --- a/R/mortality_processes.R +++ b/R/mortality_processes.R @@ -116,7 +116,7 @@ reset_target <- function(variables, events, target, state, parameters, timestep) # onwards infectiousness variables$infectivity$queue_update(0, target) - + # treated compartment residence time: if(!is.null(variables$dt)) { variables$dt$queue_update(parameters$dt, target) diff --git a/R/processes.R b/R/processes.R index 1a7b2ebb..a8c20efb 100644 --- a/R/processes.R +++ b/R/processes.R @@ -30,7 +30,7 @@ create_processes <- function( correlations, lagged_eir, lagged_infectivity, - timesteps, + timesteps, mixing = 1, mixing_index = 1 ) { @@ -105,22 +105,22 @@ create_processes <- function( 0 ) ) - + # ======================= # Antimalarial Resistance # ======================= # Add an a new process which governs the transition from Tr to S when # antimalarial resistance is simulated. The rate of transition switches # from a parameter to a variable when antimalarial resistance == TRUE. - + # Assign the dt input to a separate object with the default single parameter value: dt_input <- parameters$dt - - # If antimalarial resistance is switched on, assign dt variable values to the + + # If antimalarial resistance is switched on, assign dt variable values to the if(parameters$antimalarial_resistance) { dt_input <- variables$dt } - + # Create the progression process for Tr --> S specifying dt_input as the rate: processes <- c( processes,