Skip to content

Commit

Permalink
hotfix(tdis.py::setup_perioddata): in case of pre-defined (csvfile) s…
Browse files Browse the repository at this point in the history
…tress periods, base perlen on end_datetime - start_datetime (what you see is what you get, and so that gaps between stress periods don't affect perlen); add trap for missing required columns
  • Loading branch information
aleaf committed Oct 17, 2023
1 parent c278ba2 commit 9c73e80
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions mfsetup/tdis.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,18 +506,22 @@ def setup_perioddata(model,
'nstp_column': 'nstp',
'tsmult_column': 'tsmult'
}

csv_config = tdis_perioddata_config['csvfile']
renames = {csv_config.get(k): v
for k, v in defaults.items() if k in csv_config}
perioddata.rename(columns=renames, inplace=True)
required_cols = defaults.values()
for col in required_cols:
if col not in perioddata.columns:
raise KeyError(f"{col} column missing in supplied stress "
f"period table {csvfile}.")
perioddata['start_datetime'] = pd.to_datetime(perioddata['start_datetime'])
perioddata['end_datetime'] = pd.to_datetime(perioddata['end_datetime'])
perioddata['per'] = np.arange(len(perioddata))
time_edges = getattr((perioddata['end_datetime'] -
perioddata['start_datetime'][0]).dt,
model.time_units).tolist()
time_edges = [0] + time_edges
perlen = np.diff(time_edges)
perlen = getattr((perioddata['end_datetime'] -
perioddata['start_datetime']).dt,
model.time_units).tolist()
# set initial steady-state stress period to at least length 1
if perioddata['steady'][0] and perlen[0] < 1:
perlen[0] = 1
Expand Down

0 comments on commit 9c73e80

Please sign in to comment.