Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Issue #443 clipping msw model #1478

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

Merged
merged 24 commits into from
Mar 10, 2025
Merged

Conversation

JoerivanEngelen
Copy link
Contributor

@JoerivanEngelen JoerivanEngelen commented Mar 7, 2025

Fixes #443 and #364

Description

  • Adds clipping method to imod.msw.MetaSwapModel, this includes a special case for clip_box method of PrecipitationMapping, and EvapotranspirationMapping: These should not be clipped if a MeteoGridCopy instance is part of the model. Otherwise nonsensical mappings are generated.
  • Add imod.msw.MetaSwapModel.clip_box method to public API
  • Override clip_box method in MeteoMapping, should clip meteo attribute instead of dataset attribute.
  • Refactor: Move time slice clipping logic to imod.common.utilities.clip.
  • Refactor: Make meteo class variable an attribute. This makes more sense. I think I made it a class variable before to please mypy.
  • Boyscouting: Add some extra docstring information on usecase to imod.msw.MeteoGridCopy

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 requested a review from Manangka March 7, 2025 12:35
# grid is independent of model grid and we do not want to perform
# transformations on meteo data in this case.
if has_meteogrid_copy and isinstance(pkg, MeteoMapping):
clipped[key] = deepcopy(pkg)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this necessary? You have a clip_box method in the MeteoMapping class. I would expect either that method to be called here or that that method isn't necessary

Copy link
Contributor Author

@JoerivanEngelen JoerivanEngelen Mar 10, 2025

Choose a reason for hiding this comment

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

The special-case is only necessary when a MeteoGridCopy is assigned to the model. This object just copies a pointer file mete_grid.inp which contains paths to a lot of meteo ASCII files, which are commonly very large. In this case, we do not want to clip these large datasets, nor create mappings to clipped meteo grids (as we do not want to clip these). This is a very common usecase for iMOD5 models.

The MeteoMapping.clip_box method should be called when a MeteoGrid object is assigned to the model.

return indexer, repeat_stress


def clip_time_slice(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like that you refactored out duplicate code and reduced it to this single method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

timestamps with data.
"""
# First, "pop" and filter.
keys, values = repeat_stress.values.T
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could rename keys to times or period

keep = (keys >= time_start) & (keys <= time_end)
new_keys = keys[keep]
new_values = values[keep]
# Now detect which "value" entries have gone missing
Copy link
Collaborator

Choose a reason for hiding this comment

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

The code belonging to this code doesn't look for missing entries but for unique entries right?
The comment confuses me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've clarified this function with better naming and comments, as it was very confusing


# Update the key-value pairs. Discard keys that have been "promoted".
keep = np.isin(new_keys, insert_keys, assume_unique=True, invert=True)
new_keys = new_keys[keep]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't new_keys equal to insert_keys? and new_values to insert_values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've clarified this function with better naming and comments, as it was very confusing

Copy link

@JoerivanEngelen JoerivanEngelen merged commit 51aaf58 into master Mar 10, 2025
7 checks passed
@JoerivanEngelen JoerivanEngelen deleted the issue_#443_clipping_msw_model branch March 10, 2025 13:03
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.

Add clipping method to MetaSwapModel
2 participants