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°.
.map and .mask
.map
The .map() method runs a function across every element in a collection and returns a collection. It is one of the most useful tools in our arsenal.
.mask
Masking is another widely used method to process an image. It can be difficult to understand at first, so let’s look at the description of the mask method:
“The output image retains the metadata and footprint of the input image.” That’s the important line from the description. Anything within the mask is kept as is, and anything outside the mask is converted to a "masked" value. A mask call looks like so:
Using the .mask and .map functions, we will modify our code to mask out any pixels with a sensor zenith angle greater than 25 degrees. The function to do so will look like this:
Remember that we will want to do this to every image in the collection, so we will use the .map() method again, like so:
//Masking collections
// A function to assign high sensor zenith angle cells to null
var MaskSensorPixels = function(anImage) {
var LessThan25 = anImage.select('SensorZenith').lte(2500); // Angle is stored as angle * 100 in MOD09
return anImage.mask(LessThan25);
};
// 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;
};
// 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);
var MergedMODIS = JoinedMODIS.map(MergeBands);
var MakedMODIS = ee.ImageCollection(MergedMODIS).map(MaskSensorPixels);
The next step is to reclassify the snow cover into a snow/no snow/missing scheme.