3

I'm trying to plot a chart and get data from Google Earth Engine. I'm using MODIS-Aqua/L3SMI data in Earth Engine.

I have used Earth Engines in built functions to compare average sea surface temperatures by day of year per year. However, it's pretty busy and would like to calculate an average per month then plot the different years of the data set. Using the code here I've been able to get an average per month over all years in the data set.

var sst = ee.ImageCollection('NASA/OCEANDATA/MODIS- 
Aqua/L3SMI').select('sst').filterDate(ee.Date('2013-01-01'), ee.Date('2017- 
12-31'))

var byMonth = ee.ImageCollection.fromImages(
months.map(function (m) {
return sst.filter(ee.Filter.calendarRange(m, m, 'month'))
            .select(0).mean()
            .set('month', m);
 }));

Can this code be altered to pull out the year information as well, so I can get the data by per month per year at all?

5
var sst = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI')
    .select('sst')
    .filterDate(ee.Date('2013-01-01'), ee.Date('2017-12-31'))

var months = ee.List.sequence(1, 12);
var years = ee.List.sequence(2013, 2017);

var byMonthYear = ee.ImageCollection.fromImages(
  years.map(function(y) {
    return months.map(function (m) {
      return sst
        .filter(ee.Filter.calendarRange(y, y, 'year'))
        .filter(ee.Filter.calendarRange(m, m, 'month'))
        .mean()
        .set('month', m).set('year', y);
  });
}).flatten());
print(byMonthYear)
  • Thanks that's great, was really struggling how to add in a year part to this code. I'm very new to this so I really appreciate your help – mikejwilliamson Jul 28 '18 at 7: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.