0

I am new to google earth engine (and js admittedly) and I have a collection of points in Bangladesh that I am trying to extract the rainfall value for each point over the entire CHIRPS image collection and create a csv. I tested one year (1981) and it worked perfectly. However, when I tried other singular years, GEE timed out. This also happened when I tried to do this for the entire CHIRPS collection.

Can anyone help me out?

There are only 84 points and I don't think it should take hours and hours when it only took a minute or so for 1981.

var hhclustered = ee.FeatureCollection("projects/gee/iso3/bgd/clustered_bgd"),
    hh = ee.FeatureCollection("projects/gee/iso3/bgd/clustered_bgd_clipped"),
    cc = ee.FeatureCollection("projects/gee/iso3/bgd/centroid_clusters"),
    rf = ee.ImageCollection("UCSB-CHG/CHIRPS/PENTAD");

var startDate = ee.Date('2015-01-01');
var endDate = ee.Date('2015-12-31');
print(startDate);
print(endDate);

var rf = rf.filter(ee.Filter.date(startDate, endDate));

var pentad = 'pentad';
var precipitation = 'precipitation';

print(rf);

var scale = rf.first().projection().nominalScale().getInfo();

var mapFunction = function (area) {
    var first = image.reduceRegion(ee.Reducer.first(), area.geometry(), scale).get(precipitation);

    return area.set('meanPrecipitation', first);
};

var workPerHousehold = function (image, newList) {
    newList = ee.List(newList);
    var indexLastElement = ee.Number(newList.size()).subtract(1);
    var element = ee.Feature(newList.get(indexLastElement));
    var initialList = newList.remove(element);
    newList = ee.List(ee.Algorithms.If(element.get(pentad), newList, initialList));
    image = ee.Image(image);
    var meanDictionary = image.reduceRegion({
        reducer: ee.Reducer.first(),
        geometry: element.geometry(),
        scale: scale,
        bestEffort: true
    });

    // to anticipate on Error: Dictionary.get: Dictionary does not contain key: precipitation
    var precipitationValue = ee.Algorithms.If(meanDictionary.contains(precipitation), meanDictionary.get(precipitation),'null' );
     var val = 'ignore';

    return newList.add(ee.Feature(element.set(
        {  precipitation: precipitationValue,
        pentad: val
        })));

};


var workPerHH = function (household, pentadList) {
    pentadList = ee.List(pentadList).add(household);
    return rf.iterate(workPerHousehold, pentadList);
};

var pentadList = ee.List([]);
var areaAdded = ee.FeatureCollection(ee.List(cc.iterate(workPerHH, pentadList)));



var csvFields = ['cluster', precipitation,  pentad ];


var description = 'Bangladesh-precipitation-pentad-2015';
Export.table.toDrive(
                areaAdded,
                description
);

  • Does it work if your cc csv only contains 1 row? Is that how you determined that it worked correctly for 1981? – phloem Jul 16 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.