2

I have code that generates NDVI times series chart. The values are with 3 decimal places. I want to increase the decimal places to 4 or 5. Is there a way of doing that?

My code:

// Load raster data (COPERNICUS/S2_SR).
// Load vector data (shapefile).
var fc = ee.FeatureCollection(user_account+folder+shpfile_name).sort('Group');
var S2 = ee.ImageCollection(image_collection)
        .filterDate(first_date, last_date)
        .filterBounds(fc)
        .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 18);

//-----------------------------------------------------------------------------------
print(S2)
print(fc)           // CRS must be WGS84 (for the shapefile)          

//-----------------------------------------------------------------------------------
//Image Expression for calculating NDVI----------------------------------------------
var band_1 = 'B4'
var band_2 = 'B8'

var addNDVI = function(image) {
  var NDVI = image.expression(
  '(B8-B4)/(B8+B4)',
  {
    'B4': image.select('B4'),
    'B8': image.select('B8'),

  }).rename('NDVI');
  //NDVI index
  return image.addBands(NDVI.add(ee.Image(0.0)));
  //Add 0.0 value to NDVI (currently not in use)
};

// Calculate NDVIfor images in the Image collection 
var S2_withNDVI = ee.ImageCollection(S2).map(addNDVI);          
print(S2_withNDVI)

//Export NDVI Time Series into a Scatter Chart and a CSV format              
TimeSeries = Chart.image.seriesByRegion(
S2_withNDVI, fc, ee.Reducer.mean(), 'NDVI', 3, 'system:time_start', fc_ID)
    .setChartType('ScatterChart')
    .setOptions({
      title: 'NDVI Time Series For '+ Name,
      vAxis: {title: 'NDVI', format: 'Decimal'},
      hAxis: {title: 'Date'},
      lineWidth: 1,
      pointSize: 4,
      series: {
}});
/ Display.
print(TimeSeries); 
// Compute 3X3 standard deviation kernel (SD) as texture of the NDVI.
var addTexture_3X3_stdDev = function(image) {
var texture = image.select('NDVI').reduceNeighborhood({
reducer: ee.Reducer.stdDev(),
kernel: ee.Kernel.square(1),
}).rename('NDVI_3X3_stdDev')
return image.addBands(texture.add(ee.Image(0.0)));
};
var S2_Analysis = ee.ImageCollection(S2_withNDVI).map(addTexture_3X3_stdDev);
print(S2_Analysis)

//Export 3X3 kernel NDVI stdDev Time Series into a Scatter Chart and a CSV format              
var TimeSeries = Chart.image.seriesByRegion(
S2_Analysis, fc, ee.Reducer.mean(), 'NDVI_3X3_stdDev', 3, 'system:time_start', fc_ID)
    .setChartType('Table')
    .setOptions({
      title: 'NDVI 3X3 stdDev kernel Time Series For Corn Field'+ Name,
      vAxis: {title: 'stdDev', format: 'Decimal'},
      hAxis: {title: 'Date'},
      lineWidth: 1,
      pointSize: 4,
      series: {
}});
// Display.
print(TimeSeries);

1 Answer 1

1

You can specify with a format pattern. ie: add "format: '0.00000'" to the axis block you want to use it in.

2

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.