%config InlineBackend.figure_formats = ['svg']
import oscovida as ov
ov.display_binder_link("tutorial-overview-graphs.ipynb")
The most important function of oscovida
package is overview
. It takes the following parameters:
country
— a country to analyse (mandatory, str
);region
— a region of the country (optional, str
);subregion
— a subregion of the country (optional, str
);savefig
— whether to save a sigure (optional, bool
, default is False
);dates
— a range of dates in a format "2020-05-15:2020-10-20"weeks
— how many last weeks to show (optional, int
, default is zero, which means "all").The function returns a triple:
(pyplot
graph, a pandas
series for cases, a pandas
series for deaths).
This function provides six graphs:
ov.overview('Russia');
Let's see how exactly we obtain all these graphs.
Under the hood we
get_country_data()
function (see the tutorial)weeks=N
for the last N
weeks or
dates="2020-05-01:2020-10-01"
for the specific range of dates. Note that one cannot use
both dates
and weeks
together.plot_time_step
for total numbers (plot 1, see the tutorial)plot_daily_change
for daily changes (plots 2 and 3, see the tutorial)plot_reproduction_number
for R
-value and the growth factor (plots 4 and 5, see the tutorial)plot_doubling_time
for the doubling times (plot 6, see the tutorial).That's exactly how we fetch the data using weeks
inside the overview
function:
country = "Iran"
weeks = 30
cases, deaths = ov.get_country_data(country)
cases = cases[- weeks * 7:] # cut off unwanted data
deaths = deaths[- weeks * 7:] # cut off unwanted data
What we have in cases
and deaths
are Pandas time series: it is a sort of a two-row array with dates in one row and COVID cases / deaths in the other:
cases
2020-03-31 44605 2020-04-01 47593 2020-04-02 50468 2020-04-03 53183 2020-04-04 55743 ... 2020-10-22 550757 2020-10-23 556891 2020-10-24 562705 2020-10-25 568896 2020-10-26 574856 Freq: D, Name: Iran cases, Length: 210, dtype: object
And here is the example with dates
:
country = "Germany"
region="Hamburg"
dates = "2020-09-15:2020-10-25"
cases, deaths = ov.get_country_data(country, region)
date_start, date_end = dates.split(':')
cases = cases[date_start:date_end]
deaths = deaths[date_start:date_end]
ov.overview(country=country, region=region, dates=dates);
You can find more tutorials here.