0

The objective of the following script is to provide an average cumulative precipitation for a certain area, defined as geometry. However, because the geometry is so big and I am looking at so many years, GEE always exceeds its memory limit. I am usually able to generate a mean from 2007 - 2018, but never any further back than that. I have tried resampling the images, but to no avail. I realize the script is very inefficient and inelegant, but while it can be written shorter, I am not sure you can reduce the amount of calculations it has to go through. Also, running with the profiler shows that "Table Decode" takes up the most memory. Is there a way to improve the script such that it does not hit this limit?

var geometry = ee.Geometry.Polygon(
        [[[20.611582005096125, 43.680227139350066],
          [21.005732822109962, 44.00297749793862],
          [21.69781652118604, 44.67878460449116],
          [22.418669262013168, 44.97896037295039],
          [23.862868609461657, 45.11692801754022],
          [24.33527775862308, 45.0447312465754],
          [24.9095361588096, 45.199890809255194],
          [24.862133176836664, 45.41046821166596],
          [25.287303814495203, 45.512798338924846],
          [24.69007738755613, 45.638581103955794],
          [24.239519801258893, 45.483538277783154],
          [23.915199727025538, 45.46732808634292],
          [24.01575593879693, 45.5718161313184],
          [23.74189742987994, 45.66004469067013],
          [23.092405545362112, 45.504499125826634],
          [22.842598680173978, 45.34738578137168],
          [22.568278361274338, 45.224921711601795],
          [22.119988440190696, 45.08448829397715],
          [21.722189525403905, 44.872946838088914],
          [21.42259193042321, 45.171537266964904],
          [21.47068650662436, 45.64419871096055],
          [21.5192767051916, 46.02715061986298],
          [21.318588160040008, 46.182828613335175],
          [21.191677812017247, 46.54539224733879],
          [19.9930666615345, 46.14344773942803],
          [19.89716444506871, 45.76070677980506],
          [19.048566046360293, 45.73804999758513],
          [18.80547609011569, 45.316902065489344],
          [19.682010308024473, 44.93630784403325]]]);


var chirpsColl = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
                .filterDate('1988-01-01', '2018-12-31')
                .filterBounds(geometry);

var precip1988 = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
            .filterDate('1988-01-01', '1988-12-30')
            .filterBounds(geometry);

var values1988 = ee.List(precip1988.toList(precip1988.size()).iterate(function(i, c) {
  i = ee.Image(i);
  //first lower the resolution,
  var p = i.reproject({
  crs:'EPSG:32642',
  scale: 24000
})

  //then reduce by the region
  var g = p.reduceRegion({
    reducer: ee.Reducer.mean(),
    geometry: geometry,
    scale: 24000
  }).values().get(0);
  var c = ee.List(c);

  return c.add(ee.Number(c.get(-1)).add(g));
}, ee.List([1]))).slice(1);


.
.
.


var precip2018 = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
            .filterDate('2018-01-01', '2018-12-31')
            .filterBounds(geometry);

var values2018 = ee.List(precip2018.toList(precip2018.size()).iterate(function(i, c) {
  i = ee.Image(i);
  //first lower the resolution,
  var p = i.reproject({
  crs:'EPSG:32642',
  scale: 24000
})
  //then reduce by the region
  var g = p.reduceRegion({
    reducer: ee.Reducer.mean(),
    geometry: geometry,
    scale: 24000
  }).values().get(0);
  var c = ee.List(c);

  return c.add(ee.Number(c.get(-1)).add(g));
}, ee.List([1]))).slice(1);

var AllYearsCat = ee.Array.cat([values1988,  . . .  , values2018],1)

var AllYearsMean = AllYearsCat.reduce({
  reducer:ee.Reducer.mean(),
  axes: [1]}).project([0]);

var allYearsW2018 = ee.Array.cat([AllYearsMean],1)

var days = ee.List.sequence(1,364)

var allYearsChart = ui.Chart.array.values(allYearsW2018, 0, days)
.setSeriesNames(['1988-2018 Average'])
.setOptions({
  title: 'CumuPrecip 1988-2018 mean vs 2018',
  hAxis: {title: 'Day of Year', maxValue: 365},
  vAxis: {title: 'Cumulative precipitation (mm)'},
  pointSize: 0, lineWidth: 1.5
});

On a side-note, is it possible to reproject for an entire ImageCollection?

Edit: I tried circumventing the memory limit by dividing the polygon into 3 smaller polygons, then "manually" executing one after the other by adding buttons to avoid synchronous computations. This works, but if there is a better way to partition the computations into a queue without having to executing them by hand, that would be even better!

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.