Skip to content

Commit

Permalink
Merge pull request #200 from dd-harp/dev
Browse files Browse the repository at this point in the history
Travel and exposure while traveling
  • Loading branch information
smitdave authored Oct 14, 2024
2 parents 4cbb826 + 6c09002 commit 0cd6fd8
Show file tree
Hide file tree
Showing 30 changed files with 395 additions and 271 deletions.
15 changes: 9 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,9 @@ S3method(setup_hydrology,func)
S3method(setup_rainfall,func)
S3method(setup_shock,func)
S3method(setup_temperature,func)
S3method(setup_travel_static,dts)
S3method(setup_travel_static,xde)
S3method(travel_malaria,dts)
S3method(travel_malaria,xde)
S3method(traveling,dynamic)
S3method(traveling,setup)
S3method(traveling,static)
S3method(trigger_setup,dynamic)
S3method(trigger_setup,setup)
S3method(trigger_setup,static)
Expand Down Expand Up @@ -585,6 +584,7 @@ export(setup_births_static)
export(setup_care_seeking_no_behavior)
export(setup_development)
export(setup_development_func)
export(setup_dynamic_travel)
export(setup_eip_fixedlag_dts)
export(setup_exposure_multiday)
export(setup_exposure_nb)
Expand All @@ -610,21 +610,24 @@ export(setup_no_school)
export(setup_no_shock)
export(setup_no_sugar_baits)
export(setup_no_temperature)
export(setup_no_travel)
export(setup_other_blood_hosts_static)
export(setup_rainfall)
export(setup_rainfall_func)
export(setup_resources_forced)
export(setup_resources_static)
export(setup_shock)
export(setup_shock_func)
export(setup_static_travel)
export(setup_sugar_static)
export(setup_temperature)
export(setup_temperature_func)
export(setup_travel_static)
export(setup_travel_eir)
export(setup_visitors_basic)
export(setup_visitors_static)
export(shapeIt)
export(travel_malaria)
export(travel_eir)
export(traveling)
export(trigger_setup)
export(update_Linits)
export(update_MYZinits)
Expand Down
4 changes: 3 additions & 1 deletion R/blood_feeding.R
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,10 @@ compute_TaR = function(t, TiSp, F_circadian, time_traveling){
#' @export
make_TaR <- function(pars, t=0){
for(s in 1:pars$nVectors)
for(i in 1:pars$nHosts)
for(i in 1:pars$nHosts){
pars = traveling(t, pars, i)
pars$TaR[[i]][[s]] = compute_TaR(t, pars$TimeSpent[[i]], pars$BFpar$F_circadian[[s]], pars$time_traveling[[i]])
}
return(pars)
}

Expand Down
15 changes: 10 additions & 5 deletions R/exposure-multiday.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
#' @description This function translates seven days of daily entomological
#' inoculation rate (dEIR) into a multiday attack rate. The daily FoI
#' is the sum of two terms: 1) a function [F_foi] computes the local dFoI;
#' 2) a function [travel_malaria] that computes the FoI resulting from
#' 2) a function [travel_eir] and [traveling]
#' exposure while traveling.
#' @inheritParams Exposure
#' @return the function modifies **pars** and returns it: the computed FoI are stored as `pars$FoI`
#' @export
Exposure.multiday <- function(t, y, pars){
dd = t%%pars$Xday + 1
for(i in 1:pars$nHosts){
pars$EIR_D[[i]][dd] = pars$EIR[[i]]
b = F_b(y, pars, i)
pars$AR[[i]] = F_ar(pars$EIR_D[[i]], b, pars) + travel_malaria(t, pars)
pars$EIR_D[[i]] = 0*pars$EIR[[i]]
trv = pars$time_traveling[[i]]
travelEIR = travel_eir(t, pars, i)*pars$Xday
b = as.vector(F_b(y, pars, i))
pars$AR[[i]] = (1-trv)*F_ar(pars$EIR[[i]]*pars$Xday, b, pars) + trv*F_ar(travelEIR, b, pars)
#pars$EIR_D[[i]][dd] = pars$EIR[[i]]
#b = F_b(y, pars, i)
#pars$AR[[i]] = F_ar(pars$EIR_D[[i]], b, pars) + F_a(t, pars)
#pars$EIR_D[[i]] = 0*pars$EIR[[i]]
}
return(pars)
}
Expand All @@ -28,3 +32,4 @@ setup_exposure_multiday <- function(pars) {
pars$EIR_D <- pars$EIR
return(pars)
}

17 changes: 10 additions & 7 deletions R/exposure.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @param y the state variables
#' @param pars an **`xds`** object
#' @return an **`xds`** object
#' @seealso Cases: [Exposure.xde] & [Exposure.dts]. Related: [travel_malaria] & [F_ar] & [F_foi]
#' @seealso Cases: [Exposure.xde] & [Exposure.dts]. Related: [F_ar] & [F_foi]
#' @export
Exposure <- function(t, y, pars){
UseMethod("Exposure", pars$xds)
Expand All @@ -23,17 +23,19 @@ Exposure <- function(t, y, pars){
#' per infectious bite, \eqn{b} (called from \eqn{F_b},
#' as defined by an \eqn{\cal X} model).
#' The total FoI is a weighted sum of the local FoI and
#' exposure to malaria while traveling, (\eqn{T_h}):
#' \deqn{h = (1-\delta) \; F_h(E, b) + \delta\; T_h(b,t)}
#' exposure to malaria while traveling,
#' computed from the the travel EIR, \eqn{E_T}:
#' \deqn{h = (1-\delta) \; F_h(E, b) + \delta\; F_h(E_T, b,t)}
#' @inheritParams Exposure
#' @seealso Related: [Exposure] & [F_foi.pois] & [F_foi.nb] & [travel_malaria]
#' @seealso Related: [Exposure] & [F_foi.pois] & [F_foi.nb] & [travel_eir] & [traveling]
#' @return an **`xds`** object
#' @export
Exposure.xde <- function(t, y, pars){
for(i in 1:pars$nHosts){
trv = pars$time_traveling[[i]]
travelEIR = travel_eir(t, pars, i)
b = as.vector(F_b(y, pars, i))
pars$FoI[[i]] = (1-trv)*F_foi(pars$EIR[[i]], b, pars) + trv*travel_malaria(t, pars)
pars$FoI[[i]] = (1-trv)*F_foi(pars$EIR[[i]], b, pars) + trv*F_foi(travelEIR, b, pars)
}
return(pars)
}
Expand All @@ -54,13 +56,14 @@ Exposure.xde <- function(t, y, pars){
#' \deqn{\alpha = (1-\delta) \; F_\alpha(E, b) + \delta\; T_\alpha(b)}
#' @inheritParams Exposure
#' @return an **`xds`** object
#' @seealso Related: [Exposure] & [F_ar.pois] & [F_ar.nb] & [travel_malaria]
#' @seealso Related: [Exposure] & [F_ar.pois] & [F_ar.nb] & [travel_eir] & [traveling]
#' @export
Exposure.dts <- function(t, y, pars){
for(i in 1:pars$nHosts){
trv = pars$time_traveling[[i]]
travelEIR = travel_eir(t, pars, i)*pars$Xday
b = as.vector(F_b(y, pars, i))
pars$AR[[i]] = (1-trv)*F_ar(pars$EIR[[i]]*pars$Xday, b, pars) + trv*travel_malaria(t, pars)
pars$AR[[i]] = (1-trv)*F_ar(pars$EIR[[i]]*pars$Xday, b, pars) + trv*F_ar(travelEIR, b, pars)
}
return(pars)
}
Expand Down
30 changes: 30 additions & 0 deletions R/travel_eir.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

#' @title Travel EIR
#' @description Compute the EIR while traveling
#' @param t the time
#' @param pars an **`xds`** object
#' @param i the host species index
#' @return the daily travel EIR, a [numeric] vector
#' @export
travel_eir <- function(t, pars, i){
with(pars$travel_eir[[i]], return(travelEIR*F_season(t)*F_trend(t)))
}

#' @title Setup Travel EIR
#' @description Set up a function to compute the travel EIR
#' @param pars a [list]
#' @param travelEIR the time spent traveling
#' @param F_season a function describing a seasonal pattern
#' @param F_trend a function describing a trend
#' @param i the host species index
#' @return an **`xds`** object
#' @export
setup_travel_eir = function(pars, travelEIR=0, F_season=F_flat, F_trend=F_flat, i=1){
trv <- list()
trv$travelEIR <- travelEIR
trv$F_season <- F_season
trv$F_trend <- F_trend
pars$travel_eir[[i]] <- trv
return(pars)
}

83 changes: 0 additions & 83 deletions R/travel_malaria.R

This file was deleted.

94 changes: 94 additions & 0 deletions R/traveling.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

#' @title A model for the travel FoI
#' @description Implements [traveling]. The function is
#' called by [make_TaR] to set the fraction of time spent
#' traveling
#' @param t current simulation time
#' @param pars a [list]#
#' @param i host species index
#' @return an **`xds`** object
#' @export
traveling <- function(t, pars, i) {
UseMethod("traveling", pars$travel[[i]])
}

#' @title A model for the travel FoI
#' @description Implements [traveling] through a model for the travel FoI
#' @inheritParams traveling
#' @return an **`xds`** object
#' @export
traveling.static <- function(t, pars, i) {
return(pars)
}

#' @title A model for the travel FoI
#' @description Implements [traveling] through a model for the travel FoI
#' @inheritParams traveling
#' @return an **`xds`** object
#' @export
traveling.setup <- function(t, pars, i) {
pars$time_traveling[[i]] <- pars$travel[[i]]$traveling_fraction
pars <- trigger_setup(pars$BFpar)
return(pars)
}

#' @title A model for the travel FoI
#' @description Implements [traveling] through a model for the travel FoI
#' @inheritParams traveling
#' @return an **`xds`** object
#' @export
traveling.dynamic <- function(t, pars, i) {
with(pars$travel[[i]],{
pars$time_traveling[[i]] = traveling*F_season(t)*F_trend(t)
return(pars)
})
}

#' @title A function to set up malaria importation
#' @description Setup a static model for travel malaria
#' @param pars a [list]
#' @param i the host species index
#' @return a [list]
#' @export
setup_no_travel = function(pars, i=1){
trv <- list()
class(trv) <- "static"
trv$traveling_fraction <- 0
pars$travel[[i]] <- trv
return(pars)
}

#' @title A function to set up malaria importation
#' @description Setup a static model for travel malaria
#' @param pars an **`xds`** object
#' @param traveling_fraction the fraction of time spent traveling
#' @param i the host species index
#' @return a [list]
#' @export
setup_static_travel = function(pars, traveling_fraction=0, i=1){
trv <- list()
class(trv) <- "setup"
trv$traveling_fraction <- traveling_fraction
pars$travel[[i]] <- trv
return(pars)
}

#' @title A function to set up malaria importation
#' @description Setup a static model for travel malaria
#' @param pars a [list]
#' @param traveling the time spent traveling
#' @param F_season a function describing a seasonal pattern
#' @param F_trend a function describing a trend
#' @param i the host species index
#' @return a [list]
#' @export
setup_dynamic_travel = function(pars, traveling=0, F_season=F_flat, F_trend=F_flat, i=1){
trv <- list()
class(trv) <- "dynamic"
class(pars$BFpar) <- "dynamic"
trv$traveling <- traveling
trv$F_season <- F_season
trv$F_trend <- F_trend
pars$travel[[i]] <- trv
return(pars)
}
7 changes: 5 additions & 2 deletions R/xds-template.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#' - [Exposure] is called *after* [Transmission] to compute environmentally heterogeneous exposure
#' and malaria importation through travel:
#' - [setup_exposure_pois] sets up a Poisson model for environmental heterogeneity
#' - [setup_travel_static] sets up a model with no exposure through travel
#' - [setup_no_travel] sets up a model with no exposure through travel
#'
#' @param xds is used to dispatch various functions to set up and solve systems of differential equations. 'xde' for ordinary or delay differential equations; 'dts' for "discrete time systems"
#' @param frame model component subset
Expand Down Expand Up @@ -103,7 +103,10 @@ make_xds_template = function(xds='ode', frame='full',
pars <- setup_TRANSMISSION(pars)

pars <- setup_exposure_pois(pars)
pars <- setup_travel_static(pars)
pars$travel <- list()
pars <- setup_no_travel(pars, 1)
pars$travel_eir <- list()
pars <- setup_travel_eir(pars, 1)

pars$Linits = list()
pars$MYZinits = list()
Expand Down
Loading

0 comments on commit 0cd6fd8

Please sign in to comment.