2

I am trying to generate a chart and I am finding it hard to generate it. Is it a coding error in calling my functions? https://code.earthengine.google.com/?scriptPath=users%2Fmpalasimbarashe%2FProject1%3ABOA7Research

/// IMPORTING THE FEATURE COLLECTION ///
var points = points.map(function(feature){
  var sample_id = feature.get('Sample_ID');
  return ee.Feature(feature.geometry(), {'id': feature.id()})
    .set('Sample_ID', sample_id);
});

Map.addLayer(points,{color:'green'},'Root Locations');
Map.centerObject(points,10);
print(points);

var points_list = points.toList(points.size());

var keys = points_list.map(function (ele) {

  return ee.Feature(ele).get('id');
  
});

var values = points_list.map(function (ele) {

  return ee.Feature(ele).get('Sample_ID');
  
});

var dict = ee.Dictionary.fromLists(keys, values);

/// FILTERING THE SENTINEL IMAGE COLLECTION ////
var start_date = '2010-09-01';
var end_date   = '2011-05-30';

var criteria = ee.Filter.and(
    ee.Filter.bounds(points), ee.Filter.date(start_date, end_date));
var cloud_perc = 10;//Max cloud percentile per scene.    


var L7_col = ee.ImageCollection('LANDSAT/LE07/C01/T1_TOA')
                .filter(criteria)
                .filter(ee.Filter.lt('CLOUD_COVER', cloud_perc));


// - Import the SIAC atmospheric correction module
var siac = require('users/marcyinfeng/utils:SIAC');

// - Apply SIAC and retrieve bottom of atmosphere (BOA) reflectance
var L7_boa = siac.get_l7_sur(L7_col.first());
// var L8_boa = siac.get_l8_sur(L8_col.first()); 
// var S2_boa = siac.get_sur(S2_col.first()); 


// - Check and visualization
var Color_comp_01 = {bands:"B3,B2,B1", min: 0.0, max: 0.2, gamma: 1};
var Color_comp =    {bands:"B3,B2,B1", min:200, max:2000, gamma: 1};
Map.addLayer(L7_col.first(), Color_comp, 'TOA');
Map.addLayer(L7_boa, Color_comp_01, 'BOA');
Map.centerObject(L7_col.first())


////Adding SAIC to the Collection/// 
function siac_collection(img){

var siac = require('users/marcyinfeng/utils:SIAC');

return siac.get_sur(img).copyProperties(img,['system:time_start','system:time_end']);
}

var correctedCollection = L7_col.map(siac_collection)
    



///// KNDVI FUNCTION //////

var addKNDVI = function(correctedCollection){
  
  var RED = image.select('B4');
  var NIR = image.select('B8');
  
  /// COMPUTE D2 A RENAME TO d2 ///
  var D2 = NIR.subtract(RED).pow(2)
    .select([0],['d2']);
 
  /// GAMMA DEFINED AS 1/sigma^2
  var gamma = ee.Number(4e6).multiply(-2.0);

/// COMPUTE KERNEL (k) AND KNDVI ///

  var k = D2.divide(gamma).exp();
  var kndvi = ee.Image.constant(1)
    .subtract(k).divide(ee.Image.constant(1).add(k))
    .select([0],['kndvi']).clip(points);
    
     return image.addBands(ee.Image([kndvi]));
 
};

var testPoint = ee.Feature(points.first());
print(testPoint);

/// TIMESERIES CHART FOR SINGLE LOCATION ///
var chart = ui.Chart.image.series({
    imageCollection: correctedCollection.select('kndvi'),
    region: testPoint.geometry()
    }).setOptions({
      interpolateNulls: true,
      lineWidth: 1,
      pointSize: 3,
      title: 'KNDVI over Time at a Single Location',
      vAxis: {title: 'KNDVI'},
      hAxis: {title: 'Date', format: 'YYYY-MMM', gridlines: {count: 12}}
    })
print(chart)

1 Answer 1

0

Although there are some other strange things in your code (which I modified), apparently, the main issue is related with siac utils function. I used it with an image produced in your code and it generates same error message; as it can be observed in following picture.

enter image description here

Complete code used for generating chart without any error is presented below (for 5 arbitrary points in USA because your points variable is unavailable). So, you should explore correct use of siac utils function for this same purpose. I hope this helps.

