Esempio n. 1
0
import numpy as np
from utils import downloadCovidData
from utils import removeColumn
from utils import plotChart
   
confirmed, death, latitude = removeColumn(downloadCovidData(),"Hubei")
bins = [np.floor(l/15) for l in latitude]
i = -180
result = {}
x = []
while i < 180:
  result[np.floor(float(i)/15)] = np.zeros(confirmed.shape[0])
  i+=12
  x.append("{}-{}".format(15*np.floor(float(i)/15),15*np.floor(float(i+12)/15)))

for i in range(0,len(confirmed.columns)):
  if not np.isnan(bins[i]):
    result[bins[i]] += confirmed.iloc[:,i]
finalDf = pd.DataFrame(data=pd.to_datetime(confirmed.index,format='%m/%d/%y'),columns=["Date"])
cols = []
for i in result.keys():
   if np.sum(result[i]) > 0:
      label = "{}-{}".format(15*i,15*(i+1))
      cols.append(label)
      finalDf.loc[:, label] = result[i].values

for col in cols:
  finalDf[col] = np.log(1+finalDf[col])
print(finalDf)
plotChart(finalDf,title="log(Confirmed cases)",cols=cols)
Esempio n. 2
0
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.ticker as mtick
import numpy as np
from collections import Counter
from utils import downloadCovidData
from utils import plotChart

target = "Italy"
confirmed, death, _ = downloadCovidData()
confirmed = confirmed[confirmed.Date >= '2020-03-01']
print(confirmed)
cols = [target]
for col in cols:
    confirmed[col] = confirmed[col].diff()

plotChart(confirmed, title="Newly confirmed cases", cols=[target])
Esempio n. 3
0
import pandas as pd
import numpy as np
from utils import downloadCovidData
from utils import plotChart

confirmed, death, _ = downloadCovidData()
print(confirmed.columns)
death["Spain"] = 100 * death["Spain"] / confirmed["Spain"]
death["Germany"] = 100 * death["Germany"] / confirmed["Germany"]
death["Italy"] = 100 * death["Italy"] / confirmed["Italy"]
death["France"] = 100 * death["France"] / confirmed["France"]
death["Hubei"] = 100 * death["Hubei"] / confirmed["Hubei"]
plotChart(death,title="Deaths / Confirmed cases",
   cols=["Spain","Italy","France","Germany","Hubei"],
   percent=True)
Esempio n. 4
0
region = "Madrid"
finalDf = None
for nreport in range(32,999):
   try:
      df,lastModified=downloadSpainData(nreport,region)
      print(df)
      #df["HospitalizationRate"] = 100 * df["Hospitalizados"] / df["Total casos"]
      df = df.loc[:,["Total casos"]].transpose()
      df["Date"] = [datetime.datetime(*eut.parsedate(lastModified)[:6])]
      #df = df.drop("CCAA",axis=1)
      df.index = df["Date"]
      if finalDf is None:
         finalDf = df
      else:
         finalDf = pd.concat([finalDf,df],axis=0)

   except FileNotFoundError:
      break
   except Exception as e:
      pass

cols = finalDf.columns.tolist()
cols.remove("Date")

for col in cols:
  finalDf[col] = np.log(finalDf[col])

last_row = finalDf.ix[finalDf.last_valid_index()].drop("Date")
#cols = finalDf.columns[last_row.argsort()].tolist()[-5:]
plotChart(finalDf,title="Log(Confirmed cases)", cols=cols, percent=False)
Esempio n. 5
0
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import scipy
import matplotlib.ticker as mtick
import numpy as np
from collections import Counter
from utils import plotChart

confirmed = pd.read_csv("data/lombardy.csv").iloc[17:,]
print(confirmed)
confirmed["Lombardy"] = confirmed["Cases"].diff()
confirmed["LogGrowth"] = np.log(confirmed["Cases"])
confirmed["LogGrowth"] = 100*confirmed["Cases"].pct_change(periods=1)
confirmed['Date'] =  pd.to_datetime(confirmed['Date'], format='%d-%m-%Y')
confirmed.index = confirmed['Date']

def exponential(x, a, k, b):
    return a*np.exp(x*k) + b

confirmed = confirmed.iloc[1:,]
country = "LogGrowth"
print(confirmed[country])
plotChart(confirmed,title="Newly confirmed cases", cols=[country], percent=True)
from collections import Counter
from utils import downloadCovidData
from utils import plotChart
from model import forecastRegion

confirmed,death,_ = downloadCovidData()
col = "World w/o China"
confirmed[col] = np.log(1+confirmed.sum(axis=1))
confirmed["Hubei"] = confirmed["Hubei"].astype(float)
cols = ["Italy", "Spain","Hubei", "Germany", "France"]
for col in cols:
   confirmed[col] = np.log(1+confirmed[col])
