Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO Abstraction #68

Merged
merged 20 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion HSP2/ADCALC.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'''
ERRMSG = []

def adcalc(store, siminfo, uci, ts):
def adcalc(io_manager, siminfo, uci, ts):
'''Prepare to simulate advection of fully entrained constituents'''

errorsV = zeros(len(ERRMSG), dtype=int)
Expand Down
8 changes: 5 additions & 3 deletions HSP2/ATEMP.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

from numba import njit
from numpy import empty, zeros, int64
from HSP2.utilities import hoursval, make_numba_dict
from HSP2.utilities import hoursval, make_numba_dict, LAPSE

from HSP2IO.protocols import SupportsReadTS, Category

ERRMSGS = ()


def atemp(store, siminfo, uci, ts):
def atemp(io_manager:SupportsReadTS, siminfo, uci, ts):
''' high level driver for air temperature module'''

ts['LAPSE'] = hoursval(siminfo, store['TIMESERIES/LAPSE_Table'], lapselike=True)
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
Expand Down
2 changes: 1 addition & 1 deletion HSP2/CONS.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

ERRMSG = []

def cons(store, siminfo, uci, ts):
def cons(io_manager, siminfo, uci, ts):
''' Simulate behavior of conservative constituents; calculate concentration
of conservative constituents after advection'''

Expand Down
6 changes: 4 additions & 2 deletions HSP2/COPY.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pandas as pd
from typing import List, Dict

from HSP2IO.protocols import SupportsReadTS

class Copy():
"""
Partial implementation of the COPY module.
Expand All @@ -10,12 +12,12 @@ class Copy():
This functionality is not currently implemented, presently only loading from EXT SOURCES
"""

def __init__(self, store: pd.HDFStore, sim_info: Dict, ext_sources: List) -> None:
def __init__(self, io:SupportsReadTS, sim_info: Dict, ext_sources: List) -> None:
self._ts = {}
self._ts['MEAN'] = {}
self._ts['POINT'] = {}

ts = get_timeseries(store, ext_sources, sim_info)
ts = get_timeseries(io, ext_sources, sim_info)
for source in ext_sources:
themn = source.TMEMN
themsb = source.TMEMSB
Expand Down
5 changes: 1 addition & 4 deletions HSP2/GENER.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from numba import njit
import numpy as np
import pandas as pd
from typing import Dict, List

from HSP2.utilities import get_timeseries
from typing import Dict

class Gener():
"""
Expand Down
2 changes: 1 addition & 1 deletion HSP2/GQUAL.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'GQUAL: the value of sdfg is 1, but timeseries SSED4 is not available as input', #ERRMSG10
'GQUAL: the value of phytfg is 1, but timeseries PHYTO is not available as input') #ERRMSG11

def gqual(store, siminfo, uci, ts):
def gqual(io_manager, siminfo, uci, ts):
''' Simulate the behavior of a generalized quality constituent'''

errors = zeros(len(ERRMSGS)).astype(int64)
Expand Down
2 changes: 1 addition & 1 deletion HSP2/HTRCH.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

ERRMSGS =('HTRCH: Water temperature is above 66 C (150 F) -- In most cases, this indicates an instability in advection','') #ERRMSG0

def htrch(store, siminfo, uci, ts):
def htrch(io_manager, siminfo, uci, ts):
'''Simulate heat exchange and water temperature'''

advectData = uci['advectData']
Expand Down
5 changes: 3 additions & 2 deletions HSP2/HYDR.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
MAXLOOPS = 100 # newton method exit tolerance


def hydr(store, siminfo, uci, ts):
def hydr(io_manager, siminfo, uci, ts, ftables):
''' find the state of the reach/reservoir at the end of the time interval
and the outflows during the interval

Expand Down Expand Up @@ -95,7 +95,8 @@ def hydr(store, siminfo, uci, ts):
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']}"]
rchtab = ftables[f"{uci['PARAMETERS']['FTBUCI']}"]
#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
Expand Down
2 changes: 1 addition & 1 deletion HSP2/IQUAL.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

ERRMSGS =('IQUAL: A constituent must be associated with overland flow in order to receive atmospheric deposition inputs','') #ERRMSG0

def iqual(store, siminfo, uci, ts):
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'''

Expand Down
2 changes: 1 addition & 1 deletion HSP2/IWATER.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)


def iwater(store, siminfo, uci, ts):
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)
Expand Down
2 changes: 1 addition & 1 deletion HSP2/IWTGAS.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
PCFLX3 = IGCF1(3,LEV) * MFACTA
'''

def iwtgas(store, siminfo, uci, ts):
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'''

Expand Down
2 changes: 1 addition & 1 deletion HSP2/PQUAL.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
PFACTA = 1.0


def pqual(store, siminfo, uci, ts):
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'''

Expand Down
2 changes: 1 addition & 1 deletion HSP2/PSTEMP.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
MINTMP = -100
MAXTMP = 100

def pstemp(store, siminfo, uci, ts):
def pstemp(io_manager, siminfo, uci, ts):
'''Estimate soil temperatures in a pervious land segment'''
simlen = siminfo['steps']

