-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
82 lines (74 loc) · 3.24 KB
/
Copy pathmodel.py
File metadata and controls
82 lines (74 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# --- Secondary Models from FSKX ---
def get_umax(temp, b, Tmin):
return (b * (temp - Tmin)) ** 2
def get_lag(temp, b, Tmin, alpha0):
log10 = np.log(10)
umax = get_umax(temp, b, Tmin)
return -np.log(alpha0) / (umax * log10)
def get_ymax(temp):
# Linear model for maximum population density from the paper:
# MPD(xmax, ln CFU/g) = 0.037T + 12.434
# Converting from ln to log10 by dividing by ln(10)
return (0.037 * temp + 12.434) / np.log(10)
# --- Primary Growth Model: Baranyi & Roberts (1994) ---
def listeria_growth_model(t, y0, ymax, umax, lag):
log10 = np.log(10)
term_exp1 = np.exp(-umax * log10 * t)
term_exp2 = np.exp(-umax * log10 * (t - lag))
log_part = np.log(1 - term_exp1 + term_exp2)
term1 = umax * (t - lag + (log_part / (umax * log10)))
growth_exponent = umax * log10 * (t - lag + (log_part / (umax * log10)))
numerator = np.exp(growth_exponent) - 1
denominator = 10 ** ((ymax - y0))
term2 = (1 / (log10)) * np.log(1 + (numerator / denominator))
Nt = y0 + term1 - term2
return Nt
# --- Embedded Experimental Data as DataFrames ---
# Updated with actual Listeria data from ComBase export
data = {
5: pd.DataFrame([
(0.0, 3.38), (24.0, 3.36), (48.0, 3.61), (72.0, 3.66),
(96.0, 4.21), (120.0, 4.50), (144.0, 4.36), (168.0, 4.66)
], columns=["Time", "LogCFU"]),
10: pd.DataFrame([
(0.0, 3.43), (24.0, 3.43), (48.0, 3.62), (54.0, 3.85),
(60.0, 4.12), (72.0, 4.64), (96.0, 4.81), (120.0, 4.81),
(144.0, 4.81), (168.0, 4.80)
], columns=["Time", "LogCFU"]),
15: pd.DataFrame([
(0.0, 3.37), (4.0, 3.32), (5.0, 3.36), (6.0, 3.33),
(7.0, 3.43), (8.0, 3.59), (9.0, 3.58), (10.0, 3.57),
(11.0, 3.66), (12.0, 3.62), (13.0, 3.58), (14.0, 3.77),
(15.0, 3.94), (16.0, 3.87), (17.0, 4.08), (18.0, 3.91),
(19.0, 4.39), (20.0, 4.20), (22.0, 4.34), (23.0, 4.42),
(24.0, 4.78), (25.0, 4.78), (36.0, 4.88)
], columns=["Time", "LogCFU"]),
20: pd.DataFrame([
(0.0, 3.48), (1.0, 3.17), (2.0, 3.39), (3.0, 3.38),
(4.0, 3.43), (5.0, 3.64), (6.0, 3.69), (7.0, 3.66),
(8.0, 4.02), (9.0, 4.03), (10.0, 4.08), (11.0, 4.29),
(12.0, 4.33), (13.0, 4.74), (14.0, 4.73), (15.0, 4.89),
(16.0, 5.13), (17.0, 5.12), (18.0, 5.13), (19.0, 5.22),
(23.0, 5.18), (28.0, 5.20), (36.0, 5.20)
], columns=["Time", "LogCFU"]),
25: pd.DataFrame([
(0.0, 3.56), (1.0, 3.20), (2.0, 3.30), (3.0, 3.55),
(4.0, 3.42), (5.0, 3.39), (6.0, 3.85), (7.0, 4.10),
(8.0, 4.32), (9.0, 4.38), (10.0, 4.44), (11.0, 4.82),
(12.0, 4.82), (13.0, 5.14), (14.0, 5.09), (15.0, 5.16),
(28.0, 5.18), (36.0, 5.20)
], columns=["Time", "LogCFU"])
}
# --- Simulation Function ---
def simulate_growth(temp_celsius, y0, tmax, b, Tmin, alpha0):
t = np.linspace(0, tmax, 100)
umax = get_umax(temp_celsius, b, Tmin)
lag = get_lag(temp_celsius, b, Tmin, alpha0)
ymax = get_ymax(temp_celsius)
model_values = listeria_growth_model(t, y0, ymax, umax, lag)
return t, model_values
# Run simulation with default parameters
# t, model_values = simulate_growth(temp_celsius, y0, tmax, b, Tmin, alpha0)