Calculating dates of unique images for a certain area in imageCollection using Google Earth Engine

google-earth-enginegoogle-earth-engine-python-apisentinel-1

I am trying to retrieve an image from the Sentinel-1 image collection where the user provides a time of interest and a region of interest.
Since Sentinel-1 provides new images for a region only every 7 days, I want to calculate these unique dates so I could constraint the user to only pick these as a toi.
What I have so far is this code:

def get_available_dates_from_collection(collection):
    dates = collection.map(lambda image:
                           ee.Feature(None, {'date': image.date().format('YYYY-MM-dd')}))\
                                                     .distinct('date').aggregate_array('date')
    return dates.getInfo()

The function calculates all the available dates in an image collection and I use the list returned to constraint the user to pick a date within that list. Since the roi isn't considered here, 6 dates out of 7 will return the same image.

Is there a way that I could calculate the unique dates for each unique image of that region?

Best Answer

You can just filter your collection by your roi beforehand using collection.filterBounds(roi) (or roi.geometry(), depends on your roi).