1

In my code, for an unknown reason one of the features (in a FC with a few thousand conflict locations and their dates) is causing a problem leading to this error: FeatureCollection (Error) Error in map(ID=00000000000000001ae5): Number.subtract: Parameter 'left' is required. When I print it, it does't seem to be different.

I know that it cannot be a problem with the FC because the same FC works together with an other Image Collection in a script doing the same thing.

Also when I limit the FC to exclude number 137 (ID=00000000000000001ae5) then the script works. var conflicts = ee.FeatureCollection('users/welp1992/Conflicts25_Date').limit(136)

This is the FC: https://code.earthengine.google.com/?asset=users/welp1992/Conflicts25_Date

And this the Code: https://code.earthengine.google.com/?accept_repo=users/welp1992/Master

3
  • Your script cannot be opened. Try running your script with only the feature causing the error, and print all intermediate variables to find where the error occurs exactly. Get that single feature using: var feat = ee.Feature(table.filter(ee.Filter.eq('system:index', '00000000000000001ae5')).first()).
    – Kuik
    Commented Jul 6, 2020 at 13:36
  • Ok, I did mark the 'anyone can read' field. So it should be accessable right? Either this: code.earthengine.google.com/… Or this: code.earthengine.google.com/?accept_repo=users/welp1992/Master should work.
    – Mathias
    Commented Jul 6, 2020 at 14:34
  • I tried to find the error with your way (with help of the debugging guide). But the script is not running when I replace the FC with the single feature (feat).
    – Mathias
    Commented Jul 6, 2020 at 15:58

1 Answer 1

1

To debug properly, do the following:

run the code with only that feature Do this without a map(), so you can print intermediate steps

var feat = ee.Feature(conf.filter(ee.Filter.eq('system:index', '00000000000000001ae5')).first())
// You will see that there are null values
var slope = addSlopes(feat);

Adding to map reveals why: image collection has masked values at the point

Map.centerObject(feat, 10)
Map.addLayer(feat)
Map.addLayer(timeSeries)

A workaround is to filter the feature collection on null values (beforeSlope and afterSlope) and then calculate the slope change for only non-null features. Thus, you will calculate the 'slopeChange' property after filtering for null values.

var conflictsWithSlopes = conflicts.map(addSlopes)
var filtNulls = conflictsWithSlopes.filter(ee.Filter.notNull(['beforeSlope', 'afterSlope']));
var withSlopeChange = filtNulls.map(function(feat){
  return ee.Feature(feat).set('slopeChange', 
          feat.getNumber('afterSlope').subtract(feat.getNumber('beforeSlope')))
});
print('withSlopeChange', withSlopeChange)

See here a reproducible example of how to debug within a function, outside server-side mapping over a collection.

PS: you link did not work as you did not copy the full link

3
  • Thank you for your help! The debugging is more clear now! It makes sense to filter for non-null values. I tried to use your filter (in different ways) and always still get the error. var conflictsWithSlopes = conflicts.map(addSlopes) var filtNulls = conflictsWithSlopes.filter(ee.Filter.notNull(['beforeSlope', 'afterSlope'])); var withSlopeChange = filtNulls.map(function(conflicts){ return ee.FeatureCollection(conflicts).set('slopeChange', filtNulls.getNumber('afterSlope').subtract(filtNulls.getNumber('beforeSlope'))) }); Is this correct?
    – Mathias
    Commented Jul 7, 2020 at 12:48
  • Did you analyse the link I provided? That should run without error, though you will probably have to export the result.
    – Kuik
    Commented Jul 7, 2020 at 14:04
  • I did look at it, and I exported it and it works! I thought its only using/excluding this one feature now. But apparently it works.
    – Mathias
    Commented Jul 8, 2020 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.