Skip to content

Commit

Permalink
Merge pull request #88 from respec/develop
Browse files Browse the repository at this point in the history
Merge Develop into Master for release v0.10.1
  • Loading branch information
PaulDudaRESPEC authored Jun 28, 2022
2 parents 315c97b + 5ca8619 commit f9555f2
Show file tree
Hide file tree
Showing 9 changed files with 11,024 additions and 5,558 deletions.
5 changes: 5 additions & 0 deletions HSP2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def main(io_manager:IOManager, saveall:bool=False, jupyterlab:bool=True) -> None
if (activity in flags) and (not flags[activity]):
continue

if (activity == 'RQUAL') and (not flags['OXRX']) and (not flags['NUTRX']) and (not flags['PLANK']) and (not flags['PHCARB']):
continue

msg(3, f'{activity}')

ui = uci[(operation, activity, segment)] # ui is a dictionary
Expand Down Expand Up @@ -322,6 +325,8 @@ def get_flows(io_manager:SupportsReadTS, ts, flags, uci, segment, ddlinks, ddmas

if tmemn == 'ISED' or tmemn == 'ISQAL':
tmemn = tmemn + tmemsb1 # need to add sand, silt, clay subscript
if (sgrpn == 'HYDR' and smemn == 'OVOL') or (sgrpn == 'HTRCH' and smemn == 'OHEAT'):
smemsb2 = ''

smemn, tmemn = expand_timeseries_names(sgrpn, smemn, smemsb1, smemsb2, tmemn, tmemsb1, tmemsb2)

Expand Down
24 changes: 13 additions & 11 deletions HSP2/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,43 +286,45 @@ def get_timeseries(timeseries_inputs:SupportsReadTS, ext_sourcesdd, siminfo):
return ts

def save_timeseries(timeseries:SupportsWriteTS, ts, savedict, siminfo, saveall, operation, segment, activity, compress=True):
# save computed timeseries (at computation DELT)
save = {k for k,v in savedict.items() if v or saveall}
df = pd.DataFrame(index=siminfo['tindex'])
if (operation == 'IMPLND' and activity == 'IQUAL') or (operation == 'PERLND' and activity == 'PQUAL'):
for y in save:
for y in savedict.keys():
for z in set(ts.keys()):
if '/' + y in z:
zrep = z.replace('/','_')
zrep2 = zrep.replace(' ', '')
df[zrep2] = ts[z]
if '_' + y in z:
df[z] = ts[z]
df = df.astype(np.float32).sort_index(axis='columns')
elif (operation == 'RCHRES' and (activity == 'CONS' or activity == 'GQUAL')):
for y in save:
for y in savedict.keys():
for z in set(ts.keys()):
if '_' + y in z:
df[z] = ts[z]
for y in (save & set(ts.keys())):
for y in (savedict.keys() & set(ts.keys())):
df[y] = ts[y]
df = df.astype(np.float32).sort_index(axis='columns')
else:
for y in (save & set(ts.keys())):
for y in (savedict.keys() & set(ts.keys())):
df[y] = ts[y]
df = df.astype(np.float32).sort_index(axis='columns')
path = f'RESULTS/{operation}_{segment}/{activity}'
df = df.astype(np.float32).sort_index(axis='columns')

if saveall:
save_columns = df.columns
else:
save_columns = [key for key,value in savedict.items() if value or saveall]

if not df.empty:
timeseries.write_ts(
data_frame=df,
save_columns=save_columns,
category = Category.RESULTS,
operation=operation,
segment=segment,
activity=activity,
compress=compress
)
else:
print('Save DataFrame Empty for', path)
print(f'DataFrame Empty for {operation}|{activity}|{segment}')
return

def expand_timeseries_names(sgrp, smemn, smemsb1, smemsb2, tmemn, tmemsb1, tmemsb2):
Expand Down
23 changes: 16 additions & 7 deletions HSP2IO/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def __init__(self, file_path:str) -> None:
def __del__(self):
self._store.close()

def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, trace):
self.__del__()

def read_uci(self) -> UCI:
"""Read UCI related tables
Expand All @@ -26,7 +32,7 @@ def read_uci(self) -> UCI:
"""
uci = UCI()

for path in self._store.keys(): # finds ALL data sets into HDF6 file
for path in self._store.keys(): # finds ALL data sets into HDF5 file
op, module, *other = path[1:].split(sep='/', maxsplit=3)
s = '_'.join(other)
if op == 'CONTROL':
Expand Down Expand Up @@ -76,12 +82,15 @@ def read_ts(self,
operation:Union[str,None]=None,
segment:Union[str,None]=None,
activity:Union[str,None]=None) -> pd.DataFrame:
path = ''
if category == category.INPUTS:
path = f'TIMESERIES/{segment}'
elif category == category.RESULTS:
path = f'RESULTS/{operation}_{segment}/{activity}'
return read_hdf(self._store, path)
try:
path = ''
if category == category.INPUTS:
path = f'TIMESERIES/{segment}'
elif category == category.RESULTS:
path = f'RESULTS/{operation}_{segment}/{activity}'
return read_hdf(self._store, path)
except KeyError:
return pd.DataFrame()

def write_ts(self,
data_frame:pd.DataFrame,
Expand Down
12 changes: 9 additions & 3 deletions HSP2IO/io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
from pandas.core.frame import DataFrame
from HSP2IO.protocols import Category, SupportsReadUCI, SupportsReadTS, SupportsWriteTS, SupportsWriteLogging
from typing import Union
from typing import Union, List

from HSP2.uci import UCI

Expand Down Expand Up @@ -56,15 +56,21 @@ def read_uci(self, *args, **kwargs) -> UCI:
return self._uci.read_uci()

def write_ts(self,
data_frame:pd.DataFrame,
data_frame:pd.DataFrame,
save_columns: List[str],
category:Category,
operation:Union[str,None]=None,
segment:Union[str,None]=None,
activity:Union[str,None]=None,
*args, **kwargs) -> None:
key = (category, operation, segment, activity)
self._output.write_ts(data_frame, category, operation, segment, activity)
self._in_memory[key] = data_frame.copy(deep=True)

drop_columns = [c for c in data_frame.columns if c not in save_columns ]
if drop_columns:
data_frame = data_frame.drop(columns=drop_columns)

self._output.write_ts(data_frame, category, operation, segment, activity)

def read_ts(self,
category:Category,
Expand Down
2 changes: 1 addition & 1 deletion _version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.10.0'
__version__ = '0.10.1'
Loading

0 comments on commit f9555f2

Please sign in to comment.