Skip to content

Commit f9555f2

Browse files
Merge pull request #88 from respec/develop
Merge Develop into Master for release v0.10.1
2 parents 315c97b + 5ca8619 commit f9555f2

File tree

9 files changed

+11024
-5558
lines changed

9 files changed

+11024
-5558
lines changed

HSP2/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ def main(io_manager:IOManager, saveall:bool=False, jupyterlab:bool=True) -> None
9393
if (activity in flags) and (not flags[activity]):
9494
continue
9595

96+
if (activity == 'RQUAL') and (not flags['OXRX']) and (not flags['NUTRX']) and (not flags['PLANK']) and (not flags['PHCARB']):
97+
continue
98+
9699
msg(3, f'{activity}')
97100

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

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

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

HSP2/utilities.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,43 +286,45 @@ def get_timeseries(timeseries_inputs:SupportsReadTS, ext_sourcesdd, siminfo):
286286
return ts
287287

288288
def save_timeseries(timeseries:SupportsWriteTS, ts, savedict, siminfo, saveall, operation, segment, activity, compress=True):
289-
# save computed timeseries (at computation DELT)
290-
save = {k for k,v in savedict.items() if v or saveall}
291289
df = pd.DataFrame(index=siminfo['tindex'])
292290
if (operation == 'IMPLND' and activity == 'IQUAL') or (operation == 'PERLND' and activity == 'PQUAL'):
293-
for y in save:
291+
for y in savedict.keys():
294292
for z in set(ts.keys()):
295293
if '/' + y in z:
296294
zrep = z.replace('/','_')
297295
zrep2 = zrep.replace(' ', '')
298296
df[zrep2] = ts[z]
299297
if '_' + y in z:
300298
df[z] = ts[z]
301-
df = df.astype(np.float32).sort_index(axis='columns')
302299
elif (operation == 'RCHRES' and (activity == 'CONS' or activity == 'GQUAL')):
303-
for y in save:
300+
for y in savedict.keys():
304301
for z in set(ts.keys()):
305302
if '_' + y in z:
306303
df[z] = ts[z]
307-
for y in (save & set(ts.keys())):
304+
for y in (savedict.keys() & set(ts.keys())):
308305
df[y] = ts[y]
309-
df = df.astype(np.float32).sort_index(axis='columns')
310306
else:
311-
for y in (save & set(ts.keys())):
307+
for y in (savedict.keys() & set(ts.keys())):
312308
df[y] = ts[y]
313-
df = df.astype(np.float32).sort_index(axis='columns')
314-
path = f'RESULTS/{operation}_{segment}/{activity}'
309+
df = df.astype(np.float32).sort_index(axis='columns')
310+
311+
if saveall:
312+
save_columns = df.columns
313+
else:
314+
save_columns = [key for key,value in savedict.items() if value or saveall]
315+
315316
if not df.empty:
316317
timeseries.write_ts(
317318
data_frame=df,
319+
save_columns=save_columns,
318320
category = Category.RESULTS,
319321
operation=operation,
320322
segment=segment,
321323
activity=activity,
322324
compress=compress
323325
)
324326
else:
325-
print('Save DataFrame Empty for', path)
327+
print(f'DataFrame Empty for {operation}|{activity}|{segment}')
326328
return
327329

328330
def expand_timeseries_names(sgrp, smemn, smemsb1, smemsb2, tmemn, tmemsb1, tmemsb2):

HSP2IO/hdf.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ def __init__(self, file_path:str) -> None:
1616
def __del__(self):
1717
self._store.close()
1818

19+
def __enter__(self):
20+
return self
21+
22+
def __exit__(self, exc_type, exc_value, trace):
23+
self.__del__()
24+
1925
def read_uci(self) -> UCI:
2026
"""Read UCI related tables
2127
@@ -26,7 +32,7 @@ def read_uci(self) -> UCI:
2632
"""
2733
uci = UCI()
2834

29-
for path in self._store.keys(): # finds ALL data sets into HDF6 file
35+
for path in self._store.keys(): # finds ALL data sets into HDF5 file
3036
op, module, *other = path[1:].split(sep='/', maxsplit=3)
3137
s = '_'.join(other)
3238
if op == 'CONTROL':
@@ -76,12 +82,15 @@ def read_ts(self,
7682
operation:Union[str,None]=None,
7783
segment:Union[str,None]=None,
7884
activity:Union[str,None]=None) -> pd.DataFrame:
79-
path = ''
80-
if category == category.INPUTS:
81-
path = f'TIMESERIES/{segment}'
82-
elif category == category.RESULTS:
83-
path = f'RESULTS/{operation}_{segment}/{activity}'
84-
return read_hdf(self._store, path)
85+
try:
86+
path = ''
87+
if category == category.INPUTS:
88+
path = f'TIMESERIES/{segment}'
89+
elif category == category.RESULTS:
90+
path = f'RESULTS/{operation}_{segment}/{activity}'
91+
return read_hdf(self._store, path)
92+
except KeyError:
93+
return pd.DataFrame()
8594

8695
def write_ts(self,
8796
data_frame:pd.DataFrame,

HSP2IO/io.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pandas as pd
22
from pandas.core.frame import DataFrame
33
from HSP2IO.protocols import Category, SupportsReadUCI, SupportsReadTS, SupportsWriteTS, SupportsWriteLogging
4-
from typing import Union
4+
from typing import Union, List
55

66
from HSP2.uci import UCI
77

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

5858
def write_ts(self,
59-
data_frame:pd.DataFrame,
59+
data_frame:pd.DataFrame,
60+
save_columns: List[str],
6061
category:Category,
6162
operation:Union[str,None]=None,
6263
segment:Union[str,None]=None,
6364
activity:Union[str,None]=None,
6465
*args, **kwargs) -> None:
6566
key = (category, operation, segment, activity)
66-
self._output.write_ts(data_frame, category, operation, segment, activity)
6767
self._in_memory[key] = data_frame.copy(deep=True)
68+
69+
drop_columns = [c for c in data_frame.columns if c not in save_columns ]
70+
if drop_columns:
71+
data_frame = data_frame.drop(columns=drop_columns)
72+
73+
self._output.write_ts(data_frame, category, operation, segment, activity)
6874

6975
def read_ts(self,
7076
category:Category,

_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.10.0'
1+
__version__ = '0.10.1'

0 commit comments

Comments
 (0)