Skip to content

Commit

Permalink
working pipeline for india
Browse files Browse the repository at this point in the history
  • Loading branch information
vishaltomar28 committed Jul 27, 2020
1 parent f3e4d11 commit 9838a39
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 61 deletions.
5 changes: 2 additions & 3 deletions src/disease_model/models/compartment_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,10 @@ def predict_with_params(
population_data, past_health_data, params)

prediction = integrate.solve_ivp(
self.differential_equations,
fun=lambda t, y: self.differential_equations(t, y, tuple(self.parameter_config.flatten(params))),
t_span=(0, forecast_length),
t_eval=np.arange(1, forecast_length + 1),
y0=initial_state,
args=self.parameter_config.flatten(params))
y0=initial_state)

return self.format_output(prediction.y)

Expand Down
2 changes: 1 addition & 1 deletion src/disease_model/models/seir.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def differential_equations(
# pylint: disable=invalid-name,too-many-locals
s, e, i, r, _ = compartments
population = s + e + i + r
parameters = self.parameter_config.parse(args)
parameters = self.parameter_config.parse(args[0])
beta = parameters['beta']
gamma = parameters['gamma']
sigma = parameters['sigma']
Expand Down
50 changes: 25 additions & 25 deletions src/economic_model/data/sector_mapping.csv
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
lockdown_sector,sector
agriculture,
chemical,Manufacturing
commerce,"Trade, Hotels, Transport, Communication and Services Related to Broadcasting"
construction,Construction
education,Other services
fin_prof_services,"Financial, Real Estate and Professional Services"
food_consumables,
healthcare,Other services
hospitality_tourism,"Trade, Hotels, Transport, Communication and Services Related to Broadcasting"
manufacturing,Manufacturing
mining,Mining and quarrying
media,Other services
energy,"Electricity, gas, water supply & other utility services"
telecom,"Transport, storage, communication & services related to broadcasting"
public_admin,"Public Administration Defence, and Other Services"
supply_chain_ship,"Transport, storage, communication & services related to broadcasting"
forest_husb_fish,
textiles,"Trade, Hotels, Transport, Communication and Services Related to Broadcasting"
transportation ,"Transport, storage, communication & services related to broadcasting"
utilities,"Electricity, gas, water supply & other utility services"
open_border,"Transport, storage, communication & services related to broadcasting"
air_travel,"Transport, storage, communication & services related to broadcasting"
roal_rail_travel,"Transport, storage, communication & services related to broadcasting"
public_transport,"Transport, storage, communication & services related to broadcasting"
lockdown_sector,sector,id
agriculture,"TTL_01T03: Agriculture, forestry and fishing",0
chemical,TTL_20T21: Chemicals and pharmaceutical products,9
commerce,TTL_69T82: Other business sector services,30
construction,TTL_41T43: Construction,21
education,TTL_85: Education,32
fin_prof_services,TTL_64T66: Financial and insurance activities,28
food_consumables,"TTL_10T12: Food products, beverages and tobacco",4
healthcare,TTL_86T88: Human health and social work,33
hospitality_tourism,"TTL_90T96: Arts, entertainment, recreation and other service activities",34
manufacturing,TTL_24: Manufacture of basic metals,12
mining,TTL_05T06: Mining and extraction of energy producing products,1
media,"TTL_58T60: Publishing, audiovisual and broadcasting activities",25
energy,TTL_05T06: Mining and extraction of energy producing products,1
telecom,TTL_61: Telecommunications,26
public_admin,TTL_84: Public administration and defence,31
supply_chain_ship,TTL_49T53: Transportation and storage,23
forest_husb_fish,"TTL_01T03: Agriculture, forestry and fishing",0
textiles,"TTL_13T15: Textiles, wearing apparel, leather and related products",5
transportation ,TTL_49T53: Transportation and storage,23
utilities,"TTL_35T39: Electricity, gas, water supply, sewerage, waste and remediation services",20
open_border,TTL_49T53: Transportation and storage,23
air_travel,TTL_49T53: Transportation and storage,23
roal_rail_travel,TTL_49T53: Transportation and storage,23
public_transport,TTL_49T53: Transportation and storage,23
27 changes: 21 additions & 6 deletions src/economic_model/models/basic_lockdown_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""
from typing import Dict
import attr
import os
import numpy as np
import pandas as pd
from help_project.src.economic_model.utils import gva_data
from help_project.src.exitstrategies import lockdown_policy as lockdown
from help_project.src.economic_model.models.economy_simulation import simulate_economy
Expand Down Expand Up @@ -34,19 +36,32 @@ def _get_economic_vector_for_single_policy(self, lockdown_policy: lockdown.Lockd
sector_mappings.iloc[i]['lockdown_sector'])

baseline_gva = gva.get_gvas()
adjusted_gva = {}
india_input_output = pd.read_csv(os.path.dirname(__file__) + '/../data/india_input.csv')
india_input_output.columns = india_input_output.iloc[0]
india_input_output = india_input_output.iloc[1:]
india_input_output = india_input_output.set_index('To: (sector in column)')
india_input_output = india_input_output.drop(
['TXS_IMP_FNL: Taxes less subsidies on intermediate and final products (paid in foreign countries)',
'TXS_INT_FNL: Taxes less subsidies on intermediate and final products (paid in domestic agencies, includes duty on imported products)',
'TTL_INT_FNL: Total intermediate consumption at purchasers’ prices',
'TTL_97T98: Private households with employed persons'], axis=0)
india_input_output = india_input_output.drop(columns=india_input_output.columns[-8:])
india_input_output = india_input_output.drop(columns=[india_input_output.columns[-2]])
sectors = india_input_output.index.values[:-2]
labor_shocks = {}
for sector in sectors:
labor_shocks[sector]=1
for key in mapping_dict:
if key not in baseline_gva:
if key not in sectors:
continue
weights = []
for sector in mapping_dict[key]:
if sector in lockdown_policy:
weights.append(lockdown_policy[sector])
if len(weights) > 0:
adjusted_gva[key] = baseline_gva[key] * np.mean(weights)
else:
adjusted_gva[key] = baseline_gva[key]
return adjusted_gva
labor_shocks[key] = np.mean(weights)
adjusted_gvas = simulate_economy(labor_shocks)
return adjusted_gvas

def get_economic_vector(
self, lockdown_policy: lockdown.LockdownTimeSeries) -> Dict[str, float]:
Expand Down
15 changes: 10 additions & 5 deletions src/economic_model/models/economy_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def simulate_economy(shocks_to_labor_supply=None):
'rounds': 500,}

