-
Notifications
You must be signed in to change notification settings - Fork 8
Issue #1779 Implementation of MetaSWAP model splitter #1780
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
Open
verkaik
wants to merge
4
commits into
master
Choose a base branch
from
issue_#1779_msw_model_split
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from typing import List, NamedTuple | ||
|
|
||
| import numpy as np | ||
|
|
||
| from imod.typing import GridDataArray | ||
| from imod.typing.grid import ones_like | ||
|
|
||
|
|
||
| class PartitionInfo(NamedTuple): | ||
| active_domain: GridDataArray | ||
| id: int | ||
|
|
||
|
|
||
| def create_partition_info(submodel_labels: GridDataArray) -> List[PartitionInfo]: | ||
| """ | ||
| A PartitionInfo is used to partition a model or package. The partition | ||
| info's of a domain are created using a submodel_labels array. The | ||
| submodel_labels provided as input should have the same shape as a single | ||
| layer of the model grid (all layers are split the same way), and contains an | ||
| integer value in each cell. Each cell in the model grid will end up in the | ||
| submodel with the index specified by the corresponding label of that cell. | ||
| The labels should be numbers between 0 and the number of partitions. | ||
| """ | ||
| _validate_submodel_label_array(submodel_labels) | ||
|
|
||
| unique_labels = np.unique(submodel_labels.values) | ||
|
|
||
| partition_infos = [] | ||
| for label_id in unique_labels: | ||
| active_domain = submodel_labels.where(submodel_labels.values == label_id) | ||
| active_domain = ones_like(active_domain).where(active_domain.notnull(), 0) | ||
| active_domain = active_domain.astype(submodel_labels.dtype) | ||
|
|
||
| submodel_partition_info = PartitionInfo( | ||
| id=label_id, active_domain=active_domain | ||
| ) | ||
| partition_infos.append(submodel_partition_info) | ||
|
|
||
| return partition_infos | ||
|
|
||
|
|
||
| def _validate_submodel_label_array(submodel_labels: GridDataArray) -> None: | ||
| unique_labels = np.unique(submodel_labels.values) | ||
|
|
||
| if not ( | ||
| len(unique_labels) == unique_labels.max() + 1 | ||
| and unique_labels.min() == 0 | ||
| and np.issubdtype(submodel_labels.dtype, np.integer) | ||
| ): | ||
| raise ValueError( | ||
| "The submodel_label array should be integer and contain all the numbers between 0 and the number of " | ||
| "partitions minus 1." | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: We need to add a ClippablePackage and SplittablePackage interface, just like we have a RegriddingPackage interface. The fact that we need to add IPackageBase here shows how unclear things become without it. I'll open an issue for this.