0

I want to create a time-series of Sentinel-2 images that cover my entire study area (instead of individual tiles, since the study area spans 2 tiles). I mosaicked the image collection by day using the following function (where S2 is the Sentinel-2 image collection):

    function mosaicByDate(collection){
  var imagelist = S2.toList(S2.size())
  var unique_dates = imagelist.map(function(image){
    return ee.Image(image).date().format("YYYY-MM-dd")
  }).distinct()
  var imagelist_mosaic = unique_dates.map(function(d){
    d = ee.Date(d)
    var image = collection
      .filterDate(d, d.advance(1, "day"))
      .mosaic()
    return image.set(
        "system:time_start", d.millis(), 
        "system:id", d.format("YYYY-MM-dd")).copyProperties(image, image.propertyNames())
  })
  return ee.ImageCollection(imagelist_mosaic)
}

var S2_mosaic = mosaicByDate(S2)

The function works perfectly, but since there are some days where only one of the tiles is acquired (so there is no mosaicking), the time-series of images shows only half the study area for these dates. I created a filmstrip to show what this looks like.

Filmstrip of mosaicked images I now would like to remove the image dates for which there is only one tile... anyone have a suggestion how do this? Unfortunately it is not consistantly every other image, there are subsequent one-tile dates as well. The image below corresponds to the imagedates of the filmstrip shown above.

Image dates

2
  • 1
    There is few approaches you could try, one is mapping over the unique dates in your imageCollection and for each day check if there is two images. Another way could be to compute the amount of NoData values and if there is to many (find a threshold) you are probably dealing with incomplete mosaic. But without a working example it will be hard to help you!
    – Jobbo90
    Aug 24, 2021 at 6:53
  • Hi @Jobbo90, thanks for your reply! Sorry about that, here is a link to a working example I made just now: link For your first suggestion you would then manually remove the one-tile dates?
    – jkool
    Aug 24, 2021 at 8:20

1 Answer 1

1

When you set the time and id, also set a property with the number of scenes in the collection (get that before the mosaic), then filter out the images without enough scenes.

var imagelist_mosaic = unique_dates.map(function(d){
    d = ee.Date(d)
    var result = collection
      .filterDate(d, d.advance(1, "day"))

    var size = result.size();
      
    return image.mosaic().set(
        "system:time_start", d.millis(), 
        "system:id", d.format("YYYY-MM-dd"),
        "count", result.size())
      .copyProperties(image, image.propertyNames())
  })
  return ee.ImageCollection(imagelist_mosaic).filter("size > 1")
}
2
  • Hi Noel! Thanks so much. I adjusted your code a little to work for in my script (code link). Turns out the count of images does not necessarily determine the area coverage (for example, sometimes 2 image counts covers the entire area and sometimes 4 counts covers only half...) So my assumption that I could solve the problem with counts wasn't right. But, since it is consistantly the left-side of the half-images with nodata I could apply some sort of spatial filter..? Not sure how yet. Thanks again!
    – jkool
    Aug 24, 2021 at 15:17
  • Altright so I found a way! A bit of a detour but I added a polygon on the left side and filtered a collection to those bounds, then extracted the dates and filtered the final imagecollection to contain only those dates, this way there are no left-side-empty images! Thanks for all the input.
    – jkool
    Aug 24, 2021 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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