-
Notifications
You must be signed in to change notification settings - Fork 3
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 #1313 recharge from imod5 cap data #1315
Merged
JoerivanEngelen
merged 10 commits into
issue_#1260_from_imod5_data_metaswap
from
issue_#1313_recharge_from_imod5_cap_data
Dec 3, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4d207e0
Start working on import
JoerivanEngelen a3e5d98
Move util functions to imod5_converter utilities
JoerivanEngelen c520599
Cache cell area utility function for reuse
JoerivanEngelen 942503f
Add Recharge.from_imod5_cap_data classmethod
JoerivanEngelen dddc75e
Revert "Cache cell area utility function for reuse"
JoerivanEngelen b5e1c89
Recharge first layer to zero
JoerivanEngelen fed4b06
Add test for from_imod5_cap_data
JoerivanEngelen a13bc31
Update changelog
JoerivanEngelen ef7aee4
Extend docstring
JoerivanEngelen d58e47e
Add Recharge.from_imod5_cap_data if 'cap' in imod5_data
JoerivanEngelen 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 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 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 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 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 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,87 @@ | ||
from imod.logging import LogLevel, logger | ||
from imod.mf6 import StructuredDiscretization | ||
from imod.msw.utilities.common import concat_imod5 | ||
from imod.typing import GridDataArray, GridDataDict | ||
from imod.typing.grid import ones_like | ||
from imod.util.spatial import get_cell_area | ||
|
||
|
||
def get_cell_area_from_imod5_data( | ||
imod5_cap: GridDataDict, | ||
) -> GridDataArray: | ||
# area's per type of svats | ||
mf6_area = get_cell_area(imod5_cap["wetted_area"]) | ||
wetted_area = imod5_cap["wetted_area"] | ||
urban_area = imod5_cap["urban_area"] | ||
rural_area = mf6_area - (wetted_area + urban_area) | ||
if (wetted_area > mf6_area).any(): | ||
logger.log( | ||
loglevel=LogLevel.WARNING, | ||
message=f"wetted area was set to the max cell area of {mf6_area}", | ||
additional_depth=0, | ||
) | ||
wetted_area = wetted_area.where(wetted_area <= mf6_area, other=mf6_area) | ||
if (rural_area < 0.0).any(): | ||
logger.log( | ||
loglevel=LogLevel.WARNING, | ||
message="found urban area > than (cel-area - wetted area). Urban area was set to 0", | ||
additional_depth=0, | ||
) | ||
urban_area = urban_area.where(rural_area > 0.0, other=0.0) | ||
rural_area = mf6_area - (wetted_area + urban_area) | ||
return concat_imod5(rural_area, urban_area) | ||
|
||
|
||
def get_landuse_from_imod5_data( | ||
imod5_cap: GridDataDict, | ||
) -> GridDataArray: | ||
""" | ||
Get landuse from imod5 capillary zone data. This adds two subunits, one | ||
based on the landuse grid, which specifies rural landuse. The other | ||
specifies urban landuse, which is coded to value 18. | ||
""" | ||
rural_landuse = imod5_cap["landuse"] | ||
# Urban landuse = 18 | ||
urban_landuse = ones_like(rural_landuse) * 18 | ||
return concat_imod5(rural_landuse, urban_landuse) | ||
|
||
|
||
def get_rootzone_depth_from_imod5_data( | ||
imod5_cap: GridDataDict, | ||
) -> GridDataArray: | ||
""" | ||
Get rootzone depth from imod5 capillary zone data. Also does a unit | ||
conversion: iMOD5 specifies rootzone thickness in centimeters, whereas | ||
MetaSWAP requires rootzone depth in meters. | ||
""" | ||
rootzone_thickness = imod5_cap["rootzone_thickness"] * 0.01 | ||
# rootzone depth is equal for both svats. | ||
return concat_imod5(rootzone_thickness, rootzone_thickness) | ||
|
||
|
||
def is_msw_active_cell( | ||
target_dis: StructuredDiscretization, | ||
imod5_cap: GridDataDict, | ||
msw_area: GridDataArray, | ||
) -> tuple[GridDataArray, GridDataArray]: | ||
""" | ||
Return grid of cells that are active in the coupled computation, based on | ||
following criteria: | ||
|
||
- Active in top layer MODFLOW6 | ||
- Active in boundary array in CAP package | ||
- MetaSWAP area > 0 | ||
|
||
Returns | ||
------- | ||
active: xr.DataArray | ||
Active cells in any of the subunits | ||
subunit_active: xr.DataArray | ||
Cells active per subunit | ||
""" | ||
mf6_top_active = target_dis["idomain"].isel(layer=0, drop=True) | ||
subunit_active = ( | ||
(imod5_cap["boundary"] == 1) & (msw_area > 0) & (mf6_top_active >= 1) | ||
) | ||
active = subunit_active.any(dim="subunit") | ||
return active, subunit_active |
This file contains 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
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.
I would reconsider the place you put you converter code. The Recharge package now needs to now about the imod5 model. What would happen if we add another converter e.g. flopy? Then mf6 module also needs to know about that.
I would recommend moving all the converter code to a separate module. And in that module the code then knows about the imod5 data/packages and the mf6 data/packages
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.
I agree, but it would be too large of a task to fix in this PR. I created a separate issue for this: #1319