Skip to content

Commit

Permalink
Merge branch 'master' into imod5_converter_feature_branch
Browse files Browse the repository at this point in the history
# Conflicts:
#	docs/api/changelog.rst
#	imod/mf6/dis.py
#	imod/mf6/drn.py
#	imod/mf6/ic.py
#	imod/mf6/npf.py
#	imod/mf6/oc.py
#	imod/mf6/package.py
#	imod/mf6/rch.py
#	imod/mf6/riv.py
#	imod/mf6/sto.py
#	pixi.lock
  • Loading branch information
luitjansl committed Jun 26, 2024
2 parents 2e7bc85 + 8de3ac1 commit a32ec42
Show file tree
Hide file tree
Showing 25 changed files with 236 additions and 223 deletions.
22 changes: 4 additions & 18 deletions .teamcity/Nightly/NightlyProject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ object NightlyProject : Project({
buildType(NightlyUnitTests)
buildType(NightlyExamples)
buildType(NightlyTests)
buildType(NightlyPipPython310)
buildType(NightlyPipPython311)
buildType(NightlyPipPython312)
buildType(NightlyPipPython)
})

object NightlyLint : BuildType({
Expand All @@ -27,22 +25,10 @@ object NightlyLint : BuildType({
templates(LintTemplate)
})

object NightlyPipPython310 : BuildType({
name = "PipPython310"
object NightlyPipPython : BuildType({
name = "PipPython"

templates(PipPython310Template)
})

object NightlyPipPython311 : BuildType({
name = "PipPython311"

templates(PipPython311Template)
})

object NightlyPipPython312 : BuildType({
name = "PipPython312"

templates(PipPython312Template)
templates(PipPythonTemplate)
})

object NightlyMyPy : BuildType({
Expand Down
46 changes: 46 additions & 0 deletions .teamcity/Templates/PipPythonTemplate.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package Templates

import jetbrains.buildServer.configs.kotlin.DslContext
import jetbrains.buildServer.configs.kotlin.Template
import jetbrains.buildServer.configs.kotlin.buildSteps.script
import jetbrains.buildServer.configs.kotlin.matrix

object PipPythonTemplate : Template({
name = "PipPythonTemplate"

detectHangingBuilds = false

vcs {
root(DslContext.settingsRoot, "+:. => imod-python")

cleanCheckout = true
}

steps {
script {
name = "Pip install python"
id = "pip_install"
workingDir = "imod-python"
scriptContent = """
pixi run --environment %python_env% --frozen test_import
""".trimIndent()
formatStderrAsError = true
}
}

requirements {
equals("env.OS", "Windows_NT")
}

features {
matrix {
param(
"python_env", listOf(
value("py310", label = "python 3.10"),
value("py311", label = "python 3.11"),
value("py312", label = "python 3.12")
)
)
}
}
})
89 changes: 0 additions & 89 deletions .teamcity/Templates/PipPythonTemplates.kt

This file was deleted.

34 changes: 6 additions & 28 deletions .teamcity/_Self/MainProject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@ object MainProject : Project({
buildType(MyPy)
buildType(UnitTests)
buildType(Examples)
buildType(PipPython310)
buildType(PipPython311)
buildType(PipPython312)
buildType(PipPython)
buildType(Tests)

template(GitHubIntegrationTemplate)
template(LintTemplate)
template(MyPyTemplate)
template(UnitTestsTemplate)
template(ExamplesTemplate)
template(PipPython310Template)
template(PipPython311Template)
template(PipPython312Template)
template(PipPythonTemplate)

features {
buildTypeCustomChart {
Expand Down Expand Up @@ -129,22 +125,10 @@ object Examples : BuildType({
}
})

object PipPython310 : BuildType({
name = "PipPython310"
object PipPython : BuildType({
name = "PipPython"

templates(PipPython310Template, GitHubIntegrationTemplate)
})

object PipPython311 : BuildType({
name = "PipPython311"

templates(PipPython311Template, GitHubIntegrationTemplate)
})

object PipPython312 : BuildType({
name = "PipPython312"

templates(PipPython312Template, GitHubIntegrationTemplate)
templates(PipPythonTemplate, GitHubIntegrationTemplate)
})

object Tests : BuildType({
Expand Down Expand Up @@ -181,13 +165,7 @@ object Tests : BuildType({
}

dependencies {
snapshot(PipPython310) {
onDependencyFailure = FailureAction.FAIL_TO_START
}
snapshot(PipPython311) {
onDependencyFailure = FailureAction.FAIL_TO_START
}
snapshot(PipPython312) {
snapshot(PipPython) {
onDependencyFailure = FailureAction.FAIL_TO_START
}
snapshot(Examples) {
Expand Down
7 changes: 7 additions & 0 deletions docs/api/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ Changed
:class:`imod.mf6.regrid.StorageCoefficientRegridMethod`.


Fixed
~~~~~
- :func:`imod.formats.prj.open_projectfile_data` now reports the path to a
faulty IPF or IDF file in the error message.




[0.17.1] - 2024-05-16
---------------------
Expand Down
17 changes: 11 additions & 6 deletions examples/mf6/Henry.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,25 @@

# %%
# ... and the constant flux condition.
from imod.prepare.layer import create_layered_top

screen_top = create_layered_top(bottom, top)

flux_concentration = xr.DataArray(
data=np.full((1, nlay), min_concentration),
dims=["species", "cell"],
coords={"species": ["salinity"], "cell": layer},
dims=["species", "index"],
coords={"species": ["salinity"], "index": layer},
)

gwf_model["left_boundary"] = imod.mf6.WellDisStructured(
layer=layer,
row=np.full_like(layer, 1, dtype=int),
column=np.full_like(layer, 1, dtype=int),
gwf_model["left_boundary"] = imod.mf6.Well(
x=np.full_like(layer, xmin, dtype=float),
y=np.full_like(layer, y[0], dtype=float),
screen_top=screen_top.values,
screen_bottom=bottom.values,
rate=np.full_like(layer, 0.5 * (total_flux / nlay), dtype=float),
concentration=flux_concentration,
concentration_boundary_type="AUX",
minimum_thickness=0.002,
)

# %%
Expand Down
21 changes: 17 additions & 4 deletions imod/formats/prj/prj.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,20 @@ def _merge_coords(headers: List[Dict[str, Any]]) -> Dict[str, np.ndarray]:
return {k: np.unique(coords[k]) for k in coords}


def _try_read_with_func(func, path, *args, **kwargs):
try:
return func(path, *args, **kwargs)
except Exception as e:
raise type(e)(f"{e}. Error thrown while opening file: {path}")


def _create_datarray_from_paths(paths: List[str], headers: List[Dict[str, Any]]):
da = imod.formats.array_io.reading._load(
paths, use_cftime=False, _read=imod.idf._read, headers=headers
da = _try_read_with_func(
imod.formats.array_io.reading._load,
paths,
use_cftime=False,
_read=imod.idf._read,
headers=headers,
)
return da

Expand Down Expand Up @@ -786,7 +797,7 @@ def _read_package_ipf(

# Ensure the columns are identifiable.
path = Path(entry["path"])
ipf_df, indexcol, ext = imod.ipf._read_ipf(path)
ipf_df, indexcol, ext = _try_read_with_func(imod.ipf._read_ipf, path)
if indexcol == 0:
# No associated files
columns = ("x", "y", "rate")
Expand All @@ -801,7 +812,9 @@ def _read_package_ipf(
for row in ipf_df.itertuples():
filename = row[indexcol]
path_assoc = path.parent.joinpath(f"{filename}.{ext}")
df_assoc = imod.ipf.read_associated(path_assoc).iloc[:, :2]
df_assoc = _try_read_with_func(
imod.ipf.read_associated, path_assoc
).iloc[:, :2]
df_assoc.columns = ["time", "rate"]
df_assoc["x"] = row[1]
df_assoc["y"] = row[2]
Expand Down
10 changes: 5 additions & 5 deletions imod/mf6/boundary_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pathlib
import warnings
from copy import copy, deepcopy
from typing import Mapping, Optional, Union
from typing import List, Mapping, Optional, Tuple, Union

import numpy as np
import xarray as xr
Expand Down Expand Up @@ -369,12 +369,12 @@ def fill_stress_perioddata(self):

class DisStructuredBoundaryCondition(BoundaryCondition):
def _to_struct_array(self, arrdict, layer):
spec = []
spec: List[Tuple[str, np.int32 | np.float64]] = []
for key in arrdict:
if key in ["layer", "row", "column"]:
spec.append((key, np.int32))
spec.append((key, np.int32)) # type: ignore[arg-type]
else:
spec.append((key, np.float64))
spec.append((key, np.float64)) # type: ignore[arg-type]

sparse_dtype = np.dtype(spec)
nrow = next(iter(arrdict.values())).size
Expand All @@ -391,7 +391,7 @@ def _to_struct_array(self, arrdict, layer):
if key in ["layer", "cell2d"]:
spec.append((key, np.int32))
else:
spec.append((key, np.float64))
spec.append((key, np.float64)) # type: ignore[arg-type]

sparse_dtype = np.dtype(spec)
nrow = next(iter(arrdict.values())).size
Expand Down
4 changes: 2 additions & 2 deletions imod/mf6/dis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pathlib
from dataclasses import asdict
from typing import List, Optional
from typing import Any, List, Optional

import numpy as np

Expand Down Expand Up @@ -125,7 +125,7 @@ def _delrc(self, dx):

def render(self, directory, pkgname, globaltimes, binary):
disdirectory = pathlib.Path(directory) / pkgname
d = {}
d: dict[str, Any] = {}
x = self.dataset["idomain"].coords["x"]
y = self.dataset["idomain"].coords["y"]
dx, xmin, _ = imod.util.spatial.coord_reference(x)
Expand Down
4 changes: 2 additions & 2 deletions imod/mf6/ic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import warnings
from dataclasses import asdict
from typing import Optional
from typing import Any, Optional

import numpy as np

Expand Down Expand Up @@ -88,7 +88,7 @@ def __init__(self, start=None, head=None, validate: bool = True):
self._validate_init_schemata(validate)

def render(self, directory, pkgname, globaltimes, binary):
d = {}
d: dict[str, Any] = {}

icdirectory = directory / pkgname
d["layered"], d["strt"] = self._compose_values(
Expand Down
Loading

0 comments on commit a32ec42

Please sign in to comment.