Google Earth Engine – Combine Two Image Collections

google-earth-engine

I am very new to GEE and I'm even having difficulties deciphering other people's potential solutions.

After processing each data source into one imageCollection each, I am trying to make a simple calculation between these two. One of the ideas that I had is to combine both imageCollections into one image collection where each image have bands from imageCollection1 and imageCollection2.
I tried the solution in the link, and while the join is successful, it doesn't seem to be able to add the second band. Is it because the metadata of the two imageCollections are different ?

https://code.earthengine.google.com/c0bb0bbdccf975d144b52031321795b6

var GRACE = ee.ImageCollection('NASA/GRACE/MASS_GRIDS/LAND')
                  .filter(ee.Filter.date('2003-08-01', '2003-12-01')).select('lwe_thickness_csr');

print(GRACE, 'GRACE')

var SWS = ee.ImageCollection('NASA/FLDAS/NOAH01/C/GL/M/V001');
SWS = SWS.filterDate('2003-08-01', '2003-12-01').select('SoilMoi100_200cm_tavg');


/// Get information about the GRACE projection.
var graceProjection = GRACE.first().projection();

///Resampling to meet GRACE resolution
var resampleSWS = SWS.map(function(image) {
    var mean = image
      // Force the next reprojection to aggregate instead of resampling.
     .reduceResolution({
        reducer: ee.Reducer.mean(),
       maxPixels: 1024
     }).rename('resampled SWS')
     // Request the data at the scale and projection of the GRACE image.
      .reproject({
       crs: graceProjection
     });
      return mean.set('system:time_start', image.get('system:time_start'))
})

print(resampleSWS, 'resampled SWS')


///Combine two image collections
var mod1 = GRACE.select('lwe_thickness_csr')
var mod2 = resampleSWS.select('resampled SWS')

var filter = ee.Filter.equals({
  leftField: 'system:time_start',
  rightField: 'system:time_start'
});

// Create the join.
var simpleJoin = ee.Join.simple();

// Applt join
var mod1join = ee.ImageCollection(simpleJoin.apply(mod1, mod2, filter))
var mod2join = ee.ImageCollection(simpleJoin.apply(mod2, mod1, filter))

print('Joined', mod1join, mod2join)

I don't see to be able to get this running right. Any suggestions?

Best Answer

I think the solution you're looking for is an inner join. It's described here

///Combine two image collections
var mod1 = GRACE.select('lwe_thickness_csr')
var mod2 = resampleSWS.select('resampled SWS')

var filter = ee.Filter.equals({
  leftField: 'system:time_start',
  rightField: 'system:time_start'
});

// Create the join.
var simpleJoin = ee.Join.inner();

// Inner join
var innerJoin = ee.ImageCollection(simpleJoin.apply(mod1, mod2, filter))

var joined = innerJoin.map(function(feature) {
  return ee.Image.cat(feature.get('primary'), feature.get('secondary'));
})

print('Joined', joined)