Following this example I have merged 2 image collections to create a synthetic twice daily Aqua and Terra composite. Now I want to generate the median image of this combined collection. For a single collection this already works with:

var collection = ee.ImageCollection('MODIS/006/MOD09GQ');
var filtered_date = collection.filterDate('2010-10-01', '2010-12-10');
var medianImage = filtered_date.median();
Map.addLayer(medianImage, {bands:['sur_refl_b02'], min:100, max:4500});

However, the merge seems to interfere with the following script.

var collection_1 = ee.ImageCollection('MODIS/006/MOD09GQ');          
var collection_2 = ee.ImageCollection('MODIS/006/MYD09GQ');
var collection_date_1 = collection_1.filterDate('2010-10-01', '2010-12-10');
var collection_date_2 = collection_2.filterDate('2010-10-01', '2010-12-10');
print('Terra collection', collection_date_1);
print('Aqua collection', collection_date_2);

// merge collections
var collection_merge = collection_date_1.merge(collection_date_2);
print('Merged collection',collection_merge);

// sort merged collection
var collection_merge_sorted = collection_merge.sort("system:time_start");
print('Sorted merged collection', collection_merge_sorted)

var medianImage_10 = collection_merge_sorted.median();
Map.addLayer(medianImage_10, {bands:['sur_refl_b02'], min:100, max:4000});

The script returns that 'collection_merge_sorted.median is not a function', which seems to be caused by the merge itself. How to avoid this?


Call ee.ImageCollection:

var medianImage_10 = ee.ImageCollection(collection_merge_sorted).median();

Link: https://code.earthengine.google.com/273462eda06defe2b6c2958cc41fabca

  • If you are only calculating the median there is also no need to sort - you can directly call ee.ImageCollection(collection_date_1.merge(collection_date_2)).median()
    – Kersten
    May 31 '18 at 20:23

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.