optimamodel / optima-tb

Optima TB-UCL model
GNU Lesser General Public License v3.0
2 stars 0 forks source link

Record flow rate #110

Closed RomeshA closed 6 years ago

RomeshA commented 6 years ago

This builds on changes introduced in #109 and records flow rate by adding two properties to the Link object - target_flow which stores the intended flow rate based on rescaled parameters, and flow which stores the actual number of people that were moved. These fields are now used by getFlow and are thus automatically used when plotting via plotting.py. The plotting functions will always show the actual flow rate. However, getFlow has an additional boolean flag to access target_flow if desired. See example below - doth_rate is set very high so that the actual flow is less than the target flow, and getFlow is used below to compare these two rates.

from optima_tb.project import Project
from optima_tb.utils import odict
from optima_tb.plotting import plotResult

cascade = '../tb-ucl-analyses/belarus/Cascade Spreadsheets/cascade-belarus.xlsx'
databook = '../tb-ucl-analyses/belarus/Databook Spreadsheets/databook-belarus.xlsx'
proj = Project(name='belarus', cascade_path=cascade,validation_level = 'avert')
proj.settings.tvec_start = 2000
proj.settings.tvec_end = 2020
proj.loadSpreadsheet(databook_path=databook)
proj.makeParset()

p = proj.parsets[0].getPar('doth_rate');
for pop in p.y.keys():
    proj.parsets[0].getPar('doth_rate').y_format[pop] = 'number'
    proj.parsets[0].getPar('doth_rate').y[pop].fill(1e4) # Make death rate very high

results = proj.runSim(parset_name='default',plot=False) # Need to uncommment import statement in project.py for this to run in develop branch

import matplotlib.pyplot as plt

# Plotting links via plotResult() now works
plotResult(proj,results,['doth_rate'])

# Plot target flow rate by calling getFlow() directly
plt.figure()
f = results.getFlow('doth_rate')
f_target = results.getFlow('doth_rate',target_flow=True)
plt.plot(results.sim_settings['tvec'],f[0]['doth_rate']['15-64'])
plt.plot(results.sim_settings['tvec'],f_target[0]['doth_rate']['15-64'])

plt.show()

Note that if the doth_rate is decreased, the link continues to move fewer people than the target. For example, in the above simulation the link actually moves about 20000 people. But if doth_rate is decreased to say, 100 people/year, then the actual flow rate will still be smaller. This appears to be because the outgoing links are already saturated in the absence of death by other causes, so the links are downscaled, and because the links are downscaled proportionately, as the doth_rate decreases, its share of outgoing people decreases correspondingly.

Would be great as part of testing this to double check against existing results to verify consistency