Skip to content

Conversation

@JoerivanEngelen
Copy link
Contributor

@JoerivanEngelen JoerivanEngelen commented May 23, 2024

Fixes #960 and #1000

Description

Adds regrid schemes which replaces the dictionaries under _regrid_method with pydantic dataclasses.
Pydantic comes with input validation base on type annotation, so requires no extra code.
See documentation here
This requires pydantic as extra dependency, so is added as dependency.

I kept _regrid_method as a class variable, as it gave problems as an attribute with imod.mf6.Package.from_file classmethod, where attributes are not forwarded.

I created a new namespace: imod.mf6.regrid where we can store all Regridding related stuff. Probably good to move other public API there as well later on, namely the imod.mf6.utilities.regridder_types.RegridderType and imod.mf6.utilities.regrid.RegridderWeightsCache. As these are more than just utilities: They are essential objects for users to do their regridding at the moment.

Checklist

  • Links to correct issue
  • Update changelog, if changes affect users
  • PR title starts with Issue #nr, e.g. Issue #737
  • Unit tests were added
  • If feature added: Added/extended example

@JoerivanEngelen JoerivanEngelen marked this pull request as ready for review May 24, 2024 14:01
@JoerivanEngelen JoerivanEngelen requested a review from luitjansl May 24, 2024 14:01
Copy link
Contributor

@luitjansl luitjansl left a comment

Choose a reason for hiding this comment

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

some comments/questions

Object containing regridder methods for the :class:`imod.mf6.ConstantHead`
package. This can be provided to the ``regrid_like`` method to regrid with
custom settings.
Copy link
Contributor

Choose a reason for hiding this comment

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

all these docstrings for each type clutter the source file more than they help. Could you make 1 docstring documenting what the xxxRegridMethod classes,are? If you want to give more information on 1 class , add a short docsring to the xxxRegridMethod class if needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Docstrings are required as these functions are public API.

I attempted it, but it didn't yield any satisfactory results, as there are just a bit too many things varying in the docstring:

  • class name the regrid method is intended for
  • regrid method class name
  • an n amount of parameter variables
  • in the example, a short name for a variable the package is assigned to, e.g. chd
  • in the example, a variable name which gets a custom setting

They are just a bit too much spread out to create a satisfactory template, without introducing significantly more complexity. For example, jinja templates which use dictionaries describing the variable names per RegridMethod class.

), # TODO: should be set to barycentric once supported
"concentration": (RegridderType.OVERLAP, "mean"),
}
_regrid_method = ConstantHeadRegridMethod()
Copy link
Contributor

Choose a reason for hiding this comment

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

why don't you make it an object variable instead of a class variable? Then tweaking these methods would be very readable:

my_special_ConstantHead_package._regrid_method.concentration = Barycentric

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I wrote in the description:

I kept _regrid_method as a class variable, as it gave problems as an attribute with imod.mf6.Package.from_file classmethod, where attributes are not forwarded.

@luitjansl luitjansl enabled auto-merge May 28, 2024 15:24
@luitjansl luitjansl added this pull request to the merge queue May 29, 2024
Merged via the queue into master with commit a3f4e5f May 29, 2024
@luitjansl luitjansl deleted the issue_#960_regrid_method_refactor branch May 29, 2024 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make regrid method a package variable rather than a class variable

3 participants