nasa / EMIT-Data-Resources

This repository provides guides, short how-tos, and tutorials to help users access and work with data from the Earth Surface Mineral Dust Source Investigation (EMIT) mission.
Apache License 2.0
138 stars 81 forks source link

How to filter cloud_cover for EMIT data using pystac? #45

Closed zxdawn closed 11 months ago

zxdawn commented 1 year ago
from pystac_client import Client

url = 'https://cmr.earthdata.nasa.gov/stac/LPCLOUD/?page=2'
collections = ['EMITL1BRAD.v001', 'EMITL1BRAD.v001']
bbox = [-99.65, 18.85, -98.5, 19.95]
date_range = "2022-05/2023-08"

catalog = Client.open(url)

params = {
'collections': collections,
'bbox': bbox,
'datetime': date_range,
'limit': 100,
}

filt = {
    "op": "lte",
    "args": [{"property": "eo:cloud_cover"}, 40]
}

# params['filter'] = filt

search = catalog.search(**params)

print('Matching STAC Items:', search.matched())

It works well without the cloud_cover filter. However, I get this error if I try to add the filter:

    215     raise APIError(str(err))
    216 if resp.status_code != 200:
--> 217     raise APIError.from_response(resp)
    218 try:
    219     return resp.content.decode("utf-8")

APIError: {"message":"If the problem persists please contact cmr-support@earthdata.nasa.gov","errors":["An unexpected error occurred. We have been alerted and are working to resolve the problem.","Unsupported parameter filter"]}

Is this not supported yet? Otherwise, I have to access the cloud_cover properties from the collections:

image

amfriesz commented 1 year ago

Hey @zxdawn, the current implementation of the CMR STAC API does not support filtering based on those properties. I think it's an important capability to include, but I can't tell you when or if that would be available. An alternative option would be to use the earthaccess package. I've include a code snippet below.

search_params = {
    "concept_id": "C2408009906-LPCLOUD", # CMR concept ID for EMITL1BRAD.001
    #"day_night_flag": "day",
    "cloud_cover": (0, 10),
    "temporal": ("2022-05", "2023-08"),
    "bounding_box": (-99.65, 18.85, -98.5, 19.95)
}

results = earthaccess.search_data(**search_params)

# Get links to data...  note that EMITL1BRAD.001 contains 2 data files per 'granule'
[x.data_links() for x in results]
zxdawn commented 11 months ago

Thanks! It works well. Close now ;)

zxdawn commented 11 months ago

It would be nice to see the support of pystac. It's useful to use pystac to check the RGB data quickly.