climate_ref.results.datasets
#
Typed, detached read surface for datasets.
DatasetsReader is reached via
Reader.datasets. It executes the shared
select_datasets query (also used by
adapter.load_catalog) and maps the rows into detached DTOs that outlive the session.
The filter and query builder live in the models layer
(climate_ref.models.dataset_query); DatasetFilter is
re-exported here so callers construct it from climate_ref.results.
DatasetCollection
#
An immutable page of datasets plus collection-level metadata.
total_count is the number of datasets matching the filter before pagination, so a caller
can tell there are more rows than the returned page. offset/limit echo back the
pagination applied to produce items (limit is None when the whole result was
returned).
Source code in packages/climate-ref/src/climate_ref/results/datasets.py
items
instance-attribute
#
The datasets on this page.
limit
instance-attribute
#
Page size requested, or None when the whole result was returned.
offset
instance-attribute
#
Rows skipped before this page.
total_count
instance-attribute
#
Total datasets matching the filter before offset/limit.
to_pandas()
#
DataFrame with one row per dataset; columns are base fields plus the facet dict expanded.
The base columns (id, slug, dataset_type, finalised, created_at, updated_at) are
emitted explicitly even when the collection is empty, so callers can select columns /
build an empty table without special-casing. Facet columns are dynamic (they depend on
the source type queried) and so are only present when at least one row has them.
Source code in packages/climate-ref/src/climate_ref/results/datasets.py
DatasetFileView
#
A single dataset file, detached from the ORM. Times are raw stored strings (no cftime).
Source code in packages/climate-ref/src/climate_ref/results/datasets.py
DatasetFilter
#
Declarative filter over datasets.
source_type is required.
It selects which which facet columns the query can target.
This limits our filtering to a single source type at a time to ensure that the files can be
collapsed into a dataframe.
Every other field is optional with None meaning "do not constrain on this axis".
Source code in packages/climate-ref/src/climate_ref/models/dataset_query.py
DatasetView
#
A single dataset, detached from the ORM.
Source code in packages/climate-ref/src/climate_ref/results/datasets.py
created_at
instance-attribute
#
Timestamp the dataset was created.
dataset_type
instance-attribute
#
The dataset's source type (e.g. CMIP6, obs4MIPs).
facets
instance-attribute
#
Dataset-specific metadata, keyed by the adapter's dataset_specific_metadata fields.
files
instance-attribute
#
The dataset's files; empty unless requested with include_files=True.
finalised
instance-attribute
#
Whether the dataset was registered via the complete (netCDF-opening) parser.
id
instance-attribute
#
Primary key of the underlying Dataset row.
slug
instance-attribute
#
The dataset's slug.
updated_at
instance-attribute
#
Timestamp the dataset was last updated.
DatasetsReader
#
Dataset read domain.
Constructed from a Database, which owns the session.
All read methods return detached DTOs that outlive the session.
list requires a DatasetFilter (with its required source_type), so unlike the other
readers -- whose filters argument is optional and defaults to "everything" -- there is no
useful all-datasets default here. This is a deliberate, documented divergence from that shared
contract: dataset facet columns are per-type, so a typed listing has to choose the type. get
keeps taking a bare slug, which is globally unique and needs no source_type.
Source code in packages/climate-ref/src/climate_ref/results/datasets.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
session
property
#
The underlying database session.
get(slug)
#
Fetch one dataset by slug, or None when no dataset has that slug.
When multiple rows share a slug (different versions), the latest is returned, ranked by
version_key then id so the choice is deterministic on a version tie.
Source code in packages/climate-ref/src/climate_ref/results/datasets.py
list(filters, *, offset=0, limit=None, include_files=False)
#
Query one source type's datasets, optionally scoped to an execution or diagnostic.
filters is required (its source_type picks the concrete type and hence the facet
columns). Deduplication to the latest version (filters.latest_only, the default) happens
in SQL via a RANK window keyed off the adapter's dataset_id_metadata, so the default
call returns exactly one row per dataset rather than every version.
Pagination (offset/limit) is applied in SQL after dedup, over rows ordered by
(slug, id) so paging is deterministic even when two datasets share a slug. total_count
is computed from a separate unpaged count over the same deduplicated statement.
Source code in packages/climate-ref/src/climate_ref/results/datasets.py
select_datasets(filter, *, latest_group_by=None)
#
Build the Select over the Dataset subclass for the given filter.
Any limit is deliberately not applied here. Callers should apply limits after filtering out superseded versions.
latest_group_by is the adapter's dataset_id_metadata,
which is used as the partition columns for the latest-version window.
It is passed in rather than looked up here because select_datasets lives in the models layer
and must not import the adapter registry, so it cannot resolve it itself; callers pass it through.
latest_group_by is required whenever filter.latest_only is True (the default):
passing latest_only=True without it raises ValueError rather than silently returning an
un-deduplicated result.
When both are set, rows are deduplicated with a
RANK() OVER (PARTITION BY <latest_group_by> ORDER BY version_key DESC) window
(applied after all other filters/joins),
keeping every row tied at the maximum version_key -- so ties are not silently dropped.
Set latest_only=False to list every version; latest_group_by is then ignored.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |