<jupyter_start><jupyter_text>Load contact matrices from Wuhan and tailor it to the camp of interest<jupyter_code>import pandas as pd
import numpy as np
wuhan_matrix=pd.read_csv('Contact_matrix_wuhan.csv',index_col=0)
moria_params=pd.read_csv('moria_params.csv',index_col=0)
moria_params_pop=moria_params[moria_params['Variable'] == 'Population_structure']
moria_params_pop_value=moria_params_pop.Value.values
contact_matrix=wuhan_matrix.values
contact_matrix.shape
# we have 1-16 in 5 year bands

age_limits=np.array([0,10,20,30,40,50,60,70,80])
n_categories=len(age_limits)-1
ind_limits=(age_limits/5).astype(int)

p=[]
for cc in range(n_categories):
    for i in range(ind_limits[cc],ind_limits[cc+1]):
        p.append(moria_params_pop_value[cc]/(ind_limits[cc+1]-ind_limits[cc]))

M=np.zeros((n_categories,n_categories))

for rr in range(n_categories):
    for cc in range(n_categories):
        V2=0
        sump=sum(p[(ind_limits[cc]+1):ind_limits[cc+1] ])*sum(p[(ind_limits[rr]+1):ind_limits[rr+1]])
        for i in range(ind_limits[cc]+1,ind_limits[cc+1]):
            for j in range(ind_limits[rr]+1,ind_limits[rr+1]):
                    V2+=contact_matrix[j-1,i-1]*p[i-1]*p[j-1]/sump
        M[rr,cc] = V2


col_names=[]
for i in range(M.shape[0]):
    col_names.append('Age '+str(age_limits[i])+'-'+str(age_limits[i+1]))
moria_contact_dict={}
for col,index in zip(col_names,list(range(n_categories))):
    moria_contact_dict[col]=M[:,index]
moria_contact_matrix=pd.DataFrame.from_dict(moria_contact_dict)
moria_contact_matrix.to_csv('moria_contact_matrix.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15096693699313787, 'fraction_numerical': 0.028072364316905803, 'mean_word_length': 6.601895734597156, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '72559', 'license': 'MIT', 'n_tokens_mistral': 657, 'n_tokens_neox': 631, 'n_words': 85, 'path': 'Parameters/.ipynb_checkpoints/Prepare contact matrix-checkpoint.ipynb', 'repo_name': 'etioro/compartmental-model', 'size': '1603'}