Skip to content

Commit 0f73a0f

Browse files
authored
EPNM paper review (#394)
1 parent eaf0951 commit 0f73a0f

File tree

11 files changed

+133
-114
lines changed

11 files changed

+133
-114
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ jobs:
1414
- name: Set up Python
1515
uses: actions/setup-python@v1
1616
with:
17-
python-version: '3.7'
17+
python-version: '3.12'
1818
- name: Install dependencies
1919
run: |
2020
python -m pip install --upgrade pip
2121
pip install -e .[develop]
2222
- name: Build documentation
2323
run: |
24-
python setup.py build_sphinx
24+
sphinx-build docs build/sphinx/
2525
- name: Deploy documentation
2626
uses: peaceiris/actions-gh-pages@v3
2727
with:

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Set up Python
1515
uses: actions/setup-python@v1
1616
with:
17-
python-version: '3.7'
17+
python-version: '3.12'
1818
- name: Install dependencies
1919
run: |
2020
python -m pip install --upgrade pip

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,6 @@ data/covid19_DTM/interim/QALY_model/postponement_non_covid_care/UZG/MZG_2016_202
170170
data/covid19_DTM/interim/QALY_model/postponement_non_covid_care/UZG/2020_2021_normalized.csv
171171
# Do not upload COVID19-Model.code-workspace for VS Studio
172172
COVID19-Model.code-workspace
173+
174+
# Macbook
175+
.DS_Store

notebooks/manuscripts/EPNM/plot-fit-sectors-EPNM.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# General packages
2-
import os
32
import numpy as np
43
import pandas as pd
54
import matplotlib.pyplot as plt
65
# EPNM functions
76
from EPNM.models.utils import initialize_model
8-
from EPNM.data.parameters import get_model_parameters
97
from EPNM.data.utils import get_sector_labels, get_sector_names, aggregate_simulation, get_sectoral_conversion_matrix
10-
from EPNM.models.TDPF import household_demand_shock, compute_income_expectations
11-
from EPNM.models.draw_functions import draw_function as draw_function
12-
from EPNM.data.calibration_data import get_NAI_value_added, get_revenue_survey, get_employment_survey, get_synthetic_GDP, get_B2B_demand
8+
from EPNM.data.calibration_data import get_revenue_survey, get_employment_survey, get_synthetic_GDP, get_B2B_demand
139
# Nicer colors
1410
colors = {"orange" : "#E69F00", "light_blue" : "#56B4E9",
1511
"green" : "#009E73", "yellow" : "#F0E442",
@@ -36,6 +32,7 @@
3632
# Initialize model
3733
params, model = initialize_model(shocks='pichler', prodfunc='half_critical')
3834

35+
# Pichler parameters
3936
model.parameters.update({'gamma_F': 15, 'gamma_H': 30, 'tau': 10, 'rho': 1-(1-0.60)/90})
4037

4138
# Aggregation functions
@@ -73,9 +70,6 @@ def aggregate_NACE21(simulation_in):
7370
date=simulation_in.coords['date']))
7471
return simulation_out
7572

76-
# Draw function
77-
from EPNM.models.draw_functions import draw_function
78-
7973
# Simulate
8074
out = model.sim([start_sim, end_sim], tau=1)
8175

@@ -132,7 +126,7 @@ def aggregate_NACE21(simulation_in):
132126
dist_temp.append(B2B_demand[j]/sum(B2B_demand)*(abs(x)-abs(y.values)) )
133127
# Sector label
134128
if sector in ['I', 'R', 'S']:
135-
ax[0,i].annotate(sector, xy=(x - 2, y + 2), fontsize=7)
129+
ax[0,i].annotate(sector, xy=(x - 2, y + 2), fontsize=6)
136130
# circle around transport
137131
if sector == 'H':
138132
from matplotlib import pyplot as plt, patches
@@ -161,8 +155,8 @@ def aggregate_NACE21(simulation_in):
161155
datasets = [data_GDP, data_revenue, data_employment]
162156
states = ['x', 'x', 'l']
163157
sizes = [params['x_0'], params['x_0'], params['l_0']]
164-
print_label = [['G45',],['G45','N79', 'R93'],['G45','N79', 'R93']]
165-
offset = [[-4,5],[-4,5],[-4,5]]
158+
print_label = [['G45', 'H49', 'N77'],['G45','N79', 'R93','I55-56', 'H49'],['G45','N79', 'R93','I55-56', 'H49']]
159+
offset = [[-5,5],[-5,5],[-5,5]]
166160
ylabels = ['Synthetic GDP\nprediction (%)', 'Revenue\nprediction (%)', 'Employment\nprediction (%)']
167161

168162
#########
@@ -205,7 +199,14 @@ def aggregate_NACE21(simulation_in):
205199
cumsize.append(sizes[k][get_sector_labels('NACE64').index(sector)]/sum(sizes[k]))
206200
# Sector label
207201
if sector in print_label[k]:
208-
ax[k+1,i].annotate(sector, xy=(x + offset[k][0], y + offset[k][1]), fontsize=7)
202+
if ((k == 1) & (i == 0) & (sector == 'I55-56')):
203+
pass
204+
elif ((k == 2) & (i == 0) & (sector == 'I55-56')):
205+
pass
206+
elif ((k == 2) & (i == 2) & (sector == 'I55-56')):
207+
pass
208+
else:
209+
ax[k+1,i].annotate(sector, xy=(x + offset[k][0], y + offset[k][1]), fontsize=6)
209210
# Circle around transport
210211
if ((sector == 'H49')):
211212
from matplotlib import pyplot as plt, patches

notebooks/manuscripts/EPNM/plot-fit-sensivity.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,30 @@
2929
## Define draw functions ##
3030
###########################
3131

32-
def draw_function_b(param_dict, samples_dict):
33-
param_dict['b_s'] = np.random.uniform(low=0.5, high=1)
34-
return param_dict
32+
def draw_function_b(parameters):
33+
parameters['b_s'] = np.random.uniform(low=0.5, high=1)
34+
return parameters
3535

36-
def draw_function_L(param_dict, samples_dict):
37-
param_dict['L'] = np.random.uniform(low=0.5, high=1)
38-
return param_dict
36+
def draw_function_L(parameters):
37+
parameters['L'] = np.random.uniform(low=0.5, high=1)
38+
return parameters
3939

40-
def draw_function_delta_S(param_dict, samples_dict):
41-
param_dict['delta_S'] = np.random.uniform(low=0.5, high=1)
42-
return param_dict
40+
def draw_function_delta_S(parameters):
41+
parameters['delta_S'] = np.random.uniform(low=0.5, high=1)
42+
return parameters
4343

44-
def draw_function_rho(param_dict, samples_dict):
45-
param_dict['rho'] = np.random.uniform(low=0.99, high=0.999) # 0.1 to 1 quarter
46-
return param_dict
44+
def draw_function_rho(parameters):
45+
parameters['rho'] = np.random.uniform(low=0.99, high=0.999) # 0.1 to 1 quarter
46+
return parameters
4747

48-
def draw_function_l_s(param_dict, samples_dict):
48+
def draw_function_l_s(parameters):
4949
r = np.random.uniform(low=0.70, high=1.30)
50-
param_dict['l_s_1'] = r*param_dict['l_s_1']
51-
param_dict['l_s_2'] = r*param_dict['l_s_2']
52-
return param_dict
50+
parameters['l_s_1'] = r*parameters['l_s_1']
51+
parameters['l_s_2'] = r*parameters['l_s_2']
52+
return parameters
5353

5454
draw_functions = [draw_function_l_s, draw_function_b, draw_function_rho, draw_function_L, draw_function_delta_S]
55-
parameter_names = ['$\\epsilon_{i,t}^S$', '$b_t$', '$\\rho$', '$L$', '$\Delta S$']
55+
parameter_names = ['$\\kappa_{i,t}^S$', '$b_t$', '$\\rho$', '$L$', '$\\Delta S$']
5656

5757
######################
5858
## Initialize model ##
@@ -69,7 +69,7 @@ def draw_function_l_s(param_dict, samples_dict):
6969

