Skip to main content
syntax highlighting
Source Link
Kersten
  • 9.9k
  • 3
  • 39
  • 59
var countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017")
var hansen = ee.Image("UMD/hansen/global_forest_change_2017_v1_5")
var CAN=countries.filter(ee.Filter.eq('country_na','Canada'))
var countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017")
var hansen = ee.Image("UMD/hansen/global_forest_change_2017_v1_5")
var CAN=countries.filter(ee.Filter.eq('country_na','Canada'))
var lossImage2016=hansen.select(['lossyear']).eq(16)
var areaImage = lossImage2016.multiply(ee.Image.pixelArea())
var lossImage2016=hansen.select(['lossyear']).eq(16)
var areaImage = lossImage2016.multiply(ee.Image.pixelArea())
var areaImageMasked=areaImage.updateMask(areaImage)
Map.addLayer(CAN,{},'Canada') //make the map
Map.addLayer(areaImageMasked,{},'areaImageMasked')
var areaImageMasked=areaImage.updateMask(areaImage)
Map.addLayer(CAN,{},'Canada') //make the map
Map.addLayer(areaImageMasked,{},'areaImageMasked')
var stats = areaImageMasked.reduceRegions({
  reducer: ee.Reducer.sum(), //variously, ''sum'' or 'ee.Reducer.sum()' are used in ee documentation
  collection: CAN
  scale:30, //scale of image pixel size should always be specified, as per guides/reducers_reduce_region
  //tileScale:16 //valid tileScale is 1 to 16.
});
print('pixels representing loss: ', stats.get('loss'), 'square meters')
var stats = areaImageMasked.reduceRegions({
  reducer: ee.Reducer.sum(), //variously, ''sum'' or 'ee.Reducer.sum()' are used in ee documentation
  collection: CAN
  scale:30, //scale of image pixel size should always be specified, as per guides/reducers_reduce_region
  //tileScale:16 //valid tileScale is 1 to 16.
});
print('pixels representing loss: ', stats.get('loss'), 'square meters')
var ecoregions = ee.FeatureCollection("RESOLVE/ECOREGIONS/2017")
var singleRegion=ecoregions.filter(ee.Filter.eq('ECO_NAME','East Siberian taiga'))
var stats = areaImageMasked.reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: singleRegion,
  scale:30,
  maxPixels:1e12 //There appear to be 9176816981 to count!!
});
var ecoregions = ee.FeatureCollection("RESOLVE/ECOREGIONS/2017")
var singleRegion=ecoregions.filter(ee.Filter.eq('ECO_NAME','East Siberian taiga'))
var stats = areaImageMasked.reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: singleRegion,
  scale:30,
  maxPixels:1e12 //There appear to be 9176816981 to count!!
});
var countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017")
var hansen = ee.Image("UMD/hansen/global_forest_change_2017_v1_5")
var CAN=countries.filter(ee.Filter.eq('country_na','Canada'))
var lossImage2016=hansen.select(['lossyear']).eq(16)
var areaImage = lossImage2016.multiply(ee.Image.pixelArea())
var areaImageMasked=areaImage.updateMask(areaImage)
Map.addLayer(CAN,{},'Canada') //make the map
Map.addLayer(areaImageMasked,{},'areaImageMasked')
var stats = areaImageMasked.reduceRegions({
  reducer: ee.Reducer.sum(), //variously, ''sum'' or 'ee.Reducer.sum()' are used in ee documentation
  collection: CAN
  scale:30, //scale of image pixel size should always be specified, as per guides/reducers_reduce_region
  //tileScale:16 //valid tileScale is 1 to 16.
});
print('pixels representing loss: ', stats.get('loss'), 'square meters')
var ecoregions = ee.FeatureCollection("RESOLVE/ECOREGIONS/2017")
var singleRegion=ecoregions.filter(ee.Filter.eq('ECO_NAME','East Siberian taiga'))
var stats = areaImageMasked.reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: singleRegion,
  scale:30,
  maxPixels:1e12 //There appear to be 9176816981 to count!!
});
var countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017")
var hansen = ee.Image("UMD/hansen/global_forest_change_2017_v1_5")
var CAN=countries.filter(ee.Filter.eq('country_na','Canada'))
var lossImage2016=hansen.select(['lossyear']).eq(16)
var areaImage = lossImage2016.multiply(ee.Image.pixelArea())
var areaImageMasked=areaImage.updateMask(areaImage)
Map.addLayer(CAN,{},'Canada') //make the map
Map.addLayer(areaImageMasked,{},'areaImageMasked')
var stats = areaImageMasked.reduceRegions({
  reducer: ee.Reducer.sum(), //variously, ''sum'' or 'ee.Reducer.sum()' are used in ee documentation
  collection: CAN
  scale:30, //scale of image pixel size should always be specified, as per guides/reducers_reduce_region
  //tileScale:16 //valid tileScale is 1 to 16.
});
print('pixels representing loss: ', stats.get('loss'), 'square meters')
var ecoregions = ee.FeatureCollection("RESOLVE/ECOREGIONS/2017")
var singleRegion=ecoregions.filter(ee.Filter.eq('ECO_NAME','East Siberian taiga'))
var stats = areaImageMasked.reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: singleRegion,
  scale:30,
  maxPixels:1e12 //There appear to be 9176816981 to count!!
});
added 746 characters in body
Source Link
antifrax
  • 138
  • 1
  • 7

A reproducible example: I want to use a reducer with a very large feature. For example, I want to sum the values in the white pixels that occur in the Canada polygon in the below image. Note that this polygon appears to be broken into 6 EE 'tiles'. We will also try the task with a less complex polygon, the East Siberian Taiga ecoregion.

enter image description hereenter image description here

OK, now let'sLet's try to sum this (sparse) raster layer. Calling "print(CAN)" shows CAN is a feature collection. You can call reduceRegion() with "geometry:CAN.geometry()" to force an aggregation of all the area lostfeatures, but the resulting polygon is too big, so this throws a 'user memory limit exceeded' error. Instead, you can call reduceRegions() with "collection:CAN":

var stats = areaImageMasked.reduceRegionreduceRegions({
  reducer: 'sum'ee.Reducer.sum(), //variously, 'sum'''sum'' or 'ee.Reducer.sum()' are used in ee documentation
  geometrycollection: CAN.geometry(), //is the ".geometry() doing anything?
  maxPixels: 1e13,
  scale:30, //scale of image pixel size should always be specified, as per guides/reducers_reduce_region
  bestEffort:true,
  //tileScale:16 //valid tileScale is 1 to 16. Here I reduce tile size (For server-side parallelization) by 16x
});
print('pixels representing loss: ', stats.get('loss'), 'square meters')

This throws 'ComputedObjecta 'computation timed out' error. The same result is obtained when setting "tileScale:16" (Errorthe max value): User memory limit exceeded'. Because there's so few pixels to count, I assume this is because ofreduce the size and complexity of the featureeach tile used for server-side parallelization. Note that I am using

Let's try the simplified version ofsame task with the country boundary vector data that is preloaded in EE (and is presumably preferred and used often). So that that's odd.East Siberian taiga polygon. This is a multi-polygon with 9147 vertices:

var ecoregions = ee.FeatureCollection("RESOLVE/ECOREGIONS/2017")
var singleRegion=ecoregions.filter(ee.Filter.eq('ECO_NAME','East Siberian taiga'))
var stats = areaImageMasked.reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: singleRegion,
  scale:30,
  maxPixels:1e12 //There appear to be 9176816981 to count!!
});

This also throws a 'computation timed out' error.and suggests I'm doing something wrong Even when clipping the input Image to the extent of the singleRegion polygon, there appear to remain ~9 billion pixels to count! This seems implausible.

A reproducible example: I want to use a reducer with a very large feature. For example, I want to sum the values in the white pixels that occur in the Canada polygon in the below image. Note that this polygon appears to be broken into 6 EE 'tiles'.

enter image description here

OK, now let's try to sum the area lost:

var stats = areaImageMasked.reduceRegion({
  reducer: 'sum', //variously, 'sum' or 'ee.Reducer.sum()' are used in ee documentation
  geometry: CAN.geometry(), //is the ".geometry() doing anything?
  maxPixels: 1e13,
  scale:30, //scale of image pixel size should always be specified, as per guides/reducers_reduce_region
  bestEffort:true,
  tileScale:16 //valid tileScale is 1 to 16. Here I reduce tile size (For server-side parallelization) by 16x
});
print('pixels representing loss: ', stats.get('loss'), 'square meters')

