Skip to content

cube metadata estimation: spatiotemporal refinement - #989

Merged
soxofaan merged 23 commits into
masterfrom
issue827-spatiotemporal-metadata-refinement
Dec 3, 2026
Merged

soxofaan merged 23 commits into
masterfrom
issue827-spatiotemporal-metadata-refinement

Conversation

@soxofaan

Copy link
Copy Markdown
Member

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

refs

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.
@soxofaan
soxofaan marked this pull request as draft November 30, 2026 12:33
@soxofaan
soxofaan requested a balanced review from Copilot November 30, 2026 12:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread openeo/metadata/__init__.py Resolved
Comment thread openeo/metadata/__init__.py Resolved
Comment thread openeo/metadata/__init__.py Resolved
Comment thread openeo/metadata/__init__.py Outdated
Comment on lines +513 to +514
if observations := estimator.estimate_observations(bbox=bbox, datetime=tuple(extent)):
estimates[self.temporal_dimension.name] = observations
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread plans/827-dimension-size-estimates.md Outdated
- 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_jupyter.py Resolved

@soxofaan soxofaan left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread openeo/metadata/__init__.py Resolved
Comment thread openeo/metadata/__init__.py Resolved
Comment thread openeo/metadata/__init__.py Resolved
Comment thread openeo/metadata/__init__.py Resolved
Comment thread openeo/metadata/__init__.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
@jdries

jdries commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

It also does not work on the basic use case: ...

This is indeed not the way to go, and I don't think this is solvable via the github variant.
I would suggest to use an agent in your IDE, and let it work until a couple of basic use cases return something plausible. (SENTINEL2_L2A, SENTINEL1_GRD, COPERNICUS_30, some Sentinel3 collection,...)

@soxofaan
soxofaan requested a balanced review from Copilot December 1, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/rest/datacube.py Resolved
Comment thread openeo/rest/datacube.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/rest/datacube.py Resolved
improve/simplify caching behavior, manage overall timing budget
don't do retries ignoring the server's instructions

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread openeo/metadata/_estimates.py Resolved
Comment thread openeo/rest/datacube.py Resolved
@soxofaan
soxofaan marked this pull request as ready for review December 3, 2026 15:02
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@soxofaan
soxofaan merged commit 4cfcbed into master Dec 3, 2026
12 checks passed
@soxofaan
soxofaan deleted the issue827-spatiotemporal-metadata-refinement branch December 3, 2026 15:36
soxofaan added a commit to Open-EO/openeo-geopyspark-driver that referenced this pull request Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants