Wednesday 27 February 2019

google earth engine - Function takes too long to run (over 72 hours)


I have an errorless code, which works for 3 days of daily data. however I wish to use it for 6000 days. It has not stopped running (we are on hour 75) There are two if statements inside a function with which I change a value if it is below a maximum or minimum, which I thought would be the problem, however when I removed those, the code is still running for more than a day (and going). The piece of the code I am showing is the piece from which I expect the long runtime comes. It can however also be earlier on in the code.


var unweighted = function(img){var uni = img.reduceRegions({

reducer: ee.Reducer.sum().unweighted(),
collection: grid2,
scale:500}).map(function(feat){
var id = ee.String(feat.get('system:index')).cat('-').cat(ee.String(img.get('system:index')));
var date = ee.String(img.get('system:index'));
var bandNames = img.bandNames().map(function(name){return ee.Number.parse(name)});
var values = ee.Feature(feat).toDictionary(img.bandNames()).values();
var array = ee.Array.cat([values, bandNames], 1);
var min = array.reduce(ee.Reducer.min(2), [0], 1);
var key = ee.String(min.get([0,1]).toInt());

var minh = feat.get('min')
var maxh = feat.get('max')
if (key>maxh){var key = maxh}
else if (minh>key){var key = minh}
return ee.Feature(feat.setMulti(ee.Dictionary.fromLists(['Minimum','id'], [key, id])));
});
return uni;
};

Preferably I would still have a minimum and maximum check. What would be even better is that every band under the minimum and over the maximum are removed for each image seperatly. However at the moment I mostly have to tackle the runtime. Can anyone see why it runs for so long, and what can I do to streamline it?



Link to code




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...