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, is_infected: Optional[List[bool]] = 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, is_infected: Optional[List[bool]] = 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¶ Initialize self. See help(type(self)) for accurate signature.
Methods
Return the number of stages of the disease
__delattr__
(name, /)Implement delattr(self, name).
__dir__
()Default dir() implementation.
__eq__
(other)Return self==value.
__format__
(format_spec, /)Default object formatter.
__ge__
(value, /)Return self>=value.
__getattribute__
(name, /)Return getattr(self, name).
__getitem__
(index)Return the values of parameters of the stage as specified index
__gt__
(value, /)Return self>value.
__init__
([name, stage, mapping, beta, …])Initialize self.
__init_subclass__
This method is called when a class is subclassed.
__le__
(value, /)Return self<=value.
__len__
()__lt__
(value, /)Return self<value.
__ne__
(value, /)Return self!=value.
__new__
(**kwargs)Create and return a new object.
__reduce__
()Helper for pickle.
__reduce_ex__
(protocol, /)Helper for pickle.
__repr__
()Return repr(self).
__setattr__
(name, value, /)Implement setattr(self, name, value).
__setitem__
(index, value)Set the value of parameters at this index.
__sizeof__
()Size of object in memory, in bytes.
__str__
()Return str(self).
__subclasshook__
Abstract classes can override this to customize issubclass().
_validate
()Check that the loaded parameters make sense
add
(name[, mapping, beta, progress, …])Add a new stage to the disease.
Assert that this disease is valid
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, …])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
__annotations__
__dataclass_fields__
__dataclass_params__
__dict__
__doc__
__hash__
__module__
__weakref__
list of weak references to the object (if defined)
_authors
_contacts
_filename
_references
_repository
_repository_branch
_repository_version
_version
Beta parameter for each stage of the disease
Contribution to the Force of Infection (FOI) parameter for each stage of the disease
Whether or not this stage is an infected stage.
Mapping label, e.g.
Name of the disease
Progress parameter for each stage of the disease
Name of the stage, e.g.
Index of the first symptomatic stage
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, is_infected: 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.
is_infected (bool) – Whether or not this stage is an infected stage. Infected stages are any where the individual is infected by the virus. Non-infected stages are thus “S” and “R”. If you don’t specify this then it will be guess based on the stage name. Note that “R” stages cannot be classed as infected. You typically don’t need to set this as the automatic guess is good. The only time you need to use this is if you want to add additional non-infected stages to “S” and “R”, e.g. “V” to represent vaccinated individuals
-
beta
: List[float] = None¶ Beta parameter for each stage of the disease
-
contrib_foi
: List[float] = 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_index
(idx)[source]¶ Return the index of disease stage ‘idx’ in this disease. Note that “S” is a special name that refers to the susceptibles. This will return -1
-
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, is_infected: 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.
is_infected (bool) – Whether or not this stage is an infected stage. Infected stages are any where the individual is infected by the virus. Non-infected stages are thus “S” and “R”. If you don’t specify this then it will be guess based on the stage name. Note that “R” stages cannot be classed as infected. You typically don’t need to set this as the automatic guess is good. The only time you need to use this is if you want to add additional non-infected stages to “S” and “R”, e.g. “V” to represent vaccinated individuals
-
is_infected
: List[bool] = None¶ Whether or not this stage is an infected stage. By default all stages other than those mapped to “R” are classes as infected stages
-
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
: List[str] = None¶ Mapping label, e.g. “*”, “E”, “I” or “R”
-
name
: str = None¶ Name of the disease
-
progress
: List[float] = None¶ Progress parameter for each stage of the disease
-
stage
: List[str] = None¶ Name of the stage, e.g. “H1”, “I2”, “E1” etc.
-
start_symptom
: int = 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
: List[float] = None¶ TooIllToMove parameter for each stage of the disease
-