This notebook is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
Why would we use drug
What value should I use for the plasma volume?
Do I need to do any unit conversions? If so, what should be converted and what are the new values?
sim_time = 8 # hours
delta_t = 0.01 # hours
sim_steps = int(sim_time / delta_t)
half_life = 3.2 # hours
plasma_volume = 3000 # milliliters
initial_aspirin_in_plasma = 2 * 325 * 1000 # micrograms
elimination_constant = -np.log(2) / half_life # inverse hours
mec = 150 # micrograms
mtc = 350 # micrograms
plasma_concentration = [[0, initial_aspirin_in_plasma / plasma_volume]]
Standard for
loop for unconstrained decay
aspirin_in_plasma = initial_aspirin_in_plasma
for step_index in range(1, sim_steps + 1):
elimination = elimination_constant * aspirin_in_plasma
aspirin_in_plasma += elimination * delta_t
plasma_concentration.append([step_index, aspirin_in_plasma / plasma_volume])
Don't forget to convert your results to a data frame!
How do I extract the "step" column and the "plasma" column from plasma_concentration
?
simulation_df = pd.DataFrame({
"step": ???,
"plasma": ???,
})
List comprehensions!
simulation_df = pd.DataFrame({
"step": [x[0] for x in plasma_concentration],
"plasma": [x[1] for x in plasma_concentration],
})
simulation_df["time"] = simulation_df["step"] * delta_t
fig, ax = plt.subplots(dpi=120) # Use dpi to change figure size in notebooks
ax.axhline(mec, color="k", linestyle="--") # Plots MEC minimum line
ax.axhline(mtc, color="k", linestyle="--") # Plots MTC maximum line
ax.plot(simulation_df["time"], simulation_df["plasma"].values, "-")
ax.text(7.5, mec + 10, "MEC")
ax.text(7.5, mtc - 20, "MTC")
ax.set_ylim(bottom=0)
ax.set_xlabel("time (hr)")
ax.set_ylabel(r"plasma concentration $(\mu{}g/\mathrm{mL})$");
Work on Exercise 7 in your textbook:
How should the one-dose aspirin example be adjusted to incorporate the weight of a male patient? About 65% to 70% of a male's body is liquid. Assume that 1 kilogram of body liquid has a volume of 1 Liter. Assume the patient has a mass of 90 kilograms (comparable to about 198 pounds).
You can discuss with the students near you.
This diagram comes from the "Extracellular fluid" article on Wikipedia, https://en.wikipedia.org/wiki/Extracellular_fluid. From this, we learn that about 7% of our body fluid consists of blood plasma.
The modifications based on our gathered information are contained in the constants body_mass
, body_fluid_volume
, and plasma_volume
.
sim_time = 8 # hours
delta_t = 0.01 # hours
sim_steps = int(sim_time / delta_t)
half_life = 3.2 # hours
body_mass = 90 # kilograms
body_fluid_volume = 0.70 * body_mass * 1000 # milliliters
plasma_volume = 0.07 * body_fluid_volume # milliliters
initial_aspirin_in_plasma = 2 * 325 * 1000 # micrograms
elimination_constant = -np.log(2) / half_life # inverse hours
mec = 150 # micrograms
mtc = 350 # micrograms
plasma_concentration = [[0, initial_aspirin_in_plasma / plasma_volume]]
This remains the same as last time.
aspirin_in_plasma = initial_aspirin_in_plasma
for step_index in range(1, sim_steps + 1):
elimination = elimination_constant * aspirin_in_plasma
aspirin_in_plasma += elimination * delta_t
plasma_concentration.append([step_index, aspirin_in_plasma / plasma_volume])
simulation_df = pd.DataFrame({
"step": [x[0] for x in plasma_concentration],
"plasma": [x[1] for x in plasma_concentration],
})
simulation_df["time"] = simulation_df["step"] * delta_t
fig, ax = plt.subplots(dpi=120) # Use dpi to change figure size in notebooks
ax.axhline(mec, color="k", linestyle="--") # Plots MEC minimum line
ax.axhline(mtc, color="k", linestyle="--") # Plots MTC maximum line
ax.plot(simulation_df["time"], simulation_df["plasma"].values, "-")
ax.text(7.5, mec + 10, "MEC")
ax.text(7.5, mtc - 20, "MTC")
ax.set_title("Aspirin model adjusted for 90 kilogram male")
ax.set_ylim(bottom=0)
ax.set_xlabel("time (hr)")
ax.set_ylabel(r"plasma concentration $(\mu{}g/\mathrm{mL})$");