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

Issue #1248 Write svat_groundwater to file and update the tests #1249

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

HendrikKok
Copy link
Contributor

@HendrikKok HendrikKok commented Oct 21, 2024

Fixes #1248

Description

This PR fixes Issue #1248 by removing the svat_groundwater from the _to_fill variable. For now the source svat == target svat.

In addition the max_abstraction_groundwater should now contains the subunit coordinate. The current implementation assigned the abstraction to all stacked subunits. This is not desirable in case the second svat represents the urban area for example. Now its up to the user to define irrigation at the subunit level.

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

Copy link

sonarcloud bot commented Nov 14, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
19.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@HendrikKok HendrikKok marked this pull request as ready for review November 18, 2024 12:59
Copy link
Contributor

@JoerivanEngelen JoerivanEngelen left a comment

Choose a reason for hiding this comment

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

Nice work! Thanks for adding these tests. I have some suggestions to improve the code and I also see some tests failing for regridding, could you try to fix these?

Also: we need to remind ourselves that this will result in primod requiring updates to its fixtures.

Changed
~~~~~~~

- Variable ``max_abstraction_groundwater`` in :class:`imod.msw.Sprinkling` now needs to
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot max_abstraction_surfacewater, please add that

Comment on lines +78 to +80
def ravel_per_subunit(array: xr.DataArray) -> np.ndarray:
# per defined well element, all subunits
array_out = array.to_numpy()[:, well_row, well_column].ravel()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please pass well_row and well_column to this function, like so:

Suggested change
def ravel_per_subunit(array: xr.DataArray) -> np.ndarray:
# per defined well element, all subunits
array_out = array.to_numpy()[:, well_row, well_column].ravel()
def ravel_per_subunit(array: xr.DataArray, well_row: np.ndarray, well_column: np.ndarray) -> np.ndarray:
# per defined well element, all subunits
array_out = array.to_numpy()[:, well_row, well_column].ravel()

I'd also prefer it if you put this helper function outside the class and add it above in this module. You can name it _ravel_per_subunit to show it is a semi-private helper function.

Comment on lines +97 to +102
layer_source = ravel_per_subunit(
layer_per_svat.where(max_rate_per_svat > 0)
).astype(dtype=np.int32)
svat_source_target = ravel_per_subunit(
svat.where(max_rate_per_svat > 0)
).astype(dtype=np.int32)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can reduce code complexity and duplication somewhat like this:

Suggested change
layer_source = ravel_per_subunit(
layer_per_svat.where(max_rate_per_svat > 0)
).astype(dtype=np.int32)
svat_source_target = ravel_per_subunit(
svat.where(max_rate_per_svat > 0)
).astype(dtype=np.int32)
is_active_per_svat = max_rate_per_svat > 0
layer_source = ravel_per_subunit(
layer_per_svat.where(is_active_per_svat)
).astype(dtype=np.int32)
svat_source_target = ravel_per_subunit(
svat.where(is_active_per_svat)
).astype(dtype=np.int32)

}

for var in self._with_subunit:
array = self.dataset[var].where(max_rate_per_svat > 0).to_numpy()
Copy link
Contributor

Choose a reason for hiding this comment

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

See previous suggestion:

Suggested change
array = self.dataset[var].where(max_rate_per_svat > 0).to_numpy()
array = self.dataset[var].where(is_active_per_svat).to_numpy()

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.

Sprinkling class of MetaSWAP model does not writes source svats for sprinkling to file
2 participants