Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e50efba
Address bugs in GQUAL and HTRCH
tredder75 Aug 5, 2021
7300202
Updates to original PLANK module
tredder75 Aug 5, 2021
e70d476
Classify OXRX + RQUAL updates
tredder75 Aug 5, 2021
3e1ede3
Customize main to handle revised RQUAL
tredder75 Aug 5, 2021
e215b68
Cumulative updates for 8/10/21
tredder75 Aug 10, 2021
70d7d30
Revisions based on testing of OXRX
tredder75 Aug 16, 2021
bae97ba
Address issue with initial reach outflow rates; implement unit conv. …
tredder75 Aug 16, 2021
d40fce3
GQUAL module - correct handling of metric units case
tredder75 Aug 16, 2021
2be4d96
GQUAL: address numba issues with OSEDx lists; simplify conversion calcs
tredder75 Aug 17, 2021
8636a6e
GQUAL - fix conflict / overwrite issue for "SSED4" time series
tredder75 Aug 23, 2021
f61daf2
HTRCH - restore njit decorator
tredder75 Aug 23, 2021
10bc67a
Nearly complete implementation of WQ classes and rqual wrapper
tredder75 Aug 23, 2021
03e0332
Update main and configuration for revised WQ implementation
tredder75 Aug 23, 2021
990dac0
Clean-up in OXRX, PLANK
tredder75 Aug 23, 2021
f0f642c
GQUAL - adjustments to address merge conflicts w/ Respec's develop br…
tredder75 Aug 25, 2021
7873f3e
Attempt to address errors generated by RQUAL jitclass implementation
tredder75 Aug 25, 2021
cf378fe
Merge pull request #40 from LimnoTech/develop
tredder75 Aug 25, 2021
3d14c79
GQUAL - address conditionals and simplify unit conversions for sed-as…
tredder75 Aug 26, 2021
d8a1fa2
RQUAL - successful numba compilation of all WQ modules
tredder75 Aug 31, 2021
c6f215d
RQUAL / WQ: updates to support WQ mass links and expanded output
tredder75 Sep 2, 2021
e8c60af
HTRCH: fix issue with (lack of) conversion to metric (tgrnd, tstop, m…
tredder75 Sep 2, 2021
89e647e
PLANK: fix bug related to benthic algae
tredder75 Sep 2, 2021
bbf8805
PLANK: fixed sloughing initialization issue
tredder75 Sep 2, 2021
b3b2435
Merge branch 'develop' into wq-updates-tmr
tredder75 Sep 2, 2021
5290431
main.py: force messaging for COPY/GENER ops
tredder75 Sep 7, 2021
005d468
PLANK: fix naming of CO2-related variables
tredder75 Sep 7, 2021
adf0500
RQUAL: configure njit function to wrap RQUAL class
tredder75 Sep 7, 2021
c78614e
GENER: corrections to time series referencing & naming
tredder75 Sep 8, 2021
e97c278
Merge branch 'develop' into wq-updates-tmr
tredder75 Sep 8, 2021
399e861
Gener Class - apply scale factors to timeseries read from Copy and Ge…
ptomasula Sep 8, 2021
8d8ad32
Merge branch 'develop' into wq-updates-tmr
tredder75 Sep 8, 2021
b9cff24
Merge branch 'wq-updates-tmr' into GENER-AdditionalTesting
ptomasula Sep 13, 2021
60e76ea
Try Except block for unsupported GENER features
ptomasula Sep 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HSP2/GENER.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def __init__(self, segment: str, copies: Dict, geners: Dict, ddlinks: Dict, ddge
if link.SVOL == 'COPY':
copy = copies[link.SVOLNO]
ts = copy.get_ts(link.SMEMN,link.SMEMSB1)
if link.MFACTOR != 1: ts *= link.MFACTOR
elif link.SVOL == 'GENER':
gener = geners[link.SVOLNO]
ts = gener.get_ts()
if link.MFACTOR != 1: ts *= link.MFACTOR
else:
raise NotImplementedError(f"Invalid SVOL. GENER module does not currently support reading TimeSeries for '{link.SVOL}'")

Expand Down
4 changes: 2 additions & 2 deletions HSP2/PLANK_Class.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def simulate(self, tw, phval, co2, tss, OXRX, NUTRX, iphyto, izoo, iorn, iorp, i
# sestonic algae growth & respiration
#-----------------------------------------------------------
if self.PHYFG == 1: # simulate phytoplankton, phyrx only called here
(po4,no3,tam,dox,self.orn,self.orp,self.orc,bod,self.phyto,self.limphy,self.co2,self.phycla,
(po4,no3,tam,dox,self.orn,self.orp,self.orc,bod,self.phyto,self.limphy,self.pyco2,self.phycla,
dophy,bodphy,tamphy,no3phy,po4phy,phdth,phgro,ornphy,orpphy,orcphy) \
= self.phyrx(self.phylit,tw,self.talgrl,self.talgrh,self.talgrm,self.malgr,self.cmmp, \
self.cmmnp,NUTRX.TAMFG,self.AMRFG,self.NSFG,self.cmmn,self.cmmlt,self.delt60, \
Expand All @@ -716,7 +716,7 @@ def simulate(self, tw, phval, co2, tss, OXRX, NUTRX, iphyto, izoo, iorn, iorp, i
# zooplankton growth & death:
#-----------------------------------------------------------
if self.ZOOFG == 1: # simulate zooplankton, zorx only called here
(dox,bod,self.zoo,self.orn,self.orp,self.orc,tam,no3,po4,zeat,zco2,dozoo,bodzoo,nitzoo,po4zoo,zgro,zdth,zorn,zorp,zorc) \
(dox,bod,self.zoo,self.orn,self.orp,self.orc,tam,no3,po4,zeat,self.zoco2,dozoo,bodzoo,nitzoo,po4zoo,zgro,zdth,zorn,zorp,zorc) \
= self.zorx(self.zfil20,self.tczfil,tw,self.phyto,self.mzoeat,self.zexdel,self.cvpb, \
self.zres20,self.tczres,NUTRX.anaer,self.zomass,NUTRX.TAMFG,self.refr, \
self.ZFOOD,self.zd,self.oxzd,self.cvbn,self.cvbp,self.cvbc,self.cvnrbo,self.cvbo, \
Expand Down
45 changes: 31 additions & 14 deletions HSP2/RQUAL.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
import numpy as np
from numpy import where, zeros, array, float64
from numba import types
from numba import types, njit
from numba.typed import Dict

from HSP2.utilities import make_numba_dict, initm
Expand All @@ -27,9 +27,6 @@
def rqual(store, siminfo, uci, uci_oxrx, uci_nutrx, uci_plank, uci_phcarb, ts):
''' Simulate constituents involved in biochemical transformations'''

#ERRMSGS =('')
#errors = zeros(len(ERRMSGS), dtype=np.int32)

# simulation information:
delt60 = siminfo['delt'] / 60 # delt60 - simulation time interval in hours
simlen = siminfo['steps']
Expand Down Expand Up @@ -157,22 +154,42 @@ def rqual(store, siminfo, uci, uci_oxrx, uci_nutrx, uci_plank, uci_phcarb, ts):
# initialize & run integerated WQ simulation:
#---------------------------------------------------------------------

(err_oxrx, err_nutrx, err_plank, err_phcarb) \
= _rqual_run(siminfo_, ui, ui_oxrx, ui_nutrx, ui_plank, ui_phcarb, ts)

#---------------------------------------------------------------------
# compile errors & return:
#---------------------------------------------------------------------

(errors, ERRMSGS) = _compile_errors(NUTFG, PLKFG, PHFG, err_oxrx, err_nutrx, err_plank, err_phcarb)

return errors, ERRMSGS


@njit(cache=True)
def _rqual_run(siminfo_, ui, ui_oxrx, ui_nutrx, ui_plank, ui_phcarb, ts):

# initialize WQ simulation:
RQUAL = RQUAL_Class(siminfo_, ui, ui_oxrx, ui_nutrx, ui_plank, ui_phcarb, ts)

# run WQ simulation:
RQUAL.simulate(ts)

#---------------------------------------------------------------------
# compile errors & return:
#---------------------------------------------------------------------
errlen_oxr = len(RQUAL.OXRX.errors)
# return error data:
#TO-DO! - return PHCARB errors once implemented
errors_PHCARB = zeros(2, dtype=np.int64)

return RQUAL.OXRX.errors, RQUAL.NUTRX.errors, RQUAL.PLANK.errors, errors_PHCARB

def _compile_errors(NUTFG, PLKFG, PHFG, err_oxrx, err_nutrx, err_plank, err_phcarb):

errlen_oxr = len(err_oxrx)
errlen_ntr = 0; errlen_plk = 0; errlen_phc = 0

if NUTFG == 1:
errlen_ntr = len(RQUAL.NUTRX.errors)
errlen_ntr = len(err_nutrx)
if PLKFG == 1:
errlen_plk += len(RQUAL.PLANK.errors)
errlen_plk += len(err_plank)
if PHFG == 1:
#errlen_phc += len(RQUAL.PHCARB.errors)
pass
Expand All @@ -185,22 +202,22 @@ def rqual(store, siminfo, uci, uci_oxrx, uci_nutrx, uci_plank, uci_phcarb, ts):
ierr = -1
for i in range(errlen_oxr):
ierr += 1
errors[ierr] = RQUAL.OXRX.errors[i]
errors[ierr] = err_oxrx[i]
ERRMSGS += (ERRMSGS_oxrx[i],)

for i in range(errlen_ntr):
ierr += 1
errors[ierr] = RQUAL.NUTRX.errors[i]
errors[ierr] = err_nutrx[i]
ERRMSGS += (ERRMSGS_nutrx[i],)

for i in range(errlen_plk):
ierr += 1
errors[ierr] = RQUAL.PLANK.errors[i]
errors[ierr] = err_plank[i]
ERRMSGS += (ERRMSGS_plank[i],)

for i in range(errlen_phc):
ierr += 1
errors[ierr] = RQUAL.PHCARB.errors[i]
errors[ierr] = err_phcarb[i]
ERRMSGS += (ERRMSGS_phcarb[i],)

return errors, ERRMSGS
Expand Down
19 changes: 13 additions & 6 deletions HSP2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ def main(hdfname, saveall=False, jupyterlab=True):
# main processing loop
msg(1, f'Simulation Start: {start}, Stop: {stop}')
for _, operation, segment, delt in opseq.itertuples():
msg(2, f'{operation} {segment} DELT(minutes): {delt}')

if operation == 'COPY':
copy_instances[segment] = activities[operation](store, siminfo, ddext_sources[(operation,segment)])
elif operation == 'GENER':
gener_instances[segment] = activities[operation](segment, copy_instances, gener_instances, ddlinks, ddgener)
try:
gener_instances[segment] = activities[operation](segment, copy_instances, gener_instances, ddlinks, ddgener)
except NotImplementedError as e:
print(f"GENER '{segment}' encountered unsupported feature during initialization and may not function correctly. Unsupported feature: '{e}'")
else:
msg(2, f'{operation} {segment} DELT(minutes): {delt}')
siminfo['delt'] = delt
siminfo['tindex'] = date_range(start, stop, freq=Minute(delt))[1:]
siminfo['steps'] = len(siminfo['tindex'])
Expand Down Expand Up @@ -239,7 +243,11 @@ def get_uci(store):
siminfo['units'] = int(temp['Units'])
elif module == 'LINKS':
for row in store[path].fillna('').itertuples():
ddlinks[f'{row.TVOLNO}{row.TOPFST}'].append(row)
if row.TVOLNO != '':
ddlinks[f'{row.TVOLNO}'].append(row)
else:
ddlinks[f'{row.TOPFST}'].append(row)

elif module == 'MASS_LINKS':
for row in store[path].replace('na','').itertuples():
ddmasslinks[row.MLNO].append(row)
Expand Down Expand Up @@ -418,9 +426,8 @@ def get_gener_timeseries(ts: Dict, gener_instances: Dict, ddlinks: List) -> Dict
if link.SVOL == 'GENER':
gener = gener_instances[link.SVOLNO]
series = gener.get_ts()
if link.MFACTOR != 1:
series *= link.MFACTOR
ts[f'{link.TMEMN}{link.TMEMSB1}{link.TMEMSB2}'] = series
ts[f'{link.TMEMN}{link.TMEMSB1} {link.TMEMSB2}'.rstrip()] = series

return ts


Expand Down