Fitting Bacteria Data!

Today, we fit the bacteria growth curve of the bacteria we measured on Wednesday 4/10. It was reasonable, though I wish we had more points at the beginning of the growth. It fluctuated wildly at first.

The blue points indicated the measured absorption level of laser light passing through the bacteria. The optimal was 600nm, we used 635nm because they are cheap and easy. The red line is our mathematical fit to the data.

  • As is typical of non-linear curve fitting, Python was unable to find a solution without an initial guess, so we provided it one through trial and error.
  • We fit the data to Euler solution to the differential equation given by:
  • gamma is the growth rate. beta is the density-dependent factor
  • We found gamma = 0.033 1/min, beta = -0.0077 1/minV, n0 = .45 V

Lots of exciting work could be done with this. But we are ending this here and moving on with this class, unless a student wants to do more with it.

The code for the fit is given by:

import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit

#Growth Data
time = np.array([25, 50, 70, 90, 110, 130, 150, 170, 190, 210, 230, 250, 270, 290, 310, 330])
volt = np.array([4.6, 3.2, 3.2, 2.8, 1.9, 0.65, 0.49, 0.5, 0.323, 0.37, 0.37, 0.38, 0.39, 0.38, 0.37, 0.25])

# Get Data into fittable form
time = time - time[0]
pop  = volt[0] - volt

# plot the Data
#plt.semilogy (time, pop, 'o')
plt.plot (time, pop, 'o')
plt.xlabel ('time (minutes)')
plt.ylabel ('population (voltage)')

#Create a function to solve the differential equation
# dN/dt = +GN - BN^2

def GetGrowthRateSolution (tt, gg, bb, n0):
    
    # Build population
    nn    = np.zeros(np.size(tt))
    nn[0] = n0
    dt    = tt[1] - tt[0]
    
    for ii in range(len(tt)-1):
        nn[ii+1]  = nn[ii] + dt * (gg * nn[ii]) + dt * (bb * (nn[ii])**2)

    return nn

#plt.plot (time, GetGrowthRateSolution (time, 0.005, -0.001, 1.0))
    
g0  = 0.005
b0  = -0.001
n0  = 1.0

guess = [g0, b0, n0]
popt, pcov = curve_fit(GetGrowthRateSolution, time, pop, guess)
print(popt)

plt.plot (time, GetGrowthRateSolution (time, popt[0], popt[1], popt[2]),'--r')

Leave a comment