Skip to content

Commit

Permalink
Merge branch 'main' into secondary-infections
Browse files Browse the repository at this point in the history
  • Loading branch information
mghosh00 authored Nov 26, 2024
2 parents 939c9a6 + 1cc1fb9 commit bd91057
Show file tree
Hide file tree
Showing 41 changed files with 19,005 additions and 28,134 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/coverage-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v1
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.11'
architecture: x64

- name: install pyEpiabm
Expand Down
19 changes: 15 additions & 4 deletions .github/workflows/doc-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v1
- name: Set up Python '3.11'
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.11'
architecture: x64

- name: install pyEpiabm
Expand All @@ -33,3 +33,14 @@ jobs:
run: |
cd pyEpiabm
python run_tests.py --docs
Validate-CITATION-cff:
name: Validate CITATION.cff
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate CITATION.cff
uses: dieghernan/cff-validator@v3
8 changes: 4 additions & 4 deletions .github/workflows/func-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v1
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.11'
architecture: x64

- name: install pyEpiabm
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/os-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v1
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.11'
architecture: x64

- name: install pyEpiabm
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/style-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v1
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.11'
architecture: x64

- name: install pyEpiabm
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
Expand Down
56 changes: 46 additions & 10 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# CITATION.cff file for Epiabm, generated with cffinit.
# This CITATION.cff file was generated with cffinit.

cff-version: 1.1.0
cff-version: 1.2.0
title: Epiabm
message: >-
If you use this software, please cite it using the
metadata from this file.
message: "Please cite this software using the metadata from 'preferred-citation'."
type: software
authors:
- given-names: 'Kit '
- given-names: Kit
family-names: Gallagher
email: [email protected]
affiliation: 'Mathematical Institute, University of Oxford'
Expand All @@ -21,6 +19,9 @@ authors:
- given-names: Nathan
family-names: Schofield
affiliation: 'Mathematical Institute, University of Oxford'
- given-names: Matthew
family-names: Ghosh
affiliation: 'Doctoral Training Centre, University of Oxford'
- given-names: Henriette
family-names: Capel
affiliation: 'Department of Statistics, University of Oxford'
Expand All @@ -33,6 +34,9 @@ authors:
- given-names: Jiayuan
family-names: Zhu
affiliation: 'Department of Engineering, University of Oxford'
- given-names: Abbie
family-names: Evans
affiliation: 'Doctoral Training Centre, University of Oxford'
- given-names: Patricia
family-names: Lamirande
affiliation: 'Mathematical Institute, University of Oxford'
Expand All @@ -41,13 +45,13 @@ authors:
affiliation: 'Department of Computer Science, University of Oxford'
- given-names: Richard
family-names: Creswell
affiliation: 'Department of Engineering, University of Oxford'
affiliation: 'Department of Computer Science, University of Oxford'
- given-names: Isaac
family-names: Ellmen
affiliation: 'Department of Statistics, University of Oxford'
- given-names: Pietro
family-names: Monticone
affiliation: 'University of Turin'
affiliation: University of Turin
identifiers:
- type: doi
value: 10.5281/zenodo.7327443
Expand All @@ -63,5 +67,37 @@ keywords:
- Agent-Based Modelling
- Epidemiology
license: BSD-3-Clause
version: 1.1.0
date-released: '2023-10-17'
version: 1.2.0
date-released: '2024-08-06'

preferred-citation:
type: article
authors:
- given-names: Kit
family-names: Gallagher
orcid: 'https://orcid.org/0000-0003-1401-115X'
- given-names: Ioana
family-names: Bouros
- given-names: Nicholas
family-names: Fan
- given-names: Elizabeth
family-names: Hayman
- given-names: Luke
family-names: Heirene
- given-names: Patricia
family-names: Lamirande
- given-names: Annabelle
family-names: "Lemenuel-Diot"
- given-names: Ben
family-names: Lambert
- given-names: David
family-names: Gavaghan
- given-names: Richard
family-names: Creswell
doi: "10.5334/jors.449"
journal: "Journal of Open Research Software"
month: 3
title: "Epidemiological Agent-Based Modelling Software (Epiabm)"
issue: 1
volume: 12
year: 2024
2 changes: 1 addition & 1 deletion pyEpiabm/pyEpiabm/core/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def set_id(self, id: str, cells: typing.List):
raise TypeError("Provided id must be a string")

