Skip to content

Conversation

@timothey-cs
Copy link
Collaborator

@timothey-cs timothey-cs commented Dec 3, 2025

Fixes #112

Add augment_from_xarray function to EOProduct.
It takes values from to_xarray and add cube:dimensions and cube:variables to product properties

@timothey-cs timothey-cs requested a review from sbrunato December 3, 2025 14:45
@timothey-cs timothey-cs self-assigned this Dec 3, 2025
@timothey-cs timothey-cs changed the title feat: add argument_from_xarray for EOProduct feat: add augment_from_xarray for EOProduct Dec 3, 2025
@timothey-cs timothey-cs force-pushed the feat/add_argument_from_xarray branch from 7d40d45 to 556fc1a Compare December 3, 2025 15:09
@timothey-cs timothey-cs force-pushed the feat/add_argument_from_xarray branch from 556fc1a to 9ec4e69 Compare December 3, 2025 15:11
dimensions = {}
variables = {}

for _, ds in xd.items():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for _, ds in xd.items():
for ds in xd.values():


for _, ds in xd.items():
# Dimensions
for dim_name, _ in ds.sizes.items():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for dim_name, _ in ds.sizes.items():
for dim_name in ds.sizes.keys():

for var_name, var in ds.data_vars.items():
variables[str(var_name)] = {"dimensions": list(var.dims), "type": "data"}

asset.setdefault("properties", {})
Copy link
Collaborator

Choose a reason for hiding this comment

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

put metadata directly at asset level, do not add .properties attribute, see https://github.com/stac-extensions/datacube/blob/main/examples/item_asset.json

information from its xarray representation.
:returns: updated EOProduct
"""
for asset_key, asset in self.assets.items():
Copy link
Collaborator

Choose a reason for hiding this comment

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

some EOProducts may not have assets. In that case, directly run product.to_xarray() and put metadata in product.properties.
See example https://github.com/stac-extensions/datacube/blob/main/examples/item.json


return xd

def augment_from_xarray(self) -> EOProduct:
Copy link
Collaborator

Choose a reason for hiding this comment

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

please also add reference_system if available (try reading data from different collections: S2_MSI_L1C, S3_SLSTR_L1RBT, MERIS_ALAMO_L2_V2.2, CAMS_EAC4 https://eodag.readthedocs.io/en/latest/notebooks/tutos/tuto_cds.html)

https://github.com/stac-extensions/datacube/tree/main?tab=readme-ov-file#dimension-object

@sbrunato sbrunato marked this pull request as draft December 8, 2025 09:59
@timothey-cs timothey-cs force-pushed the feat/add_argument_from_xarray branch from cb42244 to 2732f2d Compare December 8, 2025 14:48
@timothey-cs timothey-cs marked this pull request as ready for review December 8, 2025 14:55
@timothey-cs timothey-cs requested a review from sbrunato December 8, 2025 14:55
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.

augment from xarray

3 participants