Expand Down
2 changes: 1 addition & 1 deletion HSP2/PWATER.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'PWATER: High Water Table code not implemented', #ERRMSG9
)

def pwater(store, siminfo, uci, ts):
def pwater(io_manager, siminfo, uci, ts):
''' PERLND WATER module
CALL: pwater(store, general, ui, ts)
store is the Pandas/PyTable open store
Expand Down
2 changes: 1 addition & 1 deletion HSP2/PWTGAS.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
MFACTB = 0.


def pwtgas(store, siminfo, uci, ts):
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']
Expand Down
10 changes: 5 additions & 5 deletions HSP2/RQUAL.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
ERRMSGS_phcarb = ('PHCARB: Error -- Invalid CONS index specified for ALKCON (i.e., ALKCON > NCONS).',
'PHCARB: Error -- A satisfactory solution for pH has not been reached.')

def rqual(store, siminfo, uci, uci_oxrx, uci_nutrx, uci_plank, uci_phcarb, ts):
def rqual(io_manager, siminfo, uci, uci_oxrx, uci_nutrx, uci_plank, uci_phcarb, ts, monthdata):
''' Simulate constituents involved in biochemical transformations'''

# simulation information:
Expand Down Expand Up @@ -109,7 +109,7 @@ def rqual(store, siminfo, uci, uci_oxrx, uci_nutrx, uci_plank, uci_phcarb, ts):
NUADFX = zeros(simlen)

if nuadfg_dd > 0:
NUADFX = initmd(siminfo, store, 'MONTHDATA/MONTHDATA' + str(nuadfg_dd), 0.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)]
Expand All @@ -124,7 +124,7 @@ def rqual(store, siminfo, uci, uci_oxrx, uci_nutrx, uci_plank, uci_phcarb, ts):
NUADCN = zeros(simlen)

if nuadfg_wd > 0:
NUADCN = initmd(siminfo, store, 'MONTHDATA/MONTHDATA' + str(nuadfg_wd), 0.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)]
Expand Down Expand Up @@ -160,7 +160,7 @@ def rqual(store, siminfo, uci, uci_oxrx, uci_nutrx, uci_plank, uci_phcarb, ts):
pladfg_dd = int(ui_plank['PLADFG' + str(j)])

if pladfg_dd > 0:
PLADFX = initmd(siminfo, store, 'MONTHDATA/MONTHDATA' + str(pladfg_dd), 0.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)]
Expand All @@ -175,7 +175,7 @@ def rqual(store, siminfo, uci, uci_oxrx, uci_nutrx, uci_plank, uci_phcarb, ts):
pladfg_wd = int(ui_plank['PLADFG' + str(n+1)])

if pladfg_wd > 0:
PLADCN = initmd(siminfo, store, 'MONTHDATA/MONTHDATA' + str(pladfg_wd), 0.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)]
Expand Down
2 changes: 1 addition & 1 deletion HSP2/SEDMNT.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
PDETS= DETS*MFACTA # convert dimensional variables to external units
'''

def sedmnt(store, siminfo, uci, ts):
def sedmnt(io_manager, siminfo, uci, ts):
''' Produce and remove sediment from the land surface'''

simlen = siminfo['steps']
Expand Down
2 changes: 1 addition & 1 deletion HSP2/SEDTRN.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'SEDTRN: Simulation of sediment requires all 3 "auxiliary flags" (AUX1FG, etc) in section HYDR must be turned on', #ERRMSG5
'SEDTRN: When specifying the initial composition of the bed, the fraction of sand, silt, and clay must sum to a value close to 1.0.') #ERRMSG6

def sedtrn(store, siminfo, uci, ts):
def sedtrn(io_manager, siminfo, uci, ts):
''' Simulate behavior of inorganic sediment'''

# simlen = siminfo['steps']
Expand Down
10 changes: 6 additions & 4 deletions HSP2/SNOW.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
from numpy import zeros, ones, full, nan, int64
from math import sqrt, floor
from numba import njit
from HSP2.utilities import hourflag, monthval, hoursval, make_numba_dict, initm
from HSP2.utilities import hourflag, monthval, hoursval, make_numba_dict, initm, SEASONS, SVP

from HSP2IO.protocols import SupportsReadTS, Category

ERRMSGS = ('Snow simulation cannot function properly with delt> 360', #ERRMSG0
)


def snow(store, siminfo, uci, ts):
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
Expand All @@ -33,8 +35,8 @@ def snow(store, siminfo, uci, ts):
steps = siminfo['steps'] # number of simulation timesteps
UUNITS = siminfo['units']

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

cloudfg = 'CLOUD' in ts

Expand Down
2 changes: 1 addition & 1 deletion HSP2/SOLIDS.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ERRMSG = []


def solids(store, siminfo, uci, ts):
def solids(io_manager, siminfo, uci, ts):
'''Accumulate and remove solids from the impervious land segment'''

simlen = siminfo['steps']
Expand Down
Loading