I'm trying to create a list of images in Google Earth Engine. These images are generated by a function. The input to this function is a number. Here's a simplified version of the problem I'm encountering:
I have the following function that multiplies a number by an image, and returns an image as a result:
function multiply_by_2(num) {
// Multiply the number by an image with the value 2
var image1 = ee.Image(2);
// Convert num to an image for multiplication
var image2 = ee.Image(num);
// Multiply the two images together
var result = image1.multiply(image2);
return result;
}
If I call the function with a single number, it behaves as expected:
var number = ee.Number(5);
var multiplied_number = multiply_by_2(number);
print(multiplied_number);
Result in console:
But if I try to use map, which should apply this function to every number in a list, I get an error:
var number_list = ee.List.sequence(1,10);
var multiplied_list = number_list.map(multiply_by_2);
print(multiplied_list)
Result in console:
The error complains that Image.multiply
has been given a floating point number instead of an image. But in my function, I'm giving Image.multiply
an image! What's going on here?