Skip to content

Issue: 'FUNCTION TO REDUCE COLLECTION TO SINGLE IMAGE PER YEAR BY MEDOID' #40

@Towhid-Islam

Description

@Towhid-Islam

Thank you so much for developing the amazing tool in GEE. I found that medoid method was applied to create yearly landsat composite (article link). I found the relevant codes in GEE for this operation (medoid method):

// make a medoid composite with equal weight among indices
var medoidMosaic = function(inCollection, dummyCollection) {
  
  // fill in missing years with the dummy collection
  // ** braaten edit 2023-05-02: toList and If are resource intensive, simply
  // ** merging the inCollection and dummyCollection should achieve the goal
  // ** of have at least one image for the median operation.
  var imageCount = inCollection.toList(1).length();                                                            // get the number of images 
  var finalCollection = ee.ImageCollection(ee.Algorithms.If(imageCount.gt(0), inCollection, dummyCollection)); // if the number of images in this year is 0, then use the dummy collection, otherwise use the SR collection
  // var finalCollection = inCollection.merge(dummyCollection);
  
  // calculate median across images in collection per band
  var median = finalCollection.median();                                                                       // calculate the median of the annual image collection - returns a single 6 band image - the collection median per band
  
  // calculate the different between the median and the observation per image per band
  var difFromMedian = finalCollection.map(function(img) {
    var diff = ee.Image(img).subtract(median).pow(ee.Image.constant(2));                                       // get the difference between each image/band and the corresponding band median and take to power of 2 to make negatives positive and make greater differences weight more
    return diff.reduce('sum').addBands(img);                                                                   // per image in collection, sum the powered difference across the bands - set this as the first band add the SR bands to it - now a 7 band image collection
  });
  
  // get the medoid by selecting the image pixel with the smallest difference between median and observation per band 
  return ee.ImageCollection(difFromMedian).reduce(ee.Reducer.min(7)).select([1,2,3,4,5,6], ['B1','B2','B3','B4','B5','B7']); // find the powered difference that is the least - what image object is the closest to the median of teh collection - and then subset the SR bands and name them - leave behind the powered difference band
};

Here, .reduce(ee.Reducer.min(7) gave me output with the lowest value of the pixels rather than the closest value to the median. I am not so sure through, this may lead to the inappropriate result. Could you please confirm that the tool actually used medoid method to prepare yearly single image? I will be very grateful for that.
I might be wrong. If so, please accept my apologies and let me know why it is alright. Thank you so much! I will be looking forward to your kind response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions