<jupyter_start><jupyter_text>The other Notebook became a bit much, so I'll be working on visualisations in this Notebook, copying the main functions from `MR-analyse-proximus-mobility-data.ipynb`  Calculating baseline $P^{gh}$<jupyter_code>import datetime
# import pandas as pd
import numpy as np
import glob
%matplotlib notebook
import matplotlib.pyplot as plt
import sys
import datetime
# sys.path.insert(0, "../tools")
from covid19model.data.mobility import * # contains all necessary functions
from covid19model.visualization.output import *

# OPTIONAL: Load the "autoreload" extension so that package code can change
%load_ext autoreload
# OPTIONAL: always reload modules so that as you change code in src, it gets loaded
%autoreload 2

agg='prov'
start_date = datetime.datetime(2020, 1, 1, 0, 0)
end_date = datetime.datetime(2021, 9, 1, 0, 0)
start_calibration_wave1 = pd.Timestamp(2020, 3, 5, 0, 0)
end_calibration_wave1 = pd.Timestamp(2020, 8, 7, 0, 0)
start_calibration_wave2 = pd.Timestamp(2020, 9, 1, 0, 0)
end_calibration_wave2 = pd.Timestamp(2021, 2, 1, 0, 0)

fig, ax = plt.subplots(figsize=(9,3))
ax.grid(False)
ax.set_xlim(start_date, end_date)
ymin, ymax = (0, 1)
ax.set_ylim(ymin, ymax)
color_timeframes(start_date, end_date, ax=ax)
# ax.set_title('test', size=14)

# Add shading denoting calibration periods
arrows = False
if arrows:
    label_cal_size = 9
    label_cal_move_up = (ymax-ymin)*0.015
    arrow_height = ymax
    ax.annotate(s='', xy=(start_calibration_wave1,arrow_height), xytext=(end_calibration_wave1,arrow_height), \
                arrowprops=dict(arrowstyle='<->'))
    label_cal1_move_right = 44 # days
    ax.text(start_calibration_wave1 + pd.Timedelta(days=label_cal1_move_right), \
            ymax + label_cal_move_up, 'calibration wave 1', size=label_cal_size)

    ax.annotate(s='', xy=(start_calibration_wave2,arrow_height), xytext=(end_calibration_wave2,arrow_height), \
                arrowprops=dict(arrowstyle='<->'))
    label_cal2_move_right = 41 # days
    ax.text(start_calibration_wave2 + pd.Timedelta(days=label_cal2_move_right), \
            ymax + label_cal_move_up, 'calibration wave 2', size=label_cal_size)

ticklabelsize = 12
plt.setp(ax.get_xticklabels(), Fontsize=ticklabelsize)
plt.setp(ax.get_yticklabels(), Fontsize=ticklabelsize)

plt.xticks(rotation=20)
# First load the data and inspect the mobility for this date range

filename = 'fractional-mobility-matrix_staytime_' + agg + '_'
data_location = '../../data/interim/mobility/' + agg + '/fractional/'

dates_proximus=[]
dates_proximus_datetime=[]

# Define date range
# sdate_prelockdown = datetime(2020, 2, 10, 0, 0)   # start date
# edate_prelockdown = datetime(2020, 3, 15, 0, 0)   # end date
delta = end_date - start_date     # as timedelta

# Fill arrays with YYYYMMDD dates and datetime dates
for i in range(delta.days + 1):
    day = start_date + datetime.timedelta(days=i)
    dates_proximus_datetime.append(day)
    dates_proximus.append(date_to_YYYYMMDD(day))
    
# Load dictionary with YYYYMMDD dates as keys and P-matrices as values
mmprox, missing_dates = load_Pmatrix_staytime(dates_proximus, data_location, \
                                        complete=False, verbose=True, return_missing=True, agg=agg)

# date array for xaxis (takes care of missing dates: needs same number of elements in array!)
dates_proximus_xaxis = dates_proximus_datetime.copy()
for d in missing_dates:
    dates_proximus_xaxis.remove(date_to_YYYYMMDD(d, inverse=True))
NIS_from = 21000
NIS_to = 10000
fractions = []
for key in mmprox:
    fractions.append(mmprox[key].loc[str(NIS_from), str(NIS_to)])
    
ax.plot(np.array(dates_proximus_xaxis)+datetime.timedelta(days=0.5), 100*np.array(fractions), color='darkgreen', linewidth=1.5, label=f'{NIS_from} to {NIS_to}')
ax.set_ylabel('% time spent', size=ticklabelsize)
ax.legend(fontsize = ticklabelsize-2, loc='upper right')#, bbox_to_anchor=(0.27, 1))

plt.savefig(f'proximus_time-spent_{NIS_from}-to-{NIS_to}.png', dpi=400, bbox_inches='tight')<jupyter_output><empty_output><jupyter_text>**Add hospitalisations**<jupyter_code># Import Sciensano data
from covid19model.data.sciensano import get_sciensano_COVID19_data_spatial, get_sciensano_COVID19_data
# sciensano_df = get_sciensano_COVID19_data_spatial(agg='arr', values='hospitalised_IN', moving_avg=True).sum(axis=1)
sciensano_df = get_sciensano_COVID19_data(update=False)['H_in']
sciensano_values= sciensano_df.values
sciensano_dates = sciensano_df.index

ax2=ax.twinx()
ax2.grid(False)
ax2.plot(sciensano_dates, sciensano_values, linewidth=2, color='maroon', alpha=0.7, label='national')
ax2.set_ylabel('new daily hospitalisations', size=ticklabelsize)

# ax2.legend(fontsize = ticklabelsize-2, loc='upper right', bbox_to_anchor=(1, 0.90))

# plt.savefig(f'proximus_time-spent_{NIS_from}-to-{NIS_to}_with-hospitalisations.png', dpi=400, bbox_inches='tight')
get_sciensano_COVID19_data?<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11812297734627832, 'fraction_numerical': 0.032766990291262135, 'mean_word_length': 5.727891156462585, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '541365', 'license': 'MIT', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1799, 'n_words': 372, 'path': 'notebooks/scratch/MR-visualise_mobility-matrices-preprint.ipynb', 'repo_name': 'UGentBiomath/COVID19-Model', 'size': '4944'}