1

I am trying to calculate the monthly average MNDISI for the 2020 period using Landsat data and then plot the values onto a graph (averaging all images in each month of each year separately across the full period). However, I keep getting the following error:

Line 185: mndisi.filterDate is not a function

You can see the code I am using below.

var jawa = ee.FeatureCollection("projects/ee-tugasakhirkkh/assets/Daerah_Penelitian");
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR");
Map.centerObject(jawa,7);
Map.addLayer(jawa,{},'Batas Administrasi Pulau Jawa',false);

//Define Research Time
  var start = ee.Date('2020-01-01');
  var end = ee.Date('2020-12-31');

//Time Variable
var n_days = ee.Number(end.difference(start,'day')).round();
var n_months = ee.Number(end.difference(start,'month')).round();
var n_years = ee.Number(end.difference(start,'year')).round();
print('Days = ', n_days);
print('Months = ', n_months);
print('Year = ', n_years);

//Cloud Mask
  function maskL8Clouds(image) {
    // Bits 3 and 5 are cloud shadow and cloud, respectively.
      var cloudShadowBitMask = ee.Number(2).pow(3).int();
      var cloudsBitMask = ee.Number(2).pow(5).int();  
      // Get the pixel QA band.
      var qa = image.select('pixel_qa');
      // Both flags should be set to zero, indicating clear conditions.
      var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0).and(qa.bitwiseAnd(cloudsBitMask).eq(0)); 
    // Return the masked image, scaled to [0, 1].
    return image.updateMask(mask).copyProperties(image, ["system:time_start"]);
  }
  
//Define Dataset
  //---------------Landsat 8 Dataset---------------
  var imageL8 = L8
                .filterMetadata('CLOUD_COVER','less_than',90)
                .map(maskL8Clouds)
                .filterDate(start,end)
                .filterBounds(jawa)
                .map(function(image) {
                return image.addBands(image.metadata('system:time_start'));
                })
                .mosaic()
                .clip(jawa);
                  
//LST Function Indices
  //Calculate NDVI (ndvi)
    {
    var ndvi = imageL8.normalizedDifference(['B5', 'B4']).rename('NDVI');
    var ndviParams = {min: -1, max: 1, palette: ['yellow', 'green', 'cyan', 'blue']};
    Map.addLayer(ndvi,ndviParams, 'NDVI',false);
    }
    
  //Select Band 10 as Brightness Temperature (BT)
    {
    var BT= imageL8.select('B10').multiply(0.1).rename('BT');
    print('Brightness Temperature',BT)
    }
    
  // Find Min and Max NDVI
    {
    var min_ndvi = ee.Number(ndvi.reduceRegion({
    reducer: ee.Reducer.min(),
    geometry: jawa,
    scale: 30,
    maxPixels: 1e9
    }).values().get(0));
    print('NDVI Min', min_ndvi);
    
    var max_ndvi = ee.Number(ndvi.reduceRegion({
    reducer: ee.Reducer.max(),
    geometry: jawa,
    scale: 30,
    maxPixels: 1e9
    }).values().get(0));
    print('NDVI Max', max_ndvi)
    }

  //Calculate the Proportion of Vegetation (pv)
    {
    var pv =(ndvi.subtract(min_ndvi).divide(max_ndvi.subtract(min_ndvi))).pow(ee.Number(2)).rename('PV'); 
    print('Proportion of Vegetation', pv);
    }
  
  //Calculate Emissivity (E)
    {
      var a = (0.004);
      var b = (0.986);
      var E = pv.multiply(a).add(b).rename('E');
      print('Emissivity',E);
    }
    
  //Calculate LST (lst)
  {
    var lst = imageL8.expression(
              '(Tb/(1 + (0.00115* (Tb / 1.438))*log(Ep)))-273.15',
              {'Tb': BT.select('BT'),
               'Ep': E.select('E')
              }).rename('LST');
    var lst_param = {min:20, max:40, palette:['040274', '040281', '0502a3', '0502b8', '0502ce', '0502e6',
                    '0602ff', '235cb1', '307ef3', '269db1', '30c8e2', '32d3ef',
                    '3be285', '3ff38f', '86e26f', '3ae237', 'b5e22e', 'd6e21f',
                    'fff705', 'ffd611', 'ffb613', 'ff8b13', 'ff6e08', 'ff500d',
                    'ff0000', 'de0101', 'c21301', 'a71001', '911003']};
    Map.addLayer(lst,lst_param,'LST Mean Tahunan', false);
  }