death["World w/o China"] = death.sum(axis=1)
start = "2020-02-25"
daysforecast = 200
target = "Spain"
print(confirmed[target])
projections, model = forecastRegion(confirmed,target,start,daysforecast)
print(projections)
projections["Forecast"] = [math.exp(x) for x in projections["Forecast"]]
projections["Forecast"] = projections["Forecast"].diff()
i = 80
projections = projections.iloc[:i,:]
print(projections)
plotChart(projections,"Newly confirmed cases",cols=["Forecast"],legend=False,labels=["Spain"])
projections["Cumulative"] = projections["Forecast"]
projections["Forecast"] = projections["Cumulative"].diff()
print(projections[["Date","Cumulative","Forecast"]])
print("MAX: ",projections["Forecast"].max())
print(projections[projections["Forecast"] == projections["Forecast"].max()])
Esempio n. 7
0
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import scipy
import matplotlib.ticker as mtick
import numpy as np
from collections import Counter
from utils import plotChart

confirmed = pd.read_csv("data/lombardy.csv").iloc[17:, ]
print(confirmed)
confirmed["Lombardy"] = confirmed["Cases"].diff()
confirmed['Date'] = pd.to_datetime(confirmed['Date'], format='%d-%m-%Y')
confirmed.index = confirmed['Date']


def exponential(x, a, k, b):
    return a * np.exp(x * k) + b


confirmed = confirmed.iloc[1:, ]
country = "Lombardy"
print(confirmed[country])
plotChart(confirmed, title="Newly confirmed cases", cols=["Lombardy"])
Esempio n. 8
0
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.ticker as mtick
import numpy as np
from collections import Counter
from utils import downloadCovidData
from utils import plotChart

confirmed, death, _ = downloadCovidData()
confirmed["World w/o China"] = np.log(
    confirmed.drop(["Hubei"], axis=1).sum(axis=1))
confirmed["Hubei"] = confirmed["Hubei"].astype(float)
cols = ["Italy", "Spain", "Hubei", "Germany", "France", "United Kingdom"]
for col in cols:
    confirmed[col] = np.log(confirmed[col])
death["World w/o China"] = death.sum(axis=1)
plotChart(confirmed,
          title="log(Confirmed cases)",
          cols=[
              "Italy", "Spain", "World w/o China", "Hubei", "France",
              "United Kingdom"
          ])
Esempio n. 9
0
i = -180
result = {}
x = []
while i < 180:
    result[np.floor(float(i) / step)] = np.zeros(confirmed.shape[0])
    i += 12
    x.append("{}-{}".format(step * np.floor(float(i) / step),
                            step * np.floor(float(i + 12) / step)))

for i in range(0, len(confirmed.columns)):
    if not np.isnan(bins[i]):
        result[bins[i]] += confirmed.iloc[:, i]
finalDf = pd.DataFrame(data=pd.to_datetime(confirmed.index, format='%m/%d/%y'),
                       columns=["Date"])
cols = []
for i in result.keys():
    if np.sum(result[i]) > 0:
        label = "{}-{}".format(step * i, step * (i + 1))
        cols.append(label)
        finalDf.loc[:, label] = result[i].values

for col in cols:
    finalDf[col] = np.log(1 + finalDf[col])
print(finalDf)
#sys.exit(1)
plotChart(finalDf,
          title="log(Confirmed cases)",
          cols=cols,
          labels=["Southern Hemisphere", "Northern Hemisphere"])
#ax.set(xlabel='Latitude', ylabel='Confirmed cases')
Esempio n. 10
0
from utils import plotSubchart
from utils import plotChart
from model import forecastRegion

target = "NY"
confirmed = downloadUsaCovidData()
last_row = confirmed.loc[confirmed.last_valid_index(), :].drop("Date")
print(confirmed.columns[last_row.argsort()])
cols = ["NY"]
#cols = confirmed.columns[last_row.argsort()].tolist()[-5:]
print(last_row[cols])
if "Date" in cols:
    cols.remove("Date")
for col in cols:
    confirmed[col] = np.log(1 + confirmed[col])
plotChart(confirmed, title="log(Confirmed cases)", cols=cols, useLabels=True)


def processState(confirmed, target):
    try:
        print("Forecasting... {}".format(target))
        startDate = "2020-03-01"
        confirmed = confirmed[confirmed["Date"] >= startDate]
        #confirmed = confirmed[confirmed[target] >= np.log(1.1)]
        base = confirmed["Date"][0].strftime("%Y-%m-%d")
        if confirmed[target].max() < np.log(1000):
            print("TARGET: {} MAX: {}".format(target, confirmed[target].max()))
            raise Exception("spam", "eggs")
        projections, model = forecastRegion(confirmed, target, base)
        f, ax = plt.subplots(1, 1)
        plotSubchart(confirmed,