Skip to content

Commit

Permalink
Merge branch 'main' into toy-spatial
Browse files Browse the repository at this point in the history
  • Loading branch information
KCGallagher authored Sep 27, 2023
2 parents 612e933 + 614f503 commit d01dd41
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 60 deletions.
15 changes: 8 additions & 7 deletions pyEpiabm/pyEpiabm/property/household_foi.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ def household_inf(infector, time: float):
@staticmethod
def household_susc(infector, infectee, time: float):
"""Calculate the susceptibility of one person to another in a given
household. Does not include interventions such as isolation,
or whether individual is a carehome resident.
household. Intervention parameters are based on the microcell
properties of the infectee. Does not include interventions such as
isolation, or whether individual is a carehome resident.
Parameters
----------
Expand All @@ -66,11 +67,11 @@ def household_susc(infector, infectee, time: float):
"""
household_susceptibility = PersonalInfection.person_susc(
infector, infectee, time)
if (hasattr(infector.microcell, 'distancing_start_time')) and (
infector.microcell.distancing_start_time is not None) and (
infector.microcell.distancing_start_time <= time):
if (hasattr(infector, 'distancing_enhanced')) and (
infector.distancing_enhanced is True):
if (hasattr(infectee.microcell, 'distancing_start_time')) and (
infectee.microcell.distancing_start_time is not None) and (
infectee.microcell.distancing_start_time <= time):
if (hasattr(infectee, 'distancing_enhanced')) and (
infectee.distancing_enhanced is True):
household_susceptibility *= Parameters.instance().\
intervention_params['social_distancing'][
'distancing_house_enhanced_susc']
Expand Down
24 changes: 11 additions & 13 deletions pyEpiabm/pyEpiabm/property/place_foi.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,14 @@ def place_inf(place, infector, time: float):
return place_inf

@staticmethod
def place_susc(place, infector, infectee,
time: float):
"""Calculate the susceptibility of a place.
Does not include interventions such as isolation,
or whether individual is a carehome resident.
def place_susc(place, infectee, time: float):
"""Calculate the susceptibility of a place. Intervention parameters
are based on the microcell properties of the infectee. Does not include
interventions such as isolation, or whether individual is a carehome
resident.
Parameters
----------
infector : Person
Infector
infectee : Person
Infectee
place : Place
Expand All @@ -80,11 +78,11 @@ def place_susc(place, infector, infectee,
"""
place_susc = 1.0
place_idx = place.place_type.value - 1
if (hasattr(infector.microcell, 'distancing_start_time')) and (
infector.microcell.distancing_start_time is not None) and (
infector.microcell.distancing_start_time <= time):
if (hasattr(infector, 'distancing_enhanced')) and (
infector.distancing_enhanced is True):
if (hasattr(infectee.microcell, 'distancing_start_time')) and (
infectee.microcell.distancing_start_time is not None) and (
infectee.microcell.distancing_start_time <= time):
if (hasattr(infectee, 'distancing_enhanced')) and (
infectee.distancing_enhanced is True):
place_susc *= Parameters.instance().\
intervention_params[
'social_distancing'][
Expand Down Expand Up @@ -153,6 +151,6 @@ def place_foi(place, infector, infectee,

infectiousness = (PlaceInfection.place_inf(place, infector, time)
* isolation_scale_inf * quarantine_scale)
susceptibility = (PlaceInfection.place_susc(place, infector, infectee,
susceptibility = (PlaceInfection.place_susc(place, infectee,
time) * carehome_scale_susc * quarantine_scale)
return (infectiousness * susceptibility)
25 changes: 12 additions & 13 deletions pyEpiabm/pyEpiabm/property/spatial_foi.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ def spatial_inf(inf_cell, infector,
return infector.infectiousness * age * closure_spatial

@staticmethod
def spatial_susc(susc_cell, infector, infectee, time: float):
def spatial_susc(susc_cell, infectee, time: float):
"""Calculate the susceptibility of one cell towards its neighbouring
cells.
cells. Intervention parameters are based on the microcell properties
of the infectee.
Parameters
----------
susc_cell : Cell
Cell receiving infections
infector : Person
Infector
infectee : Person
Infectee
time : float
Expand All @@ -114,17 +113,17 @@ def spatial_susc(susc_cell, infector, infectee, time: float):

spatial_susc *= Parameters.instance().\
intervention_params['place_closure']['closure_spatial_params'] \
if ((hasattr(infector.microcell, 'closure_start_time'))) and (
infector.is_place_closed(
if ((hasattr(infectee.microcell, 'closure_start_time'))) and (
infectee.is_place_closed(
Parameters.instance().intervention_params[
'place_closure']['closure_place_type'])) and (
infector.microcell.closure_start_time <= time) else 1
infectee.microcell.closure_start_time <= time) else 1

if (hasattr(infector.microcell, 'distancing_start_time')) and (
infector.microcell.distancing_start_time is not None) and (
infector.microcell.distancing_start_time <= time):
if (hasattr(infector, 'distancing_enhanced')) and (
infector.distancing_enhanced is True):
if (hasattr(infectee.microcell, 'distancing_start_time')) and (
infectee.microcell.distancing_start_time is not None) and (
infectee.microcell.distancing_start_time <= time):
if (hasattr(infectee, 'distancing_enhanced')) and (
infectee.distancing_enhanced is True):
spatial_susc *= Parameters.instance().\
intervention_params['social_distancing'][
'distancing_spatial_enhanced_susc']
Expand Down Expand Up @@ -196,6 +195,6 @@ def spatial_foi(inf_cell, susc_cell, infector,
inf_cell, infector, time) * carehome_scale_inf
* isolation_scale_inf * quarantine_scale)
susceptibility = (SpatialInfection.spatial_susc(
susc_cell, infector, infectee, time)
susc_cell, infectee, time)
* carehome_scale_susc * quarantine_scale)
return (infectiousness * susceptibility)
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def test_house_social_distancing(self):
result = HouseholdInfection.household_susc(
self.infector, self.infectee, self.time)

