Open-EO / openeo-geopyspark-driver

OpenEO driver for GeoPySpark (Geotrellis)
Apache License 2.0
26 stars 4 forks source link

Extend load_stac for alternative assets. #874

Closed HansVRP closed 1 week ago

HansVRP commented 1 week ago

Our collaborators on grassland watch want to make use of the following collection:

https://planetarycomputer.microsoft.com/api/stac/v1/collections/landsat-c2-l2

More specifically they are also interested in the following asset:

"qa_pixel": {
      "type": "image/tiff; application=geotiff; profile=cloud-optimized",
      "roles": [
        "cloud",
        "cloud-shadow",
        "snow-ice",
        "water-mask"
      ],
      "title": "Pixel Quality Assessment Band",
      "description": "Collection 2 Level-1 Pixel Quality Assessment Band (QA_PIXEL)",
      "raster:bands": [
        {
          "unit": "bit index",
          "nodata": 1,
          "data_type": "uint16",
          "spatial_resolution": 30
        }
      ]
    },

This item asset however lack the data role, hence it is not included as a band when using load_stac:

def is_band_asset(asset: pystac.Asset) -> bool:
        return asset.has_role("data") or "eo:bands" in asset.extra_fields

I am wondering how we could potentially still be able to load in this asset. Maybe it would make more sense to look at the type instead of the role? Or add every element which has a role?

bossie commented 1 week ago

I was kind of assuming that only "data" assets are of importance to load_stac and others were typically thumbnails, XML metadata etc.

Apparently this does not take mask assets into account, which are considered metadata.

bossie commented 1 week ago

I'll take roles like "snow-ice" etc. into consideration, in addition to "data".

bossie commented 1 week ago

Supported in the back-end.

Python client requires Python 3.9 so it will make use of the item_assets property in the collection, otherwise it will complain that there is no qa_pixel band. A workaround for this is to add the band manually:

data_cube.metadata = data_cube.metadata.append_band(Band(name="qa_pixel"))

Let me know if there are any issues.