Deltares / Deltares/imod-python

[FEATURE] - Add reader for LAK STAGE FILEOUT binary file

Open
#1,753 7 comments 0 reactions 1 assignee View on GitHub

@JoerivanEngelen is already working on this.

Since Jan 14, 2026.

enhancement
Dominant language
Python
Stars
41
Forks
12
Avg merge
21h 8m
Merged PRs (30d)
1

Description

Title
Feature request: imod.mf6 utility to read LAK stagefile.bin into an xarray object
Problem
To visualise seasonal lake dynamics, we need time series of lake stage per stress period.
When lake.lak, options contains 'STAGE FILEOUT C:/.../stagefile.bin', then MF6 writes the binary file stagefile.bin. Alas, iMOD Python lacks a function to read the written binary file.
Solution
Proposed API
• imod.mf6.read_lak_stage(path, nlakes=None) -> xr.DataArray
o dims: ("time", "lake")
o coords: time from tdis, lake as 1..NLAKES (or names if available)
o dtype: float64
Reference structure (tested)
Each record contains:
• int32 kstp, int32 kper, float64 pertim, float64 totim
• 16-char text label ("STAGE")
• int32 n1, int32 n2, int32 n3 (counters)
• then float64 stage values (NLAKES entries)
Minimal reader we used (works for 1 lake)

import struct
from pathlib import Path

def read_lak_stagebin(bin_path: Path):
    recs = []
    with open(bin_path, "rb") as f:
        while True:
            hdr = f.read(24)
            if len(hdr) < 24:
                break
            kstp, kper, pertim, totim = struct.unpack("<iid d".replace(" ",""), hdr)
            label = f.read(16).decode("ascii", "ignore").strip()
            if label.upper() != "STAGE":
                raise ValueError(f"Unexpected label: {label!r}")
            f.read(12)  # three int32
            stage = struct.unpack("<d", f.read(8))[0]
            recs.append((kper, kstp, pertim, totim, stage))
    return recs

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.