def sedmnt(io_manager, siminfo, uci, ts): ''' Produce and remove sediment from the land surface''' simlen = siminfo['steps'] ui = make_numba_dict(uci) # Note: all values converted to float automatically ui['simlen'] = siminfo['steps'] ui['uunits'] = siminfo['units'] ui['delt'] = siminfo['delt'] ui['errlen'] = len(ERRMSG) u = uci['PARAMETERS'] if 'CRVFG' in u: ts['COVERI'] = initm(siminfo, uci, u['CRVFG'], 'MONTHLY_COVER', u['COVER']) else: ts['COVERI'] = full(simlen, u['COVER']) if 'VSIVFG' in u: ts['NVSI'] = initm(siminfo, uci, u['VSIVFG'], 'MONTHLY_NVSI', u['NVSI']) else: ts['NVSI'] = full(simlen, u['NVSI']) ts['DAYFG'] = hourflag(siminfo, 0, dofirst=True).astype(float64) ############################################################################ errors = _sedmnt_(ui, ts) # run SEDMNT simulation code ############################################################################ return errors, ERRMSG
def iwtgas(io_manager, siminfo, uci, ts): ''' Estimate water temperature, dissolved oxygen, and carbon dioxide in the outflows from a impervious land segment. calculate associated fluxes through exit gate''' simlen = siminfo['steps'] ui = make_numba_dict(uci) ui['simlen'] = siminfo['steps'] ui['uunits'] = siminfo['units'] ui['errlen'] = len(ERRMSG) u = uci['PARAMETERS'] if 'WTFVFG' in u: ts['AWTF'] = initm(siminfo, uci, u['WTFVFG'], 'MONTHLY_AWTF', u['AWTF']) ts['BWTF'] = initm(siminfo, uci, u['WTFVFG'], 'MONTHLY_BWTF', u['BWTF']) else: ts['AWTF'] = full(simlen, u['AWTF']) ts['BWTF'] = full(simlen, u['BWTF']) for name in ['AIRTMP', 'WYIELD', 'SURO', 'SURLI']: if name not in ts: ts[name] = zeros(simlen) ts['DAYFG'] = hourflag(siminfo, 0, dofirst=True).astype(float64) ############################################################################ errors = _iwtgas_(ui, ts) # run IWTGAS simulation code ############################################################################ return errors, ERRMSG
def pwtgas(io_manager, siminfo, uci, ts): ''' Estimate water temperature, dissolved oxygen, and carbon dioxide in the outflows from a pervious landsegment. calculate associated fluxes through exit gates''' simlen = siminfo['steps'] ui = make_numba_dict(uci) ui['simlen'] = siminfo['steps'] ui['uunits'] = siminfo['units'] ui['errlen'] = len(ERRMSG) u = uci['PARAMETERS'] if 'IDVFG' in u: ts['IDOXP'] = initm(siminfo, uci, u['IDVFG'], 'MONTHLY_IDOXP', u['IDOXP']) else: ts['IDOXP'] = full(simlen, u['IDOXP']) if 'ICVFG' in u: ts['ICO2P'] = initm(siminfo, uci, u['ICVFG'], 'MONTHLY_ICO2P', u['ICO2P']) else: ts['ICO2P'] = full(simlen, u['ICO2P']) if 'GDVFG' in u: ts['ADOXP'] = initm(siminfo, uci, u['GDVFG'], 'MONTHLY_ADOXP', u['ADOXP']) else: ts['ADOXP'] = full(simlen, u['ADOXP']) if 'GCVFG' in u: ts['ACO2P'] = initm(siminfo, uci, u['GCVFG'], 'MONTHLY_ACO2P', u['ACO2P']) else: ts['ACO2P'] = full(simlen, u['ACO2P']) ts['DAYFG'] = hourflag(siminfo, 0, dofirst=True).astype(float64) ############################################################################ errors = _pwtgas_(ui, ts) # run PWTGAS simulation code ############################################################################ return errors, ERRMSG
def iwater(io_manager, siminfo, uci, ts): ''' Driver for IMPLND IWATER code. CALL: iwater(store, general, ui, ts) store is the Pandas/PyTable open store general is a dictionary with simulation info (OP_SEQUENCE for example) ui is a dictionary with ILS specific HSPF UCI like data ts is a dictionary with ILS specific timeseries''' # WATIN, WATDIF, IMPS not saved since trival calculation from saved data # WATIN = SUPY + SURLI # WATDIF = WATIN - (SURO + IMPEV) # IMPS = RETS + SURS steps = siminfo['steps'] # number of simulation points # insure defined, but not usable - just in case for name in ('AIRTMP', 'PETINP', 'PREC', 'RAINF', 'SNOCOV', 'WYIELD'): if name not in ts: ts[name] = full(steps, nan, dtype=float64) # treat missing flows as zero flow for name in ['SURLI']: # RTLIFG = 1 requires this timeseries if name not in ts: ts[name] = zeros(steps, dtype=float64) # Replace fixed parameters in HSPF with timeseries for name in ['PETMAX', 'PETMIN']: if name not in ts: ts[name] = full(steps, uci['PARAMETERS'][name], dtype=float64) # process optional monthly arrays to return interpolated data or constant array u = uci['PARAMETERS'] if 'VRSFG' in u: ts['RETSC'] = initm(siminfo, uci, u['VRSFG'], 'MONTHLY_RETSC', u['RETSC']) ts['NSUR'] = initm(siminfo, uci, u['VNNFG'], 'MONTHLY_NSUR', u['NSUR']) else: ts['RETSC'] = full(steps, u['RETSC']) ts['NSUR'] = full(steps, u['NSUR']) # true the first time and at 1am every day of simulation ts['HR1FG'] = hourflag(siminfo, 1, dofirst=True).astype( float64) # numba Dict limitation # true the first time and at every hour of simulation ts['HRFG'] = hoursval(siminfo, ones(24), dofirst=True).astype( float64) # numba Dict limitation ui = make_numba_dict( uci) # Note: all values coverted to float automatically ui['steps'] = steps ui['delt'] = siminfo['delt'] ui['errlen'] = len(ERRMSGS) ui['uunits'] = siminfo['units'] ############################################################################ errors = _iwater_(ui, ts) # run IWATER simulation code ############################################################################ return errors, ERRMSGS
def solids(io_manager, siminfo, uci, ts): '''Accumulate and remove solids from the impervious land segment''' simlen = siminfo['steps'] for name in ['SURO', 'SURS', 'PREC', 'SLSLD']: if name not in ts: ts[name] = zeros(simlen) u = uci['PARAMETERS'] # process optional monthly arrays to return interpolated data or constant array if 'VASDFG' in u: ts['ACCSDP'] = initm(siminfo, uci, u['VASDFG'], 'MONTHLY_ACCSDP', u['ACCSDP']) else: ts['ACCSDP'] = full(simlen, u['ACCSDP']) if 'VRSDFG' in u: ts['REMSDP'] = initm(siminfo, uci, u['VRSDFG'], 'MONTHLY_REMSDP', u['REMSDP']) else: ts['REMSDP'] = full(simlen, u['REMSDP']) ui = make_numba_dict( uci) # Note: all values converted to float automatically ui['uunits'] = siminfo['units'] ui['simlen'] = siminfo['steps'] ui['delt60'] = siminfo[ 'delt'] / 60 # delt60 - simulation time interval in hours ui['errlen'] = len(ERRMSG) ts['DAYFG'] = hourflag(siminfo, 0, dofirst=True).astype(float64) ############################################################################ errors = _solids_(ui, ts) # run SOLIDS simulation code ############################################################################ return errors, ERRMSG
def pstemp(io_manager, siminfo, uci, ts): '''Estimate soil temperatures in a pervious land segment''' simlen = siminfo['steps'] ui = make_numba_dict(uci) ui['simlen'] = siminfo['steps'] ui['uunits'] = siminfo['units'] ui['delt'] = siminfo['delt'] ui['errlen'] = len(ERRMSG) u = uci['PARAMETERS'] if 'SLTVFG' in u: ts['ASLT'] = initm(siminfo, uci, u['SLTVFG'], 'MONTHLY_ASLT', u['ASLT']) ts['BSLT'] = initm(siminfo, uci, u['SLTVFG'], 'MONTHLY_BSLT', u['BSLT']) else: ts['ASLT'] = full(simlen, u['ASLT']) ts['BSLT'] = full(simlen, u['BSLT']) if 'ULTVFG' in u: ts['ULTP1'] = initm(siminfo, uci, u['ULTVFG'], 'MONTHLY_ULTP1', u['ULTP1']) ts['ULTP2'] = initm(siminfo, uci, u['ULTVFG'], 'MONTHLY_ULTP2', u['ULTP2']) else: ts['ULTP1'] = full(simlen, u['ULTP1']) ts['ULTP2'] = full(simlen, u['ULTP2']) if 'LGTVFG' in u: ts['LGTP1'] = initm(siminfo, uci, u['LGTVFG'], 'MONTHLY_LGTP1', u['LGTP1']) ts['LGTP2'] = initm(siminfo, uci, u['LGTVFG'], 'MONTHLY_LGTP2', u['LGTP2']) else: ts['LGTP1'] = full(simlen, u['LGTP1']) ts['LGTP2'] = full(simlen, u['LGTP2']) ts['HRFG'] = hoursval(siminfo, ones(24), dofirst=True).astype( float64) # numba Dict limitation ############################################################################ errors = _pstemp_(ui, ts) # run PSTEMP simulation code ############################################################################ return errors, ERRMSG
def rqual(io_manager, siminfo, uci, uci_oxrx, uci_nutrx, uci_plank, uci_phcarb, ts, monthdata): ''' Simulate constituents involved in biochemical transformations''' # simulation information: delt60 = siminfo['delt'] / 60 # delt60 - simulation time interval in hours simlen = siminfo['steps'] delts = siminfo['delt'] * 60 uunits = siminfo['units'] siminfo_ = Dict.empty(key_type=types.unicode_type, value_type=types.float64) for key in set(siminfo.keys()): value = siminfo[key] if type(value) in {int, float}: siminfo_[key] = float(value) # module flags: ui = make_numba_dict(uci) NUTFG = int(ui['NUTFG']) PLKFG = int(ui['PLKFG']) PHFG = int(ui['PHFG']) # create numba dictionaries (empty if not simulated): ui_oxrx = make_numba_dict(uci_oxrx) ui_oxrx['errlen'] = len(ERRMSGS_oxrx) ui_nutrx = Dict.empty(key_type=types.unicode_type, value_type=types.float64) if NUTFG == 1: ui_nutrx = make_numba_dict(uci_nutrx) ui_nutrx['errlen'] = len(ERRMSGS_nutrx) ui_plank = Dict.empty(key_type=types.unicode_type, value_type=types.float64) if PLKFG == 1: ui_plank = make_numba_dict(uci_plank) ui_plank['errlen'] = len(ERRMSGS_plank) ui_phcarb = Dict.empty(key_type=types.unicode_type, value_type=types.float64) if PHFG == 1: ui_phcarb = make_numba_dict(uci_phcarb) ui_phcarb['errlen'] = len(ERRMSGS_phcarb) # hydraulic results: advectData = uci['advectData'] (nexits, vol, VOL, SROVOL, EROVOL, SOVOL, EOVOL) = advectData ui['nexits'] = nexits ui['vol'] = vol ts['VOL'] = VOL ts['SROVOL'] = SROVOL ts['EROVOL'] = EROVOL for i in range(nexits): ts['SOVOL' + str(i + 1)] = SOVOL[:, i] ts['EOVOL' + str(i + 1)] = EOVOL[:, i] phval_init = 7. tamfg = 0 phflag = 2 if 'NH3FG' in ui_nutrx: tamfg = ui_nutrx['NH3FG'] if 'PHFLAG' in ui_nutrx: phflag = ui_nutrx['PHFLAG'] if tamfg == 1: if 'PHVAL' in ui_nutrx: phval_init = ui_nutrx['PHVAL'] if 'PHVAL' not in ts: ts['PHVAL'] = full(simlen, phval_init) if phflag == 3: ts['PHVAL'] = initm(siminfo, ui_nutrx, phflag, 'MONTHLY/PHVAL', phval_init) #--------------------------------------------------------------------- # input time series processing (atm. deposition, benthic inverts, etc.) #--------------------------------------------------------------------- # NUTRX atmospheric deposition - initialize time series: if NUTFG == 1: for j in range(1, 4): n = (2 * j) - 1 # dry deposition: nuadfg_dd = int(ui_nutrx['NUADFG' + str(n)]) NUADFX = zeros(simlen) if nuadfg_dd > 0: NUADFX = initmd(siminfo, monthdata, 'MONTHDATA/MONTHDATA' + str(nuadfg_dd), 0.0) elif nuadfg_dd == -1: if 'NUADFX' + str(j) in ts: NUADFX = ts['NUADFX' + str(j)] elif 'NUADFX' + str(j) + ' 1' in ts: NUADFX = ts['NUADFX' + str(j) + ' 1'] else: pass #ERRMSG? ts['NUADFX' + str(j)] = NUADFX # wet deposition: nuadfg_wd = int(ui_nutrx['NUADFG' + str(n + 1)]) NUADCN = zeros(simlen) if nuadfg_wd > 0: NUADCN = initmd(siminfo, monthdata, 'MONTHDATA/MONTHDATA' + str(nuadfg_wd), 0.0) elif nuadfg_wd == -1: if 'NUADCN' + str(j) in ts: NUADCN = ts['NUADCN' + str(j)] elif 'NUADCN' + str(j) + ' 1' in ts: NUADCN = ts['NUADCN' + str(j) + ' 1'] else: pass #ERRMSG? ts['NUADCN' + str(j)] = NUADCN if nuadfg_dd > 0: # convert units to internal if uunits == 1: # convert from lb/ac.day to mg.ft3/l.ft2.ivl if 'NUADFX' + str(j) in ts: ts['NUADFX' + str(j)] *= 0.3677 * delt60 / 24.0 else: # convert from kg/ha.day to mg.m3/l.m2.ivl if 'NUADFX' + str(j) in ts: ts['NUADFX' + str(j)] *= 0.1 * delt60 / 24.0 elif nuadfg_dd == -1: if uunits == 1: # convert from lb/ac.day to mg.ft3/l.ft2.ivl if 'NUADFX' + str(j) in ts: ts['NUADFX' + str(j)] *= 0.3677 else: # convert from kg/ha.day to mg.m3/l.m2.ivl if 'NUADFX' + str(j) in ts: ts['NUADFX' + str(j)] *= 0.1 if PLKFG == 1: # PLANK atmospheric deposition - initialize time series: for j in range(1, 4): n = (2 * j) - 1 # dry deposition: PLADFX = zeros(simlen) pladfg_dd = int(ui_plank['PLADFG' + str(j)]) if pladfg_dd > 0: PLADFX = initmd(siminfo, monthdata, 'MONTHDATA/MONTHDATA' + str(pladfg_dd), 0.0) elif pladfg_dd == -1: if 'PLADFX' + str(j) in ts: PLADFX = ts['PLADFX' + str(j)] elif 'PLADFX' + str(j) + ' 1' in ts: PLADFX = ts['PLADFX' + str(j) + ' 1'] else: pass #ERRMSG? ts['PLADFX' + str(j)] = PLADFX # wet deposition: PLADCN = zeros(simlen) pladfg_wd = int(ui_plank['PLADFG' + str(n + 1)]) if pladfg_wd > 0: PLADCN = initmd(siminfo, monthdata, 'MONTHDATA/MONTHDATA' + str(pladfg_wd), 0.0) elif pladfg_wd == -1: if 'PLADCN' + str(j) in ts: PLADCN = ts['PLADCN' + str(j)] elif 'PLADCN' + str(j) + ' 1' in ts: PLADCN = ts['PLADCN' + str(j) + ' 1'] else: pass #ERRMSG? ts['PLADCN' + str(j)] = PLADCN if pladfg_dd > 0: # convert units to internal if uunits == 1: # convert from lb/ac.day to mg.ft3/l.ft2.ivl if 'PLADFX' + str(j) in ts: ts['PLADFX' + str(j)] *= 0.3677 * delt60 / 24.0 else: # convert from kg/ha.day to mg.m3/l.m2.ivl if 'PLADFX' + str(j) in ts: ts['PLADFX' + str(j)] *= 0.1 * delt60 / 24.0 elif pladfg_dd == -1: if uunits == 1: # convert from lb/ac.day to mg.ft3/l.ft2.ivl if 'PLADFX' + str(j) in ts: ts['PLADFX' + str(j)] *= 0.3677 else: # convert from kg/ha.day to mg.m3/l.m2.ivl if 'PLADFX' + str(j) in ts: ts['PLADFX' + str(j)] *= 0.1 # PLANK - benthic invertebrates: balfg = 0 binv_init = 0.0 binvfg = 2 if 'BALFG' in ui_plank: balfg = ui_plank['BALFG'] if balfg == 2: # user has selected multiple species with more complex kinetics if 'BINV' in ui_plank: binv_init = ui_plank['BINV'] if 'BINVFG' in ui_plank: binvfg = ui_plank['BINVFG'] if 'BINV' not in ts: ts['BINV'] = full(simlen, binv_init) if balfg == 2 and binvfg == 3: ts['BINV'] = initm(siminfo, ui_plank, binvfg, 'MONTHLY/BINV', binv_init) #--------------------------------------------------------------------- # 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) # for multiple exits, modify save table as needed if nexits > 1: u = uci_oxrx['SAVE'] for i in range(nexits): u[f'OXCF2_{i + 1}1'] = u['OXCF2_11'] u[f'OXCF2_{i + 1}2'] = u['OXCF2_12'] u = uci_nutrx['SAVE'] for i in range(nexits): u[f'NUCF9_{i + 1}1'] = u['NUCF9_11'] u[f'NUCF9_{i + 1}2'] = u['NUCF9_12'] u[f'NUCF9_{i + 1}3'] = u['NUCF9_13'] u[f'NUCF9_{i + 1}4'] = u['NUCF9_14'] u[f'OSNH4_{i + 1}1'] = u['OSNH4_11'] u[f'OSNH4_{i + 1}2'] = u['OSNH4_12'] u[f'OSNH4_{i + 1}3'] = u['OSNH4_13'] u[f'OSNH4_{i + 1}4'] = u['OSNH4_14'] u[f'OSPO4_{i + 1}1'] = u['OSPO4_11'] u[f'OSPO4_{i + 1}2'] = u['OSPO4_12'] u[f'OSPO4_{i + 1}3'] = u['OSPO4_13'] u[f'OSPO4_{i + 1}4'] = u['OSPO4_14'] u = uci_plank['SAVE'] for i in range(nexits): u[f'PKCF2_{i + 1}1'] = u['PKCF2_11'] u[f'PKCF2_{i + 1}2'] = u['PKCF2_12'] u[f'PKCF2_{i + 1}3'] = u['PKCF2_13'] u[f'PKCF2_{i + 1}4'] = u['PKCF2_14'] u[f'PKCF2_{i + 1}5'] = u['PKCF2_15'] u[f'TPKCF2_{i + 1}1'] = u['TPKCF2_11'] u[f'TPKCF2_{i + 1}2'] = u['TPKCF2_12'] u[f'TPKCF2_{i + 1}3'] = u['TPKCF2_13'] u[f'TPKCF2_{i + 1}4'] = u['TPKCF2_14'] u[f'TPKCF2_{i + 1}5'] = u['TPKCF2_15'] u = uci_phcarb['SAVE'] for i in range(nexits): u[f'OTIC{i + 1}'] = u['OTIC1'] u[f'OCO2{i + 1}'] = u['OCO21'] return errors, ERRMSGS
def cons(io_manager, siminfo, uci, ts): ''' Simulate behavior of conservative constituents; calculate concentration of conservative constituents after advection''' errorsV = zeros(len(ERRMSG), dtype=int) simlen = siminfo['steps'] uunits = siminfo['units'] AFACT = 43560.0 if uunits == 2: # si units conversion constants, 1 hectare is 10000 sq m AFACT = 1000000.0 advectData = uci['advectData'] (nexits, vol, VOL, SROVOL, EROVOL, SOVOL, EOVOL) = advectData svol = vol * AFACT ts['VOL'] = VOL ts['SROVOL'] = SROVOL ts['EROVOL'] = EROVOL for i in range(nexits): ts['SOVOL' + str(i + 1)] = SOVOL[:, i] ts['EOVOL' + str(i + 1)] = EOVOL[:, i] ui = make_numba_dict(uci) nexits = int(ui['NEXITS']) ui['simlen'] = siminfo['steps'] ui['uunits'] = siminfo['units'] ui['svol'] = svol ui['delt60'] = siminfo[ 'delt'] / 60 # delt60 - simulation time interval in hours # vol = ui['VOL'] # conactive = ui['CONACTIVE'] # dict ncons = 1 if 'PARAMETERS' in uci: if 'NCONS' in uci['PARAMETERS']: ncons = uci['PARAMETERS']['NCONS'] for index in range(ncons): icon = str(index + 1) parms = uci['CONS' + icon] conid = parms['CONID'] # string name of the conservative constituent con = parms['CON'] # initial concentration of the conservative concid = parms[ 'CONCID'] # string which specifies the concentration units for the conservative constituent. ui['conv'] = parms[ 'CONV'] # conversion factor from QTYID/VOL to the desired concentration units qtyid = parms[ 'QTYID'] # string which specifies the units for inflow or outflow of constituent; e.g. kg name = 'CONS' + icon # arbitrary identification, default CONxx ui['icon'] = index + 1 ui['con'] = con # # dry deposition; flag: COADFG; monthly COAFXM; value: COADFX # COADFG1 = ui['COADFG1'] # table-type cons-ad-flags # COADFX = getit() # flag: COADFG; monthly COAFXM; value: COADFX # # wet deposition; flag: COADFG; monthly COACNM; value COADCN # COADFG2 = ui['COADFG2'] # table-type cons-ad-flags # COADCN = getit() # flag: COADFG; monthly COACNM; value COADCN if 'FLAGS' in uci: u = uci['FLAGS'] # get atmos dep timeseries coadfg1 = u['COADFG' + str((index * 2) - 1)] if coadfg1 > 0: ts['COADFX'] = initm(siminfo, uci, coadfg1, 'CONS' + str(index) + '_MONTHLY/COADFX', 0.0) elif coadfg1 == -1: ts['COADFX'] = ts['COADFX' + str(index)] coadfg2 = u['COADFG' + str(index * 2)] if coadfg2 > 0: ts['COADCN'] = initm(siminfo, uci, coadfg2, 'CONS' + str(index) + '_MONTHLY/COADCN', 0.0) elif coadfg2 == -1: ts['COADCN'] = ts['COADCN' + str(index)] if 'COADFX' not in ts: ts['COADFX'] = zeros(simlen) if 'COADCN' not in ts: ts['COADCN'] = zeros(simlen) ############################################################################ errors = _cons_(ui, ts) # run CONS simulation code ############################################################################ if nexits > 1: u = uci['SAVE'] key1 = name + '_OCON' for i in range(nexits): u[f'{key1}{i + 1}'] = u['OCON'] del u['OCON'] return errorsV, ERRMSG
def htrch(io_manager, siminfo, uci, ts): '''Simulate heat exchange and water temperature''' advectData = uci['advectData'] (nexits, vol, VOL, SROVOL, EROVOL, SOVOL, EOVOL) = advectData ts['VOL'] = VOL ts['SROVOL'] = SROVOL ts['EROVOL'] = EROVOL for i in range(nexits): ts['SOVOL' + str(i + 1)] = SOVOL[:, i] ts['EOVOL' + str(i + 1)] = EOVOL[:, i] simlen = siminfo['steps'] ts['DAYFG'] = hourflag(siminfo, 0, dofirst=True).astype(float64) ui = make_numba_dict(uci) nexits = int(ui['NEXITS']) ui['simlen'] = siminfo['steps'] ui['uunits'] = siminfo['units'] ui['delt'] = siminfo['delt'] ui['delt60'] = siminfo['delt'] / 60 ui['errlen'] = len(ERRMSGS) ui['vol'] = vol bedflg = 0 if 'BEDFLG' in ui: bedflg = ui['BEDFLG'] tgrnd = 59.0 if bedflg == 1 or bedflg == 2: tgrnd = ui['TGRND'] tstop = 55 if 'TSTOP' in ui: tstop = ui['TSTOP'] # even though delh and deltt are not ts, numba requires them to be passed as such if 'DELH' in ui: delh = ui['DELH'] else: delh = zeros(int(tstop)) ts['DELH'] = delh if 'DELTT' in ui: deltt = ui['DELTT'] else: deltt = zeros(int(tstop)) ts['DELTT'] = deltt u = uci['PARAMETERS'] # process optional monthly arrays to return interpolated data or constant array if 'TGFLG' in u: ts['TGRND'] = initm(siminfo, uci, u['TGFLG'], 'TGRND', tgrnd) else: ts['TGRND'] = full(simlen, tgrnd) ts['LAPSE'] = hoursval(siminfo, mlapse, lapselike=True) ############################################################################ errors = _htrch_(ui, ts) # run HTRCH simulation code ############################################################################ if nexits > 1: u = uci['SAVE'] key = 'OHEAT' for i in range(nexits): u[f'{key}{i + 1}'] = u[key] del u[key] return errors, ERRMSGS
def iqual(io_manager, siminfo, uci, ts): ''' Simulate washoff of quality constituents (other than solids, Heat, dox, and co2) using simple relationships with solids And/or water yield''' simlen = siminfo['steps'] nquals = 1 if 'PARAMETERS' in uci: if 'NQUAL' in uci['PARAMETERS']: nquals = uci['PARAMETERS']['NQUAL'] constituents = [] for index in range(nquals): iqual = str(index + 1) flags = uci['IQUAL' + iqual + '_FLAGS'] constituents.append(flags['QUALID']) ui = make_numba_dict(uci) ui['simlen'] = siminfo['steps'] ui['delt60'] = siminfo['delt'] / 60 # delt60 - simulation time interval in hours ui['nquals'] = nquals ui['errlen'] = len(ERRMSGS) # constituents = ui['CONSTITUENTS'] # (short) names of constituents if 'FLAGS' in uci: u = uci['FLAGS'] index = 0 for constituent in constituents: # simulate constituent index += 1 # update UI values for this constituent here! ui_flags = uci['IQUAL' + str(index) + '_FLAGS'] ui_parms = uci['IQUAL' + str(index) + '_PARAMETERS'] qualid = ui_flags['QUALID'] qtyid = ui_flags['QTYID'] QSDFG = ui_flags['QSDFG'] QSOFG = ui_flags['QSOFG'] VQOFG = ui_flags['VQOFG'] sqo = ui_parms['SQO'] wsqop = ui_parms['WSQOP'] ui['QSDFG' + str(index)] = QSDFG ui['QSOFG' + str(index)] = QSOFG ui['VQOFG' + str(index)] = VQOFG ui['sqo' + str(index)] = sqo ui['wsqop' + str(index)] = wsqop # handle monthly tables ts['POTFW' + str(index)] = initm(siminfo, uci, ui_flags['VPFWFG'], 'IQUAL' + str(index) + '_MONTHLY/POTFW', ui_parms['POTFW']) ts['ACQOP' + str(index)] = initm(siminfo, uci, ui_flags['VQOFG'], 'IQUAL' + str(index) + '_MONTHLY/ACQOP', ui_parms['ACQOP']) ts['SQOLIM' + str(index)] = initm(siminfo, uci, ui_flags['VQOFG'], 'IQUAL' + str(index) + '_MONTHLY/SQOLIM', ui_parms['SQOLIM']) iqadfgf = 0 iqadfgc = 0 ts['IQADFX' + str(index)] = zeros(simlen) ts['IQADCN' + str(index)] = zeros(simlen) if 'FLAGS' in uci: # get atmos dep timeseries iqadfgf = u['IQADFG' + str((index * 2) - 1)] if iqadfgf > 0: ts['IQADFX' + str(index)] = initm(siminfo, uci, iqadfgf, 'IQUAL' + str(index) + '_MONTHLY/IQADFX', 0.0) elif iqadfgf == -1: ts['IQADFX' + str(index)] = ts['IQADFX' + str(index) + ' 1'] iqadfgc = u['IQADFG' + str(index * 2)] if iqadfgc > 0: ts['IQADCN' + str(index)] = initm(siminfo, uci, iqadfgc, 'IQUAL' + str(index) + '_MONTHLY/IQADCN', 0.0) elif iqadfgc == -1: ts['IQADCN' + str(index)] = ts['IQADCN' + str(index) + ' 1'] ui['iqadfgf' + str(index)] = iqadfgf ui['iqadfgc' + str(index)] = iqadfgc for name in ['SLIQSX', 'SLIQO', 'SLIQSP']: if name not in ts: ts[name] = full(simlen, -1.0E30) ts['DAYFG'] = hourflag(siminfo, 0, dofirst=True).astype(float64) ############################################################################ errors = _iqual_(ui, ts) # run IQUAL simulation code ############################################################################ return errors, ERRMSGS
def snow(io_manager:SupportsReadTS, siminfo, uci, ts): ''' high level driver for SNOW module CALL: snow(store, general, ui, ts) store is the Pandas/PyTable open store siminfo is a dictionary with simulation level infor (OP_SEQUENCE for example) ui is a dictionary with segment specific HSPF UCI like data ts is a dictionary with segment specific timeseries''' steps = siminfo['steps'] # number of simulation timesteps UUNITS = siminfo['units'] ts['SVP'] = SVP ts['SEASONS'] = monthval(siminfo, SEASONS) cloudfg = 'CLOUD' in ts # insure defined, but can't be used accidently for name in ['AIRTMP', 'CLOUD', 'DTMPG', 'PREC', 'SOLRAD', 'WINMOV']: if name not in ts: ts[name] = full(steps, nan) # Replace fixed parameters in HSPF with time series for name in ['CCFACT','COVIND','MGMELT','MWATER','SHADE','SNOEVP','SNOWCF','KMELT']: if name not in ts and name in uci['PARAMETERS']: ts[name] = full(steps, uci['PARAMETERS'][name]) # true the first time and at 6am and earlier every day of simulation ts['HR6IND'] = hour6flag(siminfo, dofirst=True).astype(float) # true the first time and at every hour of simulation ts['HRFG'] = hoursval(siminfo, ones(24), dofirst=True).astype(float) # make ICEFG available to PWATER later. siminfo['ICEFG'] = 0 if 'FLAGS' in uci: if 'ICEFG' in uci['FLAGS']: siminfo['ICEFG'] = uci['FLAGS']['ICEFG'] ui = make_numba_dict(uci) # Note: all values coverted to float automatically ui['steps'] = steps ui['uunits'] = UUNITS ui['delt'] = siminfo['delt'] ui['errlen'] = len(ERRMSGS) ui['cloudfg'] = cloudfg u = uci['PARAMETERS'] vkmfg = 0 if 'FLAGS' in uci: uf = uci['FLAGS'] if 'VKMFG' in uf: vkmfg = uf['VKMFG'] ts['KMELT'] = initm(siminfo, uci, vkmfg, 'MONTHLY_KMELT', u['KMELT']) ############################################################################ errors = _snow_(ui, ts) ############################################################################ if siminfo['delt'] > 360 and int(siminfo['ICEFLG']): errors[0] += 1 return errors, ERRMSGS
def hydr(store, siminfo, uci, ts): ''' find the state of the reach/reservoir at the end of the time interval and the outflows during the interval CALL: hydr(store, general, ui, ts) store is the Pandas/PyTable open store general is a dictionary with simulation level infor (OP_SEQUENCE for example) ui is a dictionary with RID specific HSPF UCI like data ts is a dictionary with RID specific timeseries''' steps = siminfo['steps'] # number of simulation points nexits = int(uci['PARAMETERS']['NEXITS']) u = uci['PARAMETERS'] funct = array([u[name] for name in u.keys() if name.startswith('FUNCT')]).astype(int)[0:nexits] ODGTF = array([u[name] for name in u.keys() if name.startswith('ODGTF')]).astype(int)[0:nexits] ODFVF = array([u[name] for name in u.keys() if name.startswith('ODFVF')]).astype(int)[0:nexits] u = uci['STATES'] colin = array([u[name] for name in u.keys() if name.startswith('COLIN')]).astype(float)[0:nexits] outdg = array([u[name] for name in u.keys() if name.startswith('OUTDG')]).astype(float)[0:nexits] # COLIND timeseries might come in as COLIND, COLIND0, etc. otherwise UCI default names = list( sorted([n for n in ts if n.startswith('COLIND')], reverse=True)) df = DataFrame() for i, c in enumerate(ODFVF): df[i] = ts[names.pop()][0:steps] if c < 0 else full(steps, c) COLIND = df.to_numpy() # OUTDGT timeseries might come in as OUTDGT, OUTDGT0, etc. otherwise UCI default names = list(sorted([n for n in ts if n.startswith('OUTDG')], reverse=True)) df = DataFrame() for i, c in enumerate(ODGTF): df[i] = ts[names.pop()][0:steps] if c > 0 else zeros(steps) OUTDGT = df.to_numpy() # generic SAVE table doesn't know nexits for output flows and rates if nexits > 1: u = uci['SAVE'] for key in ('O', 'OVOL'): for i in range(nexits): u[f'{key}{i+1}'] = u[key] del u[key] # optional - defined, but can't used accidently for name in ('SOLRAD', 'CLOUD', 'DEWTEMP', 'GATMP', 'WIND'): if name not in ts: ts[name] = full(steps, nan) # optional timeseries for name in ('IVOL', 'POTEV', 'PREC'): if name not in ts: ts[name] = zeros(steps) ts['CONVF'] = initm(siminfo, uci, 'VCONFG', 'MONTHLY_CONVF', 1.0) # extract key columns of specified FTable for faster access (1d vs. 2d) rchtab = store[f"FTABLES/{uci['PARAMETERS']['FTBUCI']}"] ts['volumeFT'] = rchtab['Volume'].to_numpy() * VFACT ts['depthFT'] = rchtab['Depth'].to_numpy() ts['sareaFT'] = rchtab['Area'].to_numpy() * AFACT rchtab = rchtab.to_numpy() ui = make_numba_dict( uci) # Note: all values coverted to float automatically ui['steps'] = steps ui['delt'] = siminfo['delt'] ui['nexits'] = nexits ui['errlen'] = len(ERRMSGS) ui['nrows'] = rchtab.shape[0] ui['nodfv'] = any(ODFVF) # Numba can't do 'O' + str(i) stuff yet, so do it here. Also need new style lists Olabels = List() OVOLlabels = List() for i in range(nexits): Olabels.append(f'O{i+1}') OVOLlabels.append(f'OVOL{i+1}') ########################################################################### errors = _hydr_(ui, ts, COLIND, OUTDGT, rchtab, funct, Olabels, OVOLlabels) # run reaches simulation code ########################################################################### if 'O' in ts: del ts['O'] if 'OVOL' in ts: del ts['OVOL'] return errors, ERRMSGS
def pwater(io_manager, siminfo, uci, ts): ''' PERLND WATER module CALL: pwater(store, general, ui, ts) store is the Pandas/PyTable open store general is a dictionary with simulation level info (sim_start for example) ui is a dictionary with PLS specific HSPF UCI like data ts is a dictionary with PLS specific timeseries ''' steps = siminfo['steps'] # number of simulation points #if RTOPFG == 3 and 'SURTAB' in ui: # surtab = typeT(ui['SURTAB']) # FTable # missing flows are treated as zeros for name in ('AGWLI', 'IFWLI', 'LGTMP', 'LZLI', 'PETINP', 'PREC', 'SURLI', 'UZLI'): if name not in ts: ts[name] = zeros(steps) # insure defined, but not usable accidently for name in ('AIRTMP', 'PACKI', 'PETINP', 'PREC', 'RAINF', 'SNOCOV', 'WYIELD'): if name not in ts: ts[name] = full(steps, nan) # Replace fixed parameters with time series if not already present for name in ('AGWRC', 'DEEPFR', 'INFILT', 'KVARY', 'LZSN', 'PETMIN', 'PETMAX'): if name not in ts and name in uci['PARAMETERS']: ts[name] = full(steps, uci['PARAMETERS'][name]) # process optional monthly arrays to return interpolated data or constant array u = uci['PARAMETERS'] if 'VLEFG' in u: flag = (u['VLEFG'] == 1) or (u['VLEFG'] == 3) ts['LZETP'] = initm(siminfo, uci, flag, 'MONTHLY_LZETP', u['LZETP']) ts['CEPSC'] = initm(siminfo, uci, u['VCSFG'], 'MONTHLY_CEPSC', u['CEPSC']) ts['INTFW'] = initm(siminfo, uci, u['VIFWFG'], 'MONTHLY_INTFW', u['INTFW']) ts['IRC'] = initm(siminfo, uci, u['VIRCFG'], 'MONTHLY_IRC', u['IRC']) ts['NSUR'] = initm(siminfo, uci, u['VNNFG'], 'MONTHLY_NSUR', u['NSUR']) ts['UZSN'] = initm(siminfo, uci, u['VUZFG'], 'MONTHLY_UZSN', u['UZSN']) else: ts['LZETP'] = full(steps, u['LZETP']) ts['CEPSC'] = full(steps, u['CEPSC']) ts['INTFW'] = full(steps, u['INTFW']) ts['IRC'] = full(steps, u['IRC']) ts['NSUR'] = full(steps, u['NSUR']) ts['UZSN'] = full(steps, u['UZSN']) # true the first time and at start of every day of simulation ts['DAYFG'] = hourflag(siminfo, 0, dofirst=True).astype(float) # true the first time and at every hour of simulation ts['HRFG'] = hoursval(siminfo, ones(24), dofirst=True).astype(float) ui = make_numba_dict( uci) # Note: all values coverted to float automatically ui['steps'] = siminfo['steps'] ui['delt'] = siminfo['delt'] ui['errlen'] = len(ERRMSGS) ui['uunits'] = siminfo['units'] # kludge to make ICEFG available from SNOW to PWATER ui['ICEFG'] = siminfo['ICEFG'] if 'ICEFG' in siminfo else 0.0 CSNOFG = 0 if 'CSNOFG' in ui: CSNOFG = int(ui['CSNOFG']) # make CSNOFG available to other sections u['CSNOFG'] = CSNOFG ############################################################################ errors = _pwater_(ui, ts) # traditional HSPF HPERWAT ############################################################################ return errors, ERRMSGS
def pqual(io_manager, siminfo, uci, ts): ''' Simulate quality constituents (other than sediment, heat, dox, and co2) using simple relationships with sediment and water yield''' simlen = siminfo['steps'] nquals = 1 if 'PARAMETERS' in uci: if 'NQUAL' in uci['PARAMETERS']: nquals = uci['PARAMETERS']['NQUAL'] constituents = [] for index in range(nquals): pqual = str(index + 1) flags = uci['PQUAL' + pqual + '_FLAGS'] constituents.append(flags['QUALID']) ui = make_numba_dict(uci) ui['simlen'] = siminfo['steps'] ui['delt60'] = siminfo['delt'] / 60 # delt60 - simulation time interval in hours ui['nquals'] = nquals ui['errlen'] = len(ERRMSGS) # constituents = ui['CONSTITUENTS'] # (short) names of constituents if 'FLAGS' in uci: u = uci['FLAGS'] index = 0 for constituent in constituents: # simulate constituent index += 1 # update UI values for this constituent here! ui_flags = uci['PQUAL' + str(index) + '_FLAGS'] ui_parms = uci['PQUAL' + str(index) + '_PARAMETERS'] qualid = ui_flags['QUALID'] qtyid = ui_flags['QTYID'] QSDFG = ui_flags['QSDFG'] QSOFG = ui_flags['QSOFG'] QIFWFG = ui_flags['QIFWFG'] QAGWFG = ui_flags['QAGWFG'] sqo = ui_parms['SQO'] wsqop = ui_parms['WSQOP'] ui['QSDFG' + str(index)] = QSDFG ui['QSOFG' + str(index)] = QSOFG ui['QIFWFG' + str(index)] = QIFWFG ui['QAGWFG' + str(index)] = QAGWFG ui['SQO' + str(index)] = sqo ui['WSQOP' + str(index)] = wsqop ui['VIQCFG' + str(index)] = ui_flags['VIQCFG'] ui['VAQCFG' + str(index)] = ui_flags['VAQCFG'] ts['POTFW' + str(index)] = initm(siminfo, uci, ui_flags['VPFWFG'], 'PQUAL' + str(index) + '_MONTHLY/POTFW', ui_parms['POTFW']) ts['POTFS' + str(index)] = initm(siminfo, uci, ui_flags['VPFSFG'], 'PQUAL' + str(index) + '_MONTHLY/POTFS', ui_parms['POTFS']) ts['ACQOP' + str(index)] = initm(siminfo, uci, ui_flags['VQOFG'], 'PQUAL' + str(index) + '_MONTHLY/ACQOP', ui_parms['ACQOP']) ts['SQOLIM' + str(index)] = initm(siminfo, uci, ui_flags['VQOFG'], 'PQUAL' + str(index) + '_MONTHLY/SQOLIM', ui_parms['SQOLIM']) ts['IOQCP' + str(index)] = initm(siminfo, uci, ui_flags['VIQCFG'], 'PQUAL' + str(index) + '_MONTHLY/IOQC', ui_parms['IOQC']) ts['AOQCP' + str(index)] = initm(siminfo, uci, ui_flags['VAQCFG'], 'PQUAL' + str(index) + '_MONTHLY/AOQC', ui_parms['AOQC']) pqadfgf = 0 pqadfgc = 0 ts['PQADFX' + str(index)] = zeros(simlen) ts['PQADCN' + str(index)] = zeros(simlen) if 'FLAGS' in uci: # get atmos dep timeseries pqadfgf = u['PQADFG' + str((index * 2) - 1)] if pqadfgf > 0: ts['PQADFX' + str(index)] = initm(siminfo, uci, pqadfgf, 'PQUAL' + str(index) + '_MONTHLY/PQADFX', 0.0) elif pqadfgf == -1: ts['PQADFX' + str(index)] = ts['PQADFX' + str(index) + ' 1'] pqadfgc = u['PQADFG' + str(index * 2)] if pqadfgc > 0: ts['PQADCN' + str(index)] = initm(siminfo, uci, pqadfgc, 'PQUAL' + str(index) + '_MONTHLY/PQADCN', 0.0) elif pqadfgc == -1: ts['PQADCN' + str(index)] = ts['PQADCN' + str(index) + ' 1'] ui['pqadfgf' + str(index)] = pqadfgf ui['pqadfgc' + str(index)] = pqadfgc for name in ['SLIQSP', 'ILIQC', 'ALIQC']: if name not in ts: ts[name] = zeros(simlen) ts['DAYFG'] = hourflag(siminfo, 0, dofirst=True).astype(float64) for name in ['SURO', 'IFWO', 'AGWO', 'PERO', 'WSSD', 'SCRSD']: if name not in ts: ts[name] = zeros(simlen) ############################################################################ errors = _pqual_(ui, ts) # run PQUAL simulation code ############################################################################ return errors, ERRMSGS