Catalog#
- class hydromodpy.results.Catalog(workspace_path, *, catalog_path=None, runs_dir=None, persistence=None, read_only=False)[source]#
Bases:
LifecycleMixin,RegistrationMixin,WritesMixin,ReadsMixin,DiscoveryMixin,SchemaDiscoveryMixin,PackageIOMixinWorkspace-level catalog of finished simulations.
Backed by DuckDB for tabular state (simulations, parameters, metrics, provenance, calibration sessions) and by Zarr / Parquet for field arrays and timeseries written under
<project>/runs/<run>/.Inspecting is reading: every caller that only reads (listings,
show, SQL queries, figures, reports) opens withread_only=True, which installs no schema, runs no migration and leaves the index file byte for byte as it found it. A writable handle is for code that produces runs.The facade owns four pieces of state:
_db: aCatalogConnection(lazy DuckDB connection released while idle, re-acquired with retry on contention)._workspace: the project catalog root._paths: aStoragePathResolvertranslating simulation ids to run directories and the Parquet/Zarr paths they hold._open_zarr_handles: liveSimulationZarrhandles, tracked sofinalizeandclosecan release them deterministically.
Parameters#
- workspace_path
Workspace directory, or direct path to a
.duckdbcatalog file.- catalog_path
Optional explicit catalog database path.
- runs_dir
Optional directory containing the per-run directories.
- persistence
Which sinks the catalog writes to (index rows, Zarr fields, Parquet tables) and how they are compressed. Field arrays are always a directory store: there is no packed form.
- read_only
Open the index read-only. The database file must already exist: an inspection never creates a phantom index.
Raises#
- hydromodpy.core.exceptions.CatalogError
If the DuckDB catalog cannot be opened or the schema migration fails.
- hydromodpy.results.errors.SchemaVersionMismatchError
If the stored catalog schema version is older than the runtime expects.
Examples#
>>> import hydromodpy as hmp >>> catalog = hmp.open("~/hmp_workspace") >>> latest = catalog.latest() >>> latest.summary()
See Also#
- hydromodpy.results.run.Run
Per-simulation view returned by catalog queries.
- hydromodpy.results.run.group.RunSet
Multi-run view returned by cohort queries.
- param workspace_path:
- type workspace_path:
Path|str- param catalog_path:
- type catalog_path:
- param runs_dir:
- type runs_dir:
- param persistence:
- type persistence:
PersistenceConfig|None- param read_only:
- type read_only:
- classmethod from_workspace(workspace, *, persistence=None)[source]#
Open the project catalog declared by a runtime workspace object.
Parameters#
- workspace
Object exposing
project_root,catalog_path, andruns_dir.- persistence
Optional storage policy.
Returns#
- Catalog
Open catalog connected to the workspace database.
- classmethod from_workspace_config(workspace, *, persistence=None)[source]#
Open the project catalog declared by a workspace configuration.
Parameters#
- workspace
Workspace configuration object.
- persistence
Optional storage policy.
Returns#
- Catalog
Open catalog connected to the configured workspace.
- classmethod from_toml(toml_path)[source]#
Open the project catalog declared in a TOML config.
Parameters#
- toml_path
HydroModPy TOML file with a workspace section.
Returns#
- Catalog
Open catalog connected to the resolved workspace.
Raises#
- FileNotFoundError
If the TOML path does not exist.
- ConfigValidationError
If the TOML payload fails Pydantic validation.
- param toml_path:
- type toml_path:
str|Path
- classmethod from_json(payload)[source]#
Open the project catalog declared in a JSON config string.
Parameters#
- payload
JSON payload validated against
HydroModPyConfig.
Returns#
- Catalog
Open catalog connected to the resolved workspace.
Raises#
- ConfigValidationError
If the JSON payload fails validation.
- classmethod from_dict(payload)[source]#
Open the project catalog declared in a dict config payload.
Parameters#
- payload
Mapping validated against
HydroModPyConfig.
Returns#
- Catalog
Open catalog connected to the resolved workspace.
Raises#
- ConfigValidationError
If the mapping fails Pydantic validation.
- param payload:
- type payload:
- property connection: CatalogConnection#
Return the DuckDB connection handle for protocol-based integrations.
- property backend: CatalogBackend#
Return the storage backend port driving SQL reads and writes.
- property sessions: CalibrationSessionNamespace#
Session-level verbs, composed rather than stapled onto this facade.
- property workspace_path: Path#
Workspace directory that owns this catalog.
- property catalog_path: Path#
Path to the project index database.
- property runs_dir: Path#
Directory holding one sub-directory per run.
- property project_path: Path#
Alias for
workspace_pathkept for protocol integrations.
- load_dataset(filters=None, *, fields=None, include_params=True, include_metrics=True, include_env=True)[source]#
Return one
xr.Datasetjoining scalars and Zarr fields.Composition entry-point for ML/DL pipelines: bundles parameters, metrics,
runs_environmentmetadata, and (optionally) lazy Zarr fields into a singlexarray.Datasetindexed bysim_id. Seehydromodpy.results.catalog.dataset_loader.DatasetLoader.- Return type:
- Parameters:
Parameters#
- filters
Catalog filters used to select the simulation cohort.
- fields
Optional field names to include from Zarr stores.
- include_params
Include parameter columns in the dataset.
- include_metrics
Include metric columns in the dataset.
- include_env
Include runtime environment metadata.
Returns#
- xarray.Dataset
Dataset indexed by
sim_idwith scalar tables and optional lazy field arrays.
- property frame#
Every simulation as one DataFrame row (alias of
list_simulations).
- read(ref, var, *, time=None, layer=None, sel=None, bbox=None)[source]#
Read
varfor the run referenced byref(the by-id read path).refis resolved throughresolve()(full UUID, unique prefix, or name). For an already-resolvedRun, usehydromodpy.read().