-
Notifications
You must be signed in to change notification settings - Fork 7
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 recsMetadata
Metadata
Assignees
Labels
Type
Projects
Status