var points = /* color: #d63000 */ee.Geometry.MultiPoint(
        [[-110.405078125, 44.25361685192184],
         [-99.94609375, 45.31406722110093],
         [-110.053515625, 36.00529263111045],
         [-96.342578125, 36.92415953072664],
         [-92.73906250000002, 41.352646664873]]);

points = ee.FeatureCollection(points);

/// IMPORTING THE FEATURE COLLECTION ///
var points = points.map(function(feature){
  var sample_id = feature.get('Sample_ID');
  return ee.Feature(feature.geometry(), {'id': feature.id()})
    .set('Sample_ID', sample_id);
});

Map.addLayer(points,{color:'green'},'Root Locations');
Map.centerObject(points,10);
print(points);

var points_list = points.toList(points.size());

var keys = points_list.map(function (ele) {

  return ee.Feature(ele).get('id');
  
});

var values = points_list.map(function (ele) {

  return ee.Feature(ele).get('Sample_ID');
  
});

var dict = ee.Dictionary.fromLists(keys, values);

/// FILTERING THE SENTINEL IMAGE COLLECTION ////
var start_date = '2010-09-01';
var end_date   = '2011-05-30';

var criteria = ee.Filter.and(
    ee.Filter.bounds(points), ee.Filter.date(start_date, end_date));
var cloud_perc = 10;//Max cloud percentile per scene.    


var L7_col = ee.ImageCollection('LANDSAT/LE07/C01/T1_TOA')
                .filter(criteria)
                .filter(ee.Filter.lt('CLOUD_COVER', cloud_perc));


// - Import the SIAC atmospheric correction module
var siac = require('users/marcyinfeng/utils:SIAC');

// - Apply SIAC and retrieve bottom of atmosphere (BOA) reflectance
var L7_boa = siac.get_l7_sur(L7_col.first());
// var L8_boa = siac.get_l8_sur(L8_col.first()); 
// var S2_boa = siac.get_sur(S2_col.first()); 


// - Check and visualization
var Color_comp_01 = {bands:"B3,B2,B1", min: 0.0, max: 0.2, gamma: 1};
var Color_comp =    {bands:"B3,B2,B1", min:200, max:2000, gamma: 1};
Map.addLayer(L7_col.first(), Color_comp, 'TOA');
Map.addLayer(L7_boa, Color_comp_01, 'BOA');
Map.centerObject(L7_col.first())

var test = L7_col.first();

var siac = require('users/marcyinfeng/utils:SIAC');

print("siac", siac.get_sur(test));

////Adding SAIC to the Collection/// 
function siac_collection(img){

  var siac = require('users/marcyinfeng/utils:SIAC');

  return img//siac.get_sur(img).copyProperties(img,['system:time_start','system:time_end']);

}

var correctedCollection = L7_col.map(siac_collection);

///// KNDVI FUNCTION //////

correctedCollection = correctedCollection.map(function (image){
  
  var RED = image.select('B4');
  var NIR = image.select('B8');
  
  /// COMPUTE D2 A RENAME TO d2 ///
  var D2 = NIR.subtract(RED).pow(2)
    .select([0],['d2']);
 
  /// GAMMA DEFINED AS 1/sigma^2
  var gamma = ee.Number(4e6).multiply(-2.0);

/// COMPUTE KERNEL (k) AND KNDVI ///

  var k = D2.divide(gamma).exp();
  var kndvi = ee.Image.constant(1)
    .subtract(k).divide(ee.Image.constant(1).add(k))
    .rename('kndvi')
    .clip(points);
    
     return image.addBands(kndvi);
 
});

var testPoint = ee.Feature(points.first());
print(testPoint);

/// TIMESERIES CHART FOR SINGLE LOCATION ///
var chart = ui.Chart.image.series({
    imageCollection: correctedCollection.select('kndvi'),
    region: testPoint.geometry()
    }).setOptions({
      interpolateNulls: true,
      lineWidth: 1,
      pointSize: 3,
      title: 'KNDVI over Time at a Single Location',
      vAxis: {title: 'KNDVI'},
      hAxis: {title: 'Date', format: 'YYYY-MMM', gridlines: {count: 12}}
    })
print(chart);
1
  • Yes, this helped, how can I add the new KNDVI band to my SIAC collection? Because when I check for the band it's not available hence the chart is showing inconsistent results.
    – Simba
    Aug 29, 2022 at 7:57

Your Answer

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

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