0

Link to GEE Code

I try to use this Function with ee.ImageCollection.map()

var Fail = function(Im){ var min = ee.Image(Im.reduceRegion(ee.Reducer.min(),aoi).get('B10').getInfo()) var max = ee.Image(Im.reduceRegion(ee.Reducer.max(),aoi).get('B10').getInfo()) var Failvalue = Im.expression( '( Im - min )/( max -min )', { 'Im': Im, 'min': min, 'max': max, }) return Failvalue }

Using this Function on a Single Image will not obtain an error, see Success Using this Function on an ee.Colection with .map() results in:

Failed to decode JSON. Error: Field 'value' of object '{"type":"ArgumentRef","value":null}' is missing or null. Object: {"type":"ArgumentRef","value":null}.

The problem lies within the ee.ReduceRegion(), which retrieves a dictionary. This dictionary is unpacked with .get('B10') and Determined to a value with .getInfo(), so that it can be used as numeric input in ee.Image()

is there another way to construct an Image from a number, retrieved via reduction of a region?

closed as off-topic by Vince, Andre Silva, LaughU, Jochen Schwarze, whyzar Feb 11 at 14:44

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – Vince, Andre Silva, LaughU, Jochen Schwarze, whyzar
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    While a link to a larger body of code can be useful for optional context, it is policy here that coding questions need to contain a Minimal, Complete, Verifiable example in the body of the question. This increases the probability that your code will be read (since some folks won't follow links), increases the chance that others can find your question (because body contents are indexed), and increases the chance that you'll find the problem on your own (because making a minimal example often locates the issue) – Vince Feb 10 at 13:18
  • I added the code of the function. you are right – Alexander Vocaet Feb 10 at 21:55
  • 1
    Please include the error message as text as well (again, for search purposes, but also for legibility) – Vince Feb 10 at 23:34
  • also done, thanks – Alexander Vocaet Feb 11 at 9:40
0

You cannot use getInfo() inside a mapped function, as mapping happens on the server side. GetInfo() returns objects on the client side.

As a user, you know that the output of the get('B10') will be a number, however GEE does not know that. Therefore, cast it to a ee.Number and you can use it inside your mapped function:

var Succes = function(Im){
 var min = ee.Number(ee.Image(Im.reduceRegion(ee.Reducer.min(),aoi).get('B10')));
 var max = ee.Number(ee.Image(Im.reduceRegion(ee.Reducer.max(),aoi).get('B10')));
 var SuccesImage = Im.expression(
    '( Im - min )/( max -min )', {
      'Im': Im,
      'min': min,
      'max': max,
      });
  return SuccesImage.rename('ImgExpressionOutput');
};

Link

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