Global Snow Observatory: Joining Collections

As part of our analysis, we need the snow cover tile description and the zenith angle. The Sensor zenith angle must come from another MODIS dataset, as it is not included in the standard MOD10A1 dataset. Fortunately, Google Earth Engine also contains the MOD09GA dataset. If we call it in and look at the bands it contains per the previous example, we can see the SensorZenith band (band 2 in the image below).

SensorZenith band in MOD09GA

Our goal is to get the sensor zenith angle band from MOD09GA into the imagery that contains our snow cover data. To select a particular band to work with, we can use the .select() method, like so:

var MOD09GA = ee.ImageCollection('MOD09GA').select('SensorZenith')
  .filterDate('2005-10-01', '2006-09-30');

print(MOD09GA);

Earth Engine Code Example

Joining two collections requires a common property between the two, just as it does in standard GIS software. In this case, the best way to join the collections is to join them based on their acquisition times, using the system:time_start property as the filter. We will use the join.inner() method. The code to join the two datasets together looks like this:

// First, we define the two datasets, selecting the bands we are interested in
var MOD09GA = ee.ImageCollection('MOD09GA').select('SensorZenith')
  .filterDate('2005-10-01', '2005-10-31');
var MOD10A1 = ee.ImageCollection('MOD10A1').select('Snow_Cover_Daily_Tile')
  .filterDate('2005-10-01', '2005-10-31');

// Define the join and filter
var Join = ee.Join.inner();
var FilterOnStartTime = ee.Filter.equals({
  'leftField': 'system:time_start',
  'rightField': 'system:time_start'
});

// Join the two collections, passing entries through the filter
var JoinedMODIS = Join.apply(MOD09GA, MOD10A1, FilterOnStartTime);

print(JoinedMODIS);

Earth Engine Code Example

Congratulations, we've just joined two MODIS collections, and it took less than 20 lines of code to do so! However, if you print the resulting collection, you get something like this...

Screenshot of print results

The Image Collection has now become a FeatureCollection, and all of the features need to include the bands we want. Instead, they are in the columns "primary" and "secondary," as explained in the documentation for the join. To return this to a format that we can work with, we need to run a function across the FeatureCollection, creating a new image that has the bands in the primary column and the secondary column.

// A function to merge the bands together after a join
// the bands are referred to as the 'primary' and 'secondary' properties
var MergeBands = function(aRow) {
  var anImage = ee.Image.cat(aRow.get('primary'), aRow.get('secondary'));
  return anImage;
};

var MergedMODIS = JoinedMODIS.map(MergeBands);

print(MergedMODIS);

Earth Engine Code Example

Screenshot after merging bands

Now that we have a function that joins the two collections, we need to mask out pixels that have a sensor zenith angle greater than 25°.