-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fixes #1313 # Description Construct an rch-package from iMOD5 data in the CAP package, loaded with the ``open_projectfile_data`` function. Package is used to couple MODFLOW6 to MetaSWAP models. Active cells will have a recharge rate of 0.0. At the moment, MetaSWAP can only be coupled to the first layer, as this is also the case for ``primod``. iMOD Coupler these days supports coupling to other layers as well, but ``primod`` doesn't. Picking this up for iMOD Python and ``primod`` is worthy a separate story. In detail: - Add ``Recharge.from_imod5_cap_data`` class method, to construct an empty Recharge package with 0.0 rate. - Minor refactor: Put ``GridData`` helper functions to ``msw/utilities/imod5_converter.py``, so that they can be reused. # Checklist - [x] Links to correct issue - [x] Update changelog, if changes affect users - [x] PR title starts with ``Issue #nr``, e.g. ``Issue #737`` - [x] Unit tests were added - [ ] **If feature added**: Added/extended example
- Loading branch information
1 parent
9096c42
commit 8461d63
Showing
6 changed files
with
163 additions
and
66 deletions.
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