Skip to content

Commit c62ad92

Browse files
committed
Test validates that pseudobatch work when water evaporates
1 parent 90c3eda commit c62ad92

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

tests/test_integration.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
metabolised_amount,
1414
hypothetical_concentration,
1515
)
16-
from pseudobatch.datasets import load_standard_fedbatch, load_product_inhibited_fedbatch, load_cho_cell_like_fedbatch, load_volatile_compounds_fedbatch
16+
from pseudobatch.datasets import (
17+
load_standard_fedbatch,
18+
load_product_inhibited_fedbatch,
19+
load_cho_cell_like_fedbatch,
20+
load_volatile_compounds_fedbatch,
21+
load_evaporation_fedbatch,
22+
)
1723

1824

1925
def fit_ols_model(formula_like: str, data: pd.DataFrame) -> sm.regression.linear_model.RegressionResultsWrapper:
@@ -224,3 +230,49 @@ def test_calculation_of_gaseous_yield():
224230

225231
Yxco2_true = fedbatch_df.Yxo2.iloc[0]
226232
assert np.abs(res.params[1]) == pytest.approx(Yxco2_true, 1e-6)
233+
234+
235+
def test_pseudobatch_transformation_evaporation():
236+
"""Tests that the growth rate and substrate yields are correctly estimated
237+
pseudo batch transformed data. This test utilises all simulated data points
238+
"""
239+
# correct glucose data
240+
fedbatch_df = load_evaporation_fedbatch()
241+
fedbatch_df["corrected_glucose"] = pseudobatch_transform(
242+
measured_concentration=fedbatch_df["c_Glucose"].to_numpy(),
243+
reactor_volume=fedbatch_df["v_Volume"].to_numpy(),
244+
accumulated_feed=fedbatch_df["v_Feed_accum"].to_numpy(),
245+
concentration_in_feed=fedbatch_df.s_f.iloc[
246+
0
247+
], # the glucose concentration in the feed is stored in the dataframe
248+
sample_volume=fedbatch_df["sample_volume"].to_numpy(),
249+
)
250+
251+
# correct biomass data
252+
fedbatch_df["corrected_biomass"] = pseudobatch_transform(
253+
measured_concentration=fedbatch_df["c_Biomass"].to_numpy(),
254+
reactor_volume=fedbatch_df["v_Volume"].to_numpy(),
255+
accumulated_feed=fedbatch_df["v_Feed_accum"].to_numpy(),
256+
concentration_in_feed=0,
257+
sample_volume=fedbatch_df["sample_volume"].to_numpy(),
258+
)
259+
260+
## Calculate growth rate
261+
res_corrected = fit_ols_model(
262+
formula_like="np.log(corrected_biomass) ~ timestamp", data=fedbatch_df
263+
)
264+
mu_hat = res_corrected.params[1]
265+
266+
## Calculate glucose yield coefficient
267+
model_dat = fedbatch_df
268+
res_corrected = fit_ols_model(
269+
formula_like="corrected_glucose ~ corrected_biomass", data=model_dat
270+
)
271+
Yxs = np.abs(res_corrected.params[1]) # yields have to be positive
272+
273+
# True values
274+
mu_true = fedbatch_df.mu_true.iloc[0]
275+
Yxs_true = fedbatch_df.Yxs.iloc[0]
276+
277+
assert mu_hat == pytest.approx(mu_true, 1e-4)
278+
assert Yxs == pytest.approx(Yxs_true, 1e-6)

0 commit comments

Comments
 (0)