# Normal social distancing
self.infector.microcell.distancing_start_time = 1
self.infector.distancing_enhanced = False
# Normal social distancing of infectee
self.infectee.microcell.distancing_start_time = 1
self.infectee.distancing_enhanced = False
distancing_house_susc = pe.Parameters.instance().\
intervention_params['social_distancing'][
'distancing_house_susc']
Expand All @@ -129,8 +129,8 @@ def test_house_social_distancing(self):
self.assertEqual(result*distancing_house_susc,
result_distancing)

# Enhanced social distancing
self.infector.distancing_enhanced = True
# Enhanced social distancing of infectee
self.infectee.distancing_enhanced = True
distancing_house_enhanced_susc = pe.Parameters.instance().\
intervention_params['social_distancing'][
'distancing_house_enhanced_susc']
Expand Down
19 changes: 10 additions & 9 deletions pyEpiabm/pyEpiabm/tests/test_unit/test_property/test_place_foi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUpClass(cls) -> None:
cls.time = 1.0

def test_place_susc(self):
result = PlaceInfection.place_susc(self.place, self.infector,
result = PlaceInfection.place_susc(self.place,
self.infectee, self.time)
self.assertTrue(result > 0)
self.assertIsInstance(result, float)
Expand Down Expand Up @@ -99,27 +99,28 @@ def test_place_household_quarantine(self):

def test_place_social_distancing(self):
# Not in social distancing (distancing_start_time = None)
result = PlaceInfection.place_susc(self.place, self.infector,
result = PlaceInfection.place_susc(self.place,
self.infectee, self.time)
place_idx = self.place.place_type.value - 1

# Normal social distancing
self.infector.microcell.distancing_start_time = 1
self.infector.distancing_enhanced = False
# Normal social distancing of infectee
self.infectee.microcell.distancing_start_time = 1
self.infectee.distancing_enhanced = False
distancing_place_susc = pe.Parameters.instance().\
intervention_params['social_distancing'][
'distancing_place_susc']
result_distancing = PlaceInfection.place_susc(
self.place, self.infector, self.infectee, self.time)
self.place, self.infectee, self.time)
self.assertEqual(result*distancing_place_susc[place_idx],
result_distancing)
# Enhanced social distancing
self.infector.distancing_enhanced = True

# Enhanced social distancing of infectee
self.infectee.distancing_enhanced = True
distancing_place_enhanced_susc = pe.Parameters.instance().\
intervention_params['social_distancing'][
'distancing_place_enhanced_susc']
result_distancing_enhanced = PlaceInfection.place_susc(
self.place, self.infector, self.infectee, self.time)
self.place, self.infectee, self.time)
self.assertEqual(result*distancing_place_enhanced_susc[place_idx],
result_distancing_enhanced)

Expand Down
47 changes: 34 additions & 13 deletions pyEpiabm/pyEpiabm/tests/test_unit/test_property/test_spatial_foi.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ def setUp(self) -> None:

