intake / intake-stac

Intake interface to STAC data catalogs
https://intake-stac.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
108 stars 25 forks source link

Support STAC 1.0 - part 0 #96

Closed TomAugspurger closed 3 years ago

TomAugspurger commented 3 years ago

This is a precursor PR to supporting STAC 1.0. It just updates the tests to use files from the PyStac repo, rather than sat-stac.

A followup PR will update the URLs to point to the STAC 1.0.0 versions of those files while updating the code to use PyStac 1.0.

The first two commits are just https://github.com/intake/intake-stac/pull/94 and can be ignored. https://github.com/intake/intake-stac/commit/fbf84a2f595b2e51c8c375ed2fc1746df2e6b1e6 has the actual changes.

scottyhq commented 3 years ago

Thanks for starting this @TomAugspurger ! I left some comments trying to figure out whether to use external examples for testing, or if we might want to put our own example STAC=1.0 examples in this repository (with valid asset / subcatalog links)

TomAugspurger commented 3 years ago

I think having our own STAC catalogs, with just the data we need for testing, makes sense. Now that we're at STAC 1.0, this seems more feasible. I'll look into that.

TomAugspurger commented 3 years ago

OK, updated to use some local files, rather than opening STAC objects from remote URLs.

I think the stack_bands might be a bit under-tested, but hopefully I got it right. The items I'm using came from the Planetary Computer, so URLs to data files in blob storage have to be signed to download. I don't think we want to do that in our unit tests, but here's a manual tests:

In [1]: import rasterio

In [2]: import pystac, planetary_computer, intake

In [3]: item = planetary_computer.sign_assets(pystac.read_file("https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-2-l2a/items/S2B_MSIL2A_20210610T115639_N0212_R066_T33
   ...: XWC_20210613T190000.SAFE"))

In [5]: intake_item = intake.open_stac_item(item)

In [6]: ds = intake_item.stack_bands(["B02", "B03"])().to_dask()

In [7]: ds
Out[7]:
<xarray.DataArray (band: 2, y: 10980, x: 10980)>
dask.array<concatenate, shape=(2, 10980, 10980), dtype=uint16, chunksize=(1, 10980, 10980), chunktype=numpy.ndarray>
Coordinates:
  * band     (band) int64 1 1
  * y        (y) float64 8.3e+06 8.3e+06 8.3e+06 ... 8.19e+06 8.19e+06 8.19e+06
  * x        (x) float64 5e+05 5e+05 5e+05 ... 6.098e+05 6.098e+05 6.098e+05
Attributes:
    transform:      (10.0, 0.0, 499980.0, 0.0, -10.0, 8300040.0)
    crs:            +init=epsg:32633
    res:            (10.0, 10.0)
    is_tiled:       1
    nodatavals:     (nan,)
    scales:         (1.0,)
    offsets:        (0.0,)
    AREA_OR_POINT:  Area
TomAugspurger commented 3 years ago

Yeah, releasing shortly after pystac 1.0 is my hope.