Skip to content

Commit

Permalink
Added accommodations for empty dataframes in diffusive (#735)
Browse files Browse the repository at this point in the history
* Added accommodations for empty dataframes in diffusive

* Changed datatype to numerical arrays from data frames

* Fixed bug
  • Loading branch information
JurgenZach-NOAA authored Feb 6, 2024
1 parent 189dfa6 commit 99dd6c3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
22 changes: 18 additions & 4 deletions src/model_DAforcing.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,12 +718,21 @@ def _write_lite_restart(
waterbodies_df = values['waterbody_df']
waterbodies_ids = values['waterbody_df_ids']

waterbodies_df = pd.DataFrame(data=waterbodies_df.reshape(len(waterbodies_ids), -1),
# check for empty waterbody df
if (len(waterbodies_df)==0):

waterbodies_df = pd.DataFrame()

else:

waterbodies_df = pd.DataFrame(data=waterbodies_df.reshape(len(waterbodies_ids), -1),
index=waterbodies_ids,
columns=['ifd','LkArea','LkMxE','OrificeA','OrificeC','OrificeE',
'WeirC','WeirE','WeirL','lon', 'lat', 'crs','qd0','h0','index'])
waterbodies_df.index.name = 'lake_id'
waterbodies_df.drop(columns=['lon', 'lat', 'crs'], inplace=True)

waterbodies_df.index.name = 'lake_id'
waterbodies_df.drop(columns=['lon', 'lat', 'crs'], inplace=True)

timestamp = t0 + timedelta(seconds=values['t-route_model_time'])

# create restart filenames
Expand Down Expand Up @@ -829,7 +838,12 @@ def write_flowveldepth_netcdf(values,

ndg_columns = [(j+1,'ndg') for j in range(nsteps)]
# renaming nudge columns
nudge.columns = ndg_columns

if (nudge.empty):
nudge = pd.DataFrame(columns=ndg_columns)
else:
nudge.columns = ndg_columns

# Left joining qvd and nudge values on index
qvd_ndg = pd.merge(qvd_ndg, nudge, left_index=True, right_index=True, how='left')

Expand Down
13 changes: 9 additions & 4 deletions src/troute_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,15 @@ def preprocess_static_vars(self, values: dict):
from_files=False, value_dict=values,
bmi_parameters=self._bmi_parameters,)

values['diffusive_tw_ids'] = self._network._nexus_latlon.id.values
values['diffusive_tw_latitude'] = self._network._nexus_latlon.lat.values
values['diffusive_tw_longitude'] = self._network._nexus_latlon.lon.values

if (len(self._network._nexus_latlon) > 0):
values['diffusive_tw_ids'] = self._network._nexus_latlon.id.values
values['diffusive_tw_latitude'] = self._network._nexus_latlon.lat.values
values['diffusive_tw_longitude'] = self._network._nexus_latlon.lon.values
else:
values['diffusive_tw_ids'] = np.empty(0,dtype=np.int32)
values['diffusive_tw_latitude'] = np.empty(0,dtype=np.float64)
values['diffusive_tw_longitude'] = np.empty(0,dtype=np.float64)

# Create data assimilation object with IDs but no dynamic variables yet.
# Dynamic variables will be assigned during 'run' function.
self._data_assimilation = tr.DataAssimilation(
Expand Down
Binary file not shown.

0 comments on commit 99dd6c3

Please sign in to comment.