@@ -894,7 +894,6 @@ def get_npi_data(fine_resolution=2,
894
894
counties_considered = counties_considered )
895
895
save_interaction_matrix (df_counted_joint_codes , 'joint_codes' , directory )
896
896
plot_interaction_matrix ('joint_codes' , directory )
897
- plot_multiple_prescriptions ('joint_codes' , directory )
898
897
899
898
# create dataframe to count multiple codes after incidence dependent (de-)activation
900
899
df_incid_depend = pd .DataFrame ()
@@ -1320,7 +1319,10 @@ def save_interaction_matrix(df_interactions, filename, directory):
1320
1319
1321
1320
def plot_interaction_matrix (filename , directory ):
1322
1321
"""! Reads interaction matrices from hard drive and writes heatmap plots
1323
- to hard drive.
1322
+ to hard drive. Separates diagonal and offdiagonal entries as
1323
+ interactions inside one NPI are counted for all incidence dependent
1324
+ sublevels while between NPIs only one interaction is counted if more
1325
+ than one sublevel is mentioned on each of the sides.
1324
1326
1325
1327
@param[in] filename Filename to read results from.
1326
1328
@param[in] directory Directory where to read and save data.
@@ -1347,11 +1349,16 @@ def plot_interaction_matrix(filename, directory):
1347
1349
df = pd .read_excel (
1348
1350
os .path .join (directory , filename + '.xlsx' ),
1349
1351
sheet_name = code , engine = 'openpyxl' )
1350
- # set diag = 0, access (i,i+1) as first column contains index
1351
- for i in range (df .shape [0 ]):
1352
- df .iloc [i , i + 1 ] = 0
1352
+
1353
1353
# remove first column and convert to numpy array
1354
1354
array_exclusion = df .iloc [:, 1 :].to_numpy ()
1355
+
1356
+ # separate diag and offdiag
1357
+ array_exclusion_diag = copy .deepcopy (array_exclusion .diagonal ())
1358
+ # set diag = 0
1359
+ for i in range (array_exclusion .shape [0 ]):
1360
+ array_exclusion [i , i ] = 0
1361
+
1355
1362
if filename != 'count_deactivation' :
1356
1363
# for count deactivation xlabel != ylabel
1357
1364
# else matrix is of squared form and symmetric
@@ -1380,50 +1387,34 @@ def plot_interaction_matrix(filename, directory):
1380
1387
else :
1381
1388
raise gd .DataError ('Unknown filename: ' + filename )
1382
1389
1390
+ ## plot offdiagonal (interactions between NPIs)
1383
1391
# Set vmin = 1 so that only combinations that are simultaneously active
1384
1392
# at least on one day are in color, else use white.
1385
1393
# Set vmax = 1e6 to be adjusted with colormap, this value is larger
1386
1394
# than the maximum in all dataframes, this way colors of heatmaps are
1387
1395
# comparable across different visualizations
1388
1396
# (e.g. between codes or between joint_codes and exclusions)
1389
-
1390
1397
plt .imshow (array_exclusion , cmap = cmap ,
1391
1398
norm = mpl .colors .LogNorm (vmin = 1 , vmax = 1e6 ))
1392
1399
plt .colorbar ()
1393
1400
plt .tight_layout ()
1394
1401
plt .savefig (
1395
- os .path .join (target_directory , filename + '_{}' .format (
1402
+ os .path .join (target_directory , 'InterNPIs_' + filename + '_{}' .format (
1396
1403
code )), dpi = 300 )
1397
1404
plt .close ()
1398
1405
1399
-
1400
- def plot_multiple_prescriptions (filename , directory ):
1401
- target_directory = os .path .join (
1402
- directory , 'heatmaps_mult_presc_' + filename )
1403
- if not os .path .exists (target_directory ):
1404
- os .makedirs (target_directory )
1405
-
1406
- codelist = pd .ExcelFile (os .path .join (
1407
- directory , filename + '.xlsx' ), engine = 'openpyxl' ).sheet_names
1408
-
1409
- cmap = copy .copy (mpl .cm .get_cmap ('OrRd' ))
1410
-
1411
- for code in codelist :
1412
- df = pd .read_excel (
1413
- os .path .join (directory , filename + '.xlsx' ),
1414
- sheet_name = code , engine = 'openpyxl' )
1415
- array_exclusion = df .iloc [:, 1 :].to_numpy ()
1416
- fig = plt .figure ()
1406
+ ## plot diagonal (interactions between incidence levels of one NPIs)
1407
+ plt .figure ()
1417
1408
positions = [i for i in range (len (df .columns )- 1 )]
1418
1409
plt .yticks (positions , df .columns .to_list ()[1 :])
1419
1410
plt .xticks ([])
1420
- plt .imshow (np .array ([array_exclusion . diagonal () ]).T ,
1411
+ plt .imshow (np .array ([array_exclusion_diag ]).T ,
1421
1412
cmap = cmap , norm = mpl .colors .LogNorm (vmin = 1 , vmax = 50000 ))
1422
1413
plt .colorbar ()
1423
1414
plt .title (code )
1424
1415
plt .tight_layout ()
1425
1416
plt .savefig (
1426
- os .path .join (target_directory , filename + '_{}' .format (
1417
+ os .path .join (target_directory , 'IntraNPIs_' + filename + '_{}' .format (
1427
1418
code )), dpi = 300 )
1428
1419
plt .close ()
1429
1420
0 commit comments