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(ModflowHob): Improve HOB file performance #1158 #1224

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
16 changes: 7 additions & 9 deletions flopy/modflow/mfhob.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ def load(cls, f, model, ext_unit_dict=None, check=True):
nobs = 0

# set to False for 1st call to ensure that totim cache is updated
use_cached_totim = False
tmax = model.dis.get_final_totim()
use_cached_totim = True

while True:
# read dataset 3
Expand Down Expand Up @@ -431,7 +432,6 @@ def load(cls, f, model, ext_unit_dict=None, check=True):
names = [obsnam]
tsd = [totim, hob]
nobs += 1
use_cached_totim = True
else:
names = []
tsd = []
Expand All @@ -452,7 +452,6 @@ def load(cls, f, model, ext_unit_dict=None, check=True):
hob = float(t[3])
tsd.append([totim, hob])
nobs += 1
use_cached_totim = True

obs_data.append(
HeadObservation(
Expand All @@ -466,6 +465,7 @@ def load(cls, f, model, ext_unit_dict=None, check=True):
obsname=obsnam,
mlay=mlay,
itt=itt,
tmax=tmax,
time_series_data=tsd,
names=names,
)
Expand Down Expand Up @@ -588,6 +588,7 @@ def __init__(
roff=0.0,
coff=0.0,
itt=1,
tmax=None,
mlay=None,
time_series_data=None,
names=None,
Expand Down Expand Up @@ -645,7 +646,8 @@ def __init__(
time_series_data = np.reshape(time_series_data, (1, 2))

# find indices of time series data that are valid
tmax = model.dis.get_final_totim()
if tmax is None:
tmax = model.dis.get_final_totim()
keep_idx = time_series_data[:, 0] <= tmax
time_series_data = time_series_data[keep_idx, :]

Expand Down Expand Up @@ -677,22 +679,18 @@ def __init__(
"{} names are required.".format(len(names), self.nobs)
)

# set use_cached_totim to False first to ensure totim is updated
use_cached_totim = False

# create time_series_data
self.time_series_data = self._get_empty(ncells=shape[0])
for idx in range(self.nobs):
t = time_series_data[idx, 0]
kstp, kper, toffset = model.dis.get_kstp_kper_toffset(
t, use_cached_totim
t, use_cached_totim = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When specifying an argument value in the constructor, there should not be spaces before and after the equals sign. If you fix this and resubmit, you may not need to run black.

)
self.time_series_data[idx]["totim"] = t
self.time_series_data[idx]["irefsp"] = kper
self.time_series_data[idx]["toffset"] = toffset / tomulth
self.time_series_data[idx]["hobs"] = time_series_data[idx, 1]
self.time_series_data[idx]["obsname"] = names[idx]
use_cached_totim = True

if self.nobs > 1:
self.irefsp = -self.nobs
Expand Down