I'm working on building a model in google earth engine that will estimate carrying capacities for bird species based off of a table I have of bird densities per land cover type and an image of land cover types.
I'm at a point in my process where I have an image of bird densities across my region of interest. I want to use reduceRegion() with an ee.Reducer.sum() to get the total carrying capacity across my region of interest. My code looks like this:
//Density_Image is the image of bird densities I want to reduce.
//ROI is a FeatureCollection of regions within my region of interest.
print(Density_Image.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: ROI.geometry().geometries().get(3),
maxPixels: 1e11,
tileScale: 16}));
This code works when I feed in a single feature (~1e8 pixels), but fails when I try to feed in the area covered by my entire feature collection (~2e9 pixels) because the computation takes too long.
To get around this issue, and also because I would like to store the carrying capacity of each subregion, I'm trying to write a .map() function that will loop through each feature (region) in my ROI FeatureCollection, calculate carrying capacity for that feature, and then store carrying capacity in a new property I'll set within that feature, 'pop_est'. Here is my code for that:
var pop_est_table = table.map(function(f) {
print(f);
// line above throws an error that argref = null.
Density_Image = ee.Image(remap2);
print(Density_Image);
var pop_est = Density_Image.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: f.geometry(),
bestTry: true,
maxPixels: 1e12,
tileScale: 16});
return ee.Feature(f).set('pop_est', pop_est);
});
The code I've written has at least two things wrong with it.
1) The code will run and set a new property in each feature class called 'pop_est', but these values are always 0. Additionally, trying to print f throws an error:
Feature (Error) Failed to decode JSON. Error: Field 'value' of object '{"type":"ArgumentRef","value":null}' is missing or null. Object: {"type":"ArgumentRef","value":null}.
I believe this error occurs because I am trying to call print(), a client-side function inside a server-side function, map(). I have a hunch the first error is also a result of some client-side/server-side confusion and would love some help on how to fix my code.
2) Even if this code does work I am worried that calling a reduceRegion() on each feature will take too long, causing google earth engine to shut down the computation.
How do I allow for a longer runtime or devote more computing power to this operation?
I've read that exporting is one way to attain longer runtimes, but I'm unfamiliar with the procedure.
I've tried several other approaches at this point, like clipping each feature out of my Density_Image and then putting those in an ImageCollection and mapping through that. I also tried reduceRegions(), but neither worked because their computations took too long.
No comments:
Post a Comment