//MNDWI Function Indices
  //Calculate MNDWI
  {
    var mndwi = imageL8.expression(
                '(Green - SWIR)/(Green + SWIR)',
                   {'Green': imageL8.select('B3'),
                    'SWIR': imageL8.select('B6')
                   }).rename('MNDWI');
    var mndwiParams = {min: -1, max: 1, palette: ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301']};
    Map.addLayer(mndwi,mndwiParams, 'MNDWI',false);      
  }
  
//MNDISI Function Indices
  //Calculate MNDISI
  {
    var mndisi = imageL8.expression(
                '(LST - ((MNDWI + NIR + SWIR)/3))/(LST + ((MNDWI + NIR + SWIR)/3))',
                   {'LST': lst.select('LST'),
                    'MNDWI': mndwi.select('MNDWI'),
                    'NIR' : imageL8.select('B5'),
                    'SWIR': imageL8.select('B6')
                   }).rename('MNDISI');
    var mndisiParams = {min: -1, max: 1, palette: ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301']};
    Map.addLayer(mndisi,mndisiParams, 'MNDISI');
  }

//Create Legend
  //CreatePalette
function makeColorBarParams(palette) {
  return {
    bbox: [0, 0, 1, 0.1],
    dimensions: '200x20',
    format: 'png',
    min: 0,
    max: 1,
    palette: palette,
  };
}

//Create ColorBar
var colorBar = ui.Thumbnail({
  image: ee.Image.pixelLonLat().select(0),
  params: makeColorBarParams(mndisiParams.palette),
  style: {stretch: 'vertical', margin: '0px 8px', maxHeight: '24px'},
});

//Create Panels
var legendLabels = ui.Panel({
  widgets: [
    ui.Label(mndisiParams.min, {margin: '4px 5px', textAlign: 'left'}),
    ui.Label(mndisiParams.max, {margin: '4px 170px', textAlign: 'right'})
  ],
  layout: ui.Panel.Layout.flow('horizontal')
});

var legendTitle = ui.Label({
  value: 'Average MNDISI',
  style: {fontWeight: 'bold'}
});

//Show Legend
var legendPanel = ui.Panel([legendTitle, colorBar, legendLabels]);
Map.add(legendPanel);

//Time Variable
var n_days = ee.Number(end.difference(start,'day')).round();
var n_months = ee.Number(end.difference(start,'month')).round();
var n_years = ee.Number(end.difference(start,'year')).round();
print('Days = ', n_days);
print('Months = ', n_months);
print('Year = ', n_years);

//Create Monthly Plotting Chart Terra
var months = ee.ImageCollection(
  ee.List.sequence(0,n_months).map(function(n){
    var start_month = start.advance(n,'months');
    var end_month = start_month.advance(1,'month');
    return mndisi.filterDate(start_month,end_month)
                     .select(0).mean()
                     .set('system:time_start', start_month);
  }));
  
var terra_month_2020 = ui.Chart.image.series({
  imageCollection: months,
  region:jawa,
  scale:1000,
  xProperty:'system:time_start'})
  .setOptions({
    title:'Average Monthly MNDISI in 2020',
    vAxis:{title:'MNDISI'},
    hAxis:{title:'Months'}
  });
print(terra_month_2020,'MNDISI');

From checking the GEE script, I assumed this was a minor issue and have fixed those issues, so I am not sure why the code is still failing.

1
  • Your property 'mndisi' is an image, not an imageCollection; it's calculated using .expression(), which returns an image. Only the latter you can filter by date using .filterDate().
    – hooge048
    Jan 4, 2022 at 13:12

1 Answer 1

0

Error is produced because mndisi is an image and you are using 'filterDate' for Image Collections. Your code works with this modification.

//Create Monthly Plotting Chart Terra
var months = ee.ImageCollection(
  ee.List.sequence(0,n_months).map(function(n){
    var start_month = start.advance(n,'months');
    var end_month = start_month.advance(1,'month');
    return mndisi//.filterDate(start_month,end_month)
                     .select('MNDISI')
                     .set('system:time_start', start_month);
  }));

However, running it in GEE code editor produces following (probably) unexpected result for you. You need to fix other things in your code.

enter image description here

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.