0

When trying to get Landsat 8 Level 1 data using python stackstac package, I get, either the error mentioned above for every scene or just NaN values inside the lazy xarray DataArray.

With the stackstac package I connect with a STAC Collection for Landsat Level 1 data ("https://landsatlook.usgs.gov/stac-server"), in the same way I have sucessfuly used it before for other collections (Landsat and Sentinel-2 level 2 from Microsoft Planetary Computer).

Example of code used:

import numpy as np
import stackstac
import pystac_client
import planetary_computer
import rasterio as rio
from rasterio import RasterioIOError, Env
import boto3
import pyproj

# Rasterio Environment for AWS Request Payer (Sentinel2 L1C)

Session = Env(AWS_REQUEST_PAYER='requester')

URL = "https://landsatlook.usgs.gov/stac-server"
modifier = None
collections=\["landsat-c2l1"\]

lon, lat = 37.16, -3.61
loc_buffer = 1000

date_ini = f'2021-12-01'
date_end = f'2021-12-31'
satellite = 'landsat'
bands = \['blue', 'red', 'green', 'swir16', 'swir22'\]
level = 'l1c'
resol = 20
cloud_cover = 100

stac = pystac_client.Client.open(URL, modifier=modifier)


# Create Search Query Dictionary
query_search = {
'datetime':f"{date_ini}/{date_end}",
'collections':collections,
'query':{"eo:cloud_cover": {"lt": cloud_cover}},
}

# Create Stack Options Dictionary
stack_options= {
'assets': bands,
'chunksize': 2048,
'resolution': resol,
'dtype': "float32",
'band_coords': False,
'errors_as_nodata': (RasterioIOError('.\*'), ),
}

location = (lon, lat)
point_geom = dict(type="Point", coordinates=list(location))
query_search\['intersects'\] = point_geom

# query the stac
search = stac.search(\*\*query_search)
items = search.item_collection()
\#len(items)

## stack the stac
if len(items) \> 0:
metadata = items.to_dict()\['features'\]\[0\]\["properties"\]
epsg = metadata\["proj:epsg"\]
stack_options\['epsg'\] = epsg
x_utm, y_utm = pyproj.Proj(epsg)(\*location)
bounds = (x_utm-loc_buffer, y_utm-loc_buffer, x_utm+loc_buffer, y_utm+loc_buffer)
stack_options\['bounds'\] = bounds
\#data = stackstac.stack(items, \*\*stack_options)
with Session:
gdal_session = stackstac.DEFAULT_GDAL_ENV.updated(always=dict(session=rio.session.AWSSession(boto3.Session(), requester_pays=True)))
stack_options\['gdal_env'\] = gdal_session
data = stackstac.stack(items, \*\*stack_options)

What am I doing wrong? Thanks in advance for your help

0 Answers0