2

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?

3
  • Why don't you just filter your collection by your roi beforehand using collection.filterBounds(roi) (or roi.geometry(), depends on roi)? Aug 14, 2021 at 12:31
  • @malin-fischer Yes! That worked! I calculated the dates before I filtered on my roi and didn't realize that after filtering the images back are unique! Thank you very much!
    – Kinana
    Aug 15, 2021 at 12:05
  • Great! Just posted this as an answer which you can select so that it's clear that this question does not need any support any more. Aug 15, 2021 at 17:23

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.