arcovid19 package

Module contents

Utilities to access different Argentina-Related databases of COVID-19 data from the Arcovid19 group.

Submodules

arcovid19.core module

Core functionalities for arcovid19

class arcovid19.core.Frame(df, extra=NOTHING)[source]

Bases: object

plot_cls
class arcovid19.core.Plotter(frame)[source]

Bases: object

default_plot_name_method

arcovid19.cache module

Cache abstractions for arcovid19

arcovid19.cache.DEFAULT_CACHE_DIR = '/home/docs/arcovid19_data/_cache_'

Default cache location, (default=~/arcovid_19_data/_cache_)

arcovid19.cache.CACHE = <diskcache.core.Cache object>

Default cache instance

arcovid19.cache.CACHE_EXPIRE = 3600

Time to expire of every load_cases call in seconds

arcovid19.cache.from_cache(tag, function, force=False, *args, **kwargs)[source]

Simple cache orchestration.

Parameters:
  • tag (str) – Normally every function call the cache with their own tag. We sugest “module.function” or “module.Class.function”
  • function (callable) – The function to be cached
  • force (bool (default=False)) – If the vale of the cache must be ignored and re-execute the function.
  • and kwargs (args) – All the parameters needed to execute the function.

arcovid19.cases module

Utilities to Utility function to parse all the actual cases of the COVID-19 in Argentina.

arcovid19.cases.CODE_TO_POVINCIA = {'BA': 'Bs As', 'CABA': 'CABA', 'CAT': 'Catamarca', 'CBA': 'Córdoba', 'CHA': 'Chaco', 'CHU': 'Chubut', 'COR': 'Corrientes', 'ER': 'Entre Ríos', 'FOR': 'Formosa', 'JY': 'Jujuy', 'LAR': 'La Rioja', 'LPA': 'La Pampa', 'MDZ': 'Mendoza', 'MIS': 'Misiones', 'NQ': 'Neuquén', 'RN': 'Río Negro', 'SAL': 'Salta', 'SC': 'Santa Cruz', 'SDE': 'Santiago del Estero', 'SF': 'Santa Fe', 'SJU': 'San Juan', 'SL': 'San Luis', 'TF': 'Tierra del Fuego', 'TUC': 'Tucumán'}

List of Argentina provinces

arcovid19.cases.D0 = datetime.datetime(2020, 3, 11, 0, 0)

Pandemia Start 2020-03-11

arcovid19.cases.Q1 = datetime.datetime(2020, 3, 20, 0, 0)

Argentine quarantine starts 2020-03-20

class arcovid19.cases.CasesPlot(frame)[source]

Bases: arcovid19.core.Plotter

barplot(provincia=None, confirmed=True, active=True, recovered=True, deceased=True, ax=None, **kwargs)[source]
boxplot(provincia=None, confirmed=True, active=True, recovered=True, deceased=True, ax=None, **kwargs)[source]
curva_epi_pais(ax=None, argentina=True, exclude=None, log=False, norm=False, paint=None, count_days=None, **kwargs)[source]

method: full_period_normalized()

This function plots the time series, similar to grate_full_period_all, but including a second axis and comments about the start of quarantine

opciones para paint: pandemia, cuarentena

opciones para count_days: pandemia, cuarentena

curva_epi_provincia(*args, **kwargs)[source]
default_plot_name_method = 'curva_epi_pais'
grate_full_period(*args, **kwargs)[source]
grate_full_period_all(*args, **kwargs)[source]
growth_provincia(provincia=None, confirmed=True, active=True, recovered=True, deceased=True, ax=None, log=False, norm=False, **kwargs)[source]
time_serie(provincia=None, confirmed=True, active=True, recovered=True, deceased=True, ax=None, **kwargs)[source]
time_serie_all(ax=None, argentina=True, exclude=None, **kwargs)[source]
class arcovid19.cases.CasesFrame(df, extra=NOTHING)[source]

Bases: arcovid19.core.Frame

Wrapper around the load_cases() table.

This class adds functionalities around the dataframe.

dates

Returns the dates for which we have data.

Useful to use as time column (row) list for wide (long) format.

get_provincia_name_code(provincia)[source]

Resolve and validate the name and code of a given provincia name or code.

