microsoft / PlanetaryComputerExamples

Examples of using the Planetary Computer
MIT License
366 stars 179 forks source link

CPLE_OpenFailedError #235

Closed hafez-ahmad closed 1 year ago

hafez-ahmad commented 1 year ago
import pystac_client
import planetary_computer
import odc.stac
from pystac.extensions.eo import EOExtension as eo
atalog = pystac_client.Client.open(
    "https://planetarycomputer.microsoft.com/api/stac/v1",
    modifier=planetary_computer.sign_inplace,
)
bbox_of_interest = [91.77, 22.33, 92.78, 25.349] # lon lat
time_of_interest = "2022-05-01/2022-6-31"
search = catalog.search(
    collections=["landsat-c2-l2"],
    bbox=bbox_of_interest,
    datetime=time_of_interest,
    query={"eo:cloud_cover": {"lt": 1}},
)

items = search.item_collection()
print(f"Returned {len(items)} Items")
selected_item = min(items, key=lambda item: eo.ext(item).cloud_cover)

print(
    f"Choosing {selected_item.id} from {selected_item.datetime.date()}"
    + f" with {selected_item.properties['eo:cloud_cover']}% cloud cover"
)
bands_of_interest = ["nir08", "red", "green", "blue", "qa_pixel", "lwir11"]
data = odc.stac.stac_load(
    [selected_item], bands=bands_of_interest, bbox=bbox_of_interest
).isel(time=0)
data

CPLE_OpenFailedError Traceback (most recent call last) File rasterio/_base.pyx:302, in rasterio._base.DatasetBase.init()

File rasterio/_base.pyx:213, in rasterio._base.open_dataset()

File rasterio/_err.pyx:217, in rasterio._err.exc_wrap_pointer()

CPLE_OpenFailedError: '/vsicurl/https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2022/137/043/LC09_L2SP_137043_20221022_20221025_02_T1/LC09_L2SP_137043_20221022_20221025_02_T1_SR_B3.TIF?st=2022-11-15T04%3A35%3A21Z&se=2022-11-23T04%3A35%3A21Z&sp=rl&sv=2021-06-08&sr=c&skoid=c85c15d6-d1ae-42d4-af60-e2ca0f81359b&sktid=72f988bf-86f1-41af-91ab-2d7cd011db47&skt=2022-11-16T04%3A35%3A20Z&ske=2022-11-23T04%3A35%3A20Z&sks=b&skv=2021-06-08&sig=fNaHgF31zqZk2j8ygij66ABhGFKwqYfvsnsaypqdCso%3D' not recognized as a supported file format.

During handling of the above exception, another exception occurred:

RasterioIOError Traceback (most recent call last) Cell In [94], line 2 1 bands_of_interest = ["nir08", "red", "green", "blue", "qa_pixel", "lwir11"] ----> 2 data = odc.stac.stac_load( 3 [selected_item], bands=bands_of_interest, bbox=bbox_of_interest 4 ).isel(time=0) 5 data

File /srv/conda/envs/notebook/lib/python3.10/site-packages/odc/stac/_load.py:595, in load(items, bands, groupby, resampling, dtype, chunks, pool, crs, resolution, anchor, geobox, bbox, lon, lat, x, y, like, geopolygon, progress, stac_cfg, patch_url, preserve_original_order, **kw) 592 if progress is not None: 593 _work = progress(SizedIterable(_work, totaltasks)) --> 595 for in _work: 596 pass 598 return _with_debug_info(ds, tasks=_tasks)

File /srv/conda/envs/notebook/lib/python3.10/site-packages/odc/stac/_utils.py:38, in pmap(func, inputs, pool) 34 """ 35 Wrapper for ThreadPoolExecutor.map 36 """ 37 if pool is None: ---> 38 yield from map(func, inputs) 39 return 41 if isinstance(pool, int):

File /srv/conda/envs/notebook/lib/python3.10/site-packages/odc/stac/_load.py:586, in load.._do_one(task) 580 srcs = [ 581 src 582 for src in (_parsed[idx].get(band, None) for idx, band in task.srcs) 583 if src is not None 584 ] 585 with rio_env(**_rioenv): --> 586 = _fill_2d_slice(srcs, task.dst_gbox, task.cfg, dst_slice) 587 t, y, x = task.idx_tyx 588 return (task.band, t, y, x)

File /srv/conda/envs/notebook/lib/python3.10/site-packages/odc/stac/_load.py:681, in _fill_2d_slice(srcs, dst_gbox, cfg, dst) 678 return dst 680 src, *rest = srcs --> 681 _roi, pix = rio_read(src, cfg, dst_gbox, dst=dst) 683 for src in rest: 684 # first valid pixel takes precedence over others 685 _roi, pix = rio_read(src, cfg, dst_gbox)

File /srv/conda/envs/notebook/lib/python3.10/site-packages/odc/stac/_reader.py:185, in rio_read(src, cfg, dst_geobox, dst) 181 # if resampling is nearest then ignore sub-pixel translation when deciding 182 # whether we can just paste source into destination 183 ttol = 0.9 if cfg.nearest else 0.05 --> 185 with rasterio.open(src.uri, "r", sharing=False) as rdr: 186 assert isinstance(rdr, rasterio.DatasetReader) 187 ovr_idx: Optional[int] = None

File /srv/conda/envs/notebook/lib/python3.10/site-packages/rasterio/env.py:442, in ensure_env_with_credentials..wrapper(*args, *kwds) 439 session = DummySession() 441 with env_ctor(session=session): --> 442 return f(args, **kwds)

File /srv/conda/envs/notebook/lib/python3.10/site-packages/rasterio/init.py:277, in open(fp, mode, driver, width, height, count, crs, transform, dtype, nodata, sharing, kwargs) 274 path = _parse_path(raw_dataset_path) 276 if mode == "r": --> 277 dataset = DatasetReader(path, driver=driver, sharing=sharing, kwargs) 278 elif mode == "r+": 279 dataset = get_writer_for_path(path, driver=driver)( 280 path, mode, driver=driver, sharing=sharing, **kwargs 281 )

File rasterio/_base.pyx:304, in rasterio._base.DatasetBase.init()

RasterioIOError: '/vsicurl/https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2022/137/043/LC09_L2SP_137043_20221022_20221025_02_T1/LC09_L2SP_137043_20221022_20221025_02_T1_SR_B3.TIF?st=2022-11-15T04%3A35%3A21Z&se=2022-11-23T04%3A35%3A21Z&sp=rl&sv=2021-06-08&sr=c&skoid=c85c15d6-d1ae-42d4-af60-e2ca0f81359b&sktid=72f988bf-86f1-41af-91ab-2d7cd011db47&skt=2022-11-16T04%3A35%3A20Z&ske=2022-11-23T04%3A35%3A20Z&sks=b&skv=2021-06-08&sig=fNaHgF31zqZk2j8ygij66ABhGFKwqYfvsnsaypqdCso%3D' not recognized as a supported file format.

TomAugspurger commented 1 year ago

An issue in our download process caused some invalid landsat files to be uploaded to blob storage. See https://github.com/microsoft/PlanetaryComputer/discussions/101 for more. I fixed a batch last week, and will be updating the rest over the next couple weeks.