metawards.Disease¶
-
class
metawards.
Disease
(name: Optional[str] = None, stage: Optional[List[str]] = None, mapping: Optional[List[str]] = None, beta: Optional[List[float]] = None, progress: Optional[List[float]] = None, too_ill_to_move: Optional[List[float]] = None, contrib_foi: Optional[List[float]] = None, start_symptom: Optional[int] = None, _version: Optional[str] = None, _authors: Optional[str] = None, _contacts: Optional[str] = None, _references: Optional[str] = None, _filename: Optional[str] = None, _repository: Optional[str] = None, _repository_version: Optional[str] = None, _repository_branch: Optional[str] = None)[source]¶ This class holds the parameters about a single disease
A disease is characterised as a serious of stages, each with their own values of the beta, progress, too_ill_to_move and contrib_foi parameters. To load a disease use the Disease.load function, e.g.
Examples
>>> disease = Disease.load("ncov") >>> print(disease) Disease ncov repository: https://github.com/metawards/MetaWardsData repository_branch: main repository_version: 0.2.0 beta = [0.0, 0.0, 0.95, 0.95, 0.0] progress = [1.0, 0.1923, 0.909091, 0.909091, 0.0] too_ill_to_move = [0.0, 0.0, 0.0, 0.0, 0.0] contrib_foi = [1.0, 1.0, 1.0, 1.0, 0.0]
-
__init__
(name: Optional[str] = None, stage: Optional[List[str]] = None, mapping: Optional[List[str]] = None, beta: Optional[List[float]] = None, progress: Optional[List[float]] = None, too_ill_to_move: Optional[List[float]] = None, contrib_foi: Optional[List[float]] = None, start_symptom: Optional[int] = None, _version: Optional[str] = None, _authors: Optional[str] = None, _contacts: Optional[str] = None, _references: Optional[str] = None, _filename: Optional[str] = None, _repository: Optional[str] = None, _repository_version: Optional[str] = None, _repository_branch: Optional[str] = None) → None¶
Methods
N_INF_CLASSES
()Return the number of stages of the disease __init__
(name, stage, mapping, beta, …)add
(name, mapping, beta, progress, …)Add a new stage to the disease. from_data
(data)Return a new Disease constructed from the passed data dictionary (e.g. from_json
(s)Return the Disease constructed from the passed json. get_index
(idx)Return the index of disease stage ‘idx’ in this disease get_mapping_to
(other)Return the mapping from stage index i of this disease to stage index j other the passed other disease. insert
(index, name, mapping, beta, progress, …)Insert a new stage into the disease. load
(disease, repository, folder, filename)Load the disease parameters for the specified disease. to_data
()Return a data dictionary version of this disease, suitable for serialising to, e.g., json to_json
(filename, indent, auto_bzip)Serialise the Disease to JSON. Attributes
beta
Beta parameter for each stage of the disease contrib_foi
Contribution to the Force of Infection (FOI) parameter for each stage of the disease mapping
Mapping label, e.g. name
Name of the disease progress
Progress parameter for each stage of the disease stage
Name of the stage, e.g. start_symptom
Index of the first symptomatic stage too_ill_to_move
TooIllToMove parameter for each stage of the disease -
__getitem__
(index: int) → Dict[str, Union[str, float, bool]][source]¶ Return the values of parameters of the stage as specified index
-
__setitem__
(index: int, value: Dict[str, Union[str, float, bool]]) → None[source]¶ Set the value of parameters at this index. The keys in the dictionary (and their values) match the arguments to the “insert” or “add” functions
-
add
(name: str, mapping: Optional[str] = None, beta: Optional[float] = None, progress: Optional[float] = None, too_ill_to_move: Optional[float] = None, contrib_foi: Optional[float] = None, is_start_symptom: Optional[bool] = None) → None[source]¶ Add a new stage to the disease. This will append a new stage onto the list of stages.
Parameters: - name (str) – The name of the stage, e.g. “E”, “I”, “R” etc.
- mapping (str) – Which main stage this stage should map to (if this is a sub-stage). This will be derived automatically if not set.
- beta (float) – The beta (infectivity) parameter. This should be between 0.0 amd 1.0. If not set, then this will be set automatically.
- progress (float) – The fraction of individuals at this stage who will move to the next stage. This should be between 0.0 amd 1.0. If this is not set, then this will be set automatically.
- too_ill_to_move (float) – The proportion of workers at this stage who do not travel to work. This should be between 0.0 and 1.0. If this is not set, then this will be set automatically.
- contrib_foi (float) – The contribution of individuals in this stage to the force-of-infection (foi) of the wards they visit. This should normally be 1.0 and will be set automatically if not set.
- is_start_symptom (bool) – Whether this is the start symptom of the disease. This normally doesn’t need to be set as this will be worked out automatically by the code.
-
beta
= None¶ Beta parameter for each stage of the disease
-
contrib_foi
= None¶ Contribution to the Force of Infection (FOI) parameter for each stage of the disease
-
static
from_data
(data) → metawards._disease.Disease[source]¶ Return a new Disease constructed from the passed data dictionary (e.g. deserialised from json)
-
static
from_json
(s: str) → metawards._disease.Disease[source]¶ Return the Disease constructed from the passed json. This will either load from a passed json string, or from json loaded from the passed file
-
get_mapping_to
(other)[source]¶ Return the mapping from stage index i of this disease to stage index j other the passed other disease. This returns ‘None’ if there is no need to map because the stages are the same.
The mapping will map the states according to their label, matching the ith labelled X state in this disease to the ith labelled X state in other (or to the highest labelled X state if we have more of these states than other).
Thus, is we have;
self = [“*”, “E”, “I”, “I”, “R”] other = [“*”, “E”, “I”, “I”, “I”, “R”]
then
self.get_mapping_to(other) = [0, 1, 2, 3, 5] other.get_mapping_to(self) = [0, 1, 2, 3, 3, 4]
If we can’t map a state, then we will try to map to “I”. If we still can’t map, then this is an error.
-
insert
(index: int, name: str, mapping: Optional[str] = None, beta: Optional[float] = None, progress: Optional[float] = None, too_ill_to_move: Optional[float] = None, contrib_foi: Optional[float] = None, is_start_symptom: Optional[bool] = None) → None[source]¶ Insert a new stage into the disease. This will insert a new stage into the list of stages at index ‘index’
Parameters: - index (str) – The index at which to insert the new stage
- name (str) – The name of the stage, e.g. “E”, “I”, “R” etc.
- mapping (str) – Which main stage this stage should map to (if this is a sub-stage). This will be derived automatically if not set.
- beta (float) – The beta (infectivity) parameter. This should be between 0.0 amd 1.0. If not set, then this will be set automatically.
- progress (float) – The fraction of individuals at this stage who will move to the next stage. This should be between 0.0 amd 1.0. If this is not set, then this will be set automatically.
- too_ill_to_move (float) – The proportion of workers at this stage who do not travel to work. This should be between 0.0 and 1.0. If this is not set, then this will be set automatically.
- contrib_foi (float) – The contribution of individuals in this stage to the force-of-infection (foi) of the wards they visit. This should normally be 1.0 and will be set automatically if not set.
- is_start_symptom (bool) – Whether this is the start symptom of the disease. This normally doesn’t need to be set as this will be worked out automatically by the code.
-
static
load
(disease: Optional[str] = None, repository: Optional[str] = None, folder: Optional[str] = None, filename: Optional[str] = None)[source]¶ Load the disease parameters for the specified disease. This will look for a file called f”{disease}.json” in the directory f”{repository}/{folder}/{disease}.json”
By default this will load the ncov (SARS-Cov-2) parameters from $HOME/GitHub/model_data/diseases/ncov.json
Alternatively you can provide the full path to the json file via the “filename” argument
Parameters: - disease (str) – The name of the disease to load. This is the name that will be searched for in the METAWARDSDATA diseases directory
- repository (str) – The location of the cloned METAWARDSDATA repository
- folder (str) – The name of the folder within the METAWARDSDATA repository that contains the diseases
- filename (str) – The name of the file to load the disease from - this directly loads this file without searching through the METAWARDSDATA repository
Returns: disease – The constructed and validated disease
Return type:
-
mapping
= None¶ Mapping label, e.g. “*”, “E”, “I” or “R”
-
name
= None¶ Name of the disease
-
progress
= None¶ Progress parameter for each stage of the disease
-
stage
= None¶ Name of the stage, e.g. “H1”, “I2”, “E1” etc.
-
start_symptom
= None¶ Index of the first symptomatic stage
-
to_data
() → Dict[str, any][source]¶ Return a data dictionary version of this disease, suitable for serialising to, e.g., json
-
to_json
(filename: Optional[str] = None, indent: Optional[int] = None, auto_bzip: bool = True) → str[source]¶ Serialise the Disease to JSON. This will write to a file if filename is set, otherwise it will return a JSON string.
Parameters: - filename (str) – The name of the file to write the JSON to. The absolute path to the written file will be returned. If filename is None then this will serialise to a JSON string which will be returned.
- indent (int) – The number of spaces of indent to use when writing the json
- auto_bzip (bool) – Whether or not to automatically bzip2 the written json file
Returns: Returns either the absolute path to the written file, or the json-serialised string
Return type: str
-
too_ill_to_move
= None¶ TooIllToMove parameter for each stage of the disease
-