Skip to content

Commit

Permalink
Merge branch 'beta' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
joyxyz1994 committed Oct 12, 2023
2 parents e71534c + eaeb620 commit dece5c5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
11 changes: 8 additions & 3 deletions qsdsan/_impact_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,12 @@ def get_item(cls, ID):
@classmethod
def _load_from_df(cls, name, df):
if name.lower() == 'info':
if 'kind' not in df.columns: df['kind'] = 'ImpactItem'
for num in df.index:
new = cls.__new__(cls)
kind = df.iloc[num].kind.lower()
if kind == 'streamimpactitem':
new = StreamImpactItem.__new__(StreamImpactItem)
else: new = cls.__new__(cls)
new.__init__(ID=df.iloc[num].ID,
functional_unit=df.iloc[num].functional_unit)
else:
Expand All @@ -409,8 +413,9 @@ def load_from_file(cls, path_or_dict, index_col=None):
This Excel should have multiple sheets:
- The "info" sheet should have two columns: "ID" (e.g., Cement) \
and "functional_unit" (e.g., kg) of different impact items.
- The "info" sheet should have three columns: "ID" (e.g., Cement) \
"functional_unit" (e.g., kg), and "kind" ("ImpactItem" or "StreamImpactItem")
of different impact items.
- The remaining sheets should contain characterization factors of \
impact indicators.
Expand Down
35 changes: 26 additions & 9 deletions qsdsan/_waste_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
_defined_composite_vars = ('COD', 'BOD5', 'BOD', 'uBOD', 'NOD', 'ThOD', 'cnBOD',
'C', 'N', 'P', 'K', 'Mg', 'Ca', 'solids', 'charge')

_common_composite_vars = ('_COD', '_BOD', '_uBOD', '_TC', '_TOC', '_TN',
_common_composite_vars = ('_COD', '_BOD', '_uBOD', '_ThOD', '_cnBOD',
'_TC', '_TOC', '_TN',
'_TKN', '_TP', '_TK', '_TMg', '_TCa',
'_dry_mass', '_charge', '_ThOD', '_cnBOD')
'_dry_mass', '_charge',)

_ws_specific_slots = (*_common_composite_vars,
'_pH', '_SAlk', '_ratios',
'_pH', '_SAlk', '_ratios', 'additional_properties',
# '_stream_impact_item', (pls keep this here, might be useful in debugging)
'_state', '_dstate', '_scope')

Expand Down Expand Up @@ -249,7 +250,9 @@ class WasteStream(SanStream):
TO BE IMPLEMENTED
stream_impact_item : :class:`StreamImpactItem`
The :class:`StreamImpactItem` this stream is linked to.
component_flows : kwargs
additional_properties : dict
Additional properties (e.g., turbidity).
component_flows : dict
Component flow data.
Expand All @@ -271,20 +274,28 @@ def __init__(self, ID='', flow=(), phase='l', T=298.15, P=101325.,
pH=7., SAlk=2.5, COD=None, BOD=None, uBOD=None,
ThOD=None, cnBOD=None,
TC=None, TOC=None, TN=None, TKN=None, TP=None, TK=None,
TMg=None, TCa=None, dry_mass=None, charge=None, ratios=None,
stream_impact_item=None, **component_flows):
TMg=None, TCa=None,
dry_mass=None, charge=None, ratios=None,
stream_impact_item=None, additional_properties={},
**component_flows):
SanStream.__init__(self=self, ID=ID, flow=flow, phase=phase, T=T, P=P,
units=units, price=price, thermo=thermo,
stream_impact_item=stream_impact_item, **component_flows)

self._init_ws(pH, SAlk, COD, BOD, uBOD, TC, TOC, TN, TKN,
TP, TK, TMg, TCa, ThOD, cnBOD, dry_mass, charge, ratios)
self._init_ws(pH=pH, SAlk=SAlk, COD=COD, BOD=BOD, uBOD=uBOD,
ThOD=ThOD, cnBOD=cnBOD,
TC=TC, TOC=TOC, TN=TN, TKN=TKN,
TP=TP, TK=TK, TMg=TMg, TCa=TCa,
dry_mass=dry_mass, charge=charge, ratios=ratios,
additional_properties=additional_properties,
)

def _init_ws(self, pH=7., SAlk=None, COD=None, BOD=None,
uBOD=None, ThOD=None, cnBOD=None,
TC=None, TOC=None, TN=None, TKN=None,
TP=None, TK=None, TMg=None, TCa=None,
dry_mass=None, charge=None, ratios=None):
dry_mass=None, charge=None, ratios=None,
additional_properties={}):

self._pH = pH
self._SAlk = SAlk
Expand All @@ -306,6 +317,7 @@ def _init_ws(self, pH=7., SAlk=None, COD=None, BOD=None,
self._ratios = ratios
self._state = None
self._dstate = None
self.additional_properties = {}

@staticmethod
def from_stream(stream, ID='', **kwargs):
Expand Down Expand Up @@ -2241,6 +2253,11 @@ def dry_mass(self):
def density(self):
'''[float] Density of the stream, in mg/L (kg/m3).'''
return 0.

@property
def additional_property(self):
'''[dict] Additional properties (e.g., turbidity).'''
return {}

#!!! Keep this up-to-date with WasteStream
# @property
Expand Down
10 changes: 5 additions & 5 deletions tests/test_exposan.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def test_exposan():
bsm1_sys.simulate(t_span=(0,10), method='BDF')
print(get_SRT(bsm1_sys, biomass_IDs=biomass_IDs)) # to test the `get_SRT` function

#!!! Will use bsm2 to test the junction models
# from exposan.interface import create_system as create_inter_system
# sys_inter = create_inter_system()
# sys_inter.simulate(method='BDF', t_span=(0, 3)) # the default 'RK45' method can't solve it

from exposan.cas import create_system as create_cas_system
cas_sys = create_cas_system()
cas_sys.simulate()

from exposan.interface import create_system as create_inter_system
sys_inter = create_inter_system()
#!!! Temporarily disable this test while trying to fix the issue
# sys_inter.simulate(method='BDF', t_span=(0, 3)) # the default 'RK45' method can't solve it

##### Systems with costs/impacts #####
from qsdsan.utils import clear_lca_registries

Expand Down

0 comments on commit dece5c5

Please sign in to comment.