| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import numpy as np
- import pandas as pd
- from src.plotter import Plotter
- def transform_general_to_SIR(plotter:Plotter, dataset_path='datasets/COVID-19-Todesfaelle_in_Deutschland/', plot_name='', plot_title='', sample_rate=1, exclude=[], plot_size=(12,6), yscale_log=False, plot_legend=True):
- """Function to generate the SIR split from the data in the COVID-19-Todesfaelle_in_Deutschland dataset.
- """
- # read the data
- df = pd.read_csv(dataset_path + 'COVID-19-Todesfaelle_Deutschland.csv')
- df = df.drop(df.index[1200:])
-
- # population of germany at the end of 2019
- N = 83100000
- S, I, R = np.zeros(df.shape[0]), np.zeros(df.shape[0]), np.zeros(df.shape[0])
- # S_0 = N - I_0
- S[0] = N - df['Faelle_gesamt'][0]
- # I_0 = overall cases at the day - overall death cases at the day
- I[0] = df['Faelle_gesamt'][0] - df['Todesfaelle_gesamt'][0]
- # R_0 = overall death cases at the day
- R[0] = df['Todesfaelle_gesamt'][0]
- # the recovery time is 14 days
- recovery_queue = np.zeros(14)
-
- for day in range(1, df.shape[0]):
- infections = df['Faelle_gesamt'][day] - df['Faelle_gesamt'][day-1]
- deaths = df['Todesfaelle_neu'][day]
- recoveries = recovery_queue[0]
- S[day] = S[day-1] - infections
- I[day] = I[day-1] + infections - deaths - recoveries
- R[day] = R[day-1] + deaths + recoveries
- # update recovery queue
- if I[day] < 0:
- recovery_queue[-1] -= I[day]
- I[day] = 0
- recovery_queue[:-1] = recovery_queue[1:]
- recovery_queue[-1] = infections
- t = np.arange(0, df.shape[0], 1)
- if plotter != None:
- # plot graphs
- plots = []
- labels = []
- if 'S' not in exclude:
- plots.append(S)
- labels.append('S')
-
- if 'I' not in exclude:
- plots.append(I)
- labels.append('I')
- if 'R' not in exclude:
- plots.append(R)
- labels.append('R')
- plotter.plot(t, plots, labels, plot_name, plot_title, plot_size, y_log_scale=yscale_log, plot_legend=plot_legend, xlabel='time / days', ylabel='amount of poeple')
- COVID_Data = np.asarray([t[0::sample_rate],
- S[0::sample_rate],
- I[0::sample_rate],
- R[0::sample_rate]])
- np.savetxt(f"datasets/SIR_RKI_{sample_rate}.csv", COVID_Data, delimiter=",")
-
- def state_based_data(dataset_path='datasets/state_data/Aktuell_Deutschland_SarsCov2_Infektionen.csv/'):
- pass
|