This Python script simulates the spread of a virus using Matplotlib and is customizable for various viral parameters. The code uses a polar plot to visually represent the spread of the virus within a population.
The code simulates the spread of a virus by modeling various aspects of the epidemic, including infections, recoveries, and deaths. It uses a polar plot to show the positions of individuals within a population and represents infected individuals with different colors.
- Customizable virus parameters, making it adaptable for different viruses.
- Visualization of the infection spread using a polar plot.
- Real-time updates of the number of infected, recovered, and deceased individuals.
- Random assignment of mild, severe, and fatal symptoms to infected individuals.
Before running the code, ensure you have the following:
- Python (3.7+)
- Matplotlib (for plotting)
- Numpy (for numerical operations)
You can customize the virus parameters in the COVID19_PARAMS dictionary at the beginning of the script. Adjust the values to simulate different viruses. You can change parameters such as the basic reproduction number (r0), incubation period, recovery periods, and fatality rate.
Sped up for viewing convenience
virusSimulation.mp4
- Install Pre-requisites mentioned above
- Run the command below
python virus.py
This class represents the virus simulation. It initializes the simulation, sets up the polar plot, and contains methods for spreading the virus, updating the status, and assigning symptoms.
This method initializes the population by creating individuals and patient zero.
This method simulates the spread of the virus. It calculates the number of new infections, handles the spread, and manages the exposed and infected individuals.
This method is a helper for animating the spread of the virus. It adds infected individuals one by one to the plot.
This method is a utility function to split a list into smaller chunks.
This method assigns symptoms (mild, severe, or fatal) to infected individuals and schedules their recovery or death.
This method updates the status of infected individuals, marking them as recovered or deceased.
This method updates the text annotations in the plot to display current statistics.
A generator function that runs the simulation loop until the desired number of recoveries and deaths are achieved.
This method initiates the animation of the virus spread simulation.