Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9ea9075
Optimize modelsplitter
Manangka Oct 13, 2025
07cad1a
Remove old slice_model method
Manangka Oct 14, 2025
0b631fa
Clean up modelsplitter
Manangka Oct 14, 2025
29b6f8d
Refactor modelsplitter
Manangka Oct 14, 2025
5457c49
Add documentation to the split method. More cleaning up
Manangka Oct 14, 2025
6b71831
Fix incorrect use of item()
Manangka Oct 14, 2025
f72c774
Directly call any() on the dask array
Manangka Oct 14, 2025
c201314
Fix regrid error due to use of wrong interface
Manangka Oct 14, 2025
f19553c
Rvert to earlier more efficient evaluation of has_overlap. Optimize r…
Manangka Oct 15, 2025
9a99506
Revert chunk optimization when opening zarr or nc files. Its not genr…
Manangka Oct 15, 2025
372c1f7
Merge branch 'master' into model_splitter_optimization
Manangka Oct 15, 2025
8567903
Apply review comment
Manangka Oct 16, 2025
cbe5624
Fix incorrect order of removing non-spatial dims
Manangka Oct 16, 2025
f37972f
Fix lint error
Manangka Oct 16, 2025
a32e989
Refactor updating of th buy and ssm package after splitting. Refactor…
Manangka Oct 17, 2025
04f746e
Add comments to the ModelSplitter class
Manangka Oct 17, 2025
ba1e808
Add chunking when opening netcdf files. Handle errors for code that d…
Manangka Oct 20, 2025
67ca384
Merge branch 'master' into model_splitter_optimization
Manangka Oct 20, 2025
e86f735
Move logic to test whether to skip a package into its own method. Do …
JoerivanEngelen Oct 28, 2025
1967f2d
Rename to update_dependent_packages
JoerivanEngelen Oct 28, 2025
c265e41
Reflow paragraphs to 80 characters.
JoerivanEngelen Oct 28, 2025
dd47d59
Change hardcoded reference to "index" to call to .is_empty()
JoerivanEngelen Oct 28, 2025
0273210
Add trim_time_dimension logic to ModelSplitter
JoerivanEngelen Oct 28, 2025
5afc773
format
JoerivanEngelen Oct 28, 2025
7f87bf6
Fix mypy errors
JoerivanEngelen Oct 28, 2025
037bd18
revert toml and lock file
JoerivanEngelen Oct 28, 2025
d5129f7
Merge branch 'master' into model_splitter_optimization
JoerivanEngelen Oct 28, 2025
86fd4a4
Update changelog
JoerivanEngelen Oct 28, 2025
6df0093
Reduce cognitive load a bit
JoerivanEngelen Oct 29, 2025
59157e0
Merge branch 'master' into model_splitter_optimization
JoerivanEngelen Oct 29, 2025
e8ce8f5
Merge branch 'model_splitter_optimization' into issue_#1698_model_wri…
JoerivanEngelen Oct 29, 2025
9b9ac40
Merge branch 'master' into issue_#1698_model_write_optimization
JoerivanEngelen Oct 29, 2025
01deede
Move compute upwards
JoerivanEngelen Oct 30, 2025
2eda736
Move string conversion to base class deserialization; remove redundan…
JoerivanEngelen Oct 30, 2025
8d48854
Remove ruff warning
JoerivanEngelen Oct 30, 2025
b1e9bd2
Remove NETCDF4 format specification from HFB to_netcdf call
JoerivanEngelen Oct 30, 2025
f68f2b5
Fix broken test with extra compute call
JoerivanEngelen Oct 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion imod/mf6/oc.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _render(self, directory, pkgname, globaltimes, binary):
package_times = self.dataset[datavar].coords["time"].values
starts = np.searchsorted(globaltimes, package_times) + 1
for i, s in enumerate(starts):
setting = self.dataset[datavar].isel(time=i).item()
setting = self.dataset[datavar].isel(time=i).values[()]
periods[s][key] = self._get_ocsetting(setting)