grate_full_period(provincia=None)[source]

Estimates growth rate for the period where we have data

last_growth_rate(provincia=None)[source]

Returns the last available growth rate for the whole country if provincia is None, or for only the named region.

plot_cls

alias of CasesPlot

restore_time_serie()[source]

Retrieve a new pandas.DataFrame but with observations by Date.

tot_cases

Returns latest value of total confirmed cases

arcovid19.cases.load_cases(cases_url='https://github.com/ivco19/libs/raw/master/databases/cases.xlsx', areas_pop_url='https://github.com/ivco19/libs/raw/master/databases/extra/arg_provs.dat', force=False)[source]

Utility function to parse all the actual cases of the COVID-19 in Argentina.

Parameters:
  • cases_url (str) – The url for the excel table to parse. Default is ivco19 team table.
  • areas_pop_url (str) – The url for the csv population table to parse. Default is ivco19 team table.
  • force (bool (default=False)) – If you want to ignore the local cache and retrieve a new value.
Returns:

CasesFrame – It features a pandas multi index, with the following hierarchy:

  • level 0: cod_provincia - Argentina states
  • level 1: cod_status - Four states of disease patients (R, C, A, D)

Return type:

Pandas-DataFrame like object with all the arcovid19 datatabase.

arcovid19.models module

Utilities to Utility function to parse all the actual cases of the COVID-19 in Argentina.

exception arcovid19.models.NodeNotFoundError[source]

Bases: KeyError

If a node is not found inside a graph

class arcovid19.models.Node(id, value, outgoing=NOTHING, incoming=NOTHING)[source]

Bases: object

This class is used to create and manipulated nodes.

add_neighbor(neighbor, names, values)[source]
be_neighbor(neighbor, names, values)[source]
get_connections()[source]
get_weight(neighbor)[source]
class arcovid19.models.Graph(vert_dict=NOTHING)[source]

Bases: object

This class is used to create and manipulated graphs.

It makes a heavy use of the node class A graph is made of nodes and edges. This class allows to store a value for each node and different “weights” for each edge. Also, edges are directed.

Example

>>> g = Graph()
>>> for i, inode in enumerate(['A','B','C','D']):
...     print(i)
...     g.add_node(inode, 0)
>>> nms = ['x', 'y']
>>> g.add_edge('A', 'B', nms, [1, 100])
>>> g.add_edge('A', 'C', nms, [2, 200])
>>> g.add_edge('B', 'D', nms, [3, 300])
>>> g.add_edge('D', 'B', nms, [4, 400])
>>> g.add_edge('D', 'C', nms, [5, 500])
>>> g.add_edge('C', 'C', nms, [6, 600])

# A node can be connected to itself. >>> g.add_edge(‘B’, ‘B’, nms, [333, 333]) >>> g.show() …

vert_dict

a dict containing the vertices

Type:dict
add_edge(frm, to, names=None, values=0)[source]

Link two nodes inside a graph.

Notes

Does not verify if edge already exists

Raises:NodeNotFound: – If one of the node are not tregistered in the graph
add_node(nnode, value)[source]

Adds a new node to a graph.

The node must have a value.

format_connections()[source]
format_weights()[source]
get_edge(frm, to, field)[source]
get_node(n)[source]

Retrieve a node if exists.

Parameters:n (str) –
Returns:node
Return type:a node object
get_node_ids()[source]
get_node_value(n)[source]

Returns the value of the node.

Parameters:n (str) –
Returns:value
Return type:float
get_nodes_from(nnode)[source]
get_nodes_to(nnode)[source]
node_activation(nnode, key)[source]
node_upgrade(nnode, key)[source]
resume_connections()[source]
resume_weights()[source]
set_node(n, value)[source]

Updates the Node value. The node must exists inside the graph.

Parameters:
  • n (str) – The ID or name of the node
  • value (float) – The value to be assigned to the node
class arcovid19.models.InfectionCurve(population: int = 600000, N_init: int = 10, R: float = 1.2, intervention_start: int = 15, intervention_end: int = 25, intervention_decrease: float = 70, t_incubation: float = 5.0, t_infectious: float = 9.0, t_death: float = 32.0, mild_recovery: float = 11.0, bed_stay: float = 28.0, bed_rate: float = 0.2, bed_wait: int = 5, beta: float = 1.236, sigma: float = 1.1, gamma: float = 1.1)[source]

