BioSTEAMDevelopmentGroup / BioSTEAMDevelopmentGroup/Bioindustrial-Park
Error Consultation on Fermentation Code.
- Dominant language
- Jupyter Notebook
- Stars
- 53
- Forks
- 27
- PR merge metrics
- No merged PRs in 30d
Description
I have been working on the Fermentation of Lactic Acid and tried to use the Fermentation code given in the Bioindustrial-Park/biorefineries. The code is as follows: -
import numpy as np
import pandas as pd
import biosteam as bst
from warnings import warn
from biosteam.utils import TicToc
from biorefineries.lactic import _load_system, SSCF_flowsheet, SSCF_funcs, SHF_flowsheet, SHF_funcs
from biorefineries.lactic._chemicals import sugars
from biorefineries.lactic.utils import set_yield
_load_system('SSCF')
_load_system('SHF')
#Initiate a timer
timer = TicToc('timer')
timer.tic()
run_number = 0
sugar_concs = [[], []]
lactics ={'target yield': [],
'target titer': [],
'actual yield': [],
'actual titer': []}
MPSPs = {0.89: [],
0.18: [],
1.92: []}
NPVs = {0.89: [],
0.18: [],
1.92: []}
GWPs = {0.89: [],
0.18: [],
1.92: []}
FECs = {0.89: [],
0.18: [],
1.92: []}
def compute_sugar_conc(stream):
return stream.imass[sugars].sum()/stream.F_vol
def solve_TEA(lactic_acid, lactic_tea):
lactic_acid.price = 0
for i in range(3):
MPSP = lactic_acid.price = lactic_tea.solve_price(lactic_acid)
return MPSP
def update_productivity(R301,R302,productivity):
R301.productivity = productivity
R302.productivity = productivity * R302.ferm_ratio
for unit in (R301, R302):
unit._design()
unit._cost()
def simulate_log_results(kind):
kind = kind.upper()
if 'SSCF' in kind:
flowsheet = SSCF_flowsheet
funcs = SHF_funcs
bst.main_flowsheet.set_flowsheet(flowsheet)
_load_system(kind)
R301 = flowsheet.unit.R301
R302 = flowsheet.unit.R302
lactic_acid = flowsheet.stream.lactic_acid
lactic_sys = flowsheet.system.lactic_sys
lactic_tea = lactic_sys.TEA
try:
lactic_sys.simulate()
for productivity in (0.89, 0.18, 1.92):
update_productivity(R301, R302, productivity)
MPSP = solve_TEA(lactic_acid, lactic_tea)
GWP = funcs['get_GWP']()
FEC = funcs['get_FEC']()
MPSPs[productivity].append(MPSP)
GWPs[productivity].append(GWP)
FECs[productivity].append(FEC)
NPVs[productivity].append(lactic_tea.NPV)
lactics['actual yield'].append(R301.lactic_yield)
lactics['actual titer'].append(R301.effluent_titer)
except:
warn(f'Simulation failed at target yield {round(R301.target_yield,2)},'\
f'target titer {R301.target_titer}.')
lactic_sys.empty_recycles()
lactic_sys.reset_cache()
lactics['actual yield'].append(np.nan)
lactics['actual titer'].append(np.nan)
for m in (MPSPs, NPVs, GWPs, FECs):
for n in m.keys():
m[n].append(np.nan)
global run_number
run_number += 1
print(f'Target yield is {round(R301.target_yield, 2)}, actual yield is {round(R301.cofermentation_rxns.X[0], 2)}; ' \
f'target titer is {R301.target_titer}, actual titer is {round(R301.effluent_titer)}.')
def save_data_clear():
df = pd.DataFrame({
('Lactic acid','Target Yield [g/g]'): lactics['target yield'],
('Lactic acid','Target Titer [g/L]'): lactics['target titer'],
('Lactic acid','Actual Yield [g/g]'): lactics['actual yield'],
('Lactic acid','Actual Titer [g/L]'): lactics['actual titer'],
('0.89 [g/L/hr]','MPSP [$/kg]'): MPSPs[0.89],
('0.89 [g/L/hr]','NPV [$]'): NPVs[0.89],
('0.89 [g/L/hr]', 'GWP [kg CO2-eq/kg]'): GWPs[0.89],
('0.89 [g/L/hr]', 'FEC [MJ/kg]'): FECs[0.89],
('0.18 [g/L/hr]', 'MPSP [$/kg]'): MPSPs[0.18],
('0.18 [g/L/hr]', 'NPV [$]'): NPVs[0.18],
('0.18 [g/L/hr]', 'GWP [kg CO2-eq/kg]'): GWPs[0.18],
('0.18 [g/L/hr]', 'FEC [MJ/kg]'): FECs[0.18],
('1.92 [g/L/hr]', 'MPSP [$/kg]'): MPSPs[1.92],
('1.92 [g/L/hr]', 'NPV [$]'): NPVs[1.92],
('1.92 [g/L/hr]', 'GWP [kg CO2-eq/kg]'): GWPs[1.92],
('1.92 [g/L/hr]', 'FEC [MJ/kg]'): FECs[1.92]
})
for i in (lactics, MPSPs, NPVs, GWPs, FECs):
for j in i.keys():
i[j] = []
return df
def run_TRY(yield_range, kind, mode, feed_freq, if_resistant, titer_range):
bst.speed_up()
if 'SSCF' in str(kind).upper():
flowsheet = SSCF_flowsheet
elif 'SHF' in str(kind).upper():
flowsheet = SHF_flowsheet
bst.main_flowsheet.set_flowsheet(flowsheet)
u = flowsheet.unit
R301 = u.R301
R302 = u.R302
R401 = u.R401
S402 = u.S402
R301.mode = mode
R301.feed_freq = feed_freq
R301.allow_dilution = True
if hasattr(R301, 'allow_concentration'):
R301.allow_concentration = True
R401.bypass = if_resistant
S402.bypass = if_resistant
for i in yield_range:
for j in titer_range:
lactics['target yield'].append(i)
lactics['target titer'].append(j)
R301.target_yield = i
R301.target_titer = j
set_yield(i,R301,R302)
simulate_log_results(kind)
if R301.effluent_titer + 2
_load_system('SSCF')
File "C:\Users\oshet\AppData\Local\Programs\Python\Python311\Lib\site-packages\biorefineries\lactic\__init__.py", line 76, in _load_system
bst.settings.set_thermo(_chemicals)
File "C:\Users\oshet\AppData\Local\Programs\Python\Python311\Lib\site-packages\thermosteam\_settings.py", line 137, in set_thermo
thermo = tmo.Thermo(thermo, mixture=mixture, cache=cache, skip_checks=skip_checks,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\oshet\AppData\Local\Programs\Python\Python311\Lib\site-packages\thermosteam\_thermo.py", line 139, in __init__
if not isinstance(chemicals, Chemicals): chemicals = Chemicals(chemicals, cache)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\oshet\AppData\Local\Programs\Python\Python311\Lib\site-packages\thermosteam\_chemicals.py", line 123, in __new__
chemicals = [i if isa(i, Chemical) else Chemical(i, cache=cache) for i in chemicals]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'module' object is not iterable
***
Unable to debug these errors.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.