0

I keep getting the error: Cannot add an object of type object as a layer.

It is regarding line 53 of the link below (code is also copied below, error: Map.addLayer(CF_solar, CF_solar, "CF_solar")). I think I need to process the overlay differently but having tried multiple options, I am hitting a wall. What am I doing wrong?

GEE script

// import geometry (point to zoom in to)
var home_coords = ee.Geometry.Point([-7.6, 54.4])
var region = home_coords.buffer(20000);

// load image stack for one year
var dataset = ee.ImageCollection("NASA/GLDAS/V20/NOAH/G025/T3H")
  .filterDate('2010-12-01', '2010-12-31')
  .filterBounds(home_coords)

// has keys type, id, version, bands, features, properties
//print(dataset);

// extract air temperature, SW radiation for one year
var AirTemperature = dataset.select('Tair_f_inst'); //.rename("T");
var Irradiation_ShortWave = dataset.select('SWdown_f_tavg');
var WindSpeed = dataset.select('Wind_f_inst');

// take composite (yearly mean) of irradiation and air temp and store in different bands of image
var T_G_comp = ee.Image(AirTemperature.mean().subtract(273.15))
    .addBands(ee.Image(Irradiation_ShortWave.mean()));

// ImageCollection, has same keys as above
//print(AirTemperature);

// Method for computing CFsolar mean
var CF = (
    '(1-beta*(c1 + c2*T + c3*G - T_ref) + gamma*log_10(G+1))*G/G_ref',
    {
      'beta': 0.0045,
      'c1': -3.75,
      'c2': 1.14,
      'c3': 0.0175,
      'T_ref': 25,
      'gamma': 0.1,
      'G_ref': 1000,
      'T': ee.Image(AirTemperature.mean().subtract(273.15)),
      'G': ee.Image(Irradiation_ShortWave.mean()),
    })

// use "print" to check any variables in the console
print(CF)

var T = {bands: "Tair_f_inst", min:-30, max: 688}
var G = {bands: "SWdown_f_tavg", min:-900, max: 999}
var CF_solar = {bands: "CF_solar", min: -999, max: 9310, palette: ["blue", "red", "orange", "yellow"]}


// Adding these layers is just doing a solid colour overlay. 
Map.addLayer((AirTemperature.mean().subtract(273.15)), T, "T")
Map.addLayer((Irradiation_ShortWave.mean()), G, "G")

// Cannot add this type of object to a layer

Map.addLayer(CF_solar, CF_solar, "CF_solar")


// print graphs
//print(ui.Chart.image.doySeries(Irradiation_ShortWave, home_coords, ee.Reducer.mean(), 30));
//print(ui.Chart.image.doySeries(WindSpeed, home_coords, ee.Reducer.mean(), 30));
Vince
  • 20,017
  • 15
  • 45
  • 64
gall
  • 1
  • 1
  • 1

1 Answers1

0

The error you get is because CF_solar is a JavaScript object, which EE cannot add to the Map (it's not even a EE Object). You are trying to add it in Map.addLayer(CF_solar, CF_solar, "CF_solar"). But that is not all. If you would do Map.addLayer(CF, CF_solar, "CF_solar") it wouldn't work neither, because you haven't computed CF Image correctly, that variable is just a JS list.

That list you defined as CF should be the argument of ee.Image.expression function.

// import geometry (point to zoom in to)
var home_coords = ee.Geometry.Point([-7.6, 54.4])
var region = home_coords.buffer(20000);

// load image stack for one year
var dataset = ee.ImageCollection("NASA/GLDAS/V20/NOAH/G025/T3H")
  .filterDate('2010-12-01', '2010-12-31')
  .filterBounds(home_coords)

// has keys type, id, version, bands, features, properties
//print(dataset);

// extract air temperature, SW radiation for one year
var AirTemperature = dataset.select('Tair_f_inst'); //.rename("T");
var Irradiation_ShortWave = dataset.select('SWdown_f_tavg');
var WindSpeed = dataset.select('Wind_f_inst');

// take composite (yearly mean) of irradiation and air temp and store in different bands of image
var T_G_comp = ee.Image(AirTemperature.mean().subtract(273.15))
    .addBands(ee.Image(Irradiation_ShortWave.mean()));

// ImageCollection, has same keys as above
//print(AirTemperature);

// Method for computing CFsolar mean
var CF = ee.Image().expression(
    '(1-beta*(c1 + c2*T + c3*G - T_ref) + gamma*log(G+1))*G/G_ref',
    {
      'beta': 0.0045,
      'c1': -3.75,
      'c2': 1.14,
      'c3': 0.0175,
      'T_ref': 25,
      'gamma': 0.1,
      'G_ref': 1000,
      'T': ee.Image(AirTemperature.mean().subtract(273.15)),
      'G': ee.Image(Irradiation_ShortWave.mean()),
    }).rename('CF_solar')

// use "print" to check any variables in the console
print(CF)

var T = {bands: "Tair_f_inst", min:-30, max: 688}
var G = {bands: "SWdown_f_tavg", min:-900, max: 999}
var CF_solar = {bands: "CF_solar", min: -999, max: 9310, palette: ["blue", "red", "orange", "yellow"]}


// Adding these layers is just doing a solid colour overlay. 
Map.addLayer((AirTemperature.mean().subtract(273.15)), T, "T")
Map.addLayer((Irradiation_ShortWave.mean()), G, "G")

// Cannot add this type of object to a layer
Map.addLayer(CF, CF_solar, "CF_solar")
Rodrigo E. Principe
  • 10,085
  • 1
  • 28
  • 35