# This regex will match on any string which has 1 or more digits
if not re.match("^\\d+$", id):
if not re.match("^-?\\d+$", id):
raise ValueError(f"Invalid id: {id}. id must be of the form 'i' "
f"where i is an integer")

Expand Down
2 changes: 1 addition & 1 deletion pyEpiabm/pyEpiabm/core/household.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def set_id(self, id: str):

# This regex will match on any string which takes the form "i.j.k"
# where i, j and k are integers
if not re.match("^\\d+\\.\\d+\\.\\d+$", id):
if not re.match("^-?\\d+\\.-?\\d+\\.-?\\d+$", id):
raise ValueError(f"Invalid id: {id}. id must be of the form "
f"'i.j.k' where i, j, k are integers")

Expand Down
2 changes: 1 addition & 1 deletion pyEpiabm/pyEpiabm/core/microcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def set_id(self, id):

# This regex will match on any string which takes the form "i.j" where
# i and j are integers
if not re.match("^\\d+\\.\\d+$", id):
if not re.match("^-?\\d+\\.-?\\d+$", id):
raise ValueError(f"Invalid id: {id}. id must be of the form 'i.j' "
f"where i, j are integers")

Expand Down
2 changes: 1 addition & 1 deletion pyEpiabm/pyEpiabm/core/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def set_id(self, id: str):

# This regex will match on any string which takes the form "i.j.k.l"
# where i, j, k and l are integers (k can be empty)
if not re.match("^\\d+\\.\\d+\\.\\d*\\.\\d+$", id):
if not re.match("^-?\\d+\\.-?\\d+\\.-?\\d*\\.-?\\d+$", id):
raise ValueError(f"Invalid id: {id}. id must be of the form "
f"'i.j.k.l' where i, j, k, l are integers (k"
f"can be empty)")
Expand Down
2 changes: 1 addition & 1 deletion pyEpiabm/pyEpiabm/output/_csv_dict_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, folder: str, filename: str, fieldnames: typing.List,
folder, os.path.splitext(filename)[0])
self.fieldnames = fieldnames

self.f = open(os.path.join(folder, filename), 'w')
self.f = open(os.path.join(folder, filename), 'w', newline='')
self.writer = csv.DictWriter(
self.f, fieldnames=fieldnames, delimiter=',')
self.writer.writeheader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_init(self, mock_mkdir):
mock_categories)
del m
mo.assert_called_once_with(
os.path.join('mock_folder', 'mock_filename'), 'w')
os.path.join('mock_folder', 'mock_filename'), 'w', newline='')
mo().write.assert_called_once_with('Cat1,Cat2,Cat3\r\n')
mock_mkdir.assert_called_with('mock_folder')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import unittest
from unittest.mock import patch, mock_open, call

import pyEpiabm as pe
Expand Down Expand Up @@ -87,8 +88,8 @@ def test_construct(self, mock_mkdir):
"Age group 0"])
del dem_sweep.writer
del dem_sweep.counts_writer
mo.assert_has_calls([call(file_name, 'w'),
call(counts_file_name, 'w')],
mo.assert_has_calls([call(file_name, 'w', newline=''),
call(counts_file_name, 'w', newline='')],
any_order=True)

@patch('os.makedirs')
Expand All @@ -115,8 +116,8 @@ def test_construct_age_spatial(self, mock_mkdir):
[f"Age group {i}" for i in range(17)])
del dem_sweep.writer
del dem_sweep.counts_writer
mo.assert_has_calls([call(file_name, 'w'),
call(counts_file_name, 'w')],
mo.assert_has_calls([call(file_name, 'w', newline=''),
call(counts_file_name, 'w', newline='')],
any_order=True)

@patch('os.makedirs')
Expand Down Expand Up @@ -253,3 +254,7 @@ def test_write_to_file_age_spatial(self, mock_mkdir):
mock_mkdir.assert_called_with(os.path.join(os.getcwd(),
self.dem_file_params[
"output_dir"]))


if __name__ == '__main__':
unittest.main()
9 changes: 9 additions & 0 deletions python_examples/NZ_example/NewZealand_noInt_parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,14 @@
"constant_introduce_cases": [0],
"duration_travel_stay": [2, 14],
"prob_existing_household": 0.8
},
"use_waning_immunity": 0,
"rate_multiplier_params": {
"gp_to_hosp": [0, 1],
"gp_to_death": [0, 1],
"exposed_to_infect": [0, 1],
"hosp_to_death": [0, 1],
"hosp_to_icu": [0, 1],
"icu_to_death": [0, 1]
}
}
9 changes: 9 additions & 0 deletions python_examples/NZ_example/NewZealand_parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,5 +511,14 @@
"isolation_effectiveness": 0.1,
"isolation_house_effectiveness": 0.5
}
},
"use_waning_immunity": 0,
"rate_multiplier_params": {
"gp_to_hosp": [0, 1],
"gp_to_death": [0, 1],
"exposed_to_infect": [0, 1],
"hosp_to_death": [0, 1],
"hosp_to_icu": [0, 1],
"icu_to_death": [0, 1]
}
}
9 changes: 9 additions & 0 deletions python_examples/NZ_example/NewZealand_parameters_relaxed.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,5 +511,14 @@
"isolation_effectiveness": 0.1,
"isolation_house_effectiveness": 0.5
}
},
"use_waning_immunity": 0,
"rate_multiplier_params": {
"gp_to_hosp": [0, 1],
"gp_to_death": [0, 1],
"exposed_to_infect": [0, 1],
"hosp_to_death": [0, 1],
"hosp_to_icu": [0, 1],
"icu_to_death": [0, 1]
}
}
10 changes: 5 additions & 5 deletions python_examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This script outlines all commands necessary to run a basic simulation. It models

