1

I am fairly new to Google Earth Engine. Essentially I am trying to export the mean temperature for each polygon in a the WDPA to a csv. I can export smaller subsections of the feature collection but if I try and do it for all the polygons the export fails with the following: Error: User Memory limit Exceeded

Is this possible or do i need to chop up the feature collection?

Thank you in advance!!

var wdpa = ee.FeatureCollection('WCMC/WDPA/current/polygons');

// Daily mean 2m air temperature
var dataset = ee.ImageCollection('ECMWF/ERA5/DAILY').select('mean_2m_air_temperature');

//Create a list of the years that you would like to take the mean for 
var years = ee.List.sequence(1981,2018);

//Create an image collection that calculates the mean temperature for each year
var byYear = ee.ImageCollection.fromImages(
  years.map(function (y) {
    var year = dataset.filter(ee.Filter.date(ee.Date.fromYMD(y, 01, 01), ee.Date.fromYMD(y, 12, 31)))
    .mean()
    .set('year', ee.String('Year_').cat(ee.Number(y).int()));
    return year;
  }));
print(byYear);

// extract the mean temperature for each year in each protected area
var Mean_Temp = byYear.map(function(image) {
  return image.reduceRegions({
    // collection:wdpaCentroids,
    collection: wdpa,
    reducer: ee.Reducer.mean(), 
    scale: 1000
  }).map(function(feature) {
    var empty = feature.geometry();
    return ee.Feature(null).set({
      'wdpa_pid': ee.String(feature.get('WDPA_PID')),
      'year': image.get('year'),
      'temp_mean':feature.get('mean'), 
      'name': feature.get('NAME')
    });
  });
}).flatten();
// print(Mean_Temp);

// Format the triplet to allow for a CSV to be exported
var format = function(table, rowId, colId, rowProperty, colProperty) {
  var rows = table.distinct(rowId); 
  var joined = ee.Join.saveAll('matches').apply({
    primary: rows, 
    secondary: table, 
    condition: ee.Filter.equals({
      leftField: rowId, 
      rightField: rowId
    })
  });
  return joined.map(function(row) {
      var values = ee.List(row.get('matches'))
        .map(function(feature) {
          feature = ee.Feature(feature);
          return [feature.get(colId), feature.get(colProperty)];
        }).flatten();
      return row.select([rowId, rowProperty]).set(ee.Dictionary(values));
    });
};

// Note that there's a dummy feature in there for the points ('null').
var transpose = format(Mean_Temp, 'wdpa_pid', 'year','null', 'temp_mean');
// print(transpose);

// Export the Dataset as a CSV
Export.table.toDrive({
  collection: transpose,
  description:'WDPA_Temperature',
  fileFormat: "csv"
});
Val
  • 6,585
  • 5
  • 22
  • 52

1 Answers1

0

As discussed in this doc, try setting tileScale in your reduceRegion() or reduceRegions() calls.