Exemple #1
0
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
Exemple #2
0
def hour6flag(siminfo, dofirst=False):
    '''timeseries with 1 at 6am and earlier each day, and zero otherwise'''
    hours24 = zeros(24)
    hours24[0] = 1.0
    hours24[1] = 1.0
    hours24[2] = 1.0
    hours24[3] = 1.0
    hours24[4] = 1.0
    hours24[5] = 1.0
    return hoursval(siminfo, hours24, dofirst)
Exemple #3
0
def snow(store, 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

    ts['SVP'] = store['TIMESERIES/Saturated_Vapor_Pressure_Table'].to_numpy()
    ts['SEASONS'] = monthval(siminfo, store['TIMESERIES/SEASONS_Table'])

    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 every day of simulation
    ts['HR6FG'] = hourflag(siminfo, 6, 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'] = uci['FLAGS']['ICEFG'] if 'ICEFG' in uci['FLAGS'] else 0

    ui = make_numba_dict(
        uci)  # Note: all values coverted to float automatically
    ui['steps'] = steps
    ui['delt'] = siminfo['delt']
    ui['errlen'] = len(ERRMSGS)
    ui['cloudfg'] = cloudfg

    ############################################################################
    errors = _snow_(ui, ts)
    ############################################################################

    if siminfo['delt'] > 360 and int(siminfo['ICEFLG']):
        errors[0] += 1

    return errors, ERRMSGS
Exemple #4
0
def atemp(io_manager: SupportsReadTS, siminfo, uci, ts):
    ''' high level driver for air temperature module'''

    ts['LAPSE'] = hoursval(siminfo, LAPSE, lapselike=True)

    ui = make_numba_dict(
        uci)  # Note: all values coverted to float automatically
    ui['k'] = siminfo['delt'] * 0.000833  # convert to in/timestep
    ui['steps'] = siminfo['steps']
    ui['errlen'] = len(ERRMSGS)

    ############################################################################
    errors = _atemp_(ui, ts)  # run ATEMP_ simulation code
    ############################################################################

    return errors, ERRMSGS
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
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
Exemple #8
0
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