0

I was trying to retrieving chlorophyll-a levels using Landsat9. After processed it using this function :

 //Clorophyll-a Levels
 // Coefficients
 var a0= 0.341
 var a1= -3.001
 var a2= 2.811
 var a3= -2.041
 var a4= 0.0400

function R(img){
return img.expression(
      'log10(blue/green)',
      {
        'blue': img.select('B2'),
        'green': img.select('B3')
      });
}

var Ratio = citra.map(R)

function chlor(img){
return img.expression(
      '10**(a0+a1*R+a2*R**2+a3*R**3)+a4',
      {
        'a0': a0,
        'a1': a1,
        'a2': a2,
        'a3': a3,
        'a4': a4,
        'R': Ratio
      })
}

var chl = citra.map(chlor)

var ChlVisPar = {min:0.4,max:1.5,palette:['blue','lime','yellow','orange','red']}
Map.addLayer(chl,ChlVisPar,'Chlor-a')

I cant visualize using the Map.addLayer(chla,ChlVisPar,'Chlor-a') and I got messages:

Layer error: Image.pow, argument 'image1': Invalid type.
Expected type: Image.
Actual type: ImageCollection.

How do I solve this?

2
  • The error is clear. You are trying to add an ImageCollection when an Image is expected. You either have to choose an image from the collection to show (e.g. chl.first() or use chl.get(index). Or make an aggregation (e.g. chl.median()). If you want to show every image in the collection as a layer you can use an approach such as this answer but map over indices up to the collection length, rather than the year.
    – Matt
    Commented Nov 30, 2023 at 9:36
  • Previously, I had done similar processing with a dataset in the form of images with expression features. However, I cannot carry out the cloudmasking process using the QA_PIXEL band along with other features such as bitwise. therefore I tried to recreate it by processing the imagecollection using a function. Is it possible if I can change the processing results into images, or how do I clip images in the first processing with AOI imagecollection which I have cloudmasked? Commented Nov 30, 2023 at 10:16

1 Answer 1

0

The error is not because you're trying to add an ee.ImageCollection to the Map. Actually, when you do that, the function adds a mosaic of all images inside the collection, and the inspector shows the values of each image as a series.

So, before adding each individual image into the Map, you need to fix the error.

The method ee.ImageCollection.map returns an ee.ImageCollection, thus the variable Ratio is of that type. In the function chlor you're trying to use Ratio as a variable in the expression, but you can only use ee.Image

This is how I'd solve it:

function R(img){
  return img.expression(
        'log10(blue/green)',
        {
          'blue': img.select('B2'),
          'green': img.select('B3')
        });
}

function chlor(img){
  var r = R(img)
  return ee.Image().expression(
        '10**(a0+a1*R+a2*R**2+a3*R**3)+a4',
        {
          'a0': a0,
          'a1': a1,
          'a2': a2,
          'a3': a3,
          'a4': a4,
          'R': r
        })
}

https://code.earthengine.google.com/eea2a43e47f2f84e8d67d624bbf37cf9

Then, you can add each image on the Map using different techniques. This is what I would do:

var addIC = function(col, property) {
  // choose a property to use as filter and img name
  property = property || "system:index"
  // fetch all values for that property
  var allProp = col.aggregate_array(property).getInfo()
  // loop over each value of the property
  for (var i in allProp) {
    var prop = allProp[i]
    // filter the IC with the property value and get one image
    var i = col.filter(ee.Filter.eq(property, prop)).first()
    // add to map
    Map.addLayer(i, ChlVisPar, prop)
  }
}

addIC(chl)

https://code.earthengine.google.com/28690cc4e4334673d27163b2954d4870

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.