else:
Expand Down
21 changes: 20 additions & 1 deletion imod/mf6/pkgbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ def to_netcdf(
kwargs.update({"encoding": self._netcdf_encoding()})

dataset = self.dataset

# Create encoding dict for float16 variables
for var in dataset.data_vars:
if dataset[var].dtype == np.float16:
kwargs["encoding"][var] = {"dtype": "float32"}

# Also check coordinates
for coord in dataset.coords:
if dataset[coord].dtype == np.float16:
kwargs["encoding"][coord] = {"dtype": "float32"}

if isinstance(dataset, xu.UgridDataset):
if mdal_compliant:
dataset = dataset.ugrid.to_dataset()
Expand Down Expand Up @@ -168,7 +179,7 @@ def from_file(cls, path: str | Path, **kwargs) -> Self:
# TODO: seems like a bug? Remove str() call if fixed in xarray/zarr
dataset = xr.open_zarr(str(path), **kwargs)
else:
dataset = xr.open_dataset(path, **kwargs)
dataset = xr.open_dataset(path, chunks="auto", **kwargs)

if dataset.ugrid_roles.topology:
dataset = xu.UgridDataset(dataset)
Expand All @@ -183,4 +194,12 @@ def from_file(cls, path: str | Path, **kwargs) -> Self:
if _is_scalar_nan(value):
dataset[key] = None

# to_netcdf converts strings into NetCDF "variable‑length UTF‑8 strings"
# which are loaded as dtype=object arrays. This will convert them back
# to str.
vars = ["species"]
for var in vars:
if var in dataset:
dataset[var] = dataset[var].astype(str)

return cls._from_dataset(dataset)
10 changes: 8 additions & 2 deletions imod/mf6/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
from imod.typing import GridDataArray, GridDataset
from imod.typing.grid import (
concat,
is_equal,
is_same_domain,
is_unstructured,
merge_partitions,
)
Expand Down Expand Up @@ -1622,10 +1622,16 @@ def _get_transport_models_per_flow_model(self) -> dict[str, list[str]]:

for flow_model_name in flow_models:
flow_model = self[flow_model_name]

matched_tsp_models = []
for tpt_model_name in transport_models:
tpt_model = self[tpt_model_name]
if is_equal(tpt_model.domain, flow_model.domain):
if is_same_domain(tpt_model.domain, flow_model.domain):
result[flow_model_name].append(tpt_model_name)
matched_tsp_models.append(tpt_model_name)
for tpt_model_name in matched_tsp_models:
transport_models.pop(tpt_model_name)

return result

def _generate_gwfgwt_exchanges(self) -> list[GWFGWT]:
Expand Down
8 changes: 4 additions & 4 deletions imod/mf6/wel.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def _to_mf6_package_information(
else:
message += " The first 10 unplaced wells are: \n"

is_filtered = self.dataset["id"].isin([filtered_wells])
is_filtered = self.dataset["id"].compute().isin(filtered_wells)
for i in range(min(10, len(filtered_wells))):
ids = filtered_wells[i]
x = self.dataset["x"].data[is_filtered][i]
Expand Down Expand Up @@ -1073,9 +1073,9 @@ def _assign_wells_to_layers(
) -> pd.DataFrame:
# Ensure top, bottom & k
# are broadcasted to 3d grid
like = ones_like(active)
bottom = like * bottom
top_2d = (like * top).sel(layer=1)
like = ones_like(active.compute())
bottom = like * bottom.compute()
top_2d = (like * top.compute()).sel(layer=1)
top_3d = bottom.shift(layer=1).fillna(top_2d)
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that this is necessary! I think we can probably load top and bottom in the beginning of the function? Then it is more explicit and performance for consecutive computations will be faster.

k = like * k

Expand Down
4 changes: 4 additions & 0 deletions imod/typing/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,15 @@ def is_spatial_grid(_: Any) -> bool: # noqa: F811

@dispatch
def is_equal(array1: xu.UgridDataArray, array2: xu.UgridDataArray) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice optimization shortcut!

if not is_same_domain(array1, array2):
return False
return array1.equals(array2) and array1.ugrid.grid.equals(array2.ugrid.grid)


@dispatch # type: ignore[no-redef]
def is_equal(array1: xr.DataArray, array2: xr.DataArray) -> bool: # noqa: F811
if not is_same_domain(array1, array2):
return False
return array1.equals(array2)


Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ ignore = [
"E501", # line-too-long. This rule can't be fullfilled by the ruff formatter. The same behavior as black.
"PD003",
"PD004",
"PD901",
"PD011",
"PD013",
"PD015",
Expand Down