microsoft / PlanetaryComputer

Issues, discussions, and information about the Microsoft Planetary Computer
https://planetarycomputer.microsoft.com/
MIT License
185 stars 9 forks source link

Sentinel-1-RTC proj metadata issues #158

Closed scottyhq closed 1 year ago

scottyhq commented 1 year ago

I noticed recently that proj:shape and proj:bbox are incorrect for some S1 RTC products. According to https://github.com/stac-extensions/projection#projshape shape should be in Y,X order, but s1-rtc has it flipped:

https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-1-rtc/items/S1A_IW_GRDH_1SDV_20220805T015427_20220805T015452_044411_054CC1_rtc

 'proj:transform': [10.0, 0.0, 519100.0, 0.0, -10.0, 5454150.0, 0.0, 0.0, 1.0],
 'proj:shape': [28793, 21758],
 'proj:bbox': [523650.0, 5237390.0, 804660.0, 5453770.0],

As a consequence it appears proj:bbox is also off (proj:transform is fine):

import pystac
import planetary_computer
import rasterio

stac_item = 'https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-1-rtc/items/S1A_IW_GRDH_1SDV_20220805T015427_20220805T015452_044411_054CC1_rtc'
item = planetary_computer.sign(pystac.read_file(stac_item))
href = item.assets["vv"].href

with rasterio.open(href) as src:
    print(list(src.transform))
    print(src.shape)
    print(list(src.bounds))

#[10.0, 0.0, 519100.0, 0.0, -10.0, 5454150.0, 0.0, 0.0, 1.0]
#(21758, 28793)
#[519100.0, 5236570.0, 807030.0, 5454150.0]

possibly related: https://github.com/gjoseph92/stackstac/issues/196

TomAugspurger commented 1 year ago

Thanks for the report! IIUC, proj:shape should be reversed ([21758, 28793] for this item). What's the expected proj:bbox?

scottyhq commented 1 year ago

@TomAugspurger that's correct. For bbox I expect the proj:xxxx metadata to match rasterio outputs:

Also see: https://github.com/stac-extensions/projection#projbbox # left, down, right, up

with rasterio.open(url) as src:
    left = src.transform[2]
    top = src.transform[5]
    right, bottom = src.transform * (src.width, src.height)

    # equivalent to list(src.bounds)
    bbox = [left, bottom, right, top]

# [519100.0, 5236570.0, 807030.0, 5454150.0]
TomAugspurger commented 1 year ago

We've fixed the proj:shape issue:

In [4]: pystac.read_file("https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-1-rtc/items/S1A_IW_GRDH_1SDV_20220805T015427_20220805T015452_044411_054CC1_rtc").properties["proj:shape"]
Out[4]: [21758, 28793]

Our partners at Catalyst are also looking into the proj:bbox issue.

TomAugspurger commented 1 year ago

The proj:bbox issues has been fixed as well now.

In [1]: import pystac

In [2]: pystac.read_file("https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-1-rtc/items/S1A_IW_GRDH_1SDV_20220805T015427_20220805T015452_044411_054CC1_rtc").properties["proj:shape"]
Out[2]: [21758, 28793]

In [3]: pystac.read_file("https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-1-rtc/items/S1A_IW_GRDH_1SDV_20220805T015427_20220805T015452_044411_054CC1_rtc").properties["proj:bbox"]
Out[3]: [519100.0, 5236570.0, 807030.0, 5454150.0]

(previously that was [523650.0, 5237390.0, 804660.0, 5453770.0])

Thanks again for the report and let us know how things go!