I am trying to download time series data of AVI using Sentinel 2 also I want to make a time series chart?

This is my code:

var batch = require('users/fitoprincipe/geetools:batch')
var avi = function(image) {
  return image.select().addBands(image.expression(
                          'NIR * ((1 - RED) * (NIR - RED))**(1/3)', {
                        'NIR': image.select('B8'),
                        'RED': image.select('B4')

// Import all available Sentinel 2 surface reflectance imagery as an ee.ImageCollection
// and filter for images within your study area
var S2_SR = ee.ImageCollection('COPERNICUS/S2_SR').filter(ee.Filter.date('2015-10-01', '2021-12-31')).select([
      // Make this list whichever bands you want to view or analyze
      'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8','B8A','B9','B11','B12'
var clippedSAR= S2_SR.map(function(im){ 
  return im.clip(geometry);
// Center your map at your study area
var visParams = {
  min: 0,
  max: 20000,
  gamma: 1.2,
  bands: ['B4', 'B8', 'B2'],

var chart = Chart.image.series(avi, geometry, ee.Reducer.mean(),1000, 'system:time_start').setOptions({
          title: 'AVI',
          vAxis: {title: 'NIR & RED'},
batch.Download.ImageCollection.toDrive(avi, 'work',
                {scale: 30,
                 region: geometry,
                 type: 'float',
                  description: 'Landsat8',
                  maxPixels: 1e13,
                  fileFormat: 'GeoTIFF',

1 Answer 1


You're missing a quite important step. You never actually have any imagery to work with, and simply pass the avi function instead of an ee.ImageCollection to the chart. The below adds a Sentinel 2 SR image collection, calculates AVI and removes clouds in each image within a date range, for some geometry. Note about the image collection from the EE data-set catalog:

WARNING: ESA did not produce L2 data for all L1 assets, and earlier L2 coverage is not global.

If you want your time-series to go further back, you might want to switch to the COPERNICUS/S2_HARMONIZED collection instead.

var avi = function(image) {
  image = image.divide(10000) // Rescale the bands from 0-10000 to 0-1, which the expression expects
  return image.select().addBands(image.expression('NIR * ((1 - RED) * (NIR - RED))**(1/3)', {
    'NIR': image.select('B8'),
    'RED': image.select('B4')

var geometry = ee.Geometry(Map.getBounds(true))
var startDate = '2019-01-01'
var endDate = '2022-04-01'

var cloudThreshold = 30
var filter = ee.Filter.and(
  ee.Filter.date(startDate, endDate)
var s2 = ee.ImageCollection(
    primary: ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED').filter(filter),
    secondary: ee.ImageCollection('COPERNICUS/S2_CLOUD_PROBABILITY').filter(filter),
    condition: ee.Filter.equals({
      leftField: 'system:index',
      rightField: 'system:index'
).map(function(image) {
  var cloudFree = ee.Image(image.get('cloudProbability')).lt(cloudThreshold)
  return image


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.