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

silence HantushWellModel info msg about r=1.0 #604

Merged
merged 2 commits into from
Aug 15, 2023
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
18 changes: 15 additions & 3 deletions pastas/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,11 @@ def get_step_response(

@get_stressmodel
def get_response_tmax(
self, name: str, p: ArrayLike = None, cutoff: float = 0.999
self,
name: str,
p: ArrayLike = None,
cutoff: float = 0.999,
warn: bool = True,
) -> Union[float, None]:
"""Method to get the tmax used for the response function.

Expand Down Expand Up @@ -1581,7 +1585,11 @@ def get_response_tmax(
else:
if p is None:
p = self.get_parameters(name)
tmax = self.stressmodels[name].rfunc.get_tmax(p=p, cutoff=cutoff)
if self.stressmodels[name].rfunc._name == "HantushWellModel":
kwargs = {"warn": warn}
else:
kwargs = {}
tmax = self.stressmodels[name].rfunc.get_tmax(p=p, cutoff=cutoff, **kwargs)
return tmax

@get_stressmodel
Expand Down Expand Up @@ -1857,8 +1865,12 @@ def _check_response_tmax(self, cutoff: Optional[float] = None) -> DataFrame:
check["len_oseries_calib"] = len_oseries_calib

for sm_name in self.stressmodels:
if self.stressmodels[sm_name].rfunc._name == "HantushWellModel":
kwargs = {"warn": False}
else:
kwargs = {}
check.loc[sm_name, "response_tmax"] = self.get_response_tmax(
sm_name, cutoff=cutoff
sm_name, cutoff=cutoff, **kwargs
)

check["check_ok"] = check["response_tmax"] < check["len_oseries_calib"]
Expand Down
12 changes: 10 additions & 2 deletions pastas/modelcompare.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,11 @@ def plot_response(
if smn not in ml.stressmodels:
continue
if response == "step":
step = ml.get_step_response(smn, add_0=True)
kwargs = {}
if ml.stressmodels[smn].rfunc is not None:
if ml.stressmodels[smn].rfunc._name == "HantushWellModel":
kwargs = {"warn": False}
step = ml.get_step_response(smn, add_0=True, **kwargs)
if step is None:
continue
if self.axes is None:
Expand All @@ -574,7 +578,11 @@ def plot_response(
color=self.cmap(i),
)
elif response == "block":
block = ml.get_block_response(smn)
kwargs = {}
if ml.stressmodels[smn].rfunc is not None:
if ml.stressmodels[smn].rfunc._name == "HantushWellModel":
kwargs = {"warn": False}
block = ml.get_block_response(smn, **kwargs)
if block is None:
continue
if self.axes is None:
Expand Down
6 changes: 5 additions & 1 deletion pastas/modelplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,12 @@ def results(
i = i + 1

# plot the step response
rkwargs = {}
if self.ml.stressmodels[sm_name].rfunc is not None:
if self.ml.stressmodels[sm_name].rfunc._name == "HantushWellModel":
rkwargs = {"warn": False}
response = self.ml._get_response(
block_or_step=block_or_step, name=sm_name, add_0=True
block_or_step=block_or_step, name=sm_name, add_0=True, **rkwargs
)

if response is not None:
Expand Down
31 changes: 23 additions & 8 deletions pastas/rfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ def impulse(t: ArrayLike, p: ArrayLike) -> ArrayLike:
"""

def get_t(
self, p: ArrayLike, dt: float, cutoff: float, maxtmax: Optional[int] = None
self,
p: ArrayLike,
dt: float,
cutoff: float,
maxtmax: Optional[int] = None,
warn: bool = True,
) -> ArrayLike:
"""Internal method to determine the times at which to evaluate the step
response, from t=0.
Expand All @@ -245,6 +250,9 @@ def get_t(
proportion after which the step function is cut off.
maxtmax: float, optional
The maximum time of the response, usually set to the simulation length.
warn : bool, optional
only used for HantushWellModel, whether to warn when r is set to 1.0
for calculations.

Returns
-------
Expand All @@ -254,7 +262,10 @@ def get_t(
if isinstance(dt, np.ndarray):
return dt
else:
tmax = self.get_tmax(p, cutoff)
if self._name == "HantushWellModel":
tmax = self.get_tmax(p, cutoff, warn=warn)
else:
tmax = self.get_tmax(p, cutoff)
if maxtmax is not None:
tmax = min(tmax, maxtmax)
tmax = max(tmax, 3 * dt)
Expand Down Expand Up @@ -569,16 +580,19 @@ def get_init_parameters(self, name: str) -> DataFrame:
return parameters

@staticmethod
def _get_distance_from_params(p: ArrayLike) -> float:
def _get_distance_from_params(p: ArrayLike, warn: bool = True) -> float:
if len(p) == 3:
r = 1.0
logger.info("No distance passed to HantushWellModel, assuming r=1.0.")
if warn:
logger.info("No distance passed to HantushWellModel, assuming r=1.0.")
else:
r = p[3]
return r

def get_tmax(self, p: ArrayLike, cutoff: Optional[float] = None) -> float:
r = self._get_distance_from_params(p)
def get_tmax(
self, p: ArrayLike, cutoff: Optional[float] = None, warn: bool = True
) -> float:
r = self._get_distance_from_params(p, warn=warn)
# approximate formula for tmax
if cutoff is None:
cutoff = self.cutoff
Expand Down Expand Up @@ -658,10 +672,11 @@ def step(
dt: float = 1.0,
cutoff: Optional[float] = None,
maxtmax: Optional[int] = None,
warn: bool = True,
) -> ArrayLike:
A, a, b = p[:3]
r = self._get_distance_from_params(p)
t = self.get_t(p=p, dt=dt, cutoff=cutoff, maxtmax=maxtmax)
r = self._get_distance_from_params(p, warn=warn)
t = self.get_t(p=p, dt=dt, cutoff=cutoff, maxtmax=maxtmax, warn=warn)

if self.quad:
return self.quad_step(A, a, b, r, t)
Expand Down