Skip to content

Commit

Permalink
Merge pull request #270 from SABS-R3-Epidemiology/kcgallagher-bugfix-…
Browse files Browse the repository at this point in the history
…default-workflows-268

Kcgallagher bugfix default workflows 268
  • Loading branch information
I-Bouros authored Aug 6, 2024
2 parents e8ce085 + e2c89c6 commit ad93e92
Show file tree
Hide file tree
Showing 41 changed files with 18,952 additions and 28,128 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
8 changes: 4 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 Down
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
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 @@ -250,7 +250,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
Expand Up @@ -83,7 +83,7 @@ def test_configure(self, mock_mkdir):
del test_sim.ih_status_writer
del test_sim.ih_infectiousness_writer
del test_sim.secondary_infections_writer
mo.assert_called_with(filename, 'w')
mo.assert_called_with(filename, 'w', newline='')

@patch('os.makedirs')
@patch('logging.warning')
Expand Down Expand Up @@ -132,7 +132,7 @@ def test_configure_ih_status(self, mock_mkdir):
del test_sim.ih_status_writer
del test_sim.ih_infectiousness_writer
del test_sim.secondary_infections_writer
mo.assert_called_with(filename, 'w')
mo.assert_called_with(filename, 'w', newline='')

@patch('os.makedirs')
def test_configure_ih_infectiousness(self, mock_mkdir):
Expand Down Expand Up @@ -161,7 +161,7 @@ def test_configure_ih_infectiousness(self, mock_mkdir):
del test_sim.ih_status_writer
del test_sim.ih_infectiousness_writer
del test_sim.secondary_infections_writer
mo.assert_called_with(filename, 'w')
mo.assert_called_with(filename, 'w', newline='')

@patch('os.makedirs')
def test_configure_secondary_infections(self, mock_mkdir):
Expand Down Expand Up @@ -191,7 +191,7 @@ def test_configure_secondary_infections(self, mock_mkdir):
del test_sim.ih_status_writer
del test_sim.ih_infectiousness_writer
del test_sim.secondary_infections_writer
mo.assert_called_with(filename, 'w')
mo.assert_called_with(filename, 'w', newline='')

@patch('logging.exception')
@patch('os.path.join')
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). An [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.gif](./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]
}
}
2 changes: 1 addition & 1 deletion python_examples/basic_simulation/simulation_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Pop_params are used to configure the population structure being used in this
# simulation.

pop_params = {"population_size": 100, "cell_number": 1,
pop_params = {"population_size": 1000, "cell_number": 1,
"microcell_number": 1, "household_number": 5,
"place_number": 2}

Expand Down
Loading

0 comments on commit ad93e92

Please sign in to comment.