Adapted plots to correct expiration
This commit is contained in:
parent
98aba25bd0
commit
93a6913c8c
3 changed files with 89 additions and 58 deletions
|
|
@ -1097,7 +1097,7 @@ class ShortRangeModel:
|
||||||
# Verifies if the given time falls within a short range interaction
|
# Verifies if the given time falls within a short range interaction
|
||||||
if start < time <= finish:
|
if start < time <= finish:
|
||||||
dilution = self.dilutions[index]
|
dilution = self.dilutions[index]
|
||||||
jet_origin_concentration = concentration_model.infected.expiration.jet_origin_concentration()
|
jet_origin_concentration = self.expirations[index].jet_origin_concentration()
|
||||||
# Long range concentration normalized by the virus viral load
|
# Long range concentration normalized by the virus viral load
|
||||||
long_range_normed_concentration = concentration_model.concentration(time) / concentration_model.virus.viral_load_in_sputum
|
long_range_normed_concentration = concentration_model.concentration(time) / concentration_model.virus.viral_load_in_sputum
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,44 +39,44 @@ from cara.monte_carlo.data import symptomatic_vl_frequencies
|
||||||
# thickness = [2, 2])
|
# thickness = [2, 2])
|
||||||
|
|
||||||
# print('\n<<<<<<<<<<< Peak viral concentration with short range interactions for baseline scenarios >>>>>>>>>>>')
|
# print('\n<<<<<<<<<<< Peak viral concentration with short range interactions for baseline scenarios >>>>>>>>>>>')
|
||||||
# concentration_curve(models=[exposure_module_with_short_range(
|
concentration_curve(models=[exposure_module_with_short_range(
|
||||||
# activity='Light activity',
|
activity='Light activity',
|
||||||
# expiration={"Speaking": 1, "Breathing": 2},
|
expiration={"Speaking": 1, "Breathing": 2},
|
||||||
# mask='No mask',
|
mask='No mask',
|
||||||
# sr_presence=[(10.5, 11.0), (15.0, 16.0)],
|
sr_presence=[(10.5, 11.0)],
|
||||||
# sr_activities=['Breathing', 'Speaking']),
|
sr_activities=['Speaking']),
|
||||||
# exposure_module_without_short_range(
|
exposure_module_without_short_range(
|
||||||
# activity='Light activity',
|
activity='Light activity',
|
||||||
# expiration={"Speaking": 1, "Breathing": 2},
|
expiration={"Speaking": 1, "Breathing": 2},
|
||||||
# mask='No mask',)
|
mask='No mask',)
|
||||||
# ],
|
],
|
||||||
# labels = ['Concentration with short range interactions', 'Background (long-range) concentration'],
|
labels = ['Concentration with short range interactions', 'Background (long-range) concentration'],
|
||||||
# labelsDose = ['Dose (full)', 'Dose (long-range)'],
|
labelsDose = ['Dose (full)', 'Dose (long-range)'],
|
||||||
# colors = ['salmon', 'royalblue'],
|
colors = ['salmon', 'royalblue'],
|
||||||
# linestyles = ['-', '--'],
|
linestyles = ['-', '--'],
|
||||||
# thickness = [2, 2])
|
thickness = [2, 2])
|
||||||
|
|
||||||
|
|
||||||
print('\n<<<<<<<<<<< Dose vs SR exposure time >>>>>>>>>>>')
|
print('\n<<<<<<<<<<< Dose vs SR exposure time >>>>>>>>>>>')
|
||||||
#Always assume 1h for the short range interactions.
|
#Always assume 1h for the short range interactions.
|
||||||
#Always assume that in each model there is only ONE short range interaction.
|
#Always assume that in each model there is only ONE short range interaction.
|
||||||
plot_vD_vs_exposure_time(exp_models = [
|
# plot_vD_vs_exposure_time(exp_models = [
|
||||||
baseline_model(
|
# baseline_model(
|
||||||
activity='Light activity',
|
# activity='Light activity',
|
||||||
expiration={"Speaking": 2, "Breathing": 1},
|
# expiration={"Speaking": 2, "Breathing": 1},
|
||||||
mask='No mask',
|
# mask='No mask',
|
||||||
sr_presence=[(8.5, 9.5)],
|
# sr_presence=[(8.5, 9.5)],
|
||||||
sr_activities=['Breathing']),
|
# sr_activities=['Breathing']),
|
||||||
baseline_model(
|
# baseline_model(
|
||||||
activity='Light activity',
|
# activity='Light activity',
|
||||||
expiration={"Speaking": 2, "Breathing": 1},
|
# expiration={"Speaking": 2, "Breathing": 1},
|
||||||
mask='No mask',
|
# mask='No mask',
|
||||||
sr_presence=[(8.5, 9.5)],
|
# sr_presence=[(8.5, 9.5)],
|
||||||
sr_activities=['Speaking'])],
|
# sr_activities=['Speaking'])],
|
||||||
labels = ['Breathing', 'Speaking'],
|
# labels = ['Breathing', 'Speaking'],
|
||||||
colors=['royalblue', 'darkviolet'],
|
# colors=['royalblue', 'darkviolet'],
|
||||||
linestyles=['solid', 'solid'],
|
# linestyles=['solid', 'solid'],
|
||||||
points=20,
|
# points=20,
|
||||||
time_in_minutes=True,
|
# time_in_minutes=True,
|
||||||
normalize_y_axis=True)
|
# normalize_y_axis=True)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ Date: 18/02/2021
|
||||||
Code version: 4.0.0
|
Code version: 4.0.0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from cara.monte_carlo.data import short_range_expiration_distributions, expiration_distributions, expiration_BLO_factors
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
from matplotlib.patches import Rectangle, Patch
|
from matplotlib.patches import Rectangle, Patch
|
||||||
from scipy.spatial import ConvexHull
|
from scipy.spatial import ConvexHull
|
||||||
|
|
@ -73,13 +74,23 @@ def concentration_curve(models, labels, labelsDose, colors, linestyles, thicknes
|
||||||
concentrations = [[np.mean(model.concentration(
|
concentrations = [[np.mean(model.concentration(
|
||||||
t)) for t in times] for model in tqdm(exp_models)]
|
t)) for t in times] for model in tqdm(exp_models)]
|
||||||
|
|
||||||
fig, ax = plt.subplots(figsize=(8,6))
|
fig, (ax, ax2) = plt.subplots(2, 1, sharex=True, figsize=(8,6))
|
||||||
|
|
||||||
for c, color, linestyle, width in zip(concentrations, colors, linestyles, thickness):
|
for c, color, linestyle, width in zip(concentrations, colors, linestyles, thickness):
|
||||||
ax.plot(times, c, color=color, ls=linestyle, lw=width)
|
ax.plot(times, c, color=color, ls=linestyle, lw=width)
|
||||||
|
ax2.plot(times, c, color=color, ls=linestyle, lw=width)
|
||||||
|
|
||||||
|
# zoom-in / limit the view to different portions of the data
|
||||||
|
ax.set_ylim(ax.get_ylim()[1]*0.8, ax.get_ylim()[1]) # outliers only
|
||||||
|
ax2.set_ylim(0, max(concentrations[1])) # most of the data
|
||||||
|
|
||||||
|
ax.spines['bottom'].set_visible(False)
|
||||||
|
ax2.spines['top'].set_visible(False)
|
||||||
|
ax.xaxis.tick_top()
|
||||||
|
ax.tick_params(labeltop=False) # don't put tick labels at the top
|
||||||
|
ax2.xaxis.tick_bottom()
|
||||||
#ax.set_ylim(ax.get_ylim()[0], ax.get_ylim()[1] * 1.2)
|
#ax.set_ylim(ax.get_ylim()[0], ax.get_ylim()[1] * 1.2)
|
||||||
ax.set_ylim(ax.get_ylim()[0], 90)
|
# ax.set_ylim(ax.get_ylim()[0], 90)
|
||||||
ax.spines["right"].set_visible(False)
|
ax.spines["right"].set_visible(False)
|
||||||
|
|
||||||
cumulative_doses = [np.cumsum([
|
cumulative_doses = [np.cumsum([
|
||||||
|
|
@ -88,26 +99,35 @@ def concentration_curve(models, labels, labelsDose, colors, linestyles, thicknes
|
||||||
for time1, time2 in tqdm(zip(times[:-1], times[1:]))
|
for time1, time2 in tqdm(zip(times[:-1], times[1:]))
|
||||||
]) for model in exp_models]
|
]) for model in exp_models]
|
||||||
|
|
||||||
quantile_05 = [np.cumsum([
|
# quantile_05 = [np.cumsum([
|
||||||
np.quantile(np.array(model.deposited_exposure_between_bounds(
|
# np.quantile(np.array(model.deposited_exposure_between_bounds(
|
||||||
float(time1), float(time2))), 0.05)
|
# float(time1), float(time2))), 0.05)
|
||||||
for time1, time2 in tqdm(zip(times[:-1], times[1:]))
|
# for time1, time2 in tqdm(zip(times[:-1], times[1:]))
|
||||||
]) for model in exp_models]
|
# ]) for model in exp_models]
|
||||||
|
|
||||||
quantile_95 = [np.cumsum([
|
# quantile_95 = [np.cumsum([
|
||||||
np.quantile(np.array(model.deposited_exposure_between_bounds(
|
# np.quantile(np.array(model.deposited_exposure_between_bounds(
|
||||||
float(time1), float(time2))), 0.95)
|
# float(time1), float(time2))), 0.95)
|
||||||
for time1, time2 in tqdm(zip(times[:-1], times[1:]))
|
# for time1, time2 in tqdm(zip(times[:-1], times[1:]))
|
||||||
]) for model in exp_models]
|
# ]) for model in exp_models]
|
||||||
|
|
||||||
plt.xlabel("Time of day", fontsize=14)
|
plt.xlabel("Time of day", fontsize=14)
|
||||||
plt.ylabel("Mean concentration\n(virions m$^{-3}$)", fontsize=14)
|
plt.ylabel("Mean concentration\n(virions m$^{-3}$)", fontsize=14)
|
||||||
|
|
||||||
ax1 = ax.twinx()
|
ax1 = ax.twinx()
|
||||||
|
ax11 = ax2.twinx()
|
||||||
for vd, color, width in tqdm(zip(cumulative_doses, colors, thickness)):
|
for vd, color, width in tqdm(zip(cumulative_doses, colors, thickness)):
|
||||||
ax1.plot(times[:-1], vd,
|
ax1.plot(times[:-1], vd,
|
||||||
color=color, linestyle='dotted', lw=1)
|
color=color, linestyle='dotted', lw=1)
|
||||||
|
ax11.plot(times[:-1], vd,
|
||||||
|
color=color, linestyle='dotted', lw=1)
|
||||||
ax1.scatter([times[-1]], [vd[-1]], marker='.', color=color)
|
ax1.scatter([times[-1]], [vd[-1]], marker='.', color=color)
|
||||||
|
ax11.scatter([times[-1]], [vd[-1]], marker='.', color=color)
|
||||||
|
|
||||||
|
# zoom-in / limit the view to different portions of the data
|
||||||
|
ax1.set_ylim(ax1.get_ylim()[1]*0.8, ax1.get_ylim()[1]) # outliers only
|
||||||
|
ax11.set_ylim(0, max(cumulative_doses[1])) # most of the data
|
||||||
|
ax11.spines["bottom"].set_visible(False)
|
||||||
|
|
||||||
# # Plot presence of exposed person
|
# # Plot presence of exposed person
|
||||||
# for i, model in enumerate(models):
|
# for i, model in enumerate(models):
|
||||||
|
|
@ -129,10 +149,10 @@ def concentration_curve(models, labels, labelsDose, colors, linestyles, thicknes
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
|
||||||
ax1.spines["right"].set_linestyle((0, (1, 5)))
|
# ax1.spines["right"].set_linestyle((0, (1, 5)))
|
||||||
ax1.set_ylabel('Mean cumulative dose\n(infectious virus)', fontsize=14)
|
# ax1.set_ylabel('Mean cumulative dose\n(infectious virus)', fontsize=14)
|
||||||
#ax1.set_ylim(ax1.get_ylim()[0], ax1.get_ylim()[1] * 1.3)
|
#ax1.set_ylim(ax1.get_ylim()[0], ax1.get_ylim()[1] * 1.3)
|
||||||
ax1.set_ylim(ax1.get_ylim()[0], 40)
|
# ax1.set_ylim(ax1.get_ylim()[0], 40)
|
||||||
|
|
||||||
complete_labels = labels + [label for label in labelsDose]
|
complete_labels = labels + [label for label in labelsDose]
|
||||||
complete_colors = colors + [color for color in colors]
|
complete_colors = colors + [color for color in colors]
|
||||||
|
|
@ -141,14 +161,25 @@ def concentration_curve(models, labels, labelsDose, colors, linestyles, thicknes
|
||||||
labels_legend = [mlines.Line2D([], [], color=color, label=label, linestyle=linestyle)
|
labels_legend = [mlines.Line2D([], [], color=color, label=label, linestyle=linestyle)
|
||||||
for color, label, linestyle in zip(complete_colors, complete_labels, complete_linestyles)]
|
for color, label, linestyle in zip(complete_colors, complete_labels, complete_linestyles)]
|
||||||
|
|
||||||
for i in range(len(models)):
|
# for i in range(len(models)):
|
||||||
print('Scenario: ', labels[i])
|
# print('Scenario: ', labels[i])
|
||||||
print(
|
# print(
|
||||||
f"MEAN vD = {cumulative_doses[i][-1]}\n"
|
# f"MEAN vD = {cumulative_doses[i][-1]}\n"
|
||||||
f"5th per = {quantile_05[i][-1]}\n"
|
# f"5th per = {quantile_05[i][-1]}\n"
|
||||||
f"95th per = {quantile_95[i][-1]}\n")
|
# f"95th per = {quantile_95[i][-1]}\n")
|
||||||
|
|
||||||
plt.legend(handles=labels_legend, loc='upper left')
|
ax.legend(handles=labels_legend, loc='upper right')
|
||||||
|
|
||||||
|
d = .015 # how big to make the diagonal lines in axes coordinates
|
||||||
|
# arguments to pass to plot, just so we don't keep repeating them
|
||||||
|
kwargs = dict(transform=ax.transAxes, color='k', clip_on=False)
|
||||||
|
ax.plot((-d, +d), (-d, +d), **kwargs) # top-left diagonal
|
||||||
|
ax.plot((1 - d, 1 + d), (-d, +d), **kwargs) # top-right diagonal
|
||||||
|
|
||||||
|
kwargs.update(transform=ax2.transAxes) # switch to the bottom axes
|
||||||
|
ax2.plot((-d, +d), (1 - d, 1 + d), **kwargs) # bottom-left diagonal
|
||||||
|
ax2.plot((1 - d, 1 + d), (1 - d, 1 + d), **kwargs) # bottom-right diagonal
|
||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
def plot_vD_vs_exposure_time(exp_models: typing.List[mc.ExposureModel], labels, colors, linestyles, points: int = 20, time_in_minutes: bool = False, normalize_y_axis: bool = False) -> None:
|
def plot_vD_vs_exposure_time(exp_models: typing.List[mc.ExposureModel], labels, colors, linestyles, points: int = 20, time_in_minutes: bool = False, normalize_y_axis: bool = False) -> None:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue