Selecting satellites from landsat-c2-l2
collection
#70
-
Hello, I am trying to use the I have tried setting my query to I see that the data catalog lists the spectral bands from the different sensors, but I am unsure how to search with those names ( Here is what I have tried so far, but with no luck: import stackstac
import pystac_client
import pyproj
import planetary_computer as pc
from pystac.extensions.eo import EOExtension as eo
# from pystac.extensions.sat import SatExtension as sat
catalog = pystac_client.Client.open('https://planetarycomputer.microsoft.com/api/stac/v1')
search = catalog.search(
collections=['landsat-c2-l2'],
intersects=dict(type="Point", coordinates=[20, 5]),
datetime="2008-02-01/2008-03-01",
query={"eo:cloud_cover": {"lt": 20}},
# query={"platform": {"in": ["landsat-5", "landsat-8"]}}, # Tried a few different ways to query
# query={"platform": {"neq": 'landsat-7'}},
# query={"eo:cloud_cover": {"lt": 10}, "platform": {"neq": 'landsat-7'}},
limit=1,
)
items = pc.sign(search); items[0].properties Output{'gsd': 30,
'created': '2022-05-06T16:39:43.054109Z',
'sci:doi': '10.5066/P9C7I13B',
'datetime': '2010-01-03T08:46:41.053573Z',
'platform': 'landsat-7',
'proj:epsg': 32634,
'proj:shape': [6971, 7981],
'description': 'Landsat Collection 2 Level-2',
'instruments': ['etm+'],
'eo:cloud_cover': 0.0,
'proj:transform': [30.0, 0.0, 275985.0, 0.0, -30.0, 744615.0],
'view:off_nadir': 0,
'landsat:wrs_row': '056',
'landsat:scene_id': 'LE71800562010003ASN00',
'landsat:wrs_path': '180',
'landsat:wrs_type': '2',
'view:sun_azimuth': 135.9089404,
'landsat:correction': 'L2SP',
'view:sun_elevation': 49.47199538,
'landsat:cloud_cover_land': 0.0,
'landsat:collection_number': '02',
'landsat:collection_category': 'T1'} stack = stackstac.stack(items, assets=["red", "green", "blue",])
x_utm, y_utm = pyproj.Proj(stack.crs)(lon, lat)
buffer = 3000 # meters
aoi = stack.loc[..., y_utm+buffer:y_utm-buffer, x_utm-buffer:x_utm+buffer]
data = aoi.compute()
data.plot.imshow(row="time", rgb="band", robust=True, size=6) Any suggestions or tips would be greatly appreciated! Side note: I think a tutorial notebook to explain common ways of dealing with the SLC failure and how to implement them on MPC would be a great addition to the collection. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
You can use the Using pystac-client that would be import pystac_client
catalog = pystac_client.Client.open('https://planetarycomputer.microsoft.com/api/stac/v1')
search = catalog.search(
collections=['landsat-c2-l2'],
datetime="2022-02-01/2022-03-01",
query={"platform": {"in": ["landsat-8", "landsat-9"]}},
)
next(search.get_items()) All the items returned in the (orignal post below) Agreed that a tutorial would be helpful here. I'm waiting for a couple of things to settle down before writing it up, and a couple of limitations to be removed. Right now, I don't think that pgstac supports the For now, as long as the result set isn't too large, I think you're best off filtering client-side: search = catalog.search(
collections=['landsat-c2-l2'],
intersects=dict(type="Point", coordinates=[20, 5]),
datetime="2008-02-01/2008-03-01",
query={"eo:cloud_cover": {"lt": 20}},
)
items = [item for item in search.get_all_items() if item.platform != "landsat-7"] (original post below) STAC has an alternative, more powerful / verbose query language Unfortunately, due to stac-utils/pgstac#122, this will fail for more than one value. So you'll need to do two separate searches. from pystac_client import Client
import planetary_computer as pc
# Search against the Planetary Computer STAC API
catalog = Client.open(
"https://planetarycomputer.microsoft.com/api/stac/v1"
)
# Define your area of interest
aoi = {
"type": "Polygon",
"coordinates": [
[
[-108.92460847488842, 39.09935495125271],
[-106.63067499990376, 39.09935495125271],
[-106.63067499990376, 40.47212159588767],
[-108.92460847488842, 40.47212159588767],
[-108.92460847488842, 39.09935495125271]
]
]
}
# Define your temporal range
daterange = {"interval": ["1982-08-22T00:00:00Z", "2022-06-06T23:59:59Z"]}
# Define your search with CQL2 syntax
search = catalog.search(filter_lang="cql2-json", filter={
"op": "and",
"args": [
{"op": "s_intersects", "args": [{"property": "geometry"}, aoi]},
{"op": "anyinteracts", "args": [{"property": "datetime"}, daterange]},
{"op": "=", "args": [{"property": "collection"}, "landsat-c2-l2"]},
{"op": "=", "args": [{"property": "platform"}, "landsat-8"]}
]
})
# Grab the first item from the search results and sign the assets
first_item = next(search.get_items())
pc.sign_item(first_item).assets Once that bug is fixed you'll be able to do select multiple and do it all in one search. And hopefully we can support the |
Beta Was this translation helpful? Give feedback.
-
Dear @cullen-molitor @TomAugspurger, in the latest development version of the # install sits version 1.1.0 current development package (soon on CRAN)
devtools::install_github("e-sensing/sits@dev")
# select a shapefile to serve as a region of interest
# ROI can also be defined as Lat/long boxes in WGS84
shp_file <- system.file("extdata/shapefiles/df_bsb/df_bsb.shp",
package = "sits"
)
# read the shapefile as an sf object
sf_bsb <- sf::read_sf(shp_file)
# select a subset of MSPC LANDSAT-C2-L2 collection
landsat_cube <- sits::sits_cube(
source = "MSPC",
collection = "LANDSAT-C2-L2",
roi = sf_bsb,
platform = "LANDSAT-5",
bands = c("GREEN", "NIR08", "SWIR22"),
start_date = as.Date("2008-07-18"),
end_date = as.Date("2008-10-23")
)
# list the files you want
landsat_cube$file_info[[1]] |
Beta Was this translation helpful? Give feedback.
-
Hi @TomAugspurger, indeed in |
Beta Was this translation helpful? Give feedback.
-
The important bit (at least for me) is how concise and short should the API be. IMHO, Planetary Computer users would benefit from an API that is as clean (or cleaner) than the Google Earth Engine one. |
Beta Was this translation helpful? Give feedback.
You can use the
in
operator to filter to specific platforms using the STAC query extension. Our example notebook now includes a section demonstrating this with pystac-client.Using pystac-client that would be
All the items returned in the
search
iterable will be fromlandsat-8
orlandsat-9
.(orignal post below)
Agreed that a tutorial would be helpful here. I'm waiting for a couple of things to …