Element84 / earth-search

Earth Search information and issue tracking
https://earth-search.aws.element84.com/v1
27 stars 2 forks source link

Extent mismatching between STAC items and raster files #18

Closed leandroleal closed 10 months ago

leandroleal commented 11 months ago

First of all, thank you very much for organizing such massive imagery archive in STAC and make it publicly available.

I started using the catalog and I found a mismatching of bbox provided in the STAC items and the bbox extracted from the actual images. Here is a the code to reproduce it:

import rasterio
from rasterio import warp 
from shapely.geometry import box,shape
from pystac_client import Client

client = Client.open("https://earth-search.aws.element84.com/v1")

query = client.search(
    max_items=1000,
    collections=['sentinel-2-l2a'],
    bbox = [ 5.623627, 51.948497, 5.718384, 51.997142],
    datetime=['2022-01-01T00:00:00Z', '2022-01-31T00:00:00Z'],
)

for i in query.item_collection():
    for band in  i.assets.keys():
        if band == 'nir':
            href = i.assets[band].href
            with rasterio.open(href) as ds:
                bounds = shape(rasterio.warp.transform_geom(
                    dst_crs='EPSG:4326',
                    src_crs=ds.crs,
                    geom=box(*ds.bounds),
                )).bounds
                print(f'{i.id}')
                print(f' asset: {href}')
                for x,b,i in zip(['left', 'bottom', 'right', 'top'], bounds, i.bbox):
                    print(f' {x}: rio={b:.6f} stac={i:.6f}')

Output:

S2A_31UFT_20220130_0_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2A_31UFT_20220130_0_L2A/B08.tif
 left: rio=4.436121 stac=4.436135
 bottom: rio=51.324523 stac=51.324533
 right: rio=6.077758 stac=6.077743
 top: rio=52.341355 stac=52.341346
S2A_31UFT_20220127_0_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2A_31UFT_20220127_0_L2A/B08.tif
 left: rio=4.436121 stac=4.441921
 bottom: rio=51.324523 stac=51.324533
 right: rio=6.077758 stac=6.077743
 top: rio=52.341355 stac=52.335925
S2B_31UFT_20220125_0_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2B_31UFT_20220125_0_L2A/B08.tif
 left: rio=4.436121 stac=4.436135
 bottom: rio=51.324523 stac=51.324533
 right: rio=6.077758 stac=6.077743
 top: rio=52.341355 stac=52.341346
S2B_31UFT_20220122_0_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2B_31UFT_20220122_0_L2A/B08.tif
 left: rio=4.436121 stac=4.442208
 bottom: rio=51.324523 stac=51.324533
 right: rio=6.077758 stac=6.077743
 top: rio=52.341355 stac=52.335939
S2A_31UFT_20220120_1_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2A_31UFT_20220120_1_L2A/B08.tif
 left: rio=4.436121 stac=4.436135
 bottom: rio=51.324523 stac=51.324533
 right: rio=6.077758 stac=6.051339
 top: rio=52.341355 stac=52.243705
S2A_31UFT_20220120_0_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2A_31UFT_20220120_0_L2A/B08.tif
 left: rio=4.436121 stac=4.458834
 bottom: rio=51.324523 stac=51.745699
 right: rio=6.077758 stac=6.077743
 top: rio=52.341355 stac=52.341346
S2A_31UFT_20220117_0_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2A_31UFT_20220117_0_L2A/B08.tif
 left: rio=4.436121 stac=4.444218
 bottom: rio=51.324523 stac=51.324533
 right: rio=6.077758 stac=6.077743
 top: rio=52.341355 stac=52.335888
S2B_31UFT_20220115_0_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2B_31UFT_20220115_0_L2A/B08.tif
 left: rio=4.436121 stac=4.436135
 bottom: rio=51.324523 stac=51.324533
 right: rio=6.077758 stac=6.077743
 top: rio=52.341355 stac=52.341346
S2B_31UFT_20220112_0_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2B_31UFT_20220112_0_L2A/B08.tif
 left: rio=4.436121 stac=4.440198
 bottom: rio=51.324523 stac=51.324533
 right: rio=6.077758 stac=6.077743
 top: rio=52.341355 stac=52.335966
S2A_31UFT_20220110_0_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2A_31UFT_20220110_0_L2A/B08.tif
 left: rio=4.436121 stac=4.436135
 bottom: rio=51.324523 stac=51.324533
 right: rio=6.077758 stac=6.077743
 top: rio=52.341355 stac=52.341346
S2A_31UFT_20220107_0_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2A_31UFT_20220107_0_L2A/B08.tif
 left: rio=4.436121 stac=4.438763
 bottom: rio=51.324523 stac=51.324533
 right: rio=6.077758 stac=6.077743
 top: rio=52.341355 stac=52.335971
S2B_31UFT_20220105_0_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2B_31UFT_20220105_0_L2A/B08.tif
 left: rio=4.436121 stac=4.436135
 bottom: rio=51.324523 stac=51.324533
 right: rio=6.077758 stac=6.077743
 top: rio=52.341355 stac=52.341346
S2B_31UFT_20220102_0_L2A
 asset: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/31/U/FT/2022/1/S2B_31UFT_20220102_0_L2A/B08.tif
 left: rio=4.436121 stac=4.440485
 bottom: rio=51.324523 stac=51.324533
 right: rio=6.077758 stac=6.077743
 top: rio=52.341355 stac=52.33596
gadomski commented 11 months ago

I started using the catalog and I found a mismatching of bbox provided in the STAC items and the bbox extracted from the actual images. Here is a the code to reproduce it:

Those differences look pretty small, at least at first glance -- can you visualize a couple of those scenes and see if the STAC bounding boxes are actually incorrect (as opposed to just different)?

The bounding box of a given STAC item may not exactly match the rasterio-reported bounds of the underlying rasters for a lot of reasons, including slight differences in precision handling during the generation of the STAC metadata, exclusion of nodata regions, spatial offsets between different raster assets (e.g. ASTER bands aren't perfectly aligned), and more.

gadomski commented 10 months ago

Closing at not-an-issue, please re-open with more information if needed.