0

I am looking at the soil moisture levels across districts in India between the years 2000-2019 using Google Earth Engine. I have been trying to use reduceRegions to get an individual mean value of soil moisture for each district in each year. This seems to need a reducer over space and time. Is there a way to combine two reducers to get these values?

Ideal output is .csv file containing the year, the district and the district's average soil moisture value for the 20 year period.

Here is what I have tried so far:

// Example code that gets mean value of time period for region
var districtSM2017 = meanSM.reduceRegions({
  collection: fusionIndia,
  reducer: ee.Reducer.mean(),
  scale: soilMoisture.first().projection().nominalScale(),
});
//print(districtSM2017);

// What I actually want is just the mean soil moisture for the district for each year,
// not an average for the whole time period

// Tried the below code but this function does not work with an ImageCollection

var districtSM = soilMoisture.reduceRegions({
  collection: fusionIndia,
  reducer: ee.Reducer.mean(),
  scale: soilMoisture.first().projection().nominalScale()
});
print(districtSM);

I have attached a link to my code in GEE to show what I have tried so far.

0

As I understand, you would like a mean image for every year? You can make mean images of each year for example using this code:

// Make yearly means
var yearlyMeans = ee.ImageCollection.fromImages(ee.List.sequence(2000, 2019,1).map(function(year){
  var start = ee.Date.fromYMD(year, 1,1);
  var end = ee.Date.fromYMD(ee.Number(year).add(1), 1,1);
  var meanImage = soilMoisture.filterDate(start, end).mean();
  return meanImage.set('year', year, 'system:time_start', start.millis());
}))
  // filter out years without images
  .filter(ee.Filter.listContains('system:band_names', 'ssm'));
print(yearlyMeans)

Then you can use that new generated collection. You can indeed not use reduceRegions with image collections, therefore you need to map over that image collection. You can then return a feature for every year and every region. You can export that featurecollection directly to a CSV (export.Table.toDrive).

var mapped = yearlyMeans.map(function(image){
  var districtSM = image.reduceRegions({
    collection: fusionIndia,
    reducer: ee.Reducer.mean(),
    scale: scale,
    crs: proj
  }).map(function(feat){
    return feat.set('year', image.get('year'))
  });
  return districtSM
}).flatten();

NOTE1: as you feature collection was not shared, I made a sample geometry to test the code: Link code NOTE2: I think the image collection only contains data from 2015-2020...

|improve this answer|||||
  • Thank you for the help - this is exactly what I needed – Alice Jan 20 at 10:16

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.