0

I run into an error when merging 2 image collections.

Goal: I want to merge the (identical) 250m daily Terra and Aqua MODIS collections into one image collection to obtain one collection with 2 images per day:

// ------MODIS 250M DAILY ----------------------------------------------
var modis_250m_daily_terra =  modis_250m_daily_terra.filterBounds(aoi).filterDate(date_start,date_end);
var modis_250m_daily_aqua = modis_250m_daily_aqua.filterBounds(aoi).filterDate(date_start,date_end);`

Method to merge the collections:
>`// ------MERGE MODIS 250M DAILY ----------------------------------------------
var modis1 = modis_250m_daily_terra.merge(modis_250m_daily_aqua);
// sort by date
var modis1 = modis1.sort("system:time_start");
print('MODIS Surface Reflectance Daily 250m',modis1); 
var size_modis1 = modis1.filterBounds(aoi).filterDate(date_start,date_end).toList(100000).length();
print('Total images in modis1 (250m daily) in current time frame: ', size_modis1);
print('Merged 250m MODIS',modis1);

This seems to work until in the following function, this code runs into an error "Invalid argument specified for ee.List(): sur_refl_b01", whereas this function used to work without the merge.

// ------CLOUDFUNCTION----------------------------------------------------
var cloudfunction = function(image){
  //filter the image on its high reflectance part
  var cloud = image.select('sur_refl_b01').rename('cloud');
  var cloud01 = cloud.gt(1000).lt(4000);
  image = image.updateMask(cloud01).addBands(cloud);
  var area = ee.Image.pixelArea();
  var cloudArea = cloud01.multiply(area).rename('cloudArea');
  image = image.addBands(cloudArea);
  var stats = cloudArea.reduceRegion({
    reducer: ee.Reducer.sum(),
    geometry: aoi,
    scale: 250,
  });
  return image.set(stats);
};
var collection = modis1.map(cloudfunction);
print ('Clouds pixels', collection);

I tried a way to 'join' the collections instead, but this doesn´t give the semidiurnal image collection. Any ideas on how to either avoid the error, or to improve the merge that I applied?

1

I do not think this has anything to do with merge. You have an error in the select / rename part of your cloudfunction function that should actually be:

var cloud = image.select(['sur_refl_b01'], ['cloud']);

Also your cloud01 declaration looks as it would not work as intended:

var cloud01 = cloud.gt(1000).and(cloud.lt(4000));

Following OP's comment I think the problem may be solved by surrounding merge in an ee.ImageCollection statement:

var modis1 = ee.ImageCollection(modis_250m_daily_terra.merge(modis_250m_daily_aqua))

As an aside, for efficiency reasons, I would select the sur_refl_b01 band from modis1 image collection and map cloudfunction on it rather than selecting the band on an image by image basis inside the function itself. Something like this (not tested):

var modis1 = ee.ImageCollection(
      modis_250m_daily_terra.merge(modis_250m_daily_aqua))
    .sort("system:time_start");

var modis_clouds = modis1.select(['sur_refl_b01'], ['cloud']);

function cloudfunction(image){
  var cloud01   = image.gt(1000).and(image.lt(4000));
  var area      = ee.Image.pixelArea();
  var cloudArea = cloud01.multiply(area).rename('cloudArea');
  var stats = cloudArea.reduceRegion({
    reducer: ee.Reducer.sum(),
    geometry: aoi,
    scale: 250,
  });
  return image
    .updateMask(cloud01)
    .addBands(cloudArea)
    .set(stats);
}

var collection = modis_clouds.map(cloudfunction);
print ('Clouds pixels', collection);
  • Thanks for your answer. It partially solves the fact of running into the error that I mentioned, but now it refers to image.select(...).rename is not a function. Also, it used to run with the given code if I apply it to 1 dataset, but started bugging when I applied the merge. – Wouter Neisingh May 8 '18 at 12:55

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.