# Cleaning input output table for india
india_input_output = pd.read_csv('india_input.csv')
india_input_output = pd.read_csv(os.path.dirname(__file__) + '/../data/india_input.csv')
india_input_output.columns = india_input_output.iloc[0]
india_input_output = india_input_output.iloc[1:]
india_input_output = india_input_output.set_index('To: (sector in column)')
Expand Down Expand Up @@ -121,13 +121,18 @@ def simulate_economy(shocks_to_labor_supply=None):
labor_alphas = [labor_dict, labor_requirement]
for i in range(number_sectors):
agent_parameters[i]['output_input_ratio']=output_input_ratio[i]


shocks_array=[]
for i in range(len(india_input_output)-2):
if india_input_output.index[i] in shocks_to_labor_supply.keys():
shocks_array.append(0.5 + 0.5*(shocks_to_labor_supply[india_input_output.index[i]]))
else:
shocks_array.append(1)
shocks_to_labor_supply = shocks_array
if shocks_to_labor_supply is None:
shocks_to_labor_supply = [random.uniform(0.5,1) for i in range(number_sectors)]
shocks = main(parameters,agent_parameters,labor_alphas, shocks_to_labor_supply)
GVAs=[]
GVAs={}
for i in range(number_sectors):
GVAs.append(shocks[i]*india_input_output.iloc[-1,i])
GVAs[india_input_output.index[i]]=(shocks[i]*india_input_output.iloc[-1,i])
return GVAs

Loading

0 comments on commit 9838a39

Please sign in to comment.