Google Earth Engine – Filtering Image Collection by Filename Using Wildcards

filtergoogle-earth-enginegoogle-earth-engine-javascript-apisentinel-2

I am new to GEE and now I need to filter and sort a sentinel 2 data collection by cloud coverage. Basically, I need the Ecuador tile with "T17MNT" in its id in image properties. I figure out the workflow should be something like the following, but I still have issues with the Filter.

  1. How do I use a wildcard in gee?

There are lots of images but I just want those that have "T17MNT" in "PRODUCT_ID". T17MNT stands for the granule identifier in Eduador. EE asset ids for Sentinel-2 L2 assets have the following format: COPERNICUS/S2_SR/20151128T002653_20151128T102149_T56MNN. The final 6-character string is a unique granule identifier. But other digits are dates and times and I don't want them in my filter. I assume the wildcard is something like "?T17MNT?".

  1. This is the link to the sentinel 2 dataset. See "image properties" tab. "PRODUCT_ID" might not be the correct field that contains the long name described above. but please ignore that for now, or let me know the correct one.

This is the error I receive.

ImageCollection (Error)
Filter.inList: Cannot filter using 'ListContains' with 'T17MNT' as a left operand.

This is the code I am using.

var dataset = ee.ImageCollection('COPERNICUS/S2_SR')
                  .filterDate('2020-05-23', '2020-10-25')
                  .filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE', 16))
                  .filter(ee.Filter.inList('PRODUCT_ID', 'T17MNT'))
                  .sort('CLOUDY_PIXEL_PERCENTAGE', false)

Best Answer

.filter(ee.Filter.stringContains('PRODUCT_ID','T17MNT'))