# mhm-ufz/mhm-tools architecture

> Architecture diagram of the GitHub repository mhm-ufz/mhm-tools, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mhm-ufz/mhm-tools
- Repository: https://github.com/mhm-ufz/mhm-tools

## Overview

mHM-Tools is a command-line and Python toolbox for preparing mHM inputs and evaluating model outputs. Its principal workflow is to build or adapt catchment/setup data, prepare forcings and restart-related files, then assess runs against discharge and gridded observations. The graph preserves the documented capability branches and the sampled evaluation and shared-data layers. Evidence is limited to the README and SOURCE INDEX references; unverified command-to-implementation links are dashed.

Main entry points: [`src/mhm_tools/_cli`](https://github.com/mhm-ufz/mhm-tools/tree/main/src/mhm_tools/_cli) (CLI commands), [`src/mhm_tools/post/gridded_data_evaluation.py`](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/post/gridded_data_evaluation.py) (Gridded evaluation), [`src/mhm_tools/common/file_handler.py`](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/file_handler.py) (Raster and file I/O), [`src/mhm_tools/post/discharge_evaluation.py`](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/post/discharge_evaluation.py) (Discharge evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_cli["mhm-tools CLI<br/>[_main.py]"]
  node_cli_commands["CLI commands"]
end

subgraph group_preparation["Setup preparation"]
  node_catchment["Catchment delineation<br/>[catchment.py]"]
  node_setup_ops["Setup and restart tools"]
  node_forcing_ops["Forcing preparation"]
  node_format_ops["Input data formatting"]
end

subgraph group_evaluation["Run evaluation"]
  node_discharge_eval["Discharge evaluation"]
  node_gridded_eval["Gridded evaluation"]
  node_snow_eval["Snow evaluation<br/>[snow_evaluation.py]"]
  node_twsa_eval["Water storage evaluation<br/>[twsa_evaluation.py]"]
  node_comparison["Discharge comparison"]
end

subgraph group_shared["Shared data services"]
  node_io["Raster and file I/O<br/>[file_handler.py]"]
  node_netcdf["NetCDF utilities<br/>[netcdf.py]"]
  node_xarray["Xarray utilities<br/>[xarray_utils.py]"]
  node_resolution["Grid resolution"]
  node_metrics["Metric dispatch<br/>[metrics_handler.py]"]
  node_spaef["SPAEF metric<br/>[spaef.py]"]
  node_plotter["Plotting utilities<br/>[plotter.py]"]
  node_time["Time utilities<br/>[time_utils.py]"]
  node_parallel["Parallel helpers<br/>[parallel.py]"]
  node_esri["ESRI grid support<br/>[esri_grid.py]"]
  node_logger["Logging<br/>[logger.py]"]
  node_units["Unit conversions<br/>[units.py]"]
end

node_user(("Hydrology user"))

node_user -->|"invokes"| node_cli
node_cli -.->|"dispatches"| node_cli_commands
node_cli_commands -.->|"runs delineation"| node_catchment
node_cli_commands -.->|"runs setup tools"| node_setup_ops
node_cli_commands -.->|"runs preparation"| node_forcing_ops
node_cli_commands -.->|"runs formatting"| node_format_ops
node_cli_commands -.->|"runs evaluation"| node_discharge_eval
node_cli_commands -->|"runs evaluation"| node_gridded_eval
node_cli_commands -.->|"runs evaluation"| node_snow_eval
node_cli_commands -.->|"runs evaluation"| node_twsa_eval
node_catchment -->|"uses file helpers"| node_io
node_catchment -->|"uses grid resolution"| node_resolution
node_catchment -->|"uses dataset helpers"| node_xarray
node_setup_ops -->|"reads and writes"| node_io
node_setup_ops -->|"uses grid resolution"| node_resolution
node_setup_ops -->|"uses dataset helpers"| node_xarray
node_discharge_eval -->|"uses evaluation"| node_gridded_eval
node_discharge_eval -->|"uses file helpers"| node_io
node_discharge_eval -->|"uses plots"| node_plotter
node_discharge_eval -->|"uses dataset helpers"| node_xarray
node_gridded_eval -->|"calculates metrics"| node_metrics
node_gridded_eval -->|"creates plots"| node_plotter
node_gridded_eval -->|"uses file helpers"| node_io
node_gridded_eval -->|"uses time helpers"| node_time
node_snow_eval -->|"uses evaluation"| node_gridded_eval
node_twsa_eval -->|"uses evaluation"| node_gridded_eval
node_metrics -->|"calculates SPAEF"| node_spaef
node_io -->|"uses NetCDF helpers"| node_netcdf
node_io -->|"uses dataset helpers"| node_xarray
node_io -->|"uses grid helpers"| node_esri
node_resolution -->|"reads grid files"| node_io
node_resolution -->|"uses coordinate helpers"| node_xarray

click node_cli "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/_cli/_main.py"
click node_cli_commands "https://github.com/mhm-ufz/mhm-tools/tree/main/src/mhm_tools/_cli"
click node_catchment "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/pre/catchment.py"
click node_setup_ops "https://github.com/mhm-ufz/mhm-tools/tree/main/src/mhm_tools/pre"
click node_forcing_ops "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/pre/prepare_mhm_forcings.py"
click node_format_ops "https://github.com/mhm-ufz/mhm-tools/tree/main/src/mhm_tools/pre"
click node_discharge_eval "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/post/discharge_evaluation.py"
click node_gridded_eval "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/post/gridded_data_evaluation.py"
click node_snow_eval "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/post/snow_evaluation.py"
click node_twsa_eval "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/post/twsa_evaluation.py"
click node_comparison "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/post/discharge_eval_comparison.py"
click node_io "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/file_handler.py"
click node_netcdf "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/netcdf.py"
click node_xarray "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/xarray_utils.py"
click node_resolution "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/resolution_handler.py"
click node_metrics "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/metrics/metrics_handler.py"
click node_spaef "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/metrics/spaef.py"
click node_plotter "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/plotter.py"
click node_time "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/time_utils.py"
click node_parallel "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/parallel.py"
click node_esri "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/esri_grid.py"
click node_logger "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/logger.py"
click node_units "https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/units.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_cli_commands,node_user toneBlue
class node_catchment,node_setup_ops,node_forcing_ops,node_format_ops toneAmber
class node_discharge_eval,node_gridded_eval,node_snow_eval,node_twsa_eval,node_comparison toneMint
class node_io,node_netcdf,node_xarray,node_resolution,node_metrics,node_spaef,node_plotter,node_time,node_parallel,node_esri,node_logger,node_units toneRose
```

## Components

### User interface

- [mhm-tools CLI](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/_cli/_main.py): `src/mhm_tools/_cli/_main.py`
- [CLI commands](https://github.com/mhm-ufz/mhm-tools/tree/main/src/mhm_tools/_cli): `src/mhm_tools/_cli`

### Setup preparation

- [Catchment delineation](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/pre/catchment.py): `src/mhm_tools/pre/catchment.py`
- [Setup and restart tools](https://github.com/mhm-ufz/mhm-tools/tree/main/src/mhm_tools/pre): `src/mhm_tools/pre`
- [Forcing preparation](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/pre/prepare_mhm_forcings.py): `src/mhm_tools/pre/prepare_mhm_forcings.py`
- [Input data formatting](https://github.com/mhm-ufz/mhm-tools/tree/main/src/mhm_tools/pre): `src/mhm_tools/pre`

### Run evaluation

- [Discharge evaluation](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/post/discharge_evaluation.py): `src/mhm_tools/post/discharge_evaluation.py`
- [Gridded evaluation](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/post/gridded_data_evaluation.py): `src/mhm_tools/post/gridded_data_evaluation.py`
- [Snow evaluation](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/post/snow_evaluation.py): `src/mhm_tools/post/snow_evaluation.py`
- [Water storage evaluation](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/post/twsa_evaluation.py): `src/mhm_tools/post/twsa_evaluation.py`
- [Discharge comparison](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/post/discharge_eval_comparison.py): `src/mhm_tools/post/discharge_eval_comparison.py`

### Shared data services

- [Raster and file I/O](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/file_handler.py): `src/mhm_tools/common/file_handler.py`
- [NetCDF utilities](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/netcdf.py): `src/mhm_tools/common/netcdf.py`
- [Xarray utilities](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/xarray_utils.py): `src/mhm_tools/common/xarray_utils.py`
- [Grid resolution](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/resolution_handler.py): `src/mhm_tools/common/resolution_handler.py`
- [Metric dispatch](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/metrics/metrics_handler.py): `src/mhm_tools/common/metrics/metrics_handler.py`
- [SPAEF metric](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/metrics/spaef.py): `src/mhm_tools/common/metrics/spaef.py`
- [Plotting utilities](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/plotter.py): `src/mhm_tools/common/plotter.py`
- [Time utilities](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/time_utils.py): `src/mhm_tools/common/time_utils.py`
- [Parallel helpers](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/parallel.py): `src/mhm_tools/common/parallel.py`
- [ESRI grid support](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/esri_grid.py): `src/mhm_tools/common/esri_grid.py`
- [Logging](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/logger.py): `src/mhm_tools/common/logger.py`
- [Unit conversions](https://github.com/mhm-ufz/mhm-tools/blob/main/src/mhm_tools/common/units.py): `src/mhm_tools/common/units.py`

### Other components

- **Hydrology user**

## Connections

- Hydrology user → mhm-tools CLI: invokes
- mhm-tools CLI → CLI commands: dispatches
- CLI commands → Catchment delineation: runs delineation
- CLI commands → Setup and restart tools: runs setup tools (evidence: `src/mhm_tools/_cli/_create_catchment.py`)
- CLI commands → Forcing preparation: runs preparation
- CLI commands → Input data formatting: runs formatting (evidence: `src/mhm_tools/_cli/_create_catchment.py`)
- CLI commands → Discharge evaluation: runs evaluation
- CLI commands → Gridded evaluation: runs evaluation (evidence: `src/mhm_tools/_cli/_gridded_data_evaluation.py`)
- CLI commands → Snow evaluation: runs evaluation
- CLI commands → Water storage evaluation: runs evaluation
- Catchment delineation → Raster and file I/O: uses file helpers (evidence: `src/mhm_tools/pre/catchment.py`)
- Catchment delineation → Grid resolution: uses grid resolution (evidence: `src/mhm_tools/pre/catchment.py`)
- Catchment delineation → Xarray utilities: uses dataset helpers (evidence: `src/mhm_tools/pre/catchment.py`)
- Setup and restart tools → Raster and file I/O: reads and writes (evidence: `src/mhm_tools/pre/create_mhm_restart_from_setup.py`)
- Setup and restart tools → Grid resolution: uses grid resolution (evidence: `src/mhm_tools/pre/create_mhm_restart_from_setup.py`)
- Setup and restart tools → Xarray utilities: uses dataset helpers (evidence: `src/mhm_tools/pre/create_mhm_restart_from_setup.py`)
- Discharge evaluation → Gridded evaluation: uses evaluation (evidence: `src/mhm_tools/post/discharge_evaluation.py`)
- Discharge evaluation → Raster and file I/O: uses file helpers (evidence: `src/mhm_tools/post/discharge_evaluation.py`)
- Discharge evaluation → Plotting utilities: uses plots (evidence: `src/mhm_tools/post/discharge_evaluation.py`)
- Discharge evaluation → Xarray utilities: uses dataset helpers (evidence: `src/mhm_tools/post/discharge_evaluation.py`)
- Gridded evaluation → Metric dispatch: calculates metrics (evidence: `src/mhm_tools/post/gridded_data_evaluation.py`)
- Gridded evaluation → Plotting utilities: creates plots (evidence: `src/mhm_tools/post/gridded_data_evaluation.py`)
- Gridded evaluation → Raster and file I/O: uses file helpers (evidence: `src/mhm_tools/post/gridded_data_evaluation.py`)
- Gridded evaluation → Time utilities: uses time helpers (evidence: `src/mhm_tools/post/gridded_data_evaluation.py`)
- Snow evaluation → Gridded evaluation: uses evaluation (evidence: `src/mhm_tools/post/snow_evaluation.py`)
- Water storage evaluation → Gridded evaluation: uses evaluation (evidence: `src/mhm_tools/post/twsa_evaluation.py`)
- Metric dispatch → SPAEF metric: calculates SPAEF (evidence: `src/mhm_tools/common/metrics/metrics_handler.py`)
- Raster and file I/O → NetCDF utilities: uses NetCDF helpers (evidence: `src/mhm_tools/common/file_handler.py`)
- Raster and file I/O → Xarray utilities: uses dataset helpers (evidence: `src/mhm_tools/common/file_handler.py`)
- Raster and file I/O → ESRI grid support: uses grid helpers (evidence: `src/mhm_tools/common/file_handler.py`)
- Grid resolution → Raster and file I/O: reads grid files (evidence: `src/mhm_tools/common/resolution_handler.py`)
- Grid resolution → Xarray utilities: uses coordinate helpers (evidence: `src/mhm_tools/common/resolution_handler.py`)