Bases: object

MArce documentame me siento sola.

Parameters:
  • population (int (default=600000)) – Population.
  • N_init (int (default=10)) – Number of initial infections.
  • R (float (default=1.2)) – Reproduction number.
  • intervention_start (int (default=15)) – Start intervention days.
  • intervention_end (int (default=25)) – End intervention days.
  • intervention_decrease (float (default=70)) – Decrease in transmission for intervention, percentage (0-100) 100 means total isolation.
  • t_incubation (float (default=5.)) – Length of incubation period.
  • t_infectiou (= (default=9.)) – Duration patient is infectious.
  • t_death (float (default=32.)) – Time from end of incubation to death.
  • mild_recovery (float (default=0.2)) – Recovery time for mild (not severnot severe) cases, days hospitalization rate (fraction).
  • bed_stay (float (default=28.)) – Length of hospital stay, days.
  • bed_rate (float (default=0.2)) – Hospitalization rate (fraction).
  • bed_wait (int (default=5)) – Time from first synthoms to hospitalization (days).
  • beta (float (default=1.236)) – SEIR Model beta ($beta$).
  • sigma (float (default=1.1)) – SEIR Model sigma ($sigma$).
  • gamma (float (default=1.1)) – SEIR Model gamma ($gamma$).

References

“Stochastic SIR model with Python,” epirecipes. [Online].
Available: https://tinyurl.com/y8zwvfk4. [Accessed: 09-May-2020].
do_SEIR(t_max=200, dt=1.0)[source]

This function implements a SEIR model without vital dynamics under the assumption of a closed population. Recovered individuals become immune for ever. ref.: https://www.idmod.org/docs/hiv/model-seir.html

Parameters:
  • t_max (int (default=200)) – Time range [days].
  • dt (float (default=1.)) – Time step [days].
Returns:

value

Return type:

Time series for S, E, I and R

do_SEIRF(t_max=200, dt=1.0)[source]

Documentame MARCE

Parameters:
  • t_max (int (default=200)) – Time range [days].
  • dt (float (default=1.)) – Time step [days].
Returns:

value

Return type:

Time series for S, E, I, R and F

do_SIR(t_max=200, dt=1.0)[source]

This function implements a SIR model without vital dynamics under the assumption of a closed population.

Recovered individuals become immune for ever. In this model exposed individuals become instantly infectious, i.e., there is no latency period like in the SEIR model.

Parameters:
  • t_max (int (default=200)) – Time range [days].
  • dt (float (default=1.)) – Time step [days].
Returns:

value

Return type:

Time series for S, I and R

arcovid19.models.load_infection_curve(**kwargs)[source]

Return a new instance of infection curve.

arcovid19.cli module

Command line interfaces to access different Argentina-Related databases of COVID-19 data from the Arcovid19 group.

arcovid19.cli.main()[source]

Run the arcovid19 command line interface.

arcovid19.cli.cases(*, url='https://github.com/ivco19/libs/raw/master/databases/cases.xlsx', force=False, out=None)[source]

Retrieve and store the cases database in CSV format.

url: str
The url for the excel table to parse. Default is ivco19 team table.
out: PATH (default=stdout)
The output path to the CSV file. If it’s not provided the data is printed in the stdout.
force:
If you want to ignore the local cache or retrieve a new value.
arcovid19.cli.webserver(*, host=None, port=None, nodebug=False, reload=False, load_dotenv=True)[source]

Run a development server for arcovid19 utilities.

host: str
the hostname to listen on. Set this to ‘0.0.0.0’ to have the server available externally as well. Defaults to ‘127.0.0.1’ or the host in the SERVER_NAME config variable if present.
port: int
the port of the webserver. Defaults to 5000 or the port defined in the SERVER_NAME config variable if present.
nodebug: bool
if given, disable debug mode.
reload: bool
If its True any change of the code will restart the webserver.
load_dotenv:
Load the nearest ‘.env’ and ‘.flaskenv’ files to set environment variables. Will also change the working directory to the directory containing the first file found.