Skip to content

Update openBoreHoles plugin to current mikeio API - #13

Merged
watermain merged 2 commits into
mainfrom
minor/mikeIoUpdate
Sep 10, 2026
Merged

watermain merged 2 commits into
mainfrom
minor/mikeIoUpdate

Conversation

@watermain

Copy link
Copy Markdown
Collaborator

Problem

A user reported that Plugins/openBoreHoles.py fails against a current mikeio.

The dfs0 result writing in preLeaveSimulator() used mikeio''s legacy constructor:

ds = mikeio.Dataset(data=[bh.heads for bh in bhs], time=times, items=items)

Dataset.__init__ now accepts only a mapping or sequence of DataArray, so this raises:

TypeError: Dataset.__init__() got an unexpected keyword argument ''time''

This is a fatal end-of-run failure: the heads are buffered in memory for the whole simulation and
written only at preLeaveSimulator(), so a full simulation completes and then throws away every
bore hole head it collected.

Fix

Build one DataArray per bore hole, each carrying its own time axis and ItemInfo, and pass the
list to Dataset — the same idiom the other plugins in Plugins/ already use.

Checked but unchanged

Still valid in mikeio 3, so left alone:

  • read_layer_bottoms(): mikeio.read(fn, items=item)[0].values[0] still yields (z, y, x), so the
    existing np.transpose to (x, y, z) stays correct.
  • ItemInfo(name, itemtype=EUMType.Water_Level) — unchanged signature.
  • to_dfs(fname, title=title) — title still reaches write_dfs0 via **kwargs.

A grep of the repo confirms openBoreHoles.py was the only file using the removed constructor.

Verification

Ran the patched block verbatim against mikeio 3.0.1 on python 3.14 with stub bore holes, covering a
NaN series (which __closed_solution produces when no layer has leakage) and non-equidistant time
steps. Round trip gives correct item names, Water Level / meter typing, correct timestamps, and
values matching to float32 with NaN preserved.

Not run: a full MIKE SHE simulation with a real bore hole config — worth a smoke test on a real setup
before merge.

Note on the second commit

CLAUDE.md (repo orientation for Claude Code) is a separate commit and unrelated to the mikeio fix
beyond one paragraph about mikeio version churn. Drop that commit if you would rather it went in on
its own.

🤖 Generated with Claude Code

watermain and others added 2 commits September 1, 2026 14:24
The dfs0 result writing used the legacy Dataset(data=, time=, items=)
constructor, which was removed in mikeio 3. Calling it raises
"TypeError: Dataset.__init__() got an unexpected keyword argument 'time'".

Because the write happens in preLeaveSimulator(), the failure hit at the
very end of a run and discarded all bore hole heads collected during the
simulation.

Build one DataArray per bore hole and pass the list to Dataset, matching
the pattern already used by the other plugins in this folder.

Verified against mikeio 3.0.1 on python 3.14, including NaN series (as
the closed solution can produce) and non-equidistant time steps.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Documents the three execution models (engine plugins, MShePy driver
scripts, standalone file tools), the plugin hook lifecycle, the result
file naming convention, the (x,y,z) vs (time,z,y,x) axis-order
difference between MShePy and mikeio, and the non-reentrancy constraint
on running simulations in parallel.

Includes a note to check mikeio signatures against the installed version,
prompted by the Dataset constructor removal fixed in the previous commit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates the openBoreHoles MIKE SHE plugin to be compatible with the current mikeio API, preventing an end-of-run failure when writing buffered bore hole heads to dfs0.

Changes:

  • Replaced legacy mikeio.Dataset(data=..., time=..., items=...) usage with a list of per-borehole mikeio.DataArray objects passed into mikeio.Dataset.
  • Added a “last tested” note to the openBoreHoles.py header.
  • Added CLAUDE.md repository orientation documentation (separate from the functional fix).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Plugins/openBoreHoles.py Updates dfs0 writing to the current mikeio Dataset/DataArray construction pattern to avoid runtime TypeError.
CLAUDE.md Adds repository guidance documenting script/plugin execution model and environment constraints (incl. mikeio API churn context).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Plugins/openBoreHoles.py
@watermain

Copy link
Copy Markdown
Collaborator Author

Tested locally on a real mshe setup, still runs and produces plausible output

@watermain
watermain requested a review from gedaskir September 1, 2026 14:30
@watermain
watermain merged commit 177f771 into main Sep 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants