Code for Paper Model predicted human mobility explains COVID-19 transmission in urban space without behavioral data
Operating System: Ubuntu 18.04.5 LTS CPU: AMD Ryzen Threadripper 2990WX 32-Core Processor Memory: 128G DDR4 Memory
Anaconda3-2021.05-Linux-x86_64
conda 4.7.12
python==3.7.0
important python packages:
numpy==1.21.6
matplotlib==3.4.3
datetime==4.3
pandas==1.1.5
bayesian-optimization==1.2.0
scikit-learn==0.24.2
scipy==1.6.3
seaborn==0.11.1
shapely==1.7.1
adjustText==0.7.3
setproctitle==1.3.2
Typically, a morden computer with fast internet can complete the installation within 10 mins.
- Download Anaconda according to Official Website, which can be done by the fillowing command (newer version of anaconda should also works)
wget -c https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh
- Install Anaconda through the commandline guide. Permit conda init when asked.
./Anaconda3-2021.05-Linux-x86_64.sh
-
Quit current terminal window and open a new one. You should able to see (base) before your command line.
-
Use the following command to install pre-configured environment through the provided .yml file (you should go to the directory of this project before performing the command)
conda env create -f ./anaconda_env_covid.yml
- Finally, activate the installed environment. Now you can run the example code through the following chapter.
conda activate covid
(Optional) If you need to exit the environment for other project, use the following command.
conda deactivate
(Optional) Command for creating our environment without the .yml file
conda create -n covid python==3.7
pip install numpy ipython pandas matplotlib setproctitle bayesian-optimization datetime pathlib scikit-learn scipy adjustText seaborn shapely scikit-learn scipy seaborn
In this repo, we provide the fit process of our model (in ./fit) and the source code for analyses in the main text (in ./analyses).
The fitting process contains all the cities in our experiments, including 20 counties in U.S., 5 cities in India and 5 citeis in Brazil. Here, we provide the procedure to run these codes taking the Brazil city Sao Paulo as an example:
- Activate the environment
conda activate covid
- Go to the corresponding directory
cd ./fit/brazil
- Run the following command
python simulate_ode_fit_saoPaulo_BO.py
You will get the fitted results in simulated_results_SaoPaulo_2500 directory. It contains three kinds of results: a figure that shows the fitted & real cumulated infected curve (in green and red), a json file that records the corresponding fitted model parameters, and a npy file of the fitted cumulated infected curve.
simulate_ode_fit_($cityname)_BO.py are responsible for run the fitting for each city. You can try other cities as you wish.
Note that in our experiment, we fit 40 times to test our results, and we run the code by multi-processing with 20 runs. You may change the setting for higher or lower to suit your computation power. In our case, it often takes us a few hours for each city in the default setup.
In simulate_ode_fit_($cityname)_BO.py, you can find:
MULTI_PROCESSING = 20
if __name__ == "__main__":
fit_num = 40
We also include all the experiments in our main text in the ./analyses folder. Since the simulation results are large, we provide them through this Google Drive link:
https://drive.google.com/file/d/1NiukpIDouOSJnRHe44w0ffyo5UcFrk5n/view?usp=sharing
Please put this file into ./analyses folder and decompress it!
In ./analyses, we provide the source code of our experiemnts (figxx.py), auxilliary data (./analyses/cases for covid cases curves, ./analyses/population for the number of citizens, ./analyses/fig1c_data for Apple Mobility Trends data, ./analyses/fig2b_data for NYC fine-grained infection), and the simulations provided by our model (./analyses/results, decompressed from the Google Drive archive).
As an example, we can reproduce fig.1a through the following procedures:
- Activate the environment
conda activate covid
- Go to the corresponding directory
cd ./analyses
- Download the model results and decompress
unzip results.zip
- Run the following command
python fig1a.py