This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
ModelSkill is a Python package for evaluating model skill by comparing simulation results with observations. It's primarily used for MIKE models but supports other models as well. The package handles various types of spatial and temporal data (point observations, tracks, gridded fields, DFSU files) and provides comprehensive statistical analysis and visualization.
This project uses uv for dependency management. Install dependencies with:
uv sync --group dev # Install with dev dependencies
uv sync --group test # Install with test dependenciesjust test # Run all tests (ignores notebooks)
pytest # Direct pytest invocation
pytest tests/test_comparer.py::test_name # Run specific test
pytest --disable-warnings # Run without warnings (default in justfile)just check # Run all checks: lint, typecheck, test, doctest
just lint # Lint with ruff
just format # Format with ruff
just typecheck # Type check with mypy
just doctest # Run doctests in metrics.py
just coverage # Generate HTML coverage reportjust build # Run typecheck and test, then build package with uv build
uv build # Build wheel and sdistjust docs # Build documentation with quartodoc and quarto
# Located in docs/_site after buildingAfter editing any file in roadmap/features/, regenerate the overview:
uv run roadmap/scripts/generate_overview.pyThis updates roadmap/README.md from the feature frontmatter.
- All docstrings use NumPy format (not Google or reStructuredText style)
- Include sections: Parameters, Returns, Raises, Examples, See Also, Notes as appropriate
- Example:
def function_name(param1, param2): """Short description. Longer description if needed. Parameters ---------- param1 : type Description of param1 param2 : type Description of param2 Returns ------- type Description of return value """
Key architectural decisions are documented in the /adr directory. These ADRs explain the rationale behind major design choices including:
- Why mikeio is a core dependency
- The centralized metrics module approach
- The Comparer/ComparerCollection pattern
- Using xarray for internal data structures
- The model result type hierarchy
- Supporting dual plotting backends
- The four-step workflow pattern
- The options and styling system
- Factory pattern for type detection
See /adr/README.md for the complete index.
The package follows a consistent 4-step workflow that users should follow:
- Define ModelResults - Load/create model output data
- Define Observations - Load/create observation data
- Match - Spatially and temporally match observations with model results
- Compare - Analyze and visualize using Comparer/ComparerCollection objects
Model results represent simulation output. Types inherit from a base class:
PointModelResult- Fixed point timeseries (dfs0, nc, DataFrame)TrackModelResult- Moving point timeseries (dfs0, nc, DataFrame)GridModelResult- Regular gridded fields (dfs2, nc, xarray Dataset) - extractable via spatial interpolationDfsuModelResult- Unstructured mesh fields (dfsu files) - extractable via spatial interpolationDummyModelResult- Synthetic baseline for skill comparison (e.g., mean, climatology)
Use model_result() factory function to auto-detect type from input data.
Observations represent measured data:
PointObservation- Fixed location timeseriesTrackObservation- Moving location timeseries (e.g., satellite altimetry)
Use observation() factory function to auto-detect type from input data.
The match() function aligns observations with model results in space and time:
- Spatial matching: extracts model data at observation locations (for Grid/Dfsu)
- Temporal matching: aligns timestamps within tolerance
- Returns
Comparer(single obs) orComparerCollection(multiple obs)
Can also use from_matched() when data is pre-aligned.
The core analysis objects after matching:
Comparer- Single observation vs model result(s) comparison- Contains matched xarray Dataset with observation and model data
- Has
.plotattribute (ComparerPlotter) for visualization - Provides
.skill()method returning SkillTable - Supports filtering, selecting, and aggregation
ComparerCollection- Multiple Comparers for multi-observation analysis- Dictionary-like access to individual Comparers
- Has
.plotattribute (ComparerCollectionPlotter) for multi-obs plots - Aggregated skill across observations
metrics.py- All statistical metrics (bias, rmse, r2, skill scores, etc.)- Supports both scalar and directional (circular) metrics
- Add custom metrics by registering functions
SkillTable- DataFrame-like container for skill assessment results- Multi-level indexing support (observation, model, variable, etc.)
- Styled HTML output for reports
- Plotting capabilities for metric visualization
Visualization modules:
_scatter.py- Scatter plots for model vs observation_spatial_overview.py- Maps showing observation locations_temporal_coverage.py- Timeline plots of data availability_taylor_diagram.py- Taylor diagrams for skill visualization_wind_rose.py- Directional data visualization
Plots support both matplotlib (static) and plotly (interactive) backends.
from_config() allows workflow definition via YAML/dict for reproducibility.
- Internal data storage uses xarray Datasets with standardized coordinate/variable names
- Time coordinates use pandas datetime64
- Spatial coordinates:
x,y(andzwhen applicable) - Reserved names in
_RESERVED_NAMESshould not be used for model/observation names - The
Quantityclass handles physical quantities with units and validation
test_*.py- Main unit testsmodel/- Model result loading testsobservation/- Observation loading testsintegration/- End-to-end workflow testsplot/- Visualization testsregression/- Regression test datatestdata/- Sample data files (symlinked from docs/data)
- The package depends on MIKE IO (
mikeio) for reading MIKE file formats (dfs0, dfs2, dfsu) - Type checking with mypy ignores errors in
metrics.pymodule (see pyproject.toml) - Notebooks in
notebooks/are excluded from pytest by default (pytest.ini) - Documentation uses Quarto with quartodoc for API reference generation
- Python 3.10+ required; supports through 3.13