Repository navigation
cube metadata estimation: spatiotemporal refinement - #989
Conversation
The estimates are implemented. The full test suite passes (3172 passed), and darker and isort pass. I also ran it live against the CDSE STAC. A 0.5°×0.5° bbox over a week of Sentinel-2 L2A gave x≈3560 and y≈5566 pixels and 16 observations, in about 0.5 s. What it does • Estimator: the new openeo/metadata/_estimates.py fetches the STAC collection and takes the finest resolution from item_assets or summaries. It restricts to the selected bands when they match. It uses plain requests, with a 2 s timeout and a 25-item limit. • Observations: one capped items request with the fields extension. It uses numberMatched (or context.matched) if present, otherwise the count of returned items. • Pixels: computed per x and y dimension from the bbox, using the rough degrees-to-metres conversion at the centre latitude. • Failures: every failure or timeout gives no estimate and never raises. • Sources: load_stac and metadata_from_stac on an http(s) STAC Collection URL, and load_collection via the derived_from link. The estimator is carried through filter_* and the other cube metadata operations, so estimates follow the current bbox and time extent. • Rendering: the Jupyter "Size" column shows values like ~3,560. • Opt-out: env var OPENEO_DISABLE_SIZE_ESTIMATES=1. • Tests and changelog: tests/metadata/test_estimates.py covers the estimator and cube metadata, and the CHANGELOG.md entry references #827. Deviations from the plan • Lazy network access: requests happen when an estimate is first needed (e.g. _repr_html_), not at load time, and results are cached. • API: I added CubeMetadata.estimated_dimension_sizes() instead of an estimated_size attribute on the dimensions. • Not done: there is no search-item fallback for resolution when the collection has none. There is also no per-call kwarg opt-out on load_collection/load_stac, only the env var. • Not documented: no docs/ page covers this yet.
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved estimation bugs can report incorrect spatial and temporal sizes after cube transformations, while malformed STAC metadata can prevent notebook metadata tables from rendering.
5 open issues
What changed in this PR
Adds STAC-based spatial and temporal size estimates to notebook cube metadata displays, supporting #827’s goal of making data cube structure easier to understand.
Changes:
- Adds lazy STAC probes with caching, request timeouts, and an environment-variable opt-out.
- Connects estimators to loaded cube metadata and displays approximate dimension sizes.
- Adds focused tests, an implementation plan, and changelog documentation.
| File | Description |
|---|---|
tests/metadata/test_estimates.py |
Tests estimation, filtering, caching, failures, and rendering. |
plans/827-dimension-size-estimates.md |
Documents the estimation strategy and design decisions. |
openeo/rest/datacube.py |
Transfers the collection estimator to loaded cube metadata. |
openeo/metadata/_jupyter.py |
Displays approximate spatial and temporal sizes. |
openeo/metadata/_estimates.py |
Implements STAC resolution and observation-count estimation. |
openeo/metadata/__init__.py |
Attaches estimators, preserves them during cloning, and requests dimension estimates. |
CHANGELOG.md |
Announces size estimates and the network opt-out. |
Review effort: Balanced
| if observations := estimator.estimate_observations(bbox=bbox, datetime=tuple(extent)): | ||
| estimates[self.temporal_dimension.name] = observations |
| - Sources: openEO collection `derived_from` link -> STAC collection (covers `load_collection`), collection-level metadata + automatic STAC API search probe (with item limit). | ||
| - Network: implicit by default, with a 2 s timeout and an opt-out; failures degrade to "unknown" and never raise. | ||
| - Temporal semantics: number of distinct timestamps (items) in the filtered extent. | ||
| - CRS handling: rough degrees -> metres conversion at bbox centre latitude. |
There was a problem hiding this comment.
CRS lookup of the original stac collection should be feasible? (It was already in my notebook.)
Fallback to lat lon seems rather like a secondary fallback.
soxofaan
left a comment
There was a problem hiding this comment.
I have impression this PR is escalating too much
It also does not work on the basic use case:
connection = openeo.connect(url="https://openeo.dataspace.copernicus.eu/")
cube = connection.load_collection(
"SENTINEL2_L2A",
spatial_extent={"west": 3, "south": 51, "east": 3.1, "north": 51.1},
temporal_extent=["2026-09-03", "2026-09-25"],
bands=["B03", "B04"]
)
cube.metadata
gives size "?" for both temporal and spatial dimensions
This is indeed not the way to go, and I don't think this is solvable via the github variant. |
There was a problem hiding this comment.
🟡 Changes recommended
Dimension-size estimates can be incorrect or stale due to mishandled temporal boundaries, load predicates, CRS units, and size invalidation, while GET-only STAC endpoints are incorrectly queried with POST.
11 open issues
Convert metre resolutions using projected CRS units · New Honor GET methods advertised by STAC search links · New Account for property predicates in observation count probes · New Preserve exclusive load bounds when counting temporal observations · New Invalidate temporal size after spatial filtering · New Invalidate sizes after label filtering and spatial aggregation · New Clear sizes after target-dimension metadata handling · New Match asset bands using STAC 1.1 metadata Invalidate source-item counts after temporal aggregation Avoid spatial counts when coverage is unknown or empty Estimate pixels using the output grid resolution
1 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved issues cause incorrect temporal counts, retain stale dimension sizes after filtering and transformations, and send unsupported POST requests to GET-only STAC search endpoints.
13 open issues
Honor the advertised search method during discovery · New Avoid temporal probes for empty spatial intersections · New Invalidate dimension sizes when filtering labels · New Clear sizes after target-dimension metadata handling Invalidate sizes after label filtering and spatial aggregation Invalidate temporal size after spatial filtering Preserve exclusive load bounds when counting temporal observations Account for property predicates in observation count probes Honor GET methods advertised by STAC search links Convert metre resolutions using projected CRS units Match asset bands using STAC 1.1 metadata Invalidate source-item counts after temporal aggregation Estimate pixels using the output grid resolution
1 resolved since last review
Review effort: Balanced
just a tilde was too easy to misread as minus added a tooltip to better explain
improve/simplify caching behavior, manage overall timing budget don't do retries ignoring the server's instructions
There was a problem hiding this comment.
🟡 Changes recommended
Temporal estimates omit inclusive final observations, spatial estimates miss supported asset GSD metadata, and temporal resampling can assign incorrect or stale dimension sizes.
12 open issues
Read item asset GSD from serialized collection metadata · New Update each resampled temporal dimension by name · New Invalidate dimension sizes when filtering labels Avoid temporal probes for empty spatial intersections Clear sizes after target-dimension metadata handling Invalidate sizes after label filtering and spatial aggregation Invalidate temporal size after spatial filtering Preserve exclusive load bounds when counting temporal observations Account for property predicates in observation count probes Match asset bands using STAC 1.1 metadata Invalidate source-item counts after temporal aggregation Estimate pixels using the output grid resolution
3 resolved since last review
Review effort: Balanced
…oral-metadata-refinement
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

initial copilot based implementation of cube metadata estimation from limited STAC API requests
refs