def compliance_func(t, states, param, l, effectivity): # Convert tau and l to dates l_days = pd.Timedelta(l, unit='D') # Measures start_measures = pd.to_datetime('2020-03-15') if t < start_measures: return param elif start_measures < t <= start_measures + l_days: return ramp_fun(param, effectivity * param, t, start_measures, l) else: return param * effectivity
def report6_policy_function(t, states, param, l, tau, prev_home, prev_schools, prev_work, prev_rest, scenario='1'): # Convert tau and l to dates tau_days = pd.Timedelta(tau, unit='D') l_days = pd.Timedelta(l, unit='D') # Define key policy dates t1 = pd.Timestamp('2020-03-15') # start of lockdown t2 = pd.Timestamp( '2020-05-15' ) # gradual re-opening of schools (assume 50% of nominal scenario) t3 = pd.Timestamp('2020-07-01') # start of summer: COVID-urgency very low t4 = pd.Timestamp('2020-08-01') t5 = pd.Timestamp( '2020-09-01' ) # september: lockdown relaxation narrative in newspapers reduces sense of urgency t6 = pd.Timestamp('2020-10-19') # lockdown t7 = pd.Timestamp('2020-11-16') # schools re-open t8 = pd.Timestamp('2020-12-18') # schools close t9 = pd.Timestamp('2020-12-24') t10 = pd.Timestamp('2020-12-26') t11 = pd.Timestamp('2020-12-31') t12 = pd.Timestamp('2021-01-01') t13 = pd.Timestamp('2020-01-04') # Opening of schools t14 = pd.Timestamp('2021-01-18') # start of alternative policies t15 = pd.Timestamp('2021-02-15') # Start of spring break t16 = pd.Timestamp('2021-02-21') # End of spring break # Average out september mobility if t5 < t <= t6 + tau_days: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, school=1) elif t6 + tau_days < t <= t6 + tau_days + l_days: t = pd.Timestamp(t.date()) policy_old = contact_matrix_4prev(t, school=1) policy_new = contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) return ramp_fun(policy_old, policy_new, t, tau_days, l, t6) elif t6 + tau_days + l_days < t <= t7: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t7 < t <= t8: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t8 < t <= t9: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) else: # Scenario 1: Current contact behaviour + schools open on January 18th if scenario == '1': if t9 < t <= t13: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t13 < t <= t15: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t15 < t <= t16: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) else: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) # Scenario 2: increases in work or leisure mobility elif scenario == '2a': if t9 < t <= t13: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t13 < t <= t14: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0.6) elif t14 < t <= t15: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, 1, school=0.6, SB='2a') elif t15 < t <= t16: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, 1, school=0, SB='2a') else: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, 1, school=0.6, SB='2a') elif scenario == '2b': if t9 < t <= t13: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t13 < t <= t14: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0.6) elif t14 < t <= t15: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, prev_work, 1, school=0.6, SB='2b') elif t15 < t <= t16: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, prev_work, 1, school=0, SB='2b') else: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, prev_work, 1, school=0.6, SB='2b') elif scenario == '2c': if t9 < t <= t13: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t13 < t <= t14: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0.6) elif t14 < t <= t15: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, prev_rest, school=0.6, SB='2c') elif t15 < t <= t16: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, prev_rest, school=0, SB='2c') else: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, prev_rest, school=0.6, SB='2c') # Scenario 3: Christmas mentality change elif scenario == '3': if t9 < t <= t10: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, prev_schools, prev_work, 1, school=0) elif t10 < t <= t11: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, prev_schools, prev_work, 1, school=0) elif t11 < t <= t12: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, prev_schools, prev_work, 1, school=0) elif t12 < t <= t13: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t13 < t <= t14: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t14 < t <= t15: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0.6) elif t15 < t <= t16: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) else: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1)
def report7_policy_function(t, states, param, l, tau, prev_home, prev_schools, prev_work, prev_rest, scenario='1a'): # Convert tau and l to dates tau_days = pd.Timedelta(tau, unit='D') l_days = pd.Timedelta(l, unit='D') # Define key policy dates t1 = pd.Timestamp('2020-03-15') # start of lockdown t2 = pd.Timestamp( '2020-05-15' ) # gradual re-opening of schools (assume 50% of nominal scenario) t3 = pd.Timestamp('2020-07-01') # start of summer: COVID-urgency very low t4 = pd.Timestamp('2020-08-01') t5 = pd.Timestamp( '2020-09-01' ) # september: lockdown relaxation narrative in newspapers reduces sense of urgency t6 = pd.Timestamp('2020-10-19') # lockdown t7 = pd.Timestamp('2020-11-16') # schools re-open t8 = pd.Timestamp('2020-12-18') # start Christmas holidays (schools close) t13 = pd.Timestamp('2020-01-04') # end Christmas holidays (schools open) #t14 = pd.Timestamp('2021-01-18') # start of alternative policies t15 = pd.Timestamp( '2021-02-15') # Start of Krokus holidays (schools close) t16 = pd.Timestamp('2021-02-21') # End of Krokus holidays (schools open) t17 = pd.Timestamp('2021-03-01') # release to SB March 1 t18 = pd.Timestamp('2021-04-01') # release to SB April 1 t19 = pd.Timestamp('2021-04-05') # start Eastern Holidays (schools close) t20 = pd.Timestamp('2021-04-19') # end Eastern Holidays (schools open) t21 = pd.Timestamp('2021-05-01') # release to SB May 1 # Average out september mobility if t5 < t <= t6 + tau_days: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, school=1) elif t6 + tau_days < t <= t6 + tau_days + l_days: t = pd.Timestamp(t.date()) policy_old = contact_matrix_4prev(t, school=1) policy_new = contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) return ramp_fun(policy_old, policy_new, t, tau_days, l, t6) elif t6 + tau_days + l_days < t <= t7: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t7 < t <= t8: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t8 < t <= t13: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t13 < t <= t15: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0.6) elif t15 < t <= t16: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) else: # Scenario 1: Current contact behaviour if scenario == '1': if t16 < t <= t19: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0.6) elif t19 < t <= t20: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t20 < t: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0.6) else: raise Exception('scenario ' + scenario + ' t:' + str(t)) # Scenario 2: increases in work or leisure mobility on March 1 elif scenario == '2': if t16 < t <= t17: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0.6) elif t17 < t <= t19: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, 1, school=0.6, SB='2a') elif t19 < t <= t20: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, 1, school=0, SB='2a') elif t20 < t: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, 1, school=0.6, SB='2a') else: raise Exception('scenario ' + scenario + ' t:' + str(t)) # Scenario 3: increases in work or leisure mobility on April 1 elif scenario == '3': if t16 < t <= t18: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0.6) elif t18 < t <= t19: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, 1, school=0.6, SB='2a') elif t19 < t <= t20: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, 1, school=0, SB='2a') elif t20 < t: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, 1, school=0.6, SB='2a') else: raise Exception('scenario ' + scenario + ' t:' + str(t)) # Scenario 4: increases in work or leisure mobility on May 1 elif scenario == '4': if t16 < t <= t19: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0.6) elif t19 < t <= t20: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t20 < t <= t21: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0.6) elif t > t21: t = pd.Timestamp(t.date()) return contact_matrix_4prev(t, 1, 1, 1, 1, school=0.6, SB='2a') else: raise Exception('scenario ' + scenario + ' t:' + str(t)) else: raise Exception('scenario ' + scenario + ' non-existing')
def policies_RESTORE8(t, states, param, l, l_relax, prev_schools, prev_work, prev_rest, prev_home, relaxdate, scenario=0): t = pd.Timestamp(t.date()) # Convert compliance tau and l to dates l_days = pd.Timedelta(l, unit='D') # Convert relaxation l to dates l_relax_days = pd.Timedelta(l_relax, unit='D') # Define key dates of first wave t1 = pd.Timestamp('2020-03-15') # start of lockdown t2 = pd.Timestamp( '2020-05-15' ) # gradual re-opening of schools (assume 50% of nominal scenario) t3 = pd.Timestamp('2020-07-01') # start of summer holidays t4 = pd.Timestamp('2020-09-01') # end of summer holidays # Define key dates of second wave t5 = pd.Timestamp('2020-10-19') # lockdown (1) t6 = pd.Timestamp('2020-11-02') # lockdown (2) t7 = pd.Timestamp('2020-11-16') # schools re-open t8 = pd.Timestamp('2020-12-18') # Christmas holiday starts t9 = pd.Timestamp('2021-01-04') # Christmas holiday ends t10 = pd.Timestamp('2021-02-15') # Spring break starts t11 = pd.Timestamp('2021-02-21') # Spring break ends t12 = pd.Timestamp('2021-02-28') # Contact increase in children t13 = pd.Timestamp('2021-03-26') # Start of Easter holiday t14 = pd.Timestamp('2021-04-18') # End of Easter holiday t15 = pd.Timestamp(relaxdate) # Relaxation date t16 = pd.Timestamp('2021-07-01') # Start of Summer holiday t17 = pd.Timestamp('2021-09-01') if t <= t1: return all_contact(t) elif t1 < t < t1: return all_contact(t) elif t1 < t <= t1 + l_days: policy_old = all_contact(t) policy_new = contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) return ramp_fun(policy_old, policy_new, t, t1, l) elif t1 + l_days < t <= t2: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t2 < t <= t3: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t3 < t <= t4: return contact_matrix_4prev(t, school=0) # Second wave elif t4 < t <= t5: return contact_matrix_4prev(t, school=1) elif t5 < t <= t5 + l_days: policy_old = contact_matrix_4prev(t, school=1) policy_new = contact_matrix_4prev(t, prev_schools, prev_work, prev_rest, school=1) return ramp_fun(policy_old, policy_new, t, t5, l) elif t5 + l_days < t <= t6: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t6 < t <= t7: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t7 < t <= t8: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t8 < t <= t9: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t9 < t <= t10: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t10 < t <= t11: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t11 < t <= t12: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t12 < t <= t13: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t13 < t <= t14: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) if scenario == 0: if t14 < t <= t15: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t15 < t <= t16: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t16 < t <= t17: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) else: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif scenario == 1: if t14 < t <= t15: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t15 < t <= t15 + l_relax_days: policy_old = contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) policy_new = contact_matrix_4prev(t, prev_schools, prev_work, prev_rest, work=1, transport=1, school=1) return ramp_fun(policy_old, policy_new, t, t15, l_relax) elif t15 + l_relax_days < t <= t16: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, work=1, transport=1, school=1) elif t16 < t <= t17: return contact_matrix_4prev( t, prev_home, prev_schools, prev_work, prev_rest, work=0.8, transport=0.90, school=0 ) # 20% less work mobility during summer, 10% less public transport during summer else: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, work=1, transport=1, school=1) elif scenario == 2: if t14 < t <= t15: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) elif t15 < t <= t15 + l_relax_days: policy_old = contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) policy_new = contact_matrix_4prev(t, prev_schools, prev_work, prev_rest, work=1, transport=1, school=0) return ramp_fun( policy_old, policy_new, t, t15, l_relax, ) elif t15 + l_relax_days < t <= t16: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, work=1, transport=1, school=0) elif t16 < t <= t17: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, work=0.8, transport=0.90, school=0) else: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, work=1, transport=1, school=1) elif scenario == 3: if t14 < t <= t15: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t15 < t <= t15 + l_relax_days: policy_old = contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) policy_new = contact_matrix_4prev(t, prev_schools, prev_work, prev_rest, leisure=1, others=1, transport=1, school=1) return ramp_fun(policy_old, policy_new, t, t15, l_relax) elif t15 + l_relax_days < t <= t16: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, leisure=1, others=1, transport=1, school=1) elif t16 < t <= t17: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, leisure=1, others=1, transport=0.90, school=0) else: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, leisure=1, others=1, transport=1, school=1) elif scenario == 4: if t14 < t <= t15: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) policy_new = contact_matrix_4prev(t, prev_schools, prev_work, prev_rest, leisure=1, others=1, transport=1, school=0) return ramp_fun(policy_old, policy_new, t, t15, l_relax) elif t15 + l_relax_days < t <= t16: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, leisure=1, others=1, transport=1, school=0) elif t16 < t <= t17: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, leisure=1, others=1, transport=0.90, school=0) else: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, leisure=1, others=1, transport=1, school=1) elif scenario == 5: if t14 < t <= t15: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) elif t15 < t <= t15 + l_relax_days: policy_old = contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=1) policy_new = contact_matrix_4prev(t, prev_schools, prev_work, prev_rest, work=1, leisure=1, transport=1, others=1, school=1) return ramp_fun(policy_old, policy_new, t, t15, l_relax) elif t15 + l_relax_days < t <= t16: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, work=1, leisure=1, transport=1, others=1, school=1) elif t16 < t <= t17: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, work=0.8, leisure=1, transport=0.90, others=1, school=0) else: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, work=1, leisure=1, transport=1, others=1, school=1) elif scenario == 6: if t14 < t <= t15: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) if t15 < t <= t15 + l_relax_days: policy_old = contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, school=0) policy_new = contact_matrix_4prev(t, prev_schools, prev_work, prev_rest, work=1, leisure=1, transport=1, others=1, school=0) return ramp_fun(policy_old, policy_new, t, t15, l_relax) elif t15 + l_relax_days < t <= t16: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, work=1, leisure=1, transport=1, others=1, school=0) elif t16 < t <= t17: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_rest, work=0.8, leisure=1, transport=0.90, others=1, school=0) else: return contact_matrix_4prev(t, prev_home, prev_schools, prev_work, prev_work, work=1, leisure=1, transport=1, others=1, school=1)