Skip to content

Commit e4d064e

Browse files
allow for multiple paths to be passed to read_dss
1 parent eaf5b19 commit e4d064e

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

vtools/functions/read_dss.py

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,51 +47,57 @@ def read_dss(
4747
----------
4848
filename: str|Path
4949
Path to the DSS file to read
50-
pathname: str
51-
Pathname within the DSS file to read.
50+
pathname: str|list
51+
Pathname(s) within the DSS file to read.
5252
Needs to be in the format '/A_PART/B_PART/C_PART/D_PART/E_PART/F_PART/'
5353
(e.g. '//RSAN112/FLOW////')
5454
"""
5555
ts_out_list = []
5656
col_names = []
57-
print(f"\tReading pathname: {pathname}")
58-
if len(pathname.split("/")[1:-1]) != 6:
59-
raise ValueError(f"Invalid DSS pathname: {pathname}, needs 6 parts (A-F)")
60-
ts = get_ts(str(filename), pathname)
61-
for i, tsi in enumerate(ts):
62-
ts_path = tsi[0].columns.values[0]
63-
if exclude_pathname is None or (
64-
exclude_pathname is not None
65-
and not check_exclude(ts_path, exclude_pathname)
66-
):
67-
# if not an excluded path, then carry on
68-
path_lst = (ts_path).split("/")
69-
path_e = path_lst[5]
70-
# Set default start_date and end_date to cover the full period of record if not specified
71-
tt_full = tsi[0]
72-
if start_date is None:
73-
start_date = tt_full.index[0].to_timestamp()
74-
if end_date is None:
75-
end_date = tt_full.index[-1].to_timestamp()
76-
if tt_full.index[0].to_timestamp() > end_date or (
77-
tt_full.index[-1].to_timestamp() < start_date
57+
if isinstance(pathname, str):
58+
pathname = [pathname]
59+
for path in pathname:
60+
if len(path.split("/")[1:-1]) != 6:
61+
raise ValueError(f"Invalid DSS path: {path}, needs 6 parts (A-F)")
62+
ts = get_ts(str(filename), *pathname)
63+
for path in pathname:
64+
print(f"\tReading path: {path}")
65+
for i, tsi in enumerate(ts):
66+
ts_path = tsi[0].columns.values[0]
67+
if exclude_pathname is None or (
68+
exclude_pathname is not None
69+
and not check_exclude(ts_path, exclude_pathname)
7870
):
79-
raise ValueError(
80-
f"File: {filename} does not cover the dates requested. \n\tRequested dates are: {start_date} to {end_date}, \n\tand the file covers {tt_full.index[0]} to {tt_full.index[-1]}"
71+
# if not an excluded path, then carry on
72+
path_lst = (ts_path).split("/")
73+
path_e = path_lst[5]
74+
# Set default start_date and end_date to cover the full period of record if not specified
75+
tt_full = tsi[0]
76+
if start_date is None:
77+
start_date = tt_full.index[0].to_timestamp()
78+
if end_date is None:
79+
end_date = tt_full.index[-1].to_timestamp()
80+
if tt_full.index[0].to_timestamp() > end_date or (
81+
tt_full.index[-1].to_timestamp() < start_date
82+
):
83+
raise ValueError(
84+
f"File: {filename} does not cover the dates requested. \n\tRequested dates are: {start_date} to {end_date}, \n\tand the file covers {tt_full.index[0]} to {tt_full.index[-1]}"
85+
)
86+
tt = tt_full[start_date:end_date]
87+
pidx = pd.period_range(
88+
tt.index[0], tt.index[-1], freq=dss_e2_freq[path_e]
8189
)
82-
tt = tt_full[start_date:end_date]
83-
pidx = pd.period_range(tt.index[0], tt.index[-1], freq=dss_e2_freq[path_e])
84-
ptt = pd.DataFrame(tt.values[:, 0], pidx)
90+
ptt = pd.DataFrame(tt.values[:, 0], pidx)
8591

86-
# Interpolate with rhistinterp
87-
if p > 0:
88-
col_data = rhistinterp(ptt, dt, p=p)
89-
elif p == 0:
90-
col_data = rhistinterp(ptt, dt)
91-
else:
92-
col_data = tsi[0]
93-
ts_out_list.append(col_data)
94-
col_names.append(ts_path)
92+
# Interpolate with rhistinterp
93+
if p > 0:
94+
col_data = rhistinterp(ptt, dt, p=p)
95+
elif p == 0:
96+
col_data = rhistinterp(ptt, dt)
97+
else:
98+
col_data = tsi[0]
99+
ts_out_list.append(col_data)
100+
col_names.append(ts_path)
95101

96102
if ts_out_list:
97103
ts_out = pd.concat(ts_out_list, axis=1)
@@ -101,7 +107,7 @@ def read_dss(
101107
with DSSFile(filename) as dssh:
102108
dfcat = dssh.read_catalog()
103109
raise ValueError(
104-
f"Warning: DSS data not found for {pathname}. Preview of available paths in {filename} are: {dfcat}"
110+
f"Warning: DSS data not found for {path}. Preview of available paths in {filename} are: {dfcat}"
105111
)
106112

107113
return ts_out

0 commit comments

Comments
 (0)