This throws 'ComputedObject (Error): User memory limit exceeded'. Because there's so few pixels to count, I assume this is because of the size and complexity of the feature. Note that I am using the simplified version of the country boundary vector data that is preloaded in EE (and is presumably preferred and used often). So that that's odd...and suggests I'm doing something wrong!

A reproducible example: I want to use a reducer with a very large feature. For example, I want to sum the values in the white pixels that occur in the Canada polygon in the below image. Note that this polygon appears to be broken into 6 EE 'tiles'. We will also try the task with a less complex polygon, the East Siberian Taiga ecoregion.

enter image description here

Let's try to sum this (sparse) raster layer. Calling "print(CAN)" shows CAN is a feature collection. You can call reduceRegion() with "geometry:CAN.geometry()" to force an aggregation of all the features, but the resulting polygon is too big, so this throws a 'user memory limit exceeded' error. Instead, you can call reduceRegions() with "collection:CAN":

var stats = areaImageMasked.reduceRegions({
  reducer: ee.Reducer.sum(), //variously, ''sum'' or 'ee.Reducer.sum()' are used in ee documentation
  collection: CAN
  scale:30, //scale of image pixel size should always be specified, as per guides/reducers_reduce_region
  //tileScale:16 //valid tileScale is 1 to 16.
});
print('pixels representing loss: ', stats.get('loss'), 'square meters')

This throws a 'computation timed out' error. The same result is obtained when setting "tileScale:16" (the max value) to reduce the size of each tile used for server-side parallelization.

Let's try the same task with the East Siberian taiga polygon. This is a multi-polygon with 9147 vertices:

var ecoregions = ee.FeatureCollection("RESOLVE/ECOREGIONS/2017")
var singleRegion=ecoregions.filter(ee.Filter.eq('ECO_NAME','East Siberian taiga'))
var stats = areaImageMasked.reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: singleRegion,
  scale:30,
  maxPixels:1e12 //There appear to be 9176816981 to count!!
});

This also throws a 'computation timed out' error. Even when clipping the input Image to the extent of the singleRegion polygon, there appear to remain ~9 billion pixels to count! This seems implausible.

deleted 29 characters in body
Source Link
antifrax
  • 138
  • 1
  • 7

The problem: How can onewe work around memory limits to apply a reducer over a very large feature? EE's debugging page suggests either setting using tileScale to reduce the size of the tiles used for server-side parallelization if using arrays, or to set bestEffort:true with a regular feature. Neither option works in the following example.

The taskA reproducible example: I want to use a reducer with a very large feature. For example, I want to sum the values in the white pixels that occur in the Canada polygon in the below image. Note that this polygon appears to be broken into 6 EE 'tiles'.

How can we work around memory limits in an 'EE way' ? AnsweringI have identified the following questions sub-questions which may be helpful (or I may have the wrong idea entirely)in finding an answer:

How can one work around memory limits to apply a reducer over a very large feature? EE's debugging page suggests either setting using tileScale to reduce the size of the tiles used for server-side parallelization if using arrays, or to set bestEffort:true with a regular feature. Neither option works in the following example.

The task: I want to use a reducer with a very large feature. For example, I want to sum the values in the white pixels that occur in the Canada polygon in the below image. Note that this polygon appears to be broken into 6 EE 'tiles'.

How can we work around memory limits in an 'EE way' ? Answering the following questions may be helpful (or I may have the wrong idea entirely):

The problem: How can we work around memory limits to apply a reducer over a large feature? EE's debugging page suggests either setting using tileScale to reduce the size of the tiles used for server-side parallelization if using arrays, or to set bestEffort:true with a regular feature. Neither option works in the following example.

A reproducible example: I want to use a reducer with a very large feature. For example, I want to sum the values in the white pixels that occur in the Canada polygon in the below image. Note that this polygon appears to be broken into 6 EE 'tiles'.

I have identified the following sub-questions which may be helpful in finding an answer:

Source Link
antifrax
  • 138
  • 1
  • 7
Loading