Global Snow Observatory: Calculating Snow Cover Frequency

Our dataset is now ready to be analyzed. We have an image collection of images that have a single band, called remapped, that represents a sensor-adjusted and reclassified snow cover for each day of the collection. Snow cover frequency is the number of days with a snow observation divided by the number of days with a valid observation. So, we need to count the number of times a snow value appears and the number of times a snow or land value appears. After calculating snow cover frequency, that information needs to be added to an image as a band, along with a constant time value, so that we can hand that to the reducer as discussed in the Outline and Goals section.

About Reducers

Reducers are a special method that usually doesn't take an input argument. They instead act at each pixel stack in an imageCollection and calculate a specific property of that stack, returning an image. If you think back to our reclassification scheme, pixels with snow have a value of 1, pixels with a valid observation have a value of 0, and all other pixels have a value of null. In order to calculate snow cover frequency, we need to know both the number of snow days and the number of valid days. Luckily, GEE has just the methods for this. The .count() method will count the number of times a pixel has a valid value within an imageCollection and will ignore (not count) those images that have a “masked” value so that it will count both snow and no snow values in a pixel stack. We can also count the number of snow days at a pixel directly by using the .sum() method, which adds the values in that stack of pixels. We also want to wrap this up in its own function. The code to do so appears as follows:

// Prepare MODIS snow cover data for calculating snow cover frequency
var PrepareModisSnowCover = function(StartDate, EndDate) {
  // ...existing code for joining, masking, and reclassifying...
};

var CalculateSnowCoverFrequency = function(ModisSnowCover) {
  var NumOfSnowDays = ModisSnowCover.sum();
  var NumOfValidObsDays = ModisSnowCover.count();
  var SnowCoverFrequency = NumOfSnowDays.divide(NumOfValidObsDays);
  return SnowCoverFrequency;
};

Earth Engine Code Example

Note that we have created two functions, a "prepare the dataset within a given time frame" function and a "calculate the snow cover frequency from a given dataset" function. These two functions together give us the Y axis, but we must now attach a date time stamp to each snow cover frequency. Think back to the requirements for the linearFit reducer if this doesn't make sense.