# Plot unit conversions¶

This notebook demonstrates some examples of different kinds of units, and the circumstances under which they are converted and displayed.

:

%matplotlib inline
import sys
import atomica as at
import matplotlib.pyplot as plt
import numpy as np
import sciris as sc
from IPython.display import display, HTML

Atomica 1.12.1 (2019-08-20) -- (c) the Atomica development team
2019-08-20 07:30:36.988182

:

testdir = at.parent_dir()
P = at.Project(framework='unit_demo_framework.xlsx',databook='unit_demo_databook.xlsx')
res = P.run_sim('default','default',at.ProgramInstructions(start_year=2018))

Elapsed time for running "default": 0.0145s
Elapsed time for running "default": 0.0294s


This test example has examples of parameters with different timescales, and different types of programs.

## Parameters¶

• recrate - Duration in months

• infdeath - Weekly probability

• susdeath - Daily probability

• foi - Annual probability

:

d = at.PlotData(res,outputs=['recrate','infdeath','susdeath','foi','sus:inf','susdeath:flow','dead'],pops='adults')
at.plot_series(d,axis='pops');       Notice that parameters are plotted in their native units. For example, a probability per day is shown as probability per day, matching the numbers that were entered in the databook.

Aggregating these units without specifying the aggregation method will result in either integration or averaging as most appropriate for the units of the underlying quantity:

:

for output in ['recrate','infdeath','susdeath','foi','sus:inf','susdeath:flow','dead']:
at.plot_bars(d);

/opt/hostedtoolcache/Python/3.7.4/x64/lib/python3.7/site-packages/scipy-1.3.1-py3.7-linux-x86_64.egg/scipy/integrate/quadrature.py:251: AccuracyWarning: maxiter (465) exceeded. Latest difference = 3.330955e-02
AccuracyWarning)
/opt/hostedtoolcache/Python/3.7.4/x64/lib/python3.7/site-packages/scipy-1.3.1-py3.7-linux-x86_64.egg/scipy/integrate/quadrature.py:251: AccuracyWarning: maxiter (465) exceeded. Latest difference = 2.757952e-05
AccuracyWarning)
/opt/hostedtoolcache/Python/3.7.4/x64/lib/python3.7/site-packages/scipy-1.3.1-py3.7-linux-x86_64.egg/scipy/integrate/quadrature.py:251: AccuracyWarning: maxiter (465) exceeded. Latest difference = 1.424352e-06
AccuracyWarning)
/opt/hostedtoolcache/Python/3.7.4/x64/lib/python3.7/site-packages/scipy-1.3.1-py3.7-linux-x86_64.egg/scipy/integrate/quadrature.py:251: AccuracyWarning: maxiter (465) exceeded. Latest difference = 5.970597e-05
AccuracyWarning)       Accumulation will result in the units and output name being updated appropriately:

:

d = at.PlotData(res,outputs='sus:inf',pops='adults',accumulate='integrate',project=P)
at.plot_series(d);
at.plot_series(d);  ## Programs¶

• Risk avoidance - Continuous

• Harm reduction 1 - Continuous

• Harm reduction 2 - Continuous

• Treatment 1 - One-off

• Treatment 2 - One-off

Programs with continuous coverage cover a certain number of people every year:

:

d = at.PlotData.programs(res,outputs='Risk avoidance',quantity='coverage_number')
at.plot_series(d); Programs with one-off coverage cover a number of people at each time step. This is the number that gets returned by Result.get_coverage() but it is automatically annualized for plotting:

:

annual_coverage = res.model.progset.programs['Treatment 1'].spend_data.vals/res.model.progset.programs['Treatment 1'].unit_cost.vals
timestep_coverage = res.get_coverage('number')['Treatment 1']
print('Annual coverage = %g, Timestep coverage = %g' % (annual_coverage, timestep_coverage))

Annual coverage = 29166.7, Timestep coverage = 1142.86

:

d = at.PlotData.programs(res,outputs='Treatment 1',quantity='coverage_number')
at.plot_series(d)

:

[<Figure size 432x288 with 1 Axes>] These units are handled automatically when aggregating. For example, consider computing the number of people covered over a period of time:

:

d = at.PlotData.programs(res,outputs='Treatment 1',quantity='coverage_number',t_bins=[2000,2000.5])
at.plot_bars(d);

d = at.PlotData.programs(res,outputs='Treatment 1',quantity='coverage_number',t_bins=[2000,2002])
at.plot_bars(d);  :

d = at.PlotData.programs(res,outputs='Treatment 1',quantity='coverage_eligible',t_bins=[2000,2000.5])
at.plot_bars(d);

d = at.PlotData.programs(res,outputs='Treatment 1',quantity='coverage_number',t_bins=[2000,2002])
at.plot_bars(d);  