FloPy is a Python package to create, run, and post-process MODFLOW-based models
Agent Success
Agent success rate when using this tile
66%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.14x
Baseline
Agent success rate without this tile
58%
Build a utility that reads binary groundwater model output files generated on different computer architectures, handling byte-order differences automatically.
Groundwater modeling software generates binary output files containing numerical simulation results (hydraulic heads, flow rates, etc.). These files may be created on different computer systems with different byte orders (big-endian vs little-endian). Your task is to create a reader that can correctly interpret these files regardless of the platform where they were created.
The binary files follow this structure:
Header record (repeats for each time step):
kstp (4-byte integer): time step numberkper (4-byte integer): stress period numberpertim (4-byte float): elapsed time in current stress periodtotim (4-byte float): total elapsed timetext (16-byte string): description text (e.g., 'HEAD')ncol (4-byte integer): number of columnsnrow (4-byte integer): number of rowsilay (4-byte integer): layer numberData record (follows each header):
ncol * nrow)Create a function detect_file_endianness(filename) that:
Create a class BinaryFileReader that:
get_data(idx=0) to retrieve data arrays by indexget_times() to list all available time valuesYour detection algorithm should validate that:
detect_file_endianness function correctly identifies little-endian format @testdetect_file_endianness function correctly identifies big-endian format @test@generates
def detect_file_endianness(filename: str) -> str:
"""
Detect byte order of a binary file.
Args:
filename: Path to binary file
Returns:
'little' or 'big' indicating detected byte order
Raises:
ValueError: If file format cannot be determined
"""
pass
class BinaryFileReader:
"""
Reader for cross-platform binary groundwater model files.
"""
def __init__(self, filename: str, precision: str = 'single'):
"""
Initialize reader with automatic byte-order detection.
Args:
filename: Path to binary file
precision: 'single' or 'double' for float precision
"""
pass
def get_data(self, idx: int = 0) -> tuple:
"""
Get data array for specified record index.
Args:
idx: Record index (0-based)
Returns:
tuple: (header_dict, data_array) where header_dict contains
metadata (kstp, kper, pertim, totim, text, ncol, nrow, ilay)
and data_array is a 2D numpy array of shape (nrow, ncol)
"""
pass
def get_times(self) -> list:
"""
Get list of all simulation times in file.
Returns:
list: Simulation time values (totim from each record)
"""
passProvides utilities for reading and processing MODFLOW binary output files with cross-platform byte-order handling.
tessl i tessl/pypi-flopy@3.9.0docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10