JuliaClimate / STAC.jl

SpatioTemporal Asset Catalog (STAC) julia client
MIT License
28 stars 3 forks source link

Not working with the GEOBON STAC catalogue #17

Open tpoisot opened 1 month ago

tpoisot commented 1 month ago

The following is empty:

using STAC
catalog = STAC.Catalog("https://stac.geobon.org/")
entry = catalog["chelsa-clim"]

Specifically, the output is

julia> entry = catalog["chelsa-clim"]
chelsa-clim
CHELSA Climatologies
CHELSA Climatologies
License: CC-BY-SA-4.0

But using the URL gives a list of the expected items withing this collection: https://stac.geobon.org/collections/chelsa-clim/items

Is there something I am missing?

Alexander-Barth commented 1 month ago

Thanks for the reproducer. The code is looking for item (without the endings s):

https://github.com/JuliaClimate/STAC.jl/blob/e163edb7728c8e62c20c461fe775ab25f6302e63/src/catalog.jl#L118

In stac.geobon.org's JSON however, the rel field has the value items (with an s):

julia> entry = catalog["chelsa-clim"];

julia> entry.data.links
4-element JSON3.Array{JSON3.Object, Base.CodeUnits{UInt8, String}, SubArray{UInt64, 1, Vector{UInt64}, Tuple{UnitRange{Int64}}, true}}:
 {
    "rel": "items",
   "type": "application/geo+json",
   "href": "https://stac.geobon.org/collections/chelsa-clim/items"
}
 {
    "rel": "parent",
   "type": "application/json",
   "href": "https://stac.geobon.org/"
}
 {
    "rel": "root",
   "type": "application/json",
   "href": "https://stac.geobon.org/"
}
 {
    "rel": "self",
   "type": "application/json",
   "href": "https://stac.geobon.org/collections/chelsa-clim"
}

See the spec: https://github.com/radiantearth/stac-spec/blob/2e6947df194a707354d6d5be1da6762647ee593f/commons/links.md#link-object

and example:

https://github.com/radiantearth/stac-spec/blob/2e6947df194a707354d6d5be1da6762647ee593f/examples/collection.json#L93

Does the spec also mentions items in plural for the rel field?

tpoisot commented 1 month ago

Thanks @Alexander-Barth -- you are right, neither the spec nor the types for link relations in IANA use items

@jmlord / @glaroc -- it seems that the GEOBON STAC catalogue isn't following the spec

glaroc commented 1 month ago

We are using STAC Fastapi. This might be a difference between STAC spec and STAC API spec ? Other catalogs I'm looking at use items with an "s".

https://planetarycomputer.microsoft.com/api/stac/v1/collections/terraclimate https://eocat.esa.int/eo-catalogue/collections

tpoisot commented 1 month ago

Yeah, the STAC API spec is different from the STAC spec 😕

Alexander-Barth commented 1 month ago

That would be a real bummer. The STAC spec is already quite extensive as is. Or maybe it is an extension (https://stac-extensions.github.io/) or a beta version of the spec (just a speculation). Maybe the raising an issue at https://github.com/radiantearth/stac-spec/ would help?

glaroc commented 1 month ago

In any case, if catalogs like the Planetary Computer and ESA have items instead of item, this library should probably support it. Otherwise, many users will face similar issues. The rstac R package and the Python pystac library work fine with our catalog.

Alexander-Barth commented 1 month ago

Are you able to read the items with pystac? This is what I tried, but I got also an empty list for the items.

import pystac
root_catalog = pystac.Catalog.from_file("https://stac.geobon.org/")

root_catalog.get_child("chelsa-clim").title
# output 'CHELSA Climatologies'

list(root_catalog.get_child("chelsa-clim").get_items())
# output []

list(root_catalog.get_child("chelsa-clim").get_items(recursive=True))
# output []

pystac.__version__
# output '1.10.1'

I am not very familiar with pystac, I followed the documentation here https://pystac.readthedocs.io/en/stable/quickstart.html#Crawling-Items

glaroc commented 1 month ago

@Alexander-Barth I believe you have to use pystac_client: https://pystac-client.readthedocs.io/en/latest/usage.html

Static and dynamic catalogs have different characteristics. For example, sub-catalogs are not allowed with the STAC API Spec, while they are in the STAC Spec. I guess items vs item is another difference.

Alexander-Barth commented 1 month ago

This seems to be relevant:

https://github.com/radiantearth/stac-api-spec/blob/604ade6158de15b8ab068320ca41e25e2bf0e116/overview.md?plain=1#L40