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

Update for usace issue #768

Merged
merged 2 commits into from
May 28, 2024
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
50 changes: 29 additions & 21 deletions src/troute-network/troute/nhd_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,27 +1059,30 @@ def _read_timeslice_file(f):
stns = ds.variables['stationId'][:].filled(fill_value = np.nan)
t = ds.variables['time'][:].filled(fill_value = np.nan)
qual = ds.variables['discharge_quality'][:].filled(fill_value = np.nan)

if discharge.size != 0 and stns.size != 0 and t.size != 0:
stationId = np.apply_along_axis(''.join, 1, stns.astype(str))
time_str = np.apply_along_axis(''.join, 1, t.astype(str))
stationId = np.char.strip(stationId)

stationId = np.apply_along_axis(''.join, 1, stns.astype(str))
time_str = np.apply_along_axis(''.join, 1, t.astype(str))
stationId = np.char.strip(stationId)

timeslice_observations = (pd.DataFrame({
'stationId' : stationId,
'datetime' : time_str,
'discharge' : discharge
}).
set_index(['stationId', 'datetime']).
unstack(1, fill_value = np.nan)['discharge'])

observation_quality = (pd.DataFrame({
'stationId' : stationId,
'datetime' : time_str,
'quality' : qual/100
}).
set_index(['stationId', 'datetime']).
unstack(1, fill_value = np.nan)['quality'])

timeslice_observations = (pd.DataFrame({
'stationId' : stationId,
'datetime' : time_str,
'discharge' : discharge
}).
set_index(['stationId', 'datetime']).
unstack(1, fill_value = np.nan)['discharge'])

observation_quality = (pd.DataFrame({
'stationId' : stationId,
'datetime' : time_str,
'quality' : qual/100
}).
set_index(['stationId', 'datetime']).
unstack(1, fill_value = np.nan)['quality'])
else:
timeslice_observations = pd.DataFrame()
observation_quality = pd.DataFrame()
return timeslice_observations, observation_quality

def _interpolate_one(df, interpolation_limit, frequency):
Expand Down Expand Up @@ -1157,7 +1160,12 @@ def get_obs_from_timeslices(
for f in timeslice_files:
jobs.append(delayed(_read_timeslice_file)(f))
timeslice_dataframes = parallel(jobs)


all_empty = all(df.empty for tuple in timeslice_dataframes for df in tuple)
if all_empty:
LOG.debug(f'{crosswalk_gage_field} DataFrames is empty, check timeslice files.')
return pd.DataFrame()

# create lists of observations and obs quality dataframes returned
# from _read_timeslice_file
timeslice_obs_frames = []
Expand Down
2 changes: 1 addition & 1 deletion test/LowerColorado_TX_v4/test_AnA_V4_HYFeature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ compute_parameters:
data_assimilation_parameters:
#----------
usgs_timeslices_folder : usgs_timeslices/
usace_timeslices_folder : usace_timelices/
usace_timeslices_folder : usace_timeslices/
streamflow_da:
#----------
streamflow_nudging : True
Expand Down
Loading