7070
for i,draw_function in enumerate(draw_functions):
7171
# Simulate model
72-
out = model.sim([start_sim, end_sim], method='RK45', rtol=1e-4, N=5*18, processes=18, samples={}, draw_function=draw_function)
72+
out = model.sim([start_sim, end_sim], method='RK45', rtol=1e-4, N=5*16, processes=16, draw_function=draw_function)
7373
simtime = out['date'].values
7474
# Skip row 0, column 1
7575

notebooks/manuscripts/EPNM/plot_sensitivity-grid.ipynb

Lines changed: 48 additions & 28 deletions
Large diffs are not rendered by default.

notebooks/manuscripts/EPNM/timeline.ipynb

Lines changed: 7 additions & 15 deletions
Large diffs are not rendered by default.

notebooks/manuscripts/EPNM/visualise_comparison.ipynb

Lines changed: 23 additions & 21 deletions
Large diffs are not rendered by default.

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"develop": ["pytest",
2222
"sphinx",
2323
"numpydoc",
24+
"setuptools",
2425
"sphinx_rtd_theme",
2526
"myst_parser[sphinx]"],
2627
}

src/EPNM/models/draw_functions.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
import numpy as np
22

3-
def draw_function(param_dict, samples_dict):
3+
def draw_function(parameters):
44
"""
55
Samples calibrated magnitudes of household demand/exogeneous demand shocks during the summer of 2021
66
Performs global sensitivity analysis on other parameters
77
"""
88

99
# Option 1
1010
# shocks in/out
11-
param_dict['l1'] = np.random.normal(loc=14, scale=0.2*14)
12-
param_dict['l2'] = np.random.normal(loc=7*8, scale=0.2*7*8)
11+
parameters['l1'] = np.random.normal(loc=14, scale=0.2*14)
12+
parameters['l2'] = np.random.normal(loc=7*8, scale=0.2*7*8)
1313
# hiring and Firing speed
14-
param_dict['gamma_F'] = np.random.normal(loc=28, scale=0.2*28)
15-
param_dict['gamma_H'] = 2*param_dict['gamma_F']
14+
parameters['gamma_F'] = np.random.normal(loc=28, scale=0.2*28)
15+
parameters['gamma_H'] = 2*parameters['gamma_F']
1616
# household savings and prospects
17-
param_dict['delta_S'] = np.random.uniform(low=0.5, high=1)
18-
param_dict['L'] = 1
19-
param_dict['b_s'] = 0.7
17+
parameters['delta_S'] = np.random.uniform(low=0.5, high=1)
18+
parameters['L'] = 1
19+
parameters['b_s'] = 0.7
2020
# restitution
21-
param_dict['rho'] = np.random.uniform(low=1-(1-0.50)/90, high=1-(1-1)/90)
21+
parameters['rho'] = np.random.uniform(low=1-(1-0.50)/90, high=1-(1-1)/90)
2222
# restock rate
23-
param_dict['tau'] = np.random.normal(loc=7, scale=0.2*7)
23+
parameters['tau'] = np.random.normal(loc=7, scale=0.2*7)
2424
# shocks lockdowns
25-
param_dict['l_s_1'] = np.random.normal(loc=1, scale=0.075)*param_dict['l_s_1']
26-
param_dict['l_s_2'] = np.random.normal(loc=1, scale=0.075)*param_dict['l_s_2']
27-
param_dict['c_s'] = np.random.normal(loc=1, scale=0.075)*param_dict['c_s']
28-
param_dict['c_s'] = np.where(param_dict['c_s'] > 1, 1, param_dict['c_s'])
25+
parameters['l_s_1'] = np.random.normal(loc=1, scale=0.075)*parameters['l_s_1']
26+
parameters['l_s_2'] = np.random.normal(loc=1, scale=0.075)*parameters['l_s_2']
27+
parameters['c_s'] = np.random.normal(loc=1, scale=0.075)*parameters['c_s']
28+
parameters['c_s'] = np.where(parameters['c_s'] > 1, 1, parameters['c_s'])
2929
# shocks summer 2020
30-
param_dict['ratio_c_s'] = np.random.uniform(low=0.25, high=0.75)
30+
parameters['ratio_c_s'] = np.random.uniform(low=0.25, high=0.75)
3131

32-
return param_dict
32+
return parameters

0 commit comments

Comments
 (0)