It subsequently saves the results to a .csv file, and plots a basic SIR plot of the simulation output, depicted below:

![SIR plot from simulation_flow.pt](./basic_example/simulation_outputs/simulation_flow_SIR_plot.png)
![SIR plot from simulation_flow.pt](./basic_simulation/simulation_outputs/simulation_flow_SIR_plot.png)

## Basic Infection History Simulation

Expand All @@ -20,15 +20,15 @@ These .csv files are then used in the repository https://github.com/SABS-R3-Epid

## Spatial Simulations

Contained within the `spatial_example/` directory, this script runs a basic simulation with spatial dependance. It considers a population of 1000 individuals, spread across 40 households in 20 cells, each with a single microcell.
Contained within the `spatial_example/` directory, this script runs a basic simulation with spatial dependance. It considers a population of 10000 individuals, spread across 225 cells, each with a two microcells.

It subsequently saves the results to a .csv file, and plots the infection curve for each region. There is currently no differentiation between cells, and so any variation is due to random fluctuations. Any null curves are because there were no infectious individuals seeded in that cell, and no inter-cellular infection mechanisms are currently implemented.
It subsequently saves the results to a .csv file, and plots the infection curve for each region. There is currently no differentiation between cells, and so any variation is due to random fluctuations.

![Infection curves for multiple cells.pt](./spatial_example/spatial_outputs/spatial_flow_Icurve_plot.png)

We also provide a script (`voronoi_plotting_example.py`) for visualising the spatial distribution of the epidemic, generating cells based on a single location coordinate using [Voronoi Tesselation](https://en.wikipedia.org/wiki/Voronoi_diagram).
We also provide a script (`voronoi_plotting_example.py`) for visualising the spatial distribution of the epidemic, generating cells based on a single location coordinate using [Voronoi Tesselation](https://en.wikipedia.org/wiki/Voronoi_diagram). A [grid version](./spatial_example/spatial_outputs/voronoi_grid_img.png) of this plot is also generated.

![Voronoi_grid.pt](./spatial_example/spatial_outputs/voronoi_grid_img.png)
![Voronoi grid](./spatial_example/spatial_outputs/voronoi_animation.gif)

## Age Stratified Simulation

Expand Down
9 changes: 9 additions & 0 deletions python_examples/basic_simulation/simple_parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"false_positive_rate": 0,
"place_transmission": 0.1,
"use_ages": 0,
"use_waning_immunity": 0,
"note1": "Mainly change values above this",
"age_contact": [0.6, 0.7, 0.75, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 0.75, 0.5],
Expand Down Expand Up @@ -403,5 +404,13 @@
0.47651, 0.47651, 0.47651, 0.47651,
0.47651, 0.47651, 0.47651, 0.47651,
0.47651]
},
"rate_multiplier_params": {
"gp_to_hosp": [0, 1],
"gp_to_death": [0, 1],
"exposed_to_infect": [0, 1],
"hosp_to_death": [0, 1],
"hosp_to_icu": [0, 1],
"icu_to_death": [0, 1]
}
}
Loading

0 comments on commit bd91057

Please sign in to comment.