def test_spatial_susc(self):
result = SpatialInfection.spatial_susc(
self.cell, self.infector, self.infectee, self.time)
self.cell, self.infectee, self.time)
self.assertTrue(result > 0)
self.assertIsInstance(result, float)

@patch('pyEpiabm.core.Parameters.instance')
def test_spatial_susc_no_age(self, mock_params):
mock_params.return_value.use_ages = False
result = SpatialInfection.spatial_susc(
self.cell, self.infector, self.infectee, self.time)
self.cell, self.infectee, self.time)
self.assertIsInstance(result, float)
self.assertEqual(result, 1.0)

Expand Down Expand Up @@ -94,30 +94,51 @@ def test_spatial_case_isolation(self):

def test_spatial_place_closure(self):
# Update place type, not place closure (closure_start_time = None)
self.infector.place_types.append(PlaceType.PrimarySchool)
self.infectee.place_types.append(PlaceType.PrimarySchool)
self.infector.place_types.append(PlaceType.Workplace)
result_susc = SpatialInfection.spatial_susc(
self.cell, self.infector, self.infectee, self.time)
self.cell, self.infectee, self.time)
result_inf = SpatialInfection.spatial_inf(
self.cell, self.infector, self.time)

# Update start time
closure_spatial_params = \
pe.Parameters.instance().intervention_params[
'place_closure']['closure_spatial_params']
self.infector.microcell.closure_start_time = 1
self.infectee.microcell.closure_start_time = 1

# Place closure susceptibility
# Place closure susceptibility of infectee
pe.Parameters.instance().intervention_params[
'place_closure']['closure_place_type'] = [1, 2, 3, 4, 5, 6]
result_closure_susc = SpatialInfection.spatial_susc(
self.cell, self.infector, self.infectee, self.time)
self.cell, self.infectee, self.time)
self.assertEqual(result_susc*closure_spatial_params,
result_closure_susc)

# Place closure infectiousness
# Place closure infectiousness of infector
pe.Parameters.instance().intervention_params[
'place_closure']['closure_place_type'] = [1, 2, 3, 4, 5, 6]
result_closure_inf = SpatialInfection.spatial_inf(
self.cell, self.infector, self.time)
self.assertEqual(result_inf*closure_spatial_params,
result_closure_inf)

# Place closure foi, place of infectee and infector closed
pe.Parameters.instance().intervention_params[
'place_closure']['closure_place_type'] = [1, 2, 3, 4, 5, 6]
result_closure_foi = SpatialInfection.spatial_foi(
self.cell, self.cell, self.infector, self.infectee, self.time)
self.assertEqual(result_susc * closure_spatial_params * result_inf *
closure_spatial_params, result_closure_foi)

# Place closure foi, place of only infectee closed
pe.Parameters.instance().intervention_params['place_closure'][
'closure_place_type'] = [1, 2, 3]
result_closure_foi = SpatialInfection.spatial_foi(
self.cell, self.cell, self.infector, self.infectee, self.time)
self.assertEqual(result_susc*result_inf*closure_spatial_params,
result_closure_foi)

def test_spatial_household_quarantine(self):
# Not in quarantine (quarantine_start_time = None)
result = SpatialInfection.spatial_foi(
Expand All @@ -139,7 +160,7 @@ def test_spatial_household_quarantine(self):
def test_spatial_social_distancing(self):
# Not in social distancing (distancing_start_time = None)
result = SpatialInfection.spatial_susc(
self.cell, self.infector, self.infectee, self.time)
self.cell, self.infectee, self.time)

# Normal social distancing
self.infector.microcell.distancing_start_time = 1
Expand All @@ -148,17 +169,17 @@ def test_spatial_social_distancing(self):
intervention_params['social_distancing'][
'distancing_spatial_susc']
result_distancing = SpatialInfection.spatial_susc(
self.cell, self.infector, self.infectee, self.time)
self.cell, self.infectee, self.time)
self.assertEqual(result*distancing_spatial_susc,
result_distancing)

# Enhanced social distancing
self.infector.distancing_enhanced = True
# Enhanced social distancing of infectee
self.infectee.distancing_enhanced = True
distancing_spatial_enhanced_susc = pe.Parameters.instance().\
intervention_params['social_distancing'][
'distancing_spatial_enhanced_susc']
result_distancing_enhanced = SpatialInfection.spatial_susc(
self.cell, self.infector, self.infectee, self.time)
self.cell, self.infectee, self.time)
self.assertEqual(result*distancing_spatial_enhanced_susc,
result_distancing_enhanced)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d01dd41

Please sign in to comment.