1

I have a feature collection of about 80,000 tiles, and I am trying to calculate the annual maximum drought severity index score for each tile using TerraClimate data. TerraClimate is an image collection, so I started by transforming it into a stack of images.

var drought_M = ee.ImageCollection("IDAHO_EPSCOR/TERRACLIMATE").select("pdsi")
    .filter(ee.Filter.date('2000-01-01', '2012-12-31'));

//This function creates a stack of images from the image collection
function newCollectionToImage(collection){
    var stack = ee.Image(collection.iterate(function(img, prev) {
        return ee.Image(prev).addBands(img);
    }, ee.Image(1)));
 
    stack = stack.select(ee.List.sequence(1, stack.bandNames().size().subtract(1)));
    return stack;
}

//This function renames the image collection bands
var drought_M_rename = drought_M.map(function(img){
var y = ee.String(ee.Date(img.get('system:time_start')).get("year"));
return img.set("year",y).rename(y);
});

//Apply the function to create a stack of images
var droughtImageStack = newCollectionToImage(drought_M_rename);

I tried to use reduceRegions() to get the monthly score for each tile.

var droughtImageStack = tchImg.reduceRegions(tiles, ee.Reducer.mean());

This works in the terminal, but when I try to export the dataframe as a csv, GEE returns the error:

Error: User memory limit exceeded.

I've been told before that image reductions become a lot more efficient when you map over the feature collection. I tried to use the basic intuition of how to map over a feature collection for reduceRegion() and attempted the following:

var droughtTiles = tiles.map(function(feature) {
  return feature.set(droughtImageStack.reduceRegions({
    reducer: ee.Reducer.mean(),
    geometry: feature.geometry(),
    scale: 10
  }));
});

But this map function returns an error: Required argument (collection) missing to function: Image.reduceRegions(image, collection, reducer, scale, crs, crsTransform, tileScale)...

How can I adjust my mapping function to produce monthly tile means that export?

0

There are a few issues with your code. First, instead of your function newCollectionToImage() which is really slow because you are using .iterate(), use .toBands().

//Apply the function to create a stack of images
var droughtImageStack = drought_M_rename.toBands();

Then, also make sure that you set an appropriate scale during reduceRegions(). TerraClimate has a resolution of 2.5 arc minutes, which would be about 4.5 km at the equator, so let's try it like this.

tchImg.reduceRegions({
    reducer: ee.Reducer.mean(),
    collection: feature.geometry(),
    scale: 4500
  });

If this doesn't work, have a look at this answer for an example on how to use map with .reduceRegions(). Edit: Just realized, that the answer I linked you is an answer to another one of your questions, so this might be not help you much.

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.