0

I'm calculating DVI over a region using MODIS. I am able to get the printout of the map properly but not the chart to retrieve the data. To calculate DVI, I did:

var dvi = img.expression(
    '(nir - red)',
    {
        red: img.select('sur_refl_b01'),    // 620-670nm, RED
        nir: img.select('sur_refl_b02'),    // 841-876nm, NIR
        blue: img.select('sur_refl_b03')    // 459-479nm, BLUE
      .rename('DVI')
    });

When I look at the inspector, I see the value for the DVI band, but the code for charting seems not to work. It says there's no system time.

var bandChart = ui.Chart.image.series(dvi, roi)

I also tried to add .filterDate ('2016-05-01', '2016-10-31') but it says the parameter is not a function. I.e.

var dvi = img.expression(
    '(nir - red)',
    {
        red: img.select('sur_refl_b01'),    // 620-670nm, RED
        nir: img.select('sur_refl_b02'),    // 841-876nm, NIR
        blue: img.select('sur_refl_b03')    // 459-479nm, BLUE
      .rename('DVI')
    });

I also tried to create a function (so as to specify timeframe) but that did not work either. How can I proceeed to get the chart?

var addDVI = function(image) {
  var dvi = img.expression(
    '(nir - red)',
    {
        red: img.select('sur_refl_b01'),    // 620-670nm, RED
        nir: img.select('sur_refl_b02'),    // 841-876nm, NIR
        blue: img.select('sur_refl_b03')    // 459-479nm, BLUE
      .rename('DVI')
      .filterDate('2016-05-01', '2016-10-31')

    });
    return image.addBands (dvi);
}; 
1
  • Please make your code reproducable by adding a link to your code. It seems like you will need a image collection instead of a single image to produce the chart.
    – Kuik
    Commented Jan 8, 2019 at 23:03

1 Answer 1

0

You need something like img.expression(...).copyProperties(img, 'system:time_start') (or use image if it's inside that function). When you do a computation on an image, the derived image does not retain the properties of the original image.

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.