Calibration#
pyiwfm provides a suite of calibration tools that mirror and extend IWFM’s Fortran utilities (IWFM2OBS, CalcTypHyd) with additional capabilities for model file discovery, multi-layer observation well processing, observation well clustering, and publication-quality calibration figures.
Modules#
pyiwfm.io.smpRead and write SMP (Sample/Bore) observation files. The SMP format is IWFM’s standard observation file with bore ID, date/time, value, and optional exclusion flags.
pyiwfm.io.simulation_messagesParse
SimulationMessages.outto extract warnings, errors, and their spatial locations (node, element, reach, layer IDs via regex).pyiwfm.io.hydrograph_readerRead IWFM hydrograph output
.outfiles (GW, stream, subsidence, tile drain).IWFMHydrographReaderparses the*-prefixed header for column metadata and loads time series into NumPy arrays.get_columns_as_smp_dict()bridges.outdata to the interpolation pipeline.pyiwfm.calibration.model_file_discoveryParse an IWFM simulation main file to auto-discover hydrograph
.outfile paths and observation metadata (bore IDs, layers, coordinates). Ports the discovery logic from the old Fortran IWFM2OBS program. Usesiwfm_readerutilities for comment handling and path resolution.pyiwfm.calibration.obs_well_specRead observation well specification files for multi-layer target processing. Each well has a name, coordinates, element ID, and screen top/bottom depths.
pyiwfm.calibration.iwfm2obsLinearly interpolate simulated time series to observation timestamps. For multi-layer wells, compute transmissivity-weighted composite heads using finite element shape functions from
core/interpolation.py.iwfm2obs_from_model()provides an integrated workflow that auto-discovers.outfiles, reads them directly, interpolates, and optionally computes multi-layer T-weighted averages.pyiwfm.calibration.clusteringNumPy-only fuzzy c-means clustering of observation wells. Features combine normalized spatial coordinates with temporal characteristics (amplitude, trend slope, seasonal strength). Configurable spatial/temporal weighting.
pyiwfm.calibration.calctyphydCompute typical hydrograph curves by cluster. Seasonal averaging, de-meaning per well, and membership-weighted combination produce representative seasonal patterns for each cluster. Includes Fortran
.inconfig file parsing (read_calctyphyd_config), time-series output matching the Fortran algorithm (compute_typical_hydrographs_timeseries), PEST.out/.insfile generation (write_pest_output), and date-range filtering. Verified byte-identical vs Fortran on C2VSimFG.pyiwfm.visualization.calibration_plotsPublication-quality composite figures: 1:1 observed-vs-simulated plots, residual histograms, hydrograph comparison panels, metrics tables, water budget summaries, cluster maps, and typical hydrograph curves. All use the
pyiwfm-publication.mplstylestyle sheet.pyiwfm.visualization.plottingIndividual plot functions:
plot_one_to_one()for scatter plots with identity line, regression, and metrics text box;plot_spatial_bias()for diverging-colorbar bias maps with mesh background.
CLI Commands#
# Explicit SMP mode: interpolate simulated heads to observation times
pyiwfm iwfm2obs --obs observed.smp --sim simulated.smp --output interp.smp
# Model discovery mode: auto-discover .out files from simulation main file
pyiwfm iwfm2obs --model C2VSimFG.in --obs-gw gw_obs.smp --output-gw gw_out.smp
# Model mode with stream observations
pyiwfm iwfm2obs --model C2VSimFG.in \
--obs-gw gw_obs.smp --output-gw gw_out.smp \
--obs-stream str_obs.smp --output-stream str_out.smp
# Model mode with multi-layer target processing
pyiwfm iwfm2obs --model C2VSimFG.in \
--obs-gw gw_obs.smp --output-gw gw_out.smp \
--well-spec obs_wells.txt \
--multilayer-out GW_MultiLayer.out \
--multilayer-ins GWHMultiLayer.ins
# Compute typical hydrographs
pyiwfm calctyphyd --water-levels wl.smp --weights weights.txt --output typhyd.smp
# CalcTypHyd with Fortran config file (produces PEST .out/.ins files)
pyiwfm calctyphyd --config CalcTypeHyd.in
# Deduplicate per-layer SMP output (strip %N suffixes)
pyiwfm iwfm2obs --deduplicate-smp GW_OUT.smp --output GW_OUT_dedup.smp
See the Tutorial: Calibration Workflow tutorial for a complete walkthrough.