-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEpiCenter.py
31 lines (28 loc) · 1.49 KB
/
EpiCenter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import csv
from collections import defaultdict
import glob, os, re
import numpy as np
bbest=dict()
for city in pop: #city is our tested epidemic center, for loop on all regions
w=defaultdict(int) #create default dictionary for incoming trips in every region
with open("OD_Matrix_daily_flows.csv",'r') as f:
read=csv.reader(f,delimiter=',')
next(read) #jump header
for j,i in enumerate(read): #read lines
n2=i[0] #origin of OD flow
if n2==city: #if origin corresponds to designed epidemic hub
d2=i[1] #destination of OD flow
data=i[2] #read date of OD flow from dataset as number of days from start of the year
#onset format must be the same
flow=float(i[3])
if data<onset[d2]-7 and data>onset[d2]-21:
#take mobility from 3 weeks before to one 1 week before of destination onset
w[d2]+=flow #sum the inflow in area d2 from origin == city
x,y=[],[]
for p in pop:
if p!=city: #check the Pearson correlation for each origin wrt destinations incidence peaks
x.append(log10((w[p]/pop[p]))) #fraction of inflow wrt to local population
y.append(log10(peak[p]/pop[p])) #incidence peak
R=np.corrcoef(x,y)[0][1]
bbest[city]=R*len(x)/max(n_destinations)
#Pearson correlation * # of destionations / max # of destinations per any origin in the country