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

Use istress in responses in result-plot #714

Merged
merged 5 commits into from
Apr 9, 2024

Conversation

rubencalje
Copy link
Collaborator

@rubencalje rubencalje commented Mar 27, 2024

Short Description

This PR improves the response-plots in ml.plots.results() when the influence of different stresses in a single stressmodel are plotted: ml.plots.results(split-True). This can be used in the stressmodel RechargeModel with recharge = Linear and in the stressmodel WellModel.

The old behavior would result in the following figure (see the gap on the right and the positive response for evaporation):
image

While the new behavior results in the following figure (see the different response for recharge and evaporation):
image

In this implementation, I added a get_parameters method for RechargeModel, in the same manner already existed for WellModel.

Checklist before PR can be merged:

  • closes issue #xxxx
  • is documented
  • Format code with Black formatting
  • type hints for functions and methods
  • tests added / passed
  • Example Notebook (for new features)
  • Remove output for all notebooks with changes

Copy link

codacy-production bot commented Mar 27, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.17% (target: +0.00%) 41.46%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (491b73b) 6133 4638 75.62%
Head commit (a44483f) 6167 (+34) 4653 (+15) 75.45% (-0.17%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#714) 41 17 41.46%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

You may notice some variations in coverage metrics with the latest Coverage engine update. For more details, visit the documentation

pastas/model.py Outdated

@get_stressmodel
def get_step_response(
self,
name,
p: Optional[ArrayLike] = None,
Copy link
Member

Choose a reason for hiding this comment

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

Why are these arguments removed? I don't think this is necessary and this should be retained. Same for get_block_response.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no need to specifically name these arguments, as the kwargs are already passed onto _get_response, but I will change it back. May be easier for someone to see these parameters directly.

Copy link
Member

Choose a reason for hiding this comment

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

I was specifically thinking about the case when people use this method and want to change the input, e.g., I use add0 every now and then so it's nice that these features are documented.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They are still named in the docstring, so they are documented. However, I have just added them again as arguments as well.

@@ -1520,6 +1520,36 @@ def get_water_balance(
df.index = self.prec.series.index
return df

def get_parameters(self, model=None, istress: Optional[int] = None) -> ArrayLike:
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this method private, ._get_parameters. I don't think users should use this method to get the parameters, because it is very specific for the linear model to get adapted parameters for the response function. So only for internal use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will also change WellMode.get_parameters to WellMode._get_parameters. Is this ok @dbrakenhoff ?

Copy link
Member

@dbrakenhoff dbrakenhoff Apr 3, 2024

Choose a reason for hiding this comment

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

I'm not sure. I use it quite a bit, because quite a few of the Model class' methods do not work out-of-the-box for the WellModel. In order to get the distance added to the 3 Hantush parameters, I use p = WellModel.get_parameters(model=ml), and pass that onto any model class methods, e.g. ml.get_step_response("wells", p=p).

I think in this case, this method is also useful for other users, and not just for internal use.

EDIT: I still think this isn't a very pretty solution, but I can't think of a better one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Then I am in favor of adding a get_parameters to all stressmodels (through StressModelBase), which would return the optimal parameters when a model is supplied and the initial values otherwise.

@raoulcollenteur raoulcollenteur added the enhancement Indicates improvement of existing features label Apr 3, 2024
@raoulcollenteur raoulcollenteur added this to the 1.5 milestone Apr 3, 2024
@raoulcollenteur
Copy link
Member

Looks good! I suggested a few small changes to ensure users know the arguments and not to use methods that I think are only for internal usage. Do we know if split=True is still used a lot?

@rubencalje
Copy link
Collaborator Author

Looks good! I suggested a few small changes to ensure users know the arguments and not to use methods that I think are only for internal usage. Do we know if split=True is still used a lot?

I use it. Do not know of other people.

@raoulcollenteur
Copy link
Member

@rubencalje can you resolve the conflict? Then we can merge this one I think?

@rubencalje
Copy link
Collaborator Author

@rubencalje can you resolve the conflict? Then we can merge this one I think?

This can be merged now.

@raoulcollenteur raoulcollenteur merged commit 4fcf9c8 into dev Apr 9, 2024
10 of 12 checks passed
@raoulcollenteur raoulcollenteur deleted the use_istress_in_responses_of_result_plot branch April 9, 2